From db0e6a83d01c31b4747e2d47b3989a0fa915fa0c Mon Sep 17 00:00:00 2001 From: Neil Enns Date: Mon, 6 Jan 2025 09:10:05 -0800 Subject: [PATCH] Refactor action.ts (#61) * Refactor action.ts Fixes #55 * Fix build breaks --- .vscode/settings.json | 51 +++--- README.md | 5 +- src/actions/atisLetter.ts | 16 +- src/actions/vAtisStatus.ts | 13 +- .../action/actionAdded.ts | 0 .../action/actionRemoved.ts | 0 .../action/atisLetterAdded.ts | 0 .../action/atisLetterUpdated.ts | 0 .../streamdeck/atisLetter/addAtisLetter.ts | 21 +++ .../atisLetter/atisLetterLongPress.ts | 10 ++ .../atisLetter/atisLetterShortPress.ts | 26 +++ .../atisLetter/updateAtisLetterSettings.ts | 33 ++++ src/events/streamdeck/remove.ts | 10 ++ .../streamdeck/vAtisStatus/addvAtisStatus.ts | 20 +++ .../vAtisStatus/updatevAtisStatusSettings.ts | 23 +++ .../vAtisStatus/vatisStatusLongPress.ts | 22 +++ .../vAtis/atisUpdate.ts | 0 .../vAtis/connected.ts | 0 .../vAtis/disconnected.ts | 0 src/interfaces/messages.ts | 2 +- src/managers/action.ts | 149 ++---------------- src/managers/vatis.ts | 9 +- src/plugin.ts | 14 +- tsconfig.json | 30 ++-- 24 files changed, 255 insertions(+), 199 deletions(-) rename src/{eventHandlers => events}/action/actionAdded.ts (100%) rename src/{eventHandlers => events}/action/actionRemoved.ts (100%) rename src/{eventHandlers => events}/action/atisLetterAdded.ts (100%) rename src/{eventHandlers => events}/action/atisLetterUpdated.ts (100%) create mode 100644 src/events/streamdeck/atisLetter/addAtisLetter.ts create mode 100644 src/events/streamdeck/atisLetter/atisLetterLongPress.ts create mode 100644 src/events/streamdeck/atisLetter/atisLetterShortPress.ts create mode 100644 src/events/streamdeck/atisLetter/updateAtisLetterSettings.ts create mode 100644 src/events/streamdeck/remove.ts create mode 100644 src/events/streamdeck/vAtisStatus/addvAtisStatus.ts create mode 100644 src/events/streamdeck/vAtisStatus/updatevAtisStatusSettings.ts create mode 100644 src/events/streamdeck/vAtisStatus/vatisStatusLongPress.ts rename src/{eventHandlers => events}/vAtis/atisUpdate.ts (100%) rename src/{eventHandlers => events}/vAtis/connected.ts (100%) rename src/{eventHandlers => events}/vAtis/disconnected.ts (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index d4b50f7..9d61b22 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,22 +1,35 @@ { - /* Prefer tabs over spaces for accessibility */ - "editor.insertSpaces": false, - "editor.detectIndentation": false, - /* Explorer */ - "explorer.fileNesting.enabled": true, - "explorer.fileNesting.patterns": { - "*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts", - "package.json": "package-lock.json, yarn.lock, pnpm-lock.yaml, rollup.config.mjs, tsconfig.json", - "eslint.config.js": ".markdownlint.jsonc", - "README.md": "DEVELOPMENT.md" - }, - "files.exclude": { - "node_modules": true, - "com.neil-enns.vatis.streamDeckPlugin": true, - }, - "eslint.useFlatConfig": true, - "git.enableSmartCommit": true, - "[svg]": { + /* Prefer tabs over spaces for accessibility */ + "editor.insertSpaces": false, + "editor.detectIndentation": false, + /* Explorer */ + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.patterns": { + "*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts", + "package.json": "package-lock.json, yarn.lock, pnpm-lock.yaml, rollup.config.mjs, tsconfig.json", + "eslint.config.js": ".markdownlint.jsonc", + "README.md": "DEVELOPMENT.md" + }, + "files.exclude": { + "node_modules": true, + "com.neil-enns.vatis.streamDeckPlugin": true + }, + "eslint.useFlatConfig": true, + "git.enableSmartCommit": true, + "[svg]": { "editor.formatOnSave": false + }, + "cSpell.words": [ + "Addv", + "Atis", + "atisletter", + "elgato", + "getv", + "handlev", + "streamdeck", + "Typeguard", + "Updatev", + "vatis", + "vatisstatus" + ] } -} \ No newline at end of file diff --git a/README.md b/README.md index 2b2b77b..5088b04 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,7 @@ After installation the plugin actions are available under the vATIS category: The ATIS letter action displays the station name, current AITS letter, and current altimeter for a single station in vATIS. -Pressing the action clears the new ATIS indicator in vATIS and on the action. A long -press of the action clears the new ATIS indicator on all stations in vATIS. +Pressing the action clears the new ATIS indicator in vATIS and on the action. A long press of the action clears the new ATIS indicator on all stations in vATIS. By default the pressure displays in white. For pressure reported in inches of mercury, if the value falls below 29.92 the value will show in red as a reminder that FL180 (or FL190, @@ -46,7 +45,7 @@ like this to display the information on your Stream Deck: | Station | The name of the station you want to display status for. Required. | | | Type | The type of the station. | Combined | | Current | The image to display when the ATIS letter shown is current. Optional. | ![Black background, white text](docs/images/atis-connected.png) ![Black background, white text, red text for pressure](docs/images/atis-warning.png) | -| Unavailable | The iamge to display when there is no connection to vATIS. Optional. | ![Black background, "ATIS" for letter, grey text](docs/images/atis-notconnected.png) | +| Unavailable | The image to display when there is no connection to vATIS. Optional. | ![Black background, "ATIS" for letter, grey text](docs/images/atis-notconnected.png) | | Updated | The image to display when the ATIS letter updated to a new one. Optional. | ![Orange background, white text](docs/images/atis-updated.png) | The default display automatically includes the station name, ATIS letter, and altimeter. When specifying diff --git a/src/actions/atisLetter.ts b/src/actions/atisLetter.ts index 9cee70f..c910ab9 100644 --- a/src/actions/atisLetter.ts +++ b/src/actions/atisLetter.ts @@ -7,8 +7,12 @@ import { WillAppearEvent, WillDisappearEvent, } from "@elgato/streamdeck"; +import { handleAddAtisLetter } from "@events/streamdeck/atisLetter/addAtisLetter"; +import { handleAtisLetterLongPress } from "@events/streamdeck/atisLetter/atisLetterLongPress"; +import { handleAtisLetterShortPress } from "@events/streamdeck/atisLetter/atisLetterShortPress"; +import { handleUpdateAtisLetterSettings } from "@events/streamdeck/atisLetter/updateAtisLetterSettings"; +import { handleRemove } from "@events/streamdeck/remove"; import { AtisType } from "@interfaces/messages"; -import actionManager from "@managers/action"; import { LONG_PRESS_THRESHOLD } from "@utils/constants"; @action({ UUID: "com.neil-enns.vatis.atisletter" }) @@ -30,14 +34,14 @@ export class AtisLetter extends SingletonAction { return; } - actionManager.addAtisLetter(ev.action, ev.payload.settings); + handleAddAtisLetter(ev.action, ev.payload.settings); } // When the action is removed from a profile it also gets removed from the ActionManager. override onWillDisappear( ev: WillDisappearEvent ): void | Promise { - actionManager.remove(ev.action); + handleRemove(ev.action); } // When settings are received the ActionManager is called to update the existing @@ -51,7 +55,7 @@ export class AtisLetter extends SingletonAction { return; } - actionManager.updateAtisLetterSettings(ev.action, ev.payload.settings); + handleUpdateAtisLetterSettings(ev.action, ev.payload.settings); } override onKeyDown(): Promise | void { @@ -62,9 +66,9 @@ export class AtisLetter extends SingletonAction { const pressLength = Date.now() - this._keyDownStart; if (pressLength > LONG_PRESS_THRESHOLD) { - actionManager.atisLetterLongPress(ev.action); + handleAtisLetterLongPress(); } else { - actionManager.atisLetterShortPress(ev.action); + handleAtisLetterShortPress(ev.action); } } } diff --git a/src/actions/vAtisStatus.ts b/src/actions/vAtisStatus.ts index aa1cf03..ab915ac 100644 --- a/src/actions/vAtisStatus.ts +++ b/src/actions/vAtisStatus.ts @@ -7,7 +7,10 @@ import { WillAppearEvent, WillDisappearEvent, } from "@elgato/streamdeck"; -import actionManager from "@managers/action"; +import { handleRemove } from "@events/streamdeck/remove"; +import { handleAddvAtisStatus } from "@events/streamdeck/vAtisStatus/addvAtisStatus"; +import { handleUpdatevAtisStatusSettings } from "@events/streamdeck/vAtisStatus/updatevAtisStatusSettings"; +import { handlevAtisStatusLongPress } from "@events/streamdeck/vAtisStatus/vatisStatusLongPress"; import { LONG_PRESS_THRESHOLD } from "@utils/constants"; @action({ UUID: "com.neil-enns.vatis.vatisstatus" }) @@ -28,14 +31,14 @@ export class vAtisAudioStatus extends SingletonAction { return; } - actionManager.addvAtis(ev.action, ev.payload.settings); + handleAddvAtisStatus(ev.action, ev.payload.settings); } // When the action is removed from a profile it also gets removed from the ActionManager. override onWillDisappear( ev: WillDisappearEvent ): void | Promise { - actionManager.remove(ev.action); + handleRemove(ev.action); } override onDidReceiveSettings( @@ -47,7 +50,7 @@ export class vAtisAudioStatus extends SingletonAction { return; } - actionManager.updatevAtisStatus(ev.action, ev.payload.settings); + handleUpdatevAtisStatusSettings(ev.action, ev.payload.settings); } override onKeyDown(): Promise | void { @@ -58,7 +61,7 @@ export class vAtisAudioStatus extends SingletonAction { const pressLength = Date.now() - this._keyDownStart; if (pressLength > LONG_PRESS_THRESHOLD) { - actionManager.vAtisStatusLongPress(ev.action); + handlevAtisStatusLongPress(ev.action); } } } diff --git a/src/eventHandlers/action/actionAdded.ts b/src/events/action/actionAdded.ts similarity index 100% rename from src/eventHandlers/action/actionAdded.ts rename to src/events/action/actionAdded.ts diff --git a/src/eventHandlers/action/actionRemoved.ts b/src/events/action/actionRemoved.ts similarity index 100% rename from src/eventHandlers/action/actionRemoved.ts rename to src/events/action/actionRemoved.ts diff --git a/src/eventHandlers/action/atisLetterAdded.ts b/src/events/action/atisLetterAdded.ts similarity index 100% rename from src/eventHandlers/action/atisLetterAdded.ts rename to src/events/action/atisLetterAdded.ts diff --git a/src/eventHandlers/action/atisLetterUpdated.ts b/src/events/action/atisLetterUpdated.ts similarity index 100% rename from src/eventHandlers/action/atisLetterUpdated.ts rename to src/events/action/atisLetterUpdated.ts diff --git a/src/events/streamdeck/atisLetter/addAtisLetter.ts b/src/events/streamdeck/atisLetter/addAtisLetter.ts new file mode 100644 index 0000000..b97f713 --- /dev/null +++ b/src/events/streamdeck/atisLetter/addAtisLetter.ts @@ -0,0 +1,21 @@ +import { AtisLetterSettings } from "@actions/atisLetter"; +import { AtisLetterController } from "@controllers/atisLetter"; +import { KeyAction } from "@elgato/streamdeck"; +import actionManager from "@managers/action"; + +/** + * Adds an atis letter action to the action list. Emits an atisLetterAdded + * event after the action is added. + * @param action The action + * @param settings The settings for the action + */ +export const handleAddAtisLetter = ( + action: KeyAction, + settings: AtisLetterSettings +) => { + const controller = new AtisLetterController(action, settings); + + actionManager.add(controller); + actionManager.emit("atisLetterAdded", controller); + actionManager.emit("actionAdded", controller); +}; diff --git a/src/events/streamdeck/atisLetter/atisLetterLongPress.ts b/src/events/streamdeck/atisLetter/atisLetterLongPress.ts new file mode 100644 index 0000000..310fac6 --- /dev/null +++ b/src/events/streamdeck/atisLetter/atisLetterLongPress.ts @@ -0,0 +1,10 @@ +import vAtisManager from "@managers/vatis"; + +/** + * Called when an ATIS letter action has a long press. Clears the new + * ATIS state on all stations. + * @param actionId The ID of the action that had the long press + */ +export const handleAtisLetterLongPress = () => { + vAtisManager.sendMessage({ type: "acknowledgeAtisUpdate" }); +}; diff --git a/src/events/streamdeck/atisLetter/atisLetterShortPress.ts b/src/events/streamdeck/atisLetter/atisLetterShortPress.ts new file mode 100644 index 0000000..3d91606 --- /dev/null +++ b/src/events/streamdeck/atisLetter/atisLetterShortPress.ts @@ -0,0 +1,26 @@ +import { KeyAction } from "@elgato/streamdeck"; +import actionManager from "@managers/action"; +import vAtisManager from "@managers/vatis"; + +/** + * Called when an ATIS letter action has a short press. Clears the state. + * @param actionId The ID of the action that had the short press + */ +export const handleAtisLetterShortPress = (action: KeyAction) => { + const savedAction = actionManager + .getAtisLetterControllers() + .find((entry) => entry.action.id === action.id); + + if (!savedAction?.station) { + return; + } + + // Send a clear request to vATIS + vAtisManager.sendMessage({ + type: "acknowledgeAtisUpdate", + value: { + station: savedAction.station, + atisType: savedAction.atisType, + }, + }); +}; diff --git a/src/events/streamdeck/atisLetter/updateAtisLetterSettings.ts b/src/events/streamdeck/atisLetter/updateAtisLetterSettings.ts new file mode 100644 index 0000000..0c7485b --- /dev/null +++ b/src/events/streamdeck/atisLetter/updateAtisLetterSettings.ts @@ -0,0 +1,33 @@ +import { AtisLetterSettings } from "@actions/atisLetter"; +import { KeyAction } from "@elgato/streamdeck"; +import actionManager from "@managers/action"; + +/** + * Updates the settings associated with an ATIS letter status action. + * Emits a atisLetterUpdated event if the settings require + * the action to refresh. + * @param action The action to update + * @param settings The new settings to use + */ +export const handleUpdateAtisLetterSettings = ( + action: KeyAction, + settings: AtisLetterSettings +) => { + const savedAction = actionManager + .getAtisLetterControllers() + .find((entry) => entry.action.id === action.id); + + if (!savedAction) { + return; + } + + const requiresRefresh = + savedAction.settings.station !== settings.station || + savedAction.settings.atisType !== settings.atisType; + + savedAction.settings = settings; + + if (requiresRefresh) { + actionManager.emit("atisLetterUpdated", savedAction); + } +}; diff --git a/src/events/streamdeck/remove.ts b/src/events/streamdeck/remove.ts new file mode 100644 index 0000000..4472501 --- /dev/null +++ b/src/events/streamdeck/remove.ts @@ -0,0 +1,10 @@ +import { ActionContext } from "@elgato/streamdeck"; +import actionManager from "@managers/action"; + +/** + * Removes an action from the list. Emits a removed event after the action is removed. + * @param action The action to remove + */ +export const handleRemove = (action: ActionContext) => { + actionManager.remove(action); +}; diff --git a/src/events/streamdeck/vAtisStatus/addvAtisStatus.ts b/src/events/streamdeck/vAtisStatus/addvAtisStatus.ts new file mode 100644 index 0000000..251c4e8 --- /dev/null +++ b/src/events/streamdeck/vAtisStatus/addvAtisStatus.ts @@ -0,0 +1,20 @@ +import { vAtisStatusSettings } from "@actions/vAtisStatus"; +import { vAtisStatusController } from "@controllers/vAtisStatus"; +import { KeyAction } from "@elgato/streamdeck"; +import actionManager from "@managers/action"; + +/** + * Adds a vATIS status action to the action list. Emits a vAtisStatusAdded event + * after the action is added. + * @param action The action to add + */ +export const handleAddvAtisStatus = ( + action: KeyAction, + settings: vAtisStatusSettings +) => { + const controller = new vAtisStatusController(action, settings); + + actionManager.add(controller); + actionManager.emit("vAtisStatusAdded", controller); + actionManager.emit("actionAdded", controller); +}; diff --git a/src/events/streamdeck/vAtisStatus/updatevAtisStatusSettings.ts b/src/events/streamdeck/vAtisStatus/updatevAtisStatusSettings.ts new file mode 100644 index 0000000..7cd97f8 --- /dev/null +++ b/src/events/streamdeck/vAtisStatus/updatevAtisStatusSettings.ts @@ -0,0 +1,23 @@ +import { vAtisStatusSettings } from "@actions/vAtisStatus"; +import { KeyAction } from "@elgato/streamdeck"; +import actionManager from "@managers/action"; + +/** + * Updates the settings associated with a vATIS status action. + * @param action The action to update + * @param settings The new settings to use + */ +export const handleUpdatevAtisStatusSettings = ( + action: KeyAction, + settings: vAtisStatusSettings +) => { + const savedAction = actionManager + .getvAtisStatusControllers() + .find((entry) => entry.action.id === action.id); + + if (!savedAction) { + return; + } + + savedAction.settings = settings; +}; diff --git a/src/events/streamdeck/vAtisStatus/vatisStatusLongPress.ts b/src/events/streamdeck/vAtisStatus/vatisStatusLongPress.ts new file mode 100644 index 0000000..5919013 --- /dev/null +++ b/src/events/streamdeck/vAtisStatus/vatisStatusLongPress.ts @@ -0,0 +1,22 @@ +import { KeyAction } from "@elgato/streamdeck"; +import actionManager from "@managers/action"; +import vAtisManager from "@managers/vatis"; +import { handleAsyncException } from "@utils/handleAsyncException"; + +/** + * Called when a vATIS status action has a long press. Refreshes all + * ATIS actions. + * @param actionId The ID of the action that had the long press + */ +export const handlevAtisStatusLongPress = (action: KeyAction) => { + actionManager.getAtisLetterControllers().forEach((entry) => { + entry.reset(); + }); + + // Refresh all the stations. + vAtisManager.refreshAtis(); + + action.showOk().catch((error: unknown) => { + handleAsyncException("Unable to show OK on ATIS button:", error); + }); +}; diff --git a/src/eventHandlers/vAtis/atisUpdate.ts b/src/events/vAtis/atisUpdate.ts similarity index 100% rename from src/eventHandlers/vAtis/atisUpdate.ts rename to src/events/vAtis/atisUpdate.ts diff --git a/src/eventHandlers/vAtis/connected.ts b/src/events/vAtis/connected.ts similarity index 100% rename from src/eventHandlers/vAtis/connected.ts rename to src/events/vAtis/connected.ts diff --git a/src/eventHandlers/vAtis/disconnected.ts b/src/events/vAtis/disconnected.ts similarity index 100% rename from src/eventHandlers/vAtis/disconnected.ts rename to src/events/vAtis/disconnected.ts diff --git a/src/interfaces/messages.ts b/src/interfaces/messages.ts index 235c633..6376f38 100644 --- a/src/interfaces/messages.ts +++ b/src/interfaces/messages.ts @@ -46,7 +46,7 @@ export interface GetAtis { type: "getAtis"; value?: { station: string; - atisType: AtisType; + atisType?: AtisType; }; } diff --git a/src/managers/action.ts b/src/managers/action.ts index 0ce2322..a7e1e8b 100644 --- a/src/managers/action.ts +++ b/src/managers/action.ts @@ -1,5 +1,3 @@ -import { AtisLetterSettings } from "@actions/atisLetter"; -import { vAtisStatusSettings } from "@actions/vAtisStatus"; import { AtisLetterController, isAtisLetterController, @@ -8,13 +6,11 @@ import { isvAtisStatusController, vAtisStatusController, } from "@controllers/vAtisStatus"; -import { ActionContext, KeyAction } from "@elgato/streamdeck"; +import { ActionContext } from "@elgato/streamdeck"; import { Controller } from "@interfaces/controller"; import { Atis } from "@interfaces/messages"; import vAtisManager from "@managers/vatis"; -import { handleAsyncException } from "@utils/handleAsyncException"; import mainLogger from "@utils/logger"; -import debounce from "debounce"; import { EventEmitter } from "events"; const logger = mainLogger.child({ service: "action" }); @@ -25,13 +21,6 @@ class ActionManager extends EventEmitter { private constructor() { super(); - - // Debounce the update methods to avoid rapid pinging of vATIS or - // title redraws while typing - this.updateAtisLetterSettings = debounce( - this.updateAtisLetterSettings.bind(this), - 500 - ); } /** @@ -54,45 +43,24 @@ class ActionManager extends EventEmitter { } /** - * Removes an action from the list. - * @param action The action to remove - */ - public remove(action: ActionContext): void { - this.actions = this.actions.filter( - (entry) => entry.action.id !== action.id - ); - - this.emit("actionRemoved", this.actions.length); - } - - /** - * Adds a vATIS status action to the action list. Emits a vAtisStatusAdded event - * after the action is added. - * @param action The action to add + * Adds a controller to the list of tracked actions. + * @param controller The controller to add */ - public addvAtis(action: KeyAction, settings: vAtisStatusSettings) { - const controller = new vAtisStatusController(action, settings); - + public add(controller: Controller): void { this.actions.push(controller); - this.emit("vAtisStatusAdded", controller); this.emit("actionAdded", controller); } /** - * Updates the settings associated with a vATIS status action. - * @param action The action to update - * @param settings The new settings to use + * Removes an action from the list. + * @param action The action to remove */ - public updatevAtisStatus(action: KeyAction, settings: vAtisStatusSettings) { - const savedAction = this.getvAtisStatusControllers().find( - (entry) => entry.action.id === action.id + public remove(action: ActionContext): void { + this.actions = this.actions.filter( + (entry) => entry.action.id !== action.id ); - if (!savedAction) { - return; - } - - savedAction.settings = settings; + this.emit("actionRemoved", this.actions.length); } /** @@ -105,50 +73,6 @@ class ActionManager extends EventEmitter { }); } - /** - * Adds an atis letter action to the action list. Emits an atisLetterAdded - * event after the action is added. - * @param action The action - * @param settings The settings for the action - */ - public addAtisLetter(action: KeyAction, settings: AtisLetterSettings): void { - const controller = new AtisLetterController(action, settings); - - this.actions.push(controller); - this.emit("atisLetterAdded", controller); - this.emit("actionAdded", controller); - } - - /** - * Updates the settings associated with an ATIS letter status action. - * Emits a atisLetterUpdated event if the settings require - * the action to refresh. - * @param action The action to update - * @param settings The new settings to use - */ - public updateAtisLetterSettings( - action: KeyAction, - settings: AtisLetterSettings - ) { - const savedAction = this.getAtisLetterControllers().find( - (entry) => entry.action.id === action.id - ); - - if (!savedAction) { - return; - } - - const requiresRefresh = - savedAction.settings.station !== settings.station || - savedAction.settings.atisType !== settings.atisType; - - savedAction.settings = settings; - - if (requiresRefresh) { - this.emit("atisLetterUpdated", savedAction); - } - } - /** * Updates ATIS controllers with the new data from vATIS. * @param data The new ATIS data from vATIS @@ -173,50 +97,6 @@ class ActionManager extends EventEmitter { }); } - /** - * Called when an ATIS letter action has a short press. Clears the state. - * @param actionId The ID of the action that had the short press - */ - public atisLetterShortPress(action: KeyAction) { - const savedAction = this.getAtisLetterControllers().find( - (entry) => entry.action.id === action.id - ); - - if (!savedAction?.station) { - return; - } - - // Send a clear request to vATIS - vAtisManager.sendMessage({ - type: "acknowledgeAtisUpdate", - value: { - station: savedAction.station, - atisType: savedAction.atisType, - }, - }); - } - - /** - * Called when an ATIS letter action has a long press. Refreshses the ATIS. - * @param actionId The ID of the action that had the long press - */ - public atisLetterLongPress(action: KeyAction) { - const savedAction = this.getAtisLetterControllers().find( - (entry) => entry.action.id === action.id - ); - - if (!savedAction) { - return; - } - - savedAction.reset(); - vAtisManager.refreshAtis(savedAction.station, savedAction.atisType); - - action.showOk().catch((error: unknown) => { - handleAsyncException("Unable to show OK on ATIS button:", error); - }); - } - /** * Resets the ATIS letter on all ATIS letter actions to undefined. */ @@ -272,15 +152,6 @@ class ActionManager extends EventEmitter { entry.reset(); }); } - - /** - * Called when a vAtis status action keydown event is triggered. - * Clears the new ATIS state on all ATIS stations. - * @param _ The action - */ - public vAtisStatusLongPress(_: KeyAction) { - vAtisManager.sendMessage({ type: "acknowledgeAtisUpdate" }); - } } const actionManagerInstance = ActionManager.getInstance(); diff --git a/src/managers/vatis.ts b/src/managers/vatis.ts index c6698ac..ea62ab6 100644 --- a/src/managers/vatis.ts +++ b/src/managers/vatis.ts @@ -146,10 +146,17 @@ class VatisManager extends EventEmitter { /** * Sends a message to vATIS to get the ATIS for a specific station. + * If the station is omitted refreshes all stations regardless of type. * @param station Station to refresh + * @param atisType Station type to refresh */ public refreshAtis(station?: string, atisType?: AtisType) { - if (!station || !atisType || !this.isConnected) { + if (!this.isConnected) { + return; + } + + if (!station) { + this.sendMessage({ type: "getAtis" }); return; } diff --git a/src/plugin.ts b/src/plugin.ts index 9890d78..25cf5fe 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -4,14 +4,14 @@ import mainLogger from "@utils/logger"; import vAtisManager from "@managers/vatis"; import actionManager from "@managers/action"; -import { handleConnected } from "@eventHandlers/vAtis/connected"; -import { handleDisconnected } from "@eventHandlers/vAtis/disconnected"; -import { handleActionAdded } from "@eventHandlers/action/actionAdded"; -import { handleActionRemoved } from "@eventHandlers/action/actionRemoved"; +import { handleConnected } from "@events/vAtis/connected"; +import { handleDisconnected } from "@events/vAtis/disconnected"; +import { handleActionAdded } from "@events/action/actionAdded"; +import { handleActionRemoved } from "@events/action/actionRemoved"; import { AtisLetter } from "@actions/atisLetter"; -import { handleAtisLetterAdded } from "@eventHandlers/action/atisLetterAdded"; -import { handleAtisLetterUpdated } from "@eventHandlers/action/atisLetterUpdated"; -import { handleAtisUpdate } from "@eventHandlers/vAtis/atisUpdate"; +import { handleAtisLetterAdded } from "@events/action/atisLetterAdded"; +import { handleAtisLetterUpdated } from "@events/action/atisLetterUpdated"; +import { handleAtisUpdate } from "@events/vAtis/atisUpdate"; const logger = mainLogger.child({ service: "plugin" }); diff --git a/tsconfig.json b/tsconfig.json index d768859..3b2c8b4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,21 @@ { - "extends": "@tsconfig/node20/tsconfig.json", - "compilerOptions": { - "customConditions": [ - "node" - ], - "module": "ES2022", - "moduleResolution": "Bundler", - "noImplicitOverride": true, - "paths": { + "extends": "@tsconfig/node20/tsconfig.json", + "compilerOptions": { + "customConditions": ["node"], + "module": "ES2022", + "moduleResolution": "Bundler", + "noImplicitOverride": true, + "paths": { "@actions/*": ["./src/actions/*"], "@controllers/*": ["./src/controllers/*"], - "@eventHandlers/*": ["./src/eventHandlers/*"], + "@events/*": ["./src/events/*"], "@helpers/*": ["./src/helpers/*"], "@interfaces/*": ["./src/interfaces/*"], "@managers/*": ["./src/managers/*"], "@utils/*": ["./src/utils/*"], "@root/*": ["./src/*"] } - }, - "include": [ - "src/**/*.ts" - ], - "exclude": [ - "node_modules" - ] -} \ No newline at end of file + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules"] +}