@flighthq/device 0.5.0-next.1944.cd6b6e7 → 0.5.1-edge.1047.858b9b6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -0
- package/dist/contract.js.map +1 -1
- package/dist/device.d.ts +11 -15
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +78 -358
- package/dist/device.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/device.test.ts +65 -238
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/device`. The `@fligh
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/device@0.5.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/device@0.5.1-edge.1047.858b9b6](https://github.com/flighthq/flight/tree/858b9b601de814f6b6940cbb1ffff0916b903268/packages/device)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/858b9b601de814f6b6940cbb1ffff0916b903268/LICENSE.md)
|
package/dist/contract.d.ts
CHANGED
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,UAAU,CAAC"}
|
package/dist/contract.js
CHANGED
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,UAAU,CAAC"}
|
package/dist/device.d.ts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DeviceCapabilities, DeviceDisplayMetrics, DeviceInfo, EntityConstruction, HasSystemDevice, SafeAreaInsets } from '@flighthq/types/contract';
|
|
2
2
|
export declare function createDeviceCapabilities(): DeviceCapabilities;
|
|
3
3
|
export declare function createDeviceDisplayMetrics(): DeviceDisplayMetrics;
|
|
4
4
|
export declare function createDeviceInfo(): DeviceInfo;
|
|
5
5
|
export declare function createSafeAreaInsets(): SafeAreaInsets;
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function observeDeviceHostResult(operation: string, succeeded: boolean): void;
|
|
17
|
-
export declare function refreshDeviceInfo(): void;
|
|
18
|
-
export declare function resetDeviceBackendForTest(): void;
|
|
19
|
-
export declare function setDeviceBackend(backend: DeviceBackend | null): void;
|
|
6
|
+
export declare function getDeviceCapabilities(host: HasSystemDevice, out: DeviceCapabilities): DeviceCapabilities;
|
|
7
|
+
export declare function getDeviceDisplayMetrics(host: HasSystemDevice, out: DeviceDisplayMetrics): DeviceDisplayMetrics;
|
|
8
|
+
export declare function getDeviceId(host: HasSystemDevice): string;
|
|
9
|
+
export declare function getDeviceInfo(host: HasSystemDevice, out: DeviceInfo): DeviceInfo;
|
|
10
|
+
export declare function getSafeAreaInsets(host: HasSystemDevice, out: SafeAreaInsets): SafeAreaInsets;
|
|
11
|
+
export declare function initializeDeviceCapabilities(out: EntityConstruction<DeviceCapabilities>): void;
|
|
12
|
+
export declare function initializeDeviceDisplayMetrics(out: EntityConstruction<DeviceDisplayMetrics>): void;
|
|
13
|
+
export declare function initializeDeviceInfo(out: EntityConstruction<DeviceInfo>): void;
|
|
14
|
+
export declare function initializeSafeAreaInsets(out: EntityConstruction<SafeAreaInsets>): void;
|
|
15
|
+
export declare function refreshDeviceInfo(host: HasSystemDevice): void;
|
|
20
16
|
//# sourceMappingURL=device.d.ts.map
|
package/dist/device.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,0BAA0B,CAAC;AAGlC,wBAAgB,wBAAwB,IAAI,kBAAkB,CAI7D;AAED,wBAAgB,0BAA0B,IAAI,oBAAoB,CAIjE;AAED,wBAAgB,gBAAgB,IAAI,UAAU,CAI7C;AAED,wBAAgB,oBAAoB,IAAI,cAAc,CAIrD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,kBAAkB,GAAG,kBAAkB,CAExG;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,oBAAoB,GAAG,oBAAoB,CAE9G;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAEzD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,GAAG,UAAU,CAEhF;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,GAAG,cAAc,CAE5F;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAI9F;AAED,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAQlG;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,kBAAkB,CAAC,UAAU,CAAC,GAAG,IAAI,CA0B9E;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,kBAAkB,CAAC,cAAc,CAAC,GAAG,IAAI,CAKtF;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAE7D"}
|
package/dist/device.js
CHANGED
|
@@ -1,368 +1,88 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { DeviceFormFactorUnknown } from '@flighthq/types/contract';
|
|
2
|
-
import { parseUserAgentArch, parseUserAgentFormFactor, parseUserAgentOsName, parseUserAgentOsVersion, } from '@flighthq/useragent/contract';
|
|
3
3
|
export function createDeviceCapabilities() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
hasStylus: false,
|
|
8
|
-
};
|
|
4
|
+
const out = allocateEntity();
|
|
5
|
+
initializeDeviceCapabilities(out);
|
|
6
|
+
return finishEntity(out);
|
|
9
7
|
}
|
|
10
8
|
export function createDeviceDisplayMetrics() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
logicalHeight: -1,
|
|
15
|
-
logicalWidth: -1,
|
|
16
|
-
physicalHeight: -1,
|
|
17
|
-
physicalWidth: -1,
|
|
18
|
-
pixelRatio: -1,
|
|
19
|
-
};
|
|
9
|
+
const out = allocateEntity();
|
|
10
|
+
initializeDeviceDisplayMetrics(out);
|
|
11
|
+
return finishEntity(out);
|
|
20
12
|
}
|
|
21
13
|
export function createDeviceInfo() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
boardName: '',
|
|
26
|
-
colorGamut: '',
|
|
27
|
-
cpuCores: -1,
|
|
28
|
-
fontScale: -1,
|
|
29
|
-
formFactor: DeviceFormFactorUnknown,
|
|
30
|
-
gpuRenderer: '',
|
|
31
|
-
gpuVendor: '',
|
|
32
|
-
isHdr: false,
|
|
33
|
-
isJailbroken: false,
|
|
34
|
-
isLowEndDevice: false,
|
|
35
|
-
isRooted: false,
|
|
36
|
-
isVirtual: false,
|
|
37
|
-
manufacturer: '',
|
|
38
|
-
marketingName: '',
|
|
39
|
-
model: '',
|
|
40
|
-
osBuild: '',
|
|
41
|
-
osName: '',
|
|
42
|
-
osVersion: '',
|
|
43
|
-
platformString: '',
|
|
44
|
-
productName: '',
|
|
45
|
-
supportedAbis: [],
|
|
46
|
-
totalMemory: -1,
|
|
47
|
-
webViewVersion: '',
|
|
48
|
-
};
|
|
14
|
+
const out = allocateEntity();
|
|
15
|
+
initializeDeviceInfo(out);
|
|
16
|
+
return finishEntity(out);
|
|
49
17
|
}
|
|
50
18
|
export function createSafeAreaInsets() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export function
|
|
56
|
-
return
|
|
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
|
-
out.fontScale = -1;
|
|
120
|
-
out.formFactor = parseUserAgentFormFactor(ua, nav !== null && 'maxTouchPoints' in nav ? nav.maxTouchPoints : -1);
|
|
121
|
-
const gpuInfo = readWebGpuInfo();
|
|
122
|
-
out.gpuRenderer = gpuInfo.renderer;
|
|
123
|
-
out.gpuVendor = gpuInfo.vendor;
|
|
124
|
-
out.isHdr = detectHdr();
|
|
125
|
-
// isJailbroken and isRooted are always false on web — no detection available.
|
|
126
|
-
out.isJailbroken = false;
|
|
127
|
-
const devMem = nav !== null && 'deviceMemory' in nav ? (nav.deviceMemory ?? -1) : -1;
|
|
128
|
-
out.isLowEndDevice = detectLowEndDevice(devMem, cores);
|
|
129
|
-
out.isRooted = false;
|
|
130
|
-
out.isVirtual = false;
|
|
131
|
-
out.manufacturer = '';
|
|
132
|
-
out.marketingName = '';
|
|
133
|
-
out.model = '';
|
|
134
|
-
out.osBuild = '';
|
|
135
|
-
out.osName = parseUserAgentOsName(ua);
|
|
136
|
-
out.osVersion = parseUserAgentOsVersion(ua);
|
|
137
|
-
out.platformString = ua;
|
|
138
|
-
out.productName = '';
|
|
139
|
-
out.supportedAbis = [];
|
|
140
|
-
// totalMemory: navigator.deviceMemory is in GiB; convert to bytes. -1 when absent.
|
|
141
|
-
out.totalMemory = devMem >= 0 ? devMem * 1024 * 1024 * 1024 : -1;
|
|
142
|
-
// webViewVersion is not exposed by browsers (we are the browser).
|
|
143
|
-
out.webViewVersion = '';
|
|
144
|
-
return out;
|
|
145
|
-
},
|
|
146
|
-
getSafeAreaInsets(out) {
|
|
147
|
-
// Reading CSS env(safe-area-inset-*) requires a probe element in the DOM. The web backend
|
|
148
|
-
// returns zero insets by default. Call enableWebSafeAreaInsets() to mount a live CSS-var probe
|
|
149
|
-
// that updates this when the device reports real insets (notched PWAs).
|
|
150
|
-
const insets = _safeAreaInsets;
|
|
151
|
-
if (insets !== null) {
|
|
152
|
-
out.bottom = insets.bottom;
|
|
153
|
-
out.left = insets.left;
|
|
154
|
-
out.right = insets.right;
|
|
155
|
-
out.top = insets.top;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
out.bottom = 0;
|
|
159
|
-
out.left = 0;
|
|
160
|
-
out.right = 0;
|
|
161
|
-
out.top = 0;
|
|
162
|
-
}
|
|
163
|
-
return out;
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
export function enableWebSafeAreaInsets() {
|
|
168
|
-
if (typeof document === 'undefined')
|
|
169
|
-
return () => { };
|
|
170
|
-
const el = document.createElement('div');
|
|
171
|
-
el.style.cssText =
|
|
172
|
-
'position:fixed;top:env(safe-area-inset-top,0px);right:env(safe-area-inset-right,0px);' +
|
|
173
|
-
'bottom:env(safe-area-inset-bottom,0px);left:env(safe-area-inset-left,0px);' +
|
|
174
|
-
'pointer-events:none;visibility:hidden;';
|
|
175
|
-
document.body.appendChild(el);
|
|
176
|
-
function readInsets() {
|
|
177
|
-
const style = getComputedStyle(el);
|
|
178
|
-
_safeAreaInsets = {
|
|
179
|
-
bottom: parseFloat(style.bottom) || 0,
|
|
180
|
-
left: parseFloat(style.left) || 0,
|
|
181
|
-
right: parseFloat(style.right) || 0,
|
|
182
|
-
top: parseFloat(style.top) || 0,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
readInsets();
|
|
186
|
-
const observer = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(readInsets) : null;
|
|
187
|
-
if (observer !== null)
|
|
188
|
-
observer.observe(document.documentElement);
|
|
189
|
-
return () => {
|
|
190
|
-
if (observer !== null)
|
|
191
|
-
observer.disconnect();
|
|
192
|
-
el.parentNode?.removeChild(el);
|
|
193
|
-
_safeAreaInsets = null;
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
export function explainDeviceBackend() {
|
|
197
|
-
if (_custom !== null) {
|
|
198
|
-
return { conflict: _hostConflict, layer: 'custom', operation: null, viability: 'unobserved' };
|
|
199
|
-
}
|
|
200
|
-
if (_host !== null) {
|
|
201
|
-
return {
|
|
202
|
-
conflict: _hostConflict,
|
|
203
|
-
layer: 'host',
|
|
204
|
-
operation: _hostObservation !== null ? _hostObservation.operation : null,
|
|
205
|
-
viability: _hostObservation !== null ? _hostObservation.viability : 'unobserved',
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
return { conflict: false, layer: 'host-not-enabled', operation: null, viability: 'unobserved' };
|
|
209
|
-
}
|
|
210
|
-
export function getDeviceBackend() {
|
|
211
|
-
return _custom ?? _host ?? _sentinel;
|
|
212
|
-
}
|
|
213
|
-
export function getDeviceCapabilities(out) {
|
|
214
|
-
return getDeviceBackend().getCapabilities(out);
|
|
215
|
-
}
|
|
216
|
-
export function getDeviceDisplayMetrics(out) {
|
|
217
|
-
return getDeviceBackend().getDisplayMetrics(out);
|
|
218
|
-
}
|
|
219
|
-
export function getDeviceId() {
|
|
220
|
-
return getDeviceBackend().getId();
|
|
221
|
-
}
|
|
222
|
-
export function getDeviceInfo(out) {
|
|
223
|
-
return getDeviceBackend().getInfo(out);
|
|
224
|
-
}
|
|
225
|
-
export function getSafeAreaInsets(out) {
|
|
226
|
-
return getDeviceBackend().getSafeAreaInsets(out);
|
|
227
|
-
}
|
|
228
|
-
export function installDeviceHostBackend(backend) {
|
|
229
|
-
if (_host !== null) {
|
|
230
|
-
if (_host !== backend)
|
|
231
|
-
_hostConflict = true;
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
_host = backend;
|
|
235
|
-
}
|
|
236
|
-
export function observeDeviceHostResult(operation, succeeded) {
|
|
237
|
-
_hostObservation = {
|
|
238
|
-
operation,
|
|
239
|
-
viability: succeeded ? 'available' : 'runtime-api-unavailable',
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
export function refreshDeviceInfo() {
|
|
243
|
-
const backend = getDeviceBackend();
|
|
244
|
-
const maybeRefreshable = backend;
|
|
245
|
-
if (typeof maybeRefreshable.refresh === 'function') {
|
|
246
|
-
maybeRefreshable.refresh();
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
export function resetDeviceBackendForTest() {
|
|
250
|
-
_custom = null;
|
|
251
|
-
_host = null;
|
|
252
|
-
_hostConflict = false;
|
|
253
|
-
_hostObservation = null;
|
|
254
|
-
}
|
|
255
|
-
export function setDeviceBackend(backend) {
|
|
256
|
-
_custom = backend;
|
|
257
|
-
}
|
|
258
|
-
const _sentinel = {
|
|
259
|
-
getCapabilities(out) {
|
|
260
|
-
out.hasKeyboard = false;
|
|
261
|
-
out.hasMouse = false;
|
|
262
|
-
out.hasStylus = false;
|
|
263
|
-
return out;
|
|
264
|
-
},
|
|
265
|
-
getDisplayMetrics(out) {
|
|
266
|
-
out.colorDepth = -1;
|
|
267
|
-
out.densityDpi = -1;
|
|
268
|
-
out.logicalHeight = -1;
|
|
269
|
-
out.logicalWidth = -1;
|
|
270
|
-
out.physicalHeight = -1;
|
|
271
|
-
out.physicalWidth = -1;
|
|
272
|
-
out.pixelRatio = -1;
|
|
273
|
-
return out;
|
|
274
|
-
},
|
|
275
|
-
getId() {
|
|
276
|
-
return '';
|
|
277
|
-
},
|
|
278
|
-
getInfo(out) {
|
|
279
|
-
out.arch = '';
|
|
280
|
-
out.availableMemory = -1;
|
|
281
|
-
out.boardName = '';
|
|
282
|
-
out.colorGamut = '';
|
|
283
|
-
out.cpuCores = -1;
|
|
284
|
-
out.fontScale = -1;
|
|
285
|
-
out.formFactor = DeviceFormFactorUnknown;
|
|
286
|
-
out.gpuRenderer = '';
|
|
287
|
-
out.gpuVendor = '';
|
|
288
|
-
out.isHdr = false;
|
|
289
|
-
out.isJailbroken = false;
|
|
290
|
-
out.isLowEndDevice = false;
|
|
291
|
-
out.isRooted = false;
|
|
292
|
-
out.isVirtual = false;
|
|
293
|
-
out.manufacturer = '';
|
|
294
|
-
out.marketingName = '';
|
|
295
|
-
out.model = '';
|
|
296
|
-
out.osBuild = '';
|
|
297
|
-
out.osName = '';
|
|
298
|
-
out.osVersion = '';
|
|
299
|
-
out.platformString = '';
|
|
300
|
-
out.productName = '';
|
|
301
|
-
out.supportedAbis = [];
|
|
302
|
-
out.totalMemory = -1;
|
|
303
|
-
out.webViewVersion = '';
|
|
304
|
-
return out;
|
|
305
|
-
},
|
|
306
|
-
getSafeAreaInsets(out) {
|
|
307
|
-
out.bottom = 0;
|
|
308
|
-
out.left = 0;
|
|
309
|
-
out.right = 0;
|
|
310
|
-
out.top = 0;
|
|
311
|
-
return out;
|
|
312
|
-
},
|
|
313
|
-
};
|
|
314
|
-
let _custom = null;
|
|
315
|
-
let _host = null;
|
|
316
|
-
let _hostConflict = false;
|
|
317
|
-
let _hostObservation = null;
|
|
318
|
-
let _safeAreaInsets = null;
|
|
319
|
-
function detectColorGamut() {
|
|
320
|
-
if (typeof matchMedia === 'undefined')
|
|
321
|
-
return '';
|
|
322
|
-
if (matchMedia('(color-gamut: rec2020)').matches)
|
|
323
|
-
return 'rec2020';
|
|
324
|
-
if (matchMedia('(color-gamut: p3)').matches)
|
|
325
|
-
return 'p3';
|
|
326
|
-
if (matchMedia('(color-gamut: srgb)').matches)
|
|
327
|
-
return 'srgb';
|
|
328
|
-
return '';
|
|
329
|
-
}
|
|
330
|
-
function detectDesktopUa(ua) {
|
|
331
|
-
return /win(?:dows)?nt|macintosh|mac os x|linux(?!.*android)|cros|x11/i.test(ua);
|
|
332
|
-
}
|
|
333
|
-
function detectHdr() {
|
|
334
|
-
if (typeof matchMedia === 'undefined')
|
|
335
|
-
return false;
|
|
336
|
-
return matchMedia('(dynamic-range: high)').matches;
|
|
337
|
-
}
|
|
338
|
-
function detectLowEndDevice(deviceMemoryGib, cores) {
|
|
339
|
-
// Low-end heuristic: <= 1 GiB RAM or <= 2 cores. Both sentinels (-1) = unknown = false.
|
|
340
|
-
if (deviceMemoryGib > 0 && deviceMemoryGib <= 1)
|
|
341
|
-
return true;
|
|
342
|
-
if (cores > 0 && cores <= 2)
|
|
343
|
-
return true;
|
|
344
|
-
return false;
|
|
345
|
-
}
|
|
346
|
-
function readWebGpuInfo() {
|
|
347
|
-
// Reads WEBGL_debug_renderer_info from a transient WebGL context. Returns '' when unavailable or
|
|
348
|
-
// blocked by browser privacy budget. This is best-effort — modern browsers may mask or randomize.
|
|
349
|
-
try {
|
|
350
|
-
if (typeof document === 'undefined')
|
|
351
|
-
return { renderer: '', vendor: '' };
|
|
352
|
-
const canvas = document.createElement('canvas');
|
|
353
|
-
const gl = canvas.getContext('webgl') ??
|
|
354
|
-
canvas.getContext('experimental-webgl');
|
|
355
|
-
if (gl === null)
|
|
356
|
-
return { renderer: '', vendor: '' };
|
|
357
|
-
const ext = gl.getExtension('WEBGL_debug_renderer_info');
|
|
358
|
-
if (ext === null)
|
|
359
|
-
return { renderer: '', vendor: '' };
|
|
360
|
-
const vendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL) ?? '';
|
|
361
|
-
const renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL) ?? '';
|
|
362
|
-
return { renderer, vendor };
|
|
363
|
-
}
|
|
364
|
-
catch {
|
|
365
|
-
return { renderer: '', vendor: '' };
|
|
366
|
-
}
|
|
19
|
+
const out = allocateEntity();
|
|
20
|
+
initializeSafeAreaInsets(out);
|
|
21
|
+
return finishEntity(out);
|
|
22
|
+
}
|
|
23
|
+
export function getDeviceCapabilities(host, out) {
|
|
24
|
+
return host.system.device.getCapabilities(out);
|
|
25
|
+
}
|
|
26
|
+
export function getDeviceDisplayMetrics(host, out) {
|
|
27
|
+
return host.system.device.getDisplayMetrics(out);
|
|
28
|
+
}
|
|
29
|
+
export function getDeviceId(host) {
|
|
30
|
+
return host.system.device.getId();
|
|
31
|
+
}
|
|
32
|
+
export function getDeviceInfo(host, out) {
|
|
33
|
+
return host.system.device.getInfo(out);
|
|
34
|
+
}
|
|
35
|
+
export function getSafeAreaInsets(host, out) {
|
|
36
|
+
return host.system.device.getSafeAreaInsets(out);
|
|
37
|
+
}
|
|
38
|
+
export function initializeDeviceCapabilities(out) {
|
|
39
|
+
out.hasKeyboard = false;
|
|
40
|
+
out.hasMouse = false;
|
|
41
|
+
out.hasStylus = false;
|
|
42
|
+
}
|
|
43
|
+
export function initializeDeviceDisplayMetrics(out) {
|
|
44
|
+
out.colorDepth = -1;
|
|
45
|
+
out.densityDpi = -1;
|
|
46
|
+
out.logicalHeight = -1;
|
|
47
|
+
out.logicalWidth = -1;
|
|
48
|
+
out.physicalHeight = -1;
|
|
49
|
+
out.physicalWidth = -1;
|
|
50
|
+
out.pixelRatio = -1;
|
|
51
|
+
}
|
|
52
|
+
export function initializeDeviceInfo(out) {
|
|
53
|
+
out.arch = '';
|
|
54
|
+
out.availableMemory = -1;
|
|
55
|
+
out.boardName = '';
|
|
56
|
+
out.colorGamut = '';
|
|
57
|
+
out.cpuCores = -1;
|
|
58
|
+
out.fontScale = -1;
|
|
59
|
+
out.formFactor = DeviceFormFactorUnknown;
|
|
60
|
+
out.gpuRenderer = '';
|
|
61
|
+
out.gpuVendor = '';
|
|
62
|
+
out.isHdr = false;
|
|
63
|
+
out.isJailbroken = false;
|
|
64
|
+
out.isLowEndDevice = false;
|
|
65
|
+
out.isRooted = false;
|
|
66
|
+
out.isVirtual = false;
|
|
67
|
+
out.manufacturer = '';
|
|
68
|
+
out.marketingName = '';
|
|
69
|
+
out.model = '';
|
|
70
|
+
out.osBuild = '';
|
|
71
|
+
out.osName = '';
|
|
72
|
+
out.osVersion = '';
|
|
73
|
+
out.platformString = '';
|
|
74
|
+
out.productName = '';
|
|
75
|
+
out.supportedAbis = [];
|
|
76
|
+
out.totalMemory = -1;
|
|
77
|
+
out.webViewVersion = '';
|
|
78
|
+
}
|
|
79
|
+
export function initializeSafeAreaInsets(out) {
|
|
80
|
+
out.bottom = 0;
|
|
81
|
+
out.left = 0;
|
|
82
|
+
out.right = 0;
|
|
83
|
+
out.top = 0;
|
|
84
|
+
}
|
|
85
|
+
export function refreshDeviceInfo(host) {
|
|
86
|
+
host.system.device.refresh?.();
|
|
367
87
|
}
|
|
368
88
|
//# sourceMappingURL=device.js.map
|
package/dist/device.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,KAAK;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO;QACL,UAAU,EAAE,CAAC,CAAC;QACd,UAAU,EAAE,CAAC,CAAC;QACd,aAAa,EAAE,CAAC,CAAC;QACjB,YAAY,EAAE,CAAC,CAAC;QAChB,cAAc,EAAE,CAAC,CAAC;QAClB,aAAa,EAAE,CAAC,CAAC;QACjB,UAAU,EAAE,CAAC,CAAC;KACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,IAAI,EAAE,EAAE;QACR,eAAe,EAAE,CAAC,CAAC;QACnB,SAAS,EAAE,EAAE;QACb,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AS,GAAG,EAAE,CAAC;IACnB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;IAClB,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC;IACzB,GAAG,CAAC,cAAc,GAAG,KAAK,CAAC;IAC3B,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;IACrB,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC;IACtB,GAAG,CAAC,YAAY,GAAG,EAAE,CAAC;IACtB,GAAG,CAAC,aAAa,GAAG,EAAE,CAAC;IACvB,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;IACf,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC;IACjB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;IAChB,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC;IACnB,GAAG,CAAC,cAAc,GAAG,EAAE,CAAC;IACxB,GAAG,CAAC,WAAW,GAAG,EAAE,CAAC;IACrB,GAAG,CAAC,aAAa,GAAG,EAAE,CAAC;IACvB,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;IACrB,GAAG,CAAC,cAAc,GAAG,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,GAAuC;IAC9E,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;IACf,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;IACb,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC;IACd,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAqB;IACrD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;AACjC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createDeviceCapabilities, createDeviceDisplayMetrics, createDeviceInfo, createSafeAreaInsets, getDeviceCapabilities, getDeviceDisplayMetrics, getDeviceId, getDeviceInfo, getSafeAreaInsets, refreshDeviceInfo, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createDeviceCapabilities, createDeviceDisplayMetrics, createDeviceInfo, createSafeAreaInsets, getDeviceCapabilities, getDeviceDisplayMetrics, getDeviceId, getDeviceInfo, getSafeAreaInsets, refreshDeviceInfo, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/device",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1-edge.1047.858b9b6",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,8 +38,9 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/
|
|
42
|
-
"@flighthq/
|
|
41
|
+
"@flighthq/entity": "0.5.1-edge.1047.858b9b6",
|
|
42
|
+
"@flighthq/types": "0.5.1-edge.1047.858b9b6",
|
|
43
|
+
"@flighthq/useragent": "0.5.1-edge.1047.858b9b6"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"typescript": "^5.3.0"
|
package/src/device.test.ts
CHANGED
|
@@ -3,33 +3,32 @@ import type {
|
|
|
3
3
|
DeviceCapabilities,
|
|
4
4
|
DeviceDisplayMetrics,
|
|
5
5
|
DeviceInfo,
|
|
6
|
+
HasSystemDevice,
|
|
6
7
|
SafeAreaInsets,
|
|
7
8
|
} from '@flighthq/types/contract';
|
|
8
|
-
import {
|
|
9
|
+
import { DeviceFormFactorUnknown, EntityRuntimeKey } from '@flighthq/types/contract';
|
|
9
10
|
|
|
11
|
+
import * as deviceContract from './device';
|
|
10
12
|
import {
|
|
11
13
|
createDeviceCapabilities,
|
|
12
14
|
createDeviceDisplayMetrics,
|
|
13
15
|
createDeviceInfo,
|
|
14
16
|
createSafeAreaInsets,
|
|
15
|
-
createWebDeviceBackend,
|
|
16
|
-
enableWebSafeAreaInsets,
|
|
17
|
-
getDeviceBackend,
|
|
18
17
|
getDeviceCapabilities,
|
|
19
18
|
getDeviceDisplayMetrics,
|
|
20
19
|
getDeviceId,
|
|
21
20
|
getDeviceInfo,
|
|
22
21
|
getSafeAreaInsets,
|
|
22
|
+
initializeDeviceCapabilities,
|
|
23
|
+
initializeDeviceDisplayMetrics,
|
|
24
|
+
initializeDeviceInfo,
|
|
25
|
+
initializeSafeAreaInsets,
|
|
23
26
|
refreshDeviceInfo,
|
|
24
|
-
setDeviceBackend,
|
|
25
|
-
explainDeviceBackend,
|
|
26
|
-
installDeviceHostBackend,
|
|
27
|
-
observeDeviceHostResult,
|
|
28
|
-
resetDeviceBackendForTest,
|
|
29
27
|
} from './device';
|
|
30
28
|
|
|
31
29
|
function fakeBackend(): DeviceBackend {
|
|
32
30
|
return {
|
|
31
|
+
[EntityRuntimeKey]: undefined,
|
|
33
32
|
getCapabilities(out: DeviceCapabilities): DeviceCapabilities {
|
|
34
33
|
out.hasKeyboard = true;
|
|
35
34
|
out.hasMouse = true;
|
|
@@ -87,7 +86,9 @@ function fakeBackend(): DeviceBackend {
|
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
function fakeHost(): HasSystemDevice {
|
|
90
|
+
return { system: { device: fakeBackend() } };
|
|
91
|
+
}
|
|
91
92
|
|
|
92
93
|
describe('createDeviceCapabilities', () => {
|
|
93
94
|
it('allocates a zeroed snapshot with all false capability flags', () => {
|
|
@@ -144,152 +145,15 @@ describe('createDeviceInfo', () => {
|
|
|
144
145
|
|
|
145
146
|
describe('createSafeAreaInsets', () => {
|
|
146
147
|
it('allocates zeroed edges', () => {
|
|
147
|
-
expect(createSafeAreaInsets()).
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('createWebDeviceBackend', () => {
|
|
152
|
-
it('fills the snapshot with sentinels without throwing (jsdom)', () => {
|
|
153
|
-
const backend = createWebDeviceBackend();
|
|
154
|
-
const info = backend.getInfo(createDeviceInfo());
|
|
155
|
-
expect(info.model).toBe('');
|
|
156
|
-
expect(info.manufacturer).toBe('');
|
|
157
|
-
expect(info.marketingName).toBe('');
|
|
158
|
-
expect(info.productName).toBe('');
|
|
159
|
-
expect(info.boardName).toBe('');
|
|
160
|
-
expect(info.webViewVersion).toBe('');
|
|
161
|
-
expect(info.colorGamut).toBe('');
|
|
162
|
-
expect(info.fontScale).toBe(-1);
|
|
163
|
-
expect(info.isHdr).toBe(false);
|
|
164
|
-
expect(typeof info.totalMemory).toBe('number');
|
|
165
|
-
expect(info.availableMemory).toBe(-1);
|
|
166
|
-
expect(typeof info.cpuCores).toBe('number');
|
|
167
|
-
expect(info.isJailbroken).toBe(false);
|
|
168
|
-
expect(info.isRooted).toBe(false);
|
|
169
|
-
expect(info.osBuild).toBe('');
|
|
170
|
-
expect(typeof info.formFactor).toBe('string');
|
|
171
|
-
expect(typeof info.arch).toBe('string');
|
|
172
|
-
expect(info.platformString).toBe(navigator.userAgent);
|
|
173
|
-
expect(Array.isArray(info.supportedAbis)).toBe(true);
|
|
174
|
-
expect(info.supportedAbis.length).toBe(0);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('returns zero safe-area insets on plain web (no CSS probe)', () => {
|
|
178
|
-
const backend = createWebDeviceBackend();
|
|
179
|
-
expect(backend.getSafeAreaInsets(createSafeAreaInsets())).toEqual({ bottom: 0, left: 0, right: 0, top: 0 });
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('getId returns a string (empty or a UUID) without throwing', () => {
|
|
183
|
-
const backend = createWebDeviceBackend();
|
|
184
|
-
const id = backend.getId();
|
|
185
|
-
expect(typeof id).toBe('string');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('getId returns the same value on repeated calls (stable install id)', () => {
|
|
189
|
-
const backend = createWebDeviceBackend();
|
|
190
|
-
const id1 = backend.getId();
|
|
191
|
-
const id2 = backend.getId();
|
|
192
|
-
if (id1 !== '') {
|
|
193
|
-
expect(id1).toBe(id2);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('returns display metrics with a valid pixel ratio from jsdom', () => {
|
|
198
|
-
const backend = createWebDeviceBackend();
|
|
199
|
-
const metrics = backend.getDisplayMetrics(createDeviceDisplayMetrics());
|
|
200
|
-
// jsdom exposes window.devicePixelRatio = 1 and screen.width/height
|
|
201
|
-
expect(typeof metrics.pixelRatio).toBe('number');
|
|
202
|
-
expect(typeof metrics.logicalWidth).toBe('number');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('totalMemory converts deviceMemory GiB to bytes', () => {
|
|
206
|
-
// Patch navigator.deviceMemory to a known value
|
|
207
|
-
const nav = navigator as unknown as Record<string, unknown>;
|
|
208
|
-
const original = nav['deviceMemory'];
|
|
209
|
-
try {
|
|
210
|
-
Object.defineProperty(navigator, 'deviceMemory', { configurable: true, value: 4 });
|
|
211
|
-
const backend = createWebDeviceBackend();
|
|
212
|
-
const info = backend.getInfo(createDeviceInfo());
|
|
213
|
-
expect(info.totalMemory).toBe(4 * 1024 * 1024 * 1024);
|
|
214
|
-
} finally {
|
|
215
|
-
if (original !== undefined) {
|
|
216
|
-
Object.defineProperty(navigator, 'deviceMemory', { configurable: true, value: original });
|
|
217
|
-
} else {
|
|
218
|
-
// jsdom has no deviceMemory; delete the injected one so it does not leak into a shared worker.
|
|
219
|
-
delete (navigator as unknown as Record<string, unknown>)['deviceMemory'];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('osVersion parses Android version from UA', () => {
|
|
225
|
-
const backend = createWebDeviceBackend();
|
|
226
|
-
const result = backend.getInfo(createDeviceInfo());
|
|
227
|
-
// jsdom UA results in a string; actual parsing is covered by useragent unit tests
|
|
228
|
-
expect(typeof result.osVersion).toBe('string');
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('getCapabilities returns a capability snapshot without throwing', () => {
|
|
232
|
-
const backend = createWebDeviceBackend();
|
|
233
|
-
const caps = backend.getCapabilities(createDeviceCapabilities());
|
|
234
|
-
expect(typeof caps.hasKeyboard).toBe('boolean');
|
|
235
|
-
expect(typeof caps.hasMouse).toBe('boolean');
|
|
236
|
-
expect(caps.hasStylus).toBe(false);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
describe('enableWebSafeAreaInsets', () => {
|
|
241
|
-
it('returns a dispose function and does not throw in jsdom', () => {
|
|
242
|
-
const dispose = enableWebSafeAreaInsets();
|
|
243
|
-
expect(typeof dispose).toBe('function');
|
|
244
|
-
dispose();
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe('explainDeviceBackend', () => {
|
|
249
|
-
afterEach(() => resetDeviceBackendForTest());
|
|
250
|
-
|
|
251
|
-
it('reports host-not-enabled when no backend is installed', () => {
|
|
252
|
-
resetDeviceBackendForTest();
|
|
253
|
-
const explanation = explainDeviceBackend();
|
|
254
|
-
expect(explanation.layer).toBe('host-not-enabled');
|
|
255
|
-
expect(explanation.conflict).toBe(false);
|
|
256
|
-
expect(explanation.viability).toBe('unobserved');
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('reports custom layer when a custom backend is set', () => {
|
|
260
|
-
setDeviceBackend(fakeBackend());
|
|
261
|
-
expect(explainDeviceBackend().layer).toBe('custom');
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('reports host layer when a host backend is installed', () => {
|
|
265
|
-
installDeviceHostBackend(fakeBackend());
|
|
266
|
-
expect(explainDeviceBackend().layer).toBe('host');
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('reports conflict when two different host backends are installed', () => {
|
|
270
|
-
installDeviceHostBackend(fakeBackend());
|
|
271
|
-
installDeviceHostBackend(fakeBackend());
|
|
272
|
-
expect(explainDeviceBackend().conflict).toBe(true);
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
describe('getDeviceBackend', () => {
|
|
277
|
-
it('falls back to a web backend when none is set', () => {
|
|
278
|
-
expect(getDeviceBackend()).not.toBeNull();
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it('returns the registered backend', () => {
|
|
282
|
-
const backend = fakeBackend();
|
|
283
|
-
setDeviceBackend(backend);
|
|
284
|
-
expect(getDeviceBackend()).toBe(backend);
|
|
148
|
+
expect(createSafeAreaInsets()).toMatchObject({ bottom: 0, left: 0, right: 0, top: 0 });
|
|
285
149
|
});
|
|
286
150
|
});
|
|
287
151
|
|
|
288
152
|
describe('getDeviceCapabilities', () => {
|
|
289
|
-
it('fills and returns out via the
|
|
290
|
-
|
|
153
|
+
it('fills and returns out via the host backend', () => {
|
|
154
|
+
const host = fakeHost();
|
|
291
155
|
const out = createDeviceCapabilities();
|
|
292
|
-
const result = getDeviceCapabilities(out);
|
|
156
|
+
const result = getDeviceCapabilities(host, out);
|
|
293
157
|
expect(result).toBe(out);
|
|
294
158
|
expect(out.hasKeyboard).toBe(true);
|
|
295
159
|
expect(out.hasMouse).toBe(true);
|
|
@@ -298,10 +162,10 @@ describe('getDeviceCapabilities', () => {
|
|
|
298
162
|
});
|
|
299
163
|
|
|
300
164
|
describe('getDeviceDisplayMetrics', () => {
|
|
301
|
-
it('fills and returns out via the
|
|
302
|
-
|
|
165
|
+
it('fills and returns out via the host backend', () => {
|
|
166
|
+
const host = fakeHost();
|
|
303
167
|
const out = createDeviceDisplayMetrics();
|
|
304
|
-
const result = getDeviceDisplayMetrics(out);
|
|
168
|
+
const result = getDeviceDisplayMetrics(host, out);
|
|
305
169
|
expect(result).toBe(out);
|
|
306
170
|
expect(out.colorDepth).toBe(8);
|
|
307
171
|
expect(out.densityDpi).toBe(440);
|
|
@@ -314,29 +178,17 @@ describe('getDeviceDisplayMetrics', () => {
|
|
|
314
178
|
});
|
|
315
179
|
|
|
316
180
|
describe('getDeviceId', () => {
|
|
317
|
-
it('returns
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
it('returns the value from a registered backend', () => {
|
|
322
|
-
setDeviceBackend(fakeBackend());
|
|
323
|
-
expect(getDeviceId()).toBe('test-device-id');
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it('returns a stable value across two reads (web fallback)', () => {
|
|
327
|
-
const id1 = getDeviceId();
|
|
328
|
-
const id2 = getDeviceId();
|
|
329
|
-
if (id1 !== '') {
|
|
330
|
-
expect(id1).toBe(id2);
|
|
331
|
-
}
|
|
181
|
+
it('returns the value from the host backend', () => {
|
|
182
|
+
const host = fakeHost();
|
|
183
|
+
expect(getDeviceId(host)).toBe('test-device-id');
|
|
332
184
|
});
|
|
333
185
|
});
|
|
334
186
|
|
|
335
187
|
describe('getDeviceInfo', () => {
|
|
336
|
-
it('fills and returns out via the
|
|
337
|
-
|
|
188
|
+
it('fills and returns out via the host backend', () => {
|
|
189
|
+
const host = fakeHost();
|
|
338
190
|
const out = createDeviceInfo();
|
|
339
|
-
const result = getDeviceInfo(out);
|
|
191
|
+
const result = getDeviceInfo(host, out);
|
|
340
192
|
expect(result).toBe(out);
|
|
341
193
|
expect(out.arch).toBe('arm64');
|
|
342
194
|
expect(out.availableMemory).toBe(3_000_000_000);
|
|
@@ -344,7 +196,7 @@ describe('getDeviceInfo', () => {
|
|
|
344
196
|
expect(out.colorGamut).toBe('display-p3');
|
|
345
197
|
expect(out.cpuCores).toBe(8);
|
|
346
198
|
expect(out.fontScale).toBe(1.2);
|
|
347
|
-
expect(out.formFactor).toBe(
|
|
199
|
+
expect(out.formFactor).toBe('Phone');
|
|
348
200
|
expect(out.gpuRenderer).toBe('Adreno 650');
|
|
349
201
|
expect(out.gpuVendor).toBe('Qualcomm');
|
|
350
202
|
expect(out.isHdr).toBe(true);
|
|
@@ -364,66 +216,65 @@ describe('getDeviceInfo', () => {
|
|
|
364
216
|
expect(out.totalMemory).toBe(8_000_000_000);
|
|
365
217
|
expect(out.webViewVersion).toBe('120.0.6099.230');
|
|
366
218
|
});
|
|
367
|
-
|
|
368
|
-
it('web backend returns Desktop formFactor for desktop UA', () => {
|
|
369
|
-
const backend = createWebDeviceBackend();
|
|
370
|
-
const info = backend.getInfo(createDeviceInfo());
|
|
371
|
-
// jsdom uses a desktop UA, so formFactor should be Desktop or Unknown
|
|
372
|
-
expect([DeviceFormFactorDesktop, DeviceFormFactorUnknown]).toContain(info.formFactor);
|
|
373
|
-
});
|
|
374
219
|
});
|
|
375
220
|
|
|
376
221
|
describe('getSafeAreaInsets', () => {
|
|
377
|
-
it('fills and returns out via the
|
|
378
|
-
|
|
222
|
+
it('fills and returns out via the host backend', () => {
|
|
223
|
+
const host = fakeHost();
|
|
379
224
|
const out = createSafeAreaInsets();
|
|
380
|
-
const result = getSafeAreaInsets(out);
|
|
225
|
+
const result = getSafeAreaInsets(host, out);
|
|
381
226
|
expect(result).toBe(out);
|
|
382
227
|
expect(out.top).toBe(24);
|
|
383
228
|
expect(out.bottom).toBe(16);
|
|
384
229
|
});
|
|
385
230
|
});
|
|
386
231
|
|
|
387
|
-
describe('
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
it('installs a host backend that getDeviceBackend returns', () => {
|
|
391
|
-
const backend = fakeBackend();
|
|
392
|
-
installDeviceHostBackend(backend);
|
|
393
|
-
expect(getDeviceBackend()).toBe(backend);
|
|
232
|
+
describe('initializeDeviceCapabilities', () => {
|
|
233
|
+
it('is the construction initializer of createDeviceCapabilities', () => {
|
|
234
|
+
expect(typeof initializeDeviceCapabilities).toBe('function');
|
|
394
235
|
});
|
|
236
|
+
});
|
|
395
237
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
238
|
+
describe('initializeDeviceDisplayMetrics', () => {
|
|
239
|
+
it('is the construction initializer of createDeviceDisplayMetrics', () => {
|
|
240
|
+
expect(typeof initializeDeviceDisplayMetrics).toBe('function');
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
describe('initializeDeviceInfo', () => {
|
|
244
|
+
it('is the construction initializer of createDeviceInfo', () => {
|
|
245
|
+
expect(typeof initializeDeviceInfo).toBe('function');
|
|
403
246
|
});
|
|
404
247
|
});
|
|
405
248
|
|
|
406
|
-
describe('
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
it('records a successful observation', () => {
|
|
410
|
-
installDeviceHostBackend(fakeBackend());
|
|
411
|
-
observeDeviceHostResult('getCapabilities', true);
|
|
412
|
-
const explanation = explainDeviceBackend();
|
|
413
|
-
expect(explanation.operation).toBe('getCapabilities');
|
|
414
|
-
expect(explanation.viability).toBe('available');
|
|
249
|
+
describe('initializeSafeAreaInsets', () => {
|
|
250
|
+
it('is the construction initializer of createSafeAreaInsets', () => {
|
|
251
|
+
expect(typeof initializeSafeAreaInsets).toBe('function');
|
|
415
252
|
});
|
|
253
|
+
});
|
|
416
254
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
255
|
+
describe('R3 boundary', () => {
|
|
256
|
+
it('exports no ambient-state API (setDeviceBackend, getDeviceBackend, etc.)', () => {
|
|
257
|
+
const exports = Object.keys(deviceContract);
|
|
258
|
+
const deletedSymbols = [
|
|
259
|
+
'createWebDeviceBackend',
|
|
260
|
+
'enableWebSafeAreaInsets',
|
|
261
|
+
'explainDeviceBackend',
|
|
262
|
+
'getDeviceBackend',
|
|
263
|
+
'installDeviceHostBackend',
|
|
264
|
+
'observeDeviceHostResult',
|
|
265
|
+
'resetDeviceBackendForTest',
|
|
266
|
+
'setDeviceBackend',
|
|
267
|
+
];
|
|
268
|
+
for (const symbol of deletedSymbols) {
|
|
269
|
+
expect(exports).not.toContain(symbol);
|
|
270
|
+
}
|
|
421
271
|
});
|
|
422
272
|
});
|
|
423
273
|
|
|
424
274
|
describe('refreshDeviceInfo', () => {
|
|
425
|
-
it('does not throw on
|
|
426
|
-
|
|
275
|
+
it('does not throw on a backend without refresh', () => {
|
|
276
|
+
const host = fakeHost();
|
|
277
|
+
expect(() => refreshDeviceInfo(host)).not.toThrow();
|
|
427
278
|
});
|
|
428
279
|
|
|
429
280
|
it('calls refresh() on backends that expose it', () => {
|
|
@@ -434,32 +285,8 @@ describe('refreshDeviceInfo', () => {
|
|
|
434
285
|
refreshed = true;
|
|
435
286
|
},
|
|
436
287
|
};
|
|
437
|
-
|
|
438
|
-
refreshDeviceInfo();
|
|
288
|
+
const host: HasSystemDevice = { system: { device: backend } };
|
|
289
|
+
refreshDeviceInfo(host);
|
|
439
290
|
expect(refreshed).toBe(true);
|
|
440
291
|
});
|
|
441
292
|
});
|
|
442
|
-
|
|
443
|
-
describe('resetDeviceBackendForTest', () => {
|
|
444
|
-
it('clears all backend slots', () => {
|
|
445
|
-
setDeviceBackend(fakeBackend());
|
|
446
|
-
installDeviceHostBackend(fakeBackend());
|
|
447
|
-
observeDeviceHostResult('getCapabilities', true);
|
|
448
|
-
resetDeviceBackendForTest();
|
|
449
|
-
expect(explainDeviceBackend().layer).toBe('host-not-enabled');
|
|
450
|
-
expect(explainDeviceBackend().conflict).toBe(false);
|
|
451
|
-
expect(explainDeviceBackend().viability).toBe('unobserved');
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
describe('setDeviceBackend', () => {
|
|
456
|
-
it('clears back to the web fallback when passed null', () => {
|
|
457
|
-
setDeviceBackend(fakeBackend());
|
|
458
|
-
setDeviceBackend(null);
|
|
459
|
-
expect(getDeviceBackend()).not.toBeNull();
|
|
460
|
-
// After reset, should be the web backend (not the fake)
|
|
461
|
-
const out = createDeviceInfo();
|
|
462
|
-
getDeviceInfo(out);
|
|
463
|
-
expect(out.model).toBe('');
|
|
464
|
-
});
|
|
465
|
-
});
|