@sprucelabs/spruce-heartwood-utils 24.0.2 → 24.1.0

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.
@@ -2,9 +2,10 @@ import EventEmitter from 'events';
2
2
  import { CachedValue, Device, TheaterSettingValueTypes, TheatreSettingName } from '@sprucelabs/heartwood-view-controllers';
3
3
  import { Orientation } from '../types/heartwood.types';
4
4
  export declare class HeartwoodDevice extends EventEmitter implements Device {
5
+ static Class?: new (storage: Storage) => Device;
5
6
  private storage;
6
7
  private orientation;
7
- private isGettingKiosk;
8
+ private isGettingTheatreSetting;
8
9
  protected constructor(storage: Storage);
9
10
  openUrl(url: string): void;
10
11
  static Device(storage: Storage): HeartwoodDevice;
@@ -18,5 +19,5 @@ export declare class HeartwoodDevice extends EventEmitter implements Device {
18
19
  signalSkillViewLoaded(): void;
19
20
  sendCommand(command: string, payload?: Record<string, any>): void;
20
21
  setTheatreSetting<N extends TheatreSettingName>(name: N, value: TheaterSettingValueTypes[N]): void;
21
- getTheatreSetting<N extends TheatreSettingName>(_name: N): Promise<TheaterSettingValueTypes[N] | null>;
22
+ getTheatreSetting<N extends TheatreSettingName>(name: N): Promise<TheaterSettingValueTypes[N] | null>;
22
23
  }
@@ -10,7 +10,7 @@ class HeartwoodDevice extends events_1.default {
10
10
  constructor(storage) {
11
11
  super();
12
12
  this.orientation = 'unknown-orientation';
13
- this.isGettingKiosk = false;
13
+ this.isGettingTheatreSetting = false;
14
14
  this.storage = storage;
15
15
  }
16
16
  openUrl(url) {
@@ -19,8 +19,9 @@ class HeartwoodDevice extends events_1.default {
19
19
  });
20
20
  }
21
21
  static Device(storage) {
22
+ var _a;
22
23
  (0, schema_1.assertOptions)({ storage }, ['storage']);
23
- return new this(storage);
24
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(storage);
24
25
  }
25
26
  setCachedValue(key, value) {
26
27
  this.storage.setItem(key, JSON.stringify({ value }));
@@ -58,7 +59,7 @@ class HeartwoodDevice extends events_1.default {
58
59
  payload,
59
60
  };
60
61
  const message = JSON.stringify(options);
61
- if (!this.isGettingKiosk) {
62
+ if (!this.isGettingTheatreSetting) {
62
63
  //@ts-ignore
63
64
  (_d = (_c = (_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, message);
64
65
  // @ts-ignore
@@ -74,24 +75,28 @@ class HeartwoodDevice extends events_1.default {
74
75
  value,
75
76
  });
76
77
  }
77
- async getTheatreSetting(_name) {
78
+ async getTheatreSetting(name) {
78
79
  //@ts-ignore
79
80
  if (window.api) {
80
- this.isGettingKiosk = true;
81
- this.sendCommand('getIsKioskModeEnabled');
82
- this.isGettingKiosk = false;
81
+ this.isGettingTheatreSetting = true;
82
+ this.sendCommand('getTheatreSetting', {
83
+ name,
84
+ });
85
+ this.isGettingTheatreSetting = false;
83
86
  }
84
87
  else {
85
- return false;
88
+ return null;
86
89
  }
87
90
  return new Promise((resolve) => {
88
91
  var _a, _b;
89
- let timeout = setTimeout(() => resolve(false), 250);
92
+ let timeout = setTimeout(() => resolve(null), 250);
90
93
  //@ts-ignore
91
94
  (_b = (_a = window.api) === null || _a === void 0 ? void 0 : _a.onMessage) === null || _b === void 0 ? void 0 : _b.call(_a, (json) => {
92
- const { value } = JSON.parse(json);
93
- clearTimeout(timeout);
94
- resolve(value);
95
+ const { value, name: returnedName } = JSON.parse(json);
96
+ if (name === returnedName) {
97
+ clearTimeout(timeout);
98
+ resolve(value);
99
+ }
95
100
  });
96
101
  });
97
102
  }
@@ -2,9 +2,10 @@ import EventEmitter from 'events';
2
2
  import { CachedValue, Device, TheaterSettingValueTypes, TheatreSettingName } from '@sprucelabs/heartwood-view-controllers';
3
3
  import { Orientation } from '../types/heartwood.types';
4
4
  export declare class HeartwoodDevice extends EventEmitter implements Device {
5
+ static Class?: new (storage: Storage) => Device;
5
6
  private storage;
6
7
  private orientation;
7
- private isGettingKiosk;
8
+ private isGettingTheatreSetting;
8
9
  protected constructor(storage: Storage);
9
10
  openUrl(url: string): void;
10
11
  static Device(storage: Storage): HeartwoodDevice;
@@ -18,5 +19,5 @@ export declare class HeartwoodDevice extends EventEmitter implements Device {
18
19
  signalSkillViewLoaded(): void;
19
20
  sendCommand(command: string, payload?: Record<string, any>): void;
20
21
  setTheatreSetting<N extends TheatreSettingName>(name: N, value: TheaterSettingValueTypes[N]): void;
21
- getTheatreSetting<N extends TheatreSettingName>(_name: N): Promise<TheaterSettingValueTypes[N] | null>;
22
+ getTheatreSetting<N extends TheatreSettingName>(name: N): Promise<TheaterSettingValueTypes[N] | null>;
22
23
  }
@@ -13,7 +13,7 @@ export class HeartwoodDevice extends EventEmitter {
13
13
  constructor(storage) {
14
14
  super();
15
15
  this.orientation = 'unknown-orientation';
16
- this.isGettingKiosk = false;
16
+ this.isGettingTheatreSetting = false;
17
17
  this.storage = storage;
18
18
  }
19
19
  openUrl(url) {
@@ -22,8 +22,9 @@ export class HeartwoodDevice extends EventEmitter {
22
22
  });
23
23
  }
24
24
  static Device(storage) {
25
+ var _a;
25
26
  assertOptions({ storage }, ['storage']);
26
- return new this(storage);
27
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(storage);
27
28
  }
28
29
  setCachedValue(key, value) {
29
30
  this.storage.setItem(key, JSON.stringify({ value }));
@@ -61,7 +62,7 @@ export class HeartwoodDevice extends EventEmitter {
61
62
  payload,
62
63
  };
63
64
  const message = JSON.stringify(options);
64
- if (!this.isGettingKiosk) {
65
+ if (!this.isGettingTheatreSetting) {
65
66
  //@ts-ignore
66
67
  (_d = (_c = (_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, message);
67
68
  // @ts-ignore
@@ -77,25 +78,29 @@ export class HeartwoodDevice extends EventEmitter {
77
78
  value,
78
79
  });
79
80
  }
80
- getTheatreSetting(_name) {
81
+ getTheatreSetting(name) {
81
82
  return __awaiter(this, void 0, void 0, function* () {
82
83
  //@ts-ignore
83
84
  if (window.api) {
84
- this.isGettingKiosk = true;
85
- this.sendCommand('getIsKioskModeEnabled');
86
- this.isGettingKiosk = false;
85
+ this.isGettingTheatreSetting = true;
86
+ this.sendCommand('getTheatreSetting', {
87
+ name,
88
+ });
89
+ this.isGettingTheatreSetting = false;
87
90
  }
88
91
  else {
89
- return false;
92
+ return null;
90
93
  }
91
94
  return new Promise((resolve) => {
92
95
  var _a, _b;
93
- let timeout = setTimeout(() => resolve(false), 250);
96
+ let timeout = setTimeout(() => resolve(null), 250);
94
97
  //@ts-ignore
95
98
  (_b = (_a = window.api) === null || _a === void 0 ? void 0 : _a.onMessage) === null || _b === void 0 ? void 0 : _b.call(_a, (json) => {
96
- const { value } = JSON.parse(json);
97
- clearTimeout(timeout);
98
- resolve(value);
99
+ const { value, name: returnedName } = JSON.parse(json);
100
+ if (name === returnedName) {
101
+ clearTimeout(timeout);
102
+ resolve(value);
103
+ }
99
104
  });
100
105
  });
101
106
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-heartwood-utils",
3
3
  "description": "Heartwood Utilities",
4
- "version": "24.0.2",
4
+ "version": "24.1.0",
5
5
  "skill": {
6
6
  "namespace": "heartwood"
7
7
  },