@flighthq/power 0.5.1-next.815.cc08b93 → 0.5.1-next.903.f434bc2
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/power.d.ts +2 -1
- package/dist/power.d.ts.map +1 -1
- package/dist/power.js +17 -14
- package/dist/power.js.map +1 -1
- package/package.json +4 -4
- package/src/power.test.ts +73 -53
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/power`. The `@flight
|
|
|
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/power@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/power@0.5.1-next.903.f434bc2](https://github.com/flighthq/flight/tree/f434bc233778d75aeea61995df3a8cfaec459a85/packages/power)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/f434bc233778d75aeea61995df3a8cfaec459a85/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,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,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,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/power.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HasPowerIdle, HasPowerKeepAwake, HasPowerStatus, HasPowerThermal,
|
|
1
|
+
import type { EntityConstruction, HasPowerIdle, HasPowerKeepAwake, HasPowerStatus, HasPowerThermal, Power, PowerAttachHost, PowerBatteryHealth, PowerIdleState, PowerKeepAwakeAcquireResult, PowerKeepAwakeMode, PowerKeepAwakeReleaseResult, PowerStatus, PowerThermalState } from '@flighthq/types/contract';
|
|
2
2
|
export declare function acquirePowerKeepAwake(host: HasPowerKeepAwake, mode?: PowerKeepAwakeMode): Promise<PowerKeepAwakeAcquireResult>;
|
|
3
3
|
export declare function attachPower(host: PowerAttachHost, power: Power, idleThresholdSeconds?: number): void;
|
|
4
4
|
export declare function createPower(): Power;
|
|
@@ -18,6 +18,7 @@ export declare function getPowerStatus(host: HasPowerStatus, out: PowerStatus):
|
|
|
18
18
|
export declare function getPowerSystemIdleState(host: HasPowerIdle, thresholdSeconds: number): PowerIdleState;
|
|
19
19
|
export declare function getPowerSystemIdleTime(host: HasPowerIdle): number;
|
|
20
20
|
export declare function getPowerThermalState(host: HasPowerThermal): PowerThermalState;
|
|
21
|
+
export declare function initializePower(out: EntityConstruction<Power>): void;
|
|
21
22
|
export declare function isPowerKeepAwakeActive(host: HasPowerKeepAwake): boolean;
|
|
22
23
|
export declare function makePowerBatteryHealth(): PowerBatteryHealth;
|
|
23
24
|
export declare function makePowerStatus(): PowerStatus;
|
package/dist/power.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"power.d.ts","sourceRoot":"","sources":["../src/power.ts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GAAG,EAAE,WAAW,GAAG,WAAW,CAElF;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,GAAG,cAAc,CAEpG;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAEjE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,eAAe,GAAG,iBAAiB,CAE7E;AAID,wBAAgB,eAAe,CAAC,GAAG,EAAE,kBAAkB,CAAC,KAAK,CAAC,GAAG,IAAI,CAUpE;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAEvE;AAKD,wBAAgB,sBAAsB,IAAI,kBAAkB,CAQ3D;AAID,wBAAgB,eAAe,IAAI,WAAW,CAW7C;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAEnG;AAED,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAEtE"}
|
package/dist/power.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import { clearSignal, createSignal, emitSignal, hasSignalSlots } from '@flighthq/signals/contract';
|
|
3
3
|
// AN ATTEMPT IS NEVER AN OUTCOME. The previous seam recorded that an operation had been STARTED and
|
|
4
4
|
// reported that as availability: a denied Wake Lock request was observed as 'available' because the
|
|
@@ -73,20 +73,10 @@ export function attachPower(host, power, idleThresholdSeconds = 60) {
|
|
|
73
73
|
}
|
|
74
74
|
_subscriptions.set(power, teardowns);
|
|
75
75
|
}
|
|
76
|
-
// Allocates a Power event entity with its signals left null. Call enablePowerSignals to allocate the
|
|
77
|
-
// signals to connect to, and attachPower to start delivering host events into them.
|
|
78
76
|
export function createPower() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
onDischarging: null,
|
|
83
|
-
onIdleStateChange: null,
|
|
84
|
-
onLockScreen: null,
|
|
85
|
-
onResume: null,
|
|
86
|
-
onSuspend: null,
|
|
87
|
-
onThermalStateChange: null,
|
|
88
|
-
onUnlockScreen: null,
|
|
89
|
-
});
|
|
77
|
+
const out = allocateEntity();
|
|
78
|
+
initializePower(out);
|
|
79
|
+
return finishEntity(out);
|
|
90
80
|
}
|
|
91
81
|
// Stops delivery without discarding the entity. Runs every teardown this entity opened, ATTEMPTING ALL
|
|
92
82
|
// of them: one throwing unsubscribe must not strand the rest. Does not touch the provider — that is
|
|
@@ -189,6 +179,19 @@ export function getPowerSystemIdleTime(host) {
|
|
|
189
179
|
export function getPowerThermalState(host) {
|
|
190
180
|
return host.power.thermal.getThermalState();
|
|
191
181
|
}
|
|
182
|
+
// Allocates a Power event entity with its signals left null. Call enablePowerSignals to allocate the
|
|
183
|
+
// signals to connect to, and attachPower to start delivering host events into them.
|
|
184
|
+
export function initializePower(out) {
|
|
185
|
+
out.onChange = null;
|
|
186
|
+
out.onCharging = null;
|
|
187
|
+
out.onDischarging = null;
|
|
188
|
+
out.onIdleStateChange = null;
|
|
189
|
+
out.onLockScreen = null;
|
|
190
|
+
out.onResume = null;
|
|
191
|
+
out.onSuspend = null;
|
|
192
|
+
out.onThermalStateChange = null;
|
|
193
|
+
out.onUnlockScreen = null;
|
|
194
|
+
}
|
|
192
195
|
export function isPowerKeepAwakeActive(host) {
|
|
193
196
|
return host.power.keepAwake.isActive();
|
|
194
197
|
}
|
package/dist/power.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"power.js","sourceRoot":"","sources":["../src/power.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"power.js","sourceRoot":"","sources":["../src/power.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,O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AA0B;IACvD,IAAI,MAAM,KAAK,IAAI;QAAE,UAAU,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED,IAAI,sBAAsB,GAAG,IAAI,CAAC;AAElC,oGAAoG;AACpG,8EAA8E;AAC9E,MAAM,cAAc,GAAG,IAAI,OAAO,EAAyB,CAAC;AAE5D,oGAAoG;AACpG,iFAAiF;AACjF,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAyB,CAAC;AAGjE,SAAS,cAAc,CAAI,KAA6E;IACtG,KAAK,KAAK,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/power",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.903.f434bc2",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-next.
|
|
42
|
-
"@flighthq/signals": "0.5.1-next.
|
|
43
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.903.f434bc2",
|
|
42
|
+
"@flighthq/signals": "0.5.1-next.903.f434bc2",
|
|
43
|
+
"@flighthq/types": "0.5.1-next.903.f434bc2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
package/src/power.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import { connectSignal } from '@flighthq/signals/contract';
|
|
3
3
|
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
4
4
|
import type {
|
|
@@ -46,17 +46,21 @@ function statusHost(status: Partial<PowerStatus>): PowerAttachHost & { emitChang
|
|
|
46
46
|
for (const l of listeners) l();
|
|
47
47
|
},
|
|
48
48
|
power: {
|
|
49
|
-
change:
|
|
50
|
-
|
|
49
|
+
change: (() => {
|
|
50
|
+
const out = allocateEntity<any>();
|
|
51
|
+
out.subscribe = (listener: () => void): (() => void) => {
|
|
51
52
|
listeners.add(listener);
|
|
52
53
|
return () => listeners.delete(listener);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
};
|
|
55
|
+
return finishEntity(out);
|
|
56
|
+
})(),
|
|
57
|
+
status: (() => {
|
|
58
|
+
const out = allocateEntity<any>();
|
|
59
|
+
out.getStatus = (out: PowerStatus): PowerStatus => {
|
|
57
60
|
return Object.assign(out, status);
|
|
58
|
-
}
|
|
59
|
-
|
|
61
|
+
};
|
|
62
|
+
return finishEntity(out);
|
|
63
|
+
})(),
|
|
60
64
|
},
|
|
61
65
|
};
|
|
62
66
|
}
|
|
@@ -64,12 +68,14 @@ function statusHost(status: Partial<PowerStatus>): PowerAttachHost & { emitChang
|
|
|
64
68
|
function keepAwakeHost(overrides: Partial<HasPowerKeepAwake['power']['keepAwake']> = {}): HasPowerKeepAwake {
|
|
65
69
|
return {
|
|
66
70
|
power: {
|
|
67
|
-
keepAwake:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
keepAwake: (() => {
|
|
72
|
+
const out = allocateEntity<any>();
|
|
73
|
+
out.acquire = async () => ({ reason: 'ok' }) as const;
|
|
74
|
+
out.isActive = () => false;
|
|
75
|
+
out.release = async () => ({ reason: 'ok' }) as const;
|
|
76
|
+
Object.assign(out, overrides);
|
|
77
|
+
return finishEntity(out);
|
|
78
|
+
})(),
|
|
73
79
|
},
|
|
74
80
|
};
|
|
75
81
|
}
|
|
@@ -121,18 +127,22 @@ describe('attachPower', () => {
|
|
|
121
127
|
const listeners = new Set<() => void>();
|
|
122
128
|
const host: PowerAttachHost = {
|
|
123
129
|
power: {
|
|
124
|
-
change:
|
|
125
|
-
|
|
130
|
+
change: (() => {
|
|
131
|
+
const out = allocateEntity<any>();
|
|
132
|
+
out.subscribe = (listener: () => void): (() => void) => {
|
|
126
133
|
listeners.add(listener);
|
|
127
134
|
return () => listeners.delete(listener);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
};
|
|
136
|
+
return finishEntity(out);
|
|
137
|
+
})(),
|
|
138
|
+
status: (() => {
|
|
139
|
+
const out = allocateEntity<any>();
|
|
140
|
+
out.getStatus = (out: PowerStatus): PowerStatus => {
|
|
132
141
|
out.isCharging = charging;
|
|
133
142
|
return out;
|
|
134
|
-
}
|
|
135
|
-
|
|
143
|
+
};
|
|
144
|
+
return finishEntity(out);
|
|
145
|
+
})(),
|
|
136
146
|
},
|
|
137
147
|
};
|
|
138
148
|
const power = createPower();
|
|
@@ -154,13 +164,15 @@ describe('attachPower', () => {
|
|
|
154
164
|
const listeners = new Set<(state: PowerThermalState) => void>();
|
|
155
165
|
const host: PowerAttachHost = {
|
|
156
166
|
power: {
|
|
157
|
-
thermal:
|
|
158
|
-
|
|
159
|
-
|
|
167
|
+
thermal: (() => {
|
|
168
|
+
const out = allocateEntity<any>();
|
|
169
|
+
out.getThermalState = () => 'Serious';
|
|
170
|
+
out.subscribeThermalStateChange = (listener: (state: PowerThermalState) => void): (() => void) => {
|
|
160
171
|
listeners.add(listener);
|
|
161
172
|
return () => listeners.delete(listener);
|
|
162
|
-
}
|
|
163
|
-
|
|
173
|
+
};
|
|
174
|
+
return finishEntity(out);
|
|
175
|
+
})(),
|
|
164
176
|
},
|
|
165
177
|
};
|
|
166
178
|
const power = createPower();
|
|
@@ -206,12 +218,12 @@ describe('destroyPowerKeepAwake', () => {
|
|
|
206
218
|
// Builds the provider ONCE so two hosts can genuinely alias the same object; spreading it per host
|
|
207
219
|
// would silently make them distinct and the alias assertion would prove nothing.
|
|
208
220
|
function keepAwakeProvider(destroy?: () => void): HasPowerKeepAwake['power']['keepAwake'] {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
221
|
+
const out = allocateEntity<any>();
|
|
222
|
+
out.acquire = async () => ({ reason: 'ok' }) as const;
|
|
223
|
+
out.destroy = destroy;
|
|
224
|
+
out.isActive = () => false;
|
|
225
|
+
out.release = async () => ({ reason: 'ok' }) as const;
|
|
226
|
+
return finishEntity(out);
|
|
215
227
|
}
|
|
216
228
|
|
|
217
229
|
function keepAwakeHostWith(provider: HasPowerKeepAwake['power']['keepAwake']): HasPowerKeepAwake {
|
|
@@ -271,14 +283,16 @@ describe('detachPower', () => {
|
|
|
271
283
|
let unlockTornDown = false;
|
|
272
284
|
const host: PowerAttachHost = {
|
|
273
285
|
power: {
|
|
274
|
-
sessionLock:
|
|
275
|
-
|
|
286
|
+
sessionLock: (() => {
|
|
287
|
+
const out = allocateEntity<any>();
|
|
288
|
+
out.subscribeLock = () => () => {
|
|
276
289
|
throw new Error('lock teardown failed');
|
|
277
|
-
}
|
|
278
|
-
subscribeUnlock
|
|
290
|
+
};
|
|
291
|
+
out.subscribeUnlock = () => () => {
|
|
279
292
|
unlockTornDown = true;
|
|
280
|
-
}
|
|
281
|
-
|
|
293
|
+
};
|
|
294
|
+
return finishEntity(out);
|
|
295
|
+
})(),
|
|
282
296
|
},
|
|
283
297
|
};
|
|
284
298
|
const power = createPower();
|
|
@@ -367,13 +381,15 @@ describe('getPowerSystemIdleState', () => {
|
|
|
367
381
|
let seen = -1;
|
|
368
382
|
const host = {
|
|
369
383
|
power: {
|
|
370
|
-
idle:
|
|
371
|
-
|
|
384
|
+
idle: (() => {
|
|
385
|
+
const out = allocateEntity<any>();
|
|
386
|
+
out.getIdleState = (t: number): PowerIdleState => {
|
|
372
387
|
seen = t;
|
|
373
388
|
return 'Idle';
|
|
374
|
-
}
|
|
375
|
-
getIdleTimeSeconds
|
|
376
|
-
|
|
389
|
+
};
|
|
390
|
+
out.getIdleTimeSeconds = () => 0;
|
|
391
|
+
return finishEntity(out);
|
|
392
|
+
})(),
|
|
377
393
|
},
|
|
378
394
|
};
|
|
379
395
|
expect(getPowerSystemIdleState(host, 90)).toBe('Idle');
|
|
@@ -385,10 +401,12 @@ describe('getPowerSystemIdleTime', () => {
|
|
|
385
401
|
it('returns the provider value', () => {
|
|
386
402
|
const host = {
|
|
387
403
|
power: {
|
|
388
|
-
idle:
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
404
|
+
idle: (() => {
|
|
405
|
+
const out = allocateEntity<any>();
|
|
406
|
+
out.getIdleState = (): PowerIdleState => 'Active';
|
|
407
|
+
out.getIdleTimeSeconds = () => 42;
|
|
408
|
+
return finishEntity(out);
|
|
409
|
+
})(),
|
|
392
410
|
},
|
|
393
411
|
};
|
|
394
412
|
expect(getPowerSystemIdleTime(host)).toBe(42);
|
|
@@ -399,10 +417,12 @@ describe('getPowerThermalState', () => {
|
|
|
399
417
|
it('returns the provider value', () => {
|
|
400
418
|
const host = {
|
|
401
419
|
power: {
|
|
402
|
-
thermal:
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
420
|
+
thermal: (() => {
|
|
421
|
+
const out = allocateEntity<any>();
|
|
422
|
+
out.getThermalState = (): PowerThermalState => 'Fair';
|
|
423
|
+
out.subscribeThermalStateChange = () => () => {};
|
|
424
|
+
return finishEntity(out);
|
|
425
|
+
})(),
|
|
406
426
|
},
|
|
407
427
|
};
|
|
408
428
|
expect(getPowerThermalState(host)).toBe('Fair');
|