error handling and cleanup
This commit is contained in:
parent
3eae70a39e
commit
1c5e07ee4b
5 changed files with 152 additions and 64 deletions
3
package-lock.json
generated
Normal file
3
package-lock.json
generated
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"lockfileVersion": 1
|
||||||
|
}
|
||||||
|
|
@ -5,53 +5,9 @@
|
||||||
* The first event fired when Stream Deck starts
|
* The first event fired when Stream Deck starts
|
||||||
*/
|
*/
|
||||||
$SD.onConnected(({ actionInfo, appInfo, connection, messageType, port, uuid }) => {
|
$SD.onConnected(({ actionInfo, appInfo, connection, messageType, port, uuid }) => {
|
||||||
// TODO: Remove this test logging code and replace with simple action
|
const myAction = new Action('com.elgato.template.action');
|
||||||
console.log({ object: 'stream-deck', event: 'onConnected' });
|
|
||||||
})
|
|
||||||
.onDeviceDidConnect(() => {
|
|
||||||
console.log({ object: 'stream-deck', event: 'onDeviceDidConnect' });
|
|
||||||
})
|
|
||||||
.onDeviceDidDisconnect(() => {
|
|
||||||
console.log({ object: 'stream-deck', event: 'onDeviceDidDisconnect' });
|
|
||||||
})
|
|
||||||
.onApplicationDidLaunch(() => {
|
|
||||||
console.log({ object: 'stream-deck', event: 'onApplicationDidLaunch' });
|
|
||||||
})
|
|
||||||
.onApplicationDidTerminate(() => {
|
|
||||||
console.log({ object: 'stream-deck', event: 'onApplicationDidTerminate' });
|
|
||||||
})
|
|
||||||
.onSystemDidWakeUp(() => {
|
|
||||||
console.log({ object: 'stream-deck', event: 'onSystemDidWakeUp' });
|
|
||||||
});
|
|
||||||
|
|
||||||
new Action('com.elgato.template.action')
|
myAction.onKeyUp(({ action, context, device, event, payload }) => {
|
||||||
.onDidReceiveGlobalSettings(() => {
|
console.log('Your code goes here!');
|
||||||
console.log({ object: 'action', event: 'onDidReceiveGlobalSettings' });
|
|
||||||
})
|
|
||||||
.onDidReceiveSettings(() => {
|
|
||||||
console.log({ object: 'action', event: 'onDidReceiveSettings' });
|
|
||||||
})
|
|
||||||
.onKeyDown(() => {
|
|
||||||
console.log({ object: 'action', event: 'onKeyDown' });
|
|
||||||
})
|
|
||||||
.onKeyUp(() => {
|
|
||||||
console.log({ object: 'action', event: 'onKeyUp' });
|
|
||||||
})
|
|
||||||
.onWillAppear(() => {
|
|
||||||
console.log({ object: 'action', event: 'onWillAppear' });
|
|
||||||
})
|
|
||||||
.onWillDisappear(() => {
|
|
||||||
console.log({ object: 'action', event: 'onWillDisappear' });
|
|
||||||
})
|
|
||||||
.onTitleParametersDidChange(() => {
|
|
||||||
console.log({ object: 'action', event: 'onTitleParametersDidChange' });
|
|
||||||
})
|
|
||||||
.onPropertyInspectorDidAppear(() => {
|
|
||||||
console.log({ object: 'action', event: 'onPropertyInspectorDidAppear' });
|
|
||||||
})
|
|
||||||
.onPropertyInspectorDidDisappear(() => {
|
|
||||||
console.log({ object: 'action', event: 'onPropertyInspectorDidDisappear' });
|
|
||||||
})
|
|
||||||
.onSendToPlugin(() => {
|
|
||||||
console.log({ object: 'action', event: 'onSendToPlugin' });
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,11 @@ class ELGSDAction {
|
||||||
on = EventEmitter.on;
|
on = EventEmitter.on;
|
||||||
emit = EventEmitter.emit;
|
emit = EventEmitter.emit;
|
||||||
|
|
||||||
|
|
||||||
constructor(UUID) {
|
constructor(UUID) {
|
||||||
|
if (!UUID) {
|
||||||
|
throw 'An action UUID matching the action UUID in your manifest is required when creating Actions.';
|
||||||
|
}
|
||||||
|
|
||||||
this.UUID = UUID;
|
this.UUID = UUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,7 +22,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onDidReceiveSettings(fn) {
|
onDidReceiveSettings(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.didReceiveSettings}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the didReceiveSettings event is required for onDidReceiveSettings.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.didReceiveSettings}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +35,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onKeyDown(fn) {
|
onKeyDown(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.keyDown}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the keyDown event is required for onKeyDown.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.keyDown}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,7 +48,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onKeyUp(fn) {
|
onKeyUp(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.keyUp}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the keyUp event is required for onKeyUp.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.keyUp}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +61,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onWillAppear(fn) {
|
onWillAppear(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.willAppear}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the willAppear event is required for onWillAppear.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.willAppear}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +74,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onWillDisappear(fn) {
|
onWillDisappear(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.willDisappear}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the willDisappear event is required for onWillDisappear.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.willDisappear}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +87,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onTitleParametersDidChange(fn) {
|
onTitleParametersDidChange(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.titleParametersDidChange}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the titleParametersDidChange event is required for onTitleParametersDidChange.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.titleParametersDidChange}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,7 +100,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onPropertyInspectorDidAppear(fn) {
|
onPropertyInspectorDidAppear(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.propertyInspectorDidAppear}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the propertyInspectorDidAppear event is required for onPropertyInspectorDidAppear.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.propertyInspectorDidAppear}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +113,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onPropertyInspectorDidDisappear(fn) {
|
onPropertyInspectorDidDisappear(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.propertyInspectorDidDisappear}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the propertyInspectorDidDisappear event is required for onPropertyInspectorDidDisappear.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.propertyInspectorDidDisappear}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +126,11 @@ class ELGSDAction {
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onSendToPlugin(fn) {
|
onSendToPlugin(fn) {
|
||||||
this.#on(`${this.UUID}.${Events.sendToPlugin}`, (jsn) => fn(jsn));
|
if (!fn) {
|
||||||
|
throw 'A callback function for the sendToPlugin event is required for onSendToPlugin.';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on(`${this.UUID}.${Events.sendToPlugin}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
* StreamDeck object containing all required code to establish
|
* StreamDeck object containing all required code to establish
|
||||||
* communication with SD-Software and the Property Inspector
|
* communication with SD-Software and the Property Inspector
|
||||||
*/
|
*/
|
||||||
class ELGSDStreamDeck {
|
class ELGSDStreamDeck {
|
||||||
port;
|
port;
|
||||||
uuid;
|
uuid;
|
||||||
messageType;
|
messageType;
|
||||||
|
|
@ -90,6 +90,10 @@
|
||||||
* @param {string} message
|
* @param {string} message
|
||||||
*/
|
*/
|
||||||
logMessage(message) {
|
logMessage(message) {
|
||||||
|
if (!message) {
|
||||||
|
throw 'A message is required for logMessage.';
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.websocket) {
|
if (this.websocket) {
|
||||||
const json = {
|
const json = {
|
||||||
|
|
@ -113,6 +117,10 @@
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async loadLocalization(pathPrefix) {
|
async loadLocalization(pathPrefix) {
|
||||||
|
if (!pathPrefix) {
|
||||||
|
throw 'A path to localization json is required for loadLocalization.';
|
||||||
|
}
|
||||||
|
|
||||||
const manifest = await this.readJson(`${pathPrefix}${this.language}.json`);
|
const manifest = await this.readJson(`${pathPrefix}${this.language}.json`);
|
||||||
this.localization = manifest['Localization'] ?? null;
|
this.localization = manifest['Localization'] ?? null;
|
||||||
|
|
||||||
|
|
@ -131,6 +139,10 @@
|
||||||
* @returns {Promise<any>} json
|
* @returns {Promise<any>} json
|
||||||
*/
|
*/
|
||||||
async readJson(path) {
|
async readJson(path) {
|
||||||
|
if (!path) {
|
||||||
|
throw 'A path is required to readJson.';
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = new XMLHttpRequest();
|
const req = new XMLHttpRequest();
|
||||||
req.onerror = reject;
|
req.onerror = reject;
|
||||||
|
|
@ -205,6 +217,10 @@
|
||||||
* @param {string} urlToOpen
|
* @param {string} urlToOpen
|
||||||
*/
|
*/
|
||||||
openUrl(urlToOpen) {
|
openUrl(urlToOpen) {
|
||||||
|
if (!url) {
|
||||||
|
throw 'A url is required for openUrl.';
|
||||||
|
}
|
||||||
|
|
||||||
this.send(Events.openUrl, this.uuid, {
|
this.send(Events.openUrl, this.uuid, {
|
||||||
payload: {
|
payload: {
|
||||||
url: urlToOpen,
|
url: urlToOpen,
|
||||||
|
|
@ -230,6 +246,10 @@
|
||||||
* @param {string} context
|
* @param {string} context
|
||||||
*/
|
*/
|
||||||
showAlert(context) {
|
showAlert(context) {
|
||||||
|
if (!context) {
|
||||||
|
throw 'A context is required to showAlert on the key.';
|
||||||
|
}
|
||||||
|
|
||||||
this.send(Events.showAlert, context);
|
this.send(Events.showAlert, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,6 +258,10 @@
|
||||||
* @param {string} context
|
* @param {string} context
|
||||||
*/
|
*/
|
||||||
showOk(context) {
|
showOk(context) {
|
||||||
|
if (!context) {
|
||||||
|
throw 'A context is required to showOk on the key.';
|
||||||
|
}
|
||||||
|
|
||||||
this.send(Events.showOk, context);
|
this.send(Events.showOk, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,6 +271,14 @@
|
||||||
* @param {string} context
|
* @param {string} context
|
||||||
*/
|
*/
|
||||||
setState(payload, context) {
|
setState(payload, context) {
|
||||||
|
if (!payload) {
|
||||||
|
throw 'A state is required when using setState.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw 'A context is required when using setState.';
|
||||||
|
}
|
||||||
|
|
||||||
this.send(Events.setState, context, {
|
this.send(Events.setState, context, {
|
||||||
payload: {
|
payload: {
|
||||||
state: 1 - Number(payload === 0),
|
state: 1 - Number(payload === 0),
|
||||||
|
|
@ -261,6 +293,14 @@
|
||||||
* @param [target]
|
* @param [target]
|
||||||
*/
|
*/
|
||||||
setTitle(title, context, target) {
|
setTitle(title, context, target) {
|
||||||
|
if (!title) {
|
||||||
|
throw 'A title is required for setTitle.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw 'A key context is required for setTitle.';
|
||||||
|
}
|
||||||
|
|
||||||
this.send(Events.setTitle, context, {
|
this.send(Events.setTitle, context, {
|
||||||
payload: {
|
payload: {
|
||||||
title: '' + title || '',
|
title: '' + title || '',
|
||||||
|
|
@ -275,10 +315,12 @@
|
||||||
* @param {number} [target]
|
* @param {number} [target]
|
||||||
*/
|
*/
|
||||||
clearTitle(context, target) {
|
clearTitle(context, target) {
|
||||||
|
if (!context) {
|
||||||
|
throw 'A key context is required to clearTitle.';
|
||||||
|
}
|
||||||
this.setTitle(null, context, target || Constants.hardwareAndSoftware);
|
this.setTitle(null, context, target || Constants.hardwareAndSoftware);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO; add error handling like this with nice messages for all methods for the template
|
|
||||||
/**
|
/**
|
||||||
* Send payload to property inspector
|
* Send payload to property inspector
|
||||||
* @param {string} actionUUID
|
* @param {string} actionUUID
|
||||||
|
|
@ -287,11 +329,11 @@
|
||||||
*/
|
*/
|
||||||
sendToPropertyInspector(actionUUID, context, payload) {
|
sendToPropertyInspector(actionUUID, context, payload) {
|
||||||
if (typeof actionUUID != 'string') {
|
if (typeof actionUUID != 'string') {
|
||||||
throw 'sendToPropertyInspector requires an actionUUID string';
|
throw 'An action UUID is required to sendToPropertyInspector.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof context != 'string') {
|
if (typeof context != 'string') {
|
||||||
throw 'sendToPropertyInspector requires a key context string';
|
throw 'A key context is required to sendToPropertyInspector.';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send(Events.sendToPropertyInspector, context, {
|
this.send(Events.sendToPropertyInspector, context, {
|
||||||
|
|
@ -307,6 +349,13 @@
|
||||||
* @param {number} [target]
|
* @param {number} [target]
|
||||||
*/
|
*/
|
||||||
setImage(img, context, target) {
|
setImage(img, context, target) {
|
||||||
|
if (!img) {
|
||||||
|
throw 'An image is required for setImage.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw 'A key context is required for setImage.';
|
||||||
|
}
|
||||||
this.send(Events.setImage, context, {
|
this.send(Events.setImage, context, {
|
||||||
payload: {
|
payload: {
|
||||||
image: img || '',
|
image: img || '',
|
||||||
|
|
@ -321,6 +370,14 @@
|
||||||
* @param {string} [profile]
|
* @param {string} [profile]
|
||||||
*/
|
*/
|
||||||
switchToProfile(device, profile) {
|
switchToProfile(device, profile) {
|
||||||
|
if (!device) {
|
||||||
|
throw 'A device id is required for switchToProfile.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!profile) {
|
||||||
|
throw 'A profile name is required for switchToProfile';
|
||||||
|
}
|
||||||
|
|
||||||
this.send(Events.switchToProfile, this.uuid, { device: device, payload: { profile } });
|
this.send(Events.switchToProfile, this.uuid, { device: device, payload: { profile } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,6 +387,10 @@
|
||||||
* @returns ELGSDStreamDeck
|
* @returns ELGSDStreamDeck
|
||||||
*/
|
*/
|
||||||
onConnected(fn) {
|
onConnected(fn) {
|
||||||
|
if (!fn) {
|
||||||
|
throw 'A callback function for the connected event is required for onConnected.';
|
||||||
|
}
|
||||||
|
|
||||||
this.on(Events.connected, (jsn) => fn(jsn));
|
this.on(Events.connected, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -342,8 +403,13 @@
|
||||||
*/
|
*/
|
||||||
onSendToPropertyInspector(actionUUID, fn) {
|
onSendToPropertyInspector(actionUUID, fn) {
|
||||||
if (typeof actionUUID != 'string') {
|
if (typeof actionUUID != 'string') {
|
||||||
throw 'onSendToPropertyInspector requires an actionUUID string.';
|
throw 'An action UUID string is required for onSendToPropertyInspector.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fn) {
|
||||||
|
throw 'A callback function for the sendToPropertyInspector event is required for onSendToPropertyInspector.';
|
||||||
|
}
|
||||||
|
|
||||||
this.on(`${actionUUID}.${Events.sendToPropertyInspector}`, (jsn) => fn(jsn));
|
this.on(`${actionUUID}.${Events.sendToPropertyInspector}`, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -354,6 +420,10 @@
|
||||||
* @returns ELGSDStreamDeck
|
* @returns ELGSDStreamDeck
|
||||||
*/
|
*/
|
||||||
onDeviceDidConnect(fn) {
|
onDeviceDidConnect(fn) {
|
||||||
|
if (!fn) {
|
||||||
|
throw 'A callback function for the deviceDidConnect event is required for onDeviceDidConnect.';
|
||||||
|
}
|
||||||
|
|
||||||
this.on(Events.deviceDidConnect, (jsn) => fn(jsn));
|
this.on(Events.deviceDidConnect, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -364,6 +434,10 @@
|
||||||
* @returns ELGSDStreamDeck
|
* @returns ELGSDStreamDeck
|
||||||
*/
|
*/
|
||||||
onDeviceDidDisconnect(fn) {
|
onDeviceDidDisconnect(fn) {
|
||||||
|
if (!fn) {
|
||||||
|
throw 'A callback function for the deviceDidDisconnect event is required for onDeviceDidDisconnect.';
|
||||||
|
}
|
||||||
|
|
||||||
this.on(Events.deviceDidDisconnect, (jsn) => fn(jsn));
|
this.on(Events.deviceDidDisconnect, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -374,6 +448,10 @@
|
||||||
* @returns ELGSDStreamDeck
|
* @returns ELGSDStreamDeck
|
||||||
*/
|
*/
|
||||||
onApplicationDidLaunch(fn) {
|
onApplicationDidLaunch(fn) {
|
||||||
|
if (!fn) {
|
||||||
|
throw 'A callback function for the applicationDidLaunch event is required for onApplicationDidLaunch.';
|
||||||
|
}
|
||||||
|
|
||||||
this.on(Events.applicationDidLaunch, (jsn) => fn(jsn));
|
this.on(Events.applicationDidLaunch, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -384,6 +462,10 @@
|
||||||
* @returns ELGSDStreamDeck
|
* @returns ELGSDStreamDeck
|
||||||
*/
|
*/
|
||||||
onApplicationDidTerminate(fn) {
|
onApplicationDidTerminate(fn) {
|
||||||
|
if (!fn) {
|
||||||
|
throw 'A callback function for the applicationDidTerminate event is required for onApplicationDidTerminate.';
|
||||||
|
}
|
||||||
|
|
||||||
this.on(Events.applicationDidTerminate, (jsn) => fn(jsn));
|
this.on(Events.applicationDidTerminate, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -394,6 +476,10 @@
|
||||||
* @returns ELGSDStreamDeck
|
* @returns ELGSDStreamDeck
|
||||||
*/
|
*/
|
||||||
onSystemDidWakeUp(fn) {
|
onSystemDidWakeUp(fn) {
|
||||||
|
if (!fn) {
|
||||||
|
throw 'A callback function for the systemDidWakeUp event is required for onSystemDidWakeUp.';
|
||||||
|
}
|
||||||
|
|
||||||
this.on(Events.systemDidWakeUp, (jsn) => fn(jsn));
|
this.on(Events.systemDidWakeUp, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -403,6 +489,10 @@
|
||||||
* @param {function} fn
|
* @param {function} fn
|
||||||
*/
|
*/
|
||||||
onDidReceiveGlobalSettings(fn) {
|
onDidReceiveGlobalSettings(fn) {
|
||||||
|
if (!fn) {
|
||||||
|
throw 'A callback function for the didReceiveGlobalSettings event is required for onDidReceiveGlobalSettings.';
|
||||||
|
}
|
||||||
|
|
||||||
this.on(Events.didReceiveGlobalSettings, (jsn) => fn(jsn));
|
this.on(Events.didReceiveGlobalSettings, (jsn) => fn(jsn));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class Utils {
|
||||||
const { name, type } = element;
|
const { name, type } = element;
|
||||||
const value = jsn[name];
|
const value = jsn[name];
|
||||||
const isCheckOrRadio = type === 'checkbox' || type === 'radio';
|
const isCheckOrRadio = type === 'checkbox' || type === 'radio';
|
||||||
console.log(element.type)
|
|
||||||
if (isCheckOrRadio) {
|
if (isCheckOrRadio) {
|
||||||
const isSingle = value === element.value;
|
const isSingle = value === element.value;
|
||||||
if (isSingle || (Array.isArray(value) && value.includes(element.value))) {
|
if (isSingle || (Array.isArray(value) && value.includes(element.value))) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue