-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathplatform.js
132 lines (118 loc) · 2.72 KB
/
platform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* @fileoverview I2P Platform Detection Manager
* Handles platform detection and feature support for Firefox WebExtensions
*/
// Platform configuration constants
const PLATFORM_CONFIG = {
PLATFORMS: {
ANDROID: "android",
DESKTOP: "desktop",
},
FEATURES: {
CLOSABLE: "closable",
CONTAINER_TABS: "containerTabs",
SIDEBAR: "sidebar",
},
};
/**
* Platform Manager for handling platform-specific functionality
*/
class PlatformManager {
constructor() {
// Platform state
this.platformState = {
isAndroid: false,
isInitialized: false,
};
// Initialize platform detection
this.initialize();
}
/**
* Initialize platform detection
* @private
* @return {Promise<void>}
*/
async initialize() {
try {
const platformInfo = await browser.runtime.getPlatformInfo();
this.platformState.isAndroid =
platformInfo.os === PLATFORM_CONFIG.PLATFORMS.ANDROID;
this.platformState.isInitialized = true;
console.info(
`(platform) Running in ${
this.platformState.isAndroid ? "Android" : "Desktop"
} detected`
);
} catch (error) {
console.error("Platform detection failed:", error);
this.platformState.isAndroid = false;
this.platformState.isInitialized = true;
}
}
/**
* Check if running on Android
* @return {boolean}
*/
isAndroid() {
if (!this.platformState.isInitialized) {
console.warn("Platform detection not yet initialized");
return false;
}
return this.platformState.isAndroid;
}
/**
* Check if running on Desktop
* @return {boolean}
*/
isDesktop() {
return !this.isAndroid();
}
/**
* Check if windows are closable
* @return {boolean}
*/
isClosable() {
return this.isDesktop();
}
/**
* Get current platform state
* @return {Object}
*/
getPlatformState() {
return { ...this.platformState };
}
}
// Create singleton instance
const platformManager = new PlatformManager();
/**
* Legacy API compatibility layer
*/
const PlatformAPI = {
/**
* Check if running on Android (legacy support)
* @return {boolean}
*/
isDroid() {
const isAndroid = platformManager.isAndroid();
console.log("(platform) android?", isAndroid);
return isAndroid;
},
/**
* Check if windows are not closable (legacy support)
* @return {boolean}
*/
notClosable() {
return !platformManager.isClosable();
},
};
// Export legacy API functions to window
window.isDroid = PlatformAPI.isDroid;
window.notClosable = PlatformAPI.notClosable;
// Export for testing
if (typeof module !== "undefined" && module.exports) {
module.exports = {
platformManager,
PLATFORM_CONFIG,
PlatformAPI,
};
}