From 951df00232704c6c5be45dca3fce3a300b00f728 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 05:34:21 -0800 Subject: [PATCH 1/9] Update getter and setter doc comments for consistency Fixes #364 --- src/controllers/atisLetter.ts | 58 ++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/controllers/atisLetter.ts b/src/controllers/atisLetter.ts index 69358fc..b2e4d6b 100644 --- a/src/controllers/atisLetter.ts +++ b/src/controllers/atisLetter.ts @@ -3,9 +3,9 @@ import { KeyAction } from "@elgato/streamdeck"; import { Controller } from "@interfaces/controller"; import TitleBuilder from "@root/utils/titleBuilder"; import { stringOrUndefined } from "@root/utils/utils"; -import { BaseController } from "./baseController"; -import debounce from "debounce"; import { ATIS_LETTER_CONTROLLER_TYPE } from "@utils/controllerTypes"; +import debounce from "debounce"; +import { BaseController } from "./baseController"; const defaultTemplatePath = "images/actions/atisLetter/template.svg"; @@ -57,16 +57,18 @@ export class AtisLetterController extends BaseController { //#region Getters and setters /** - * Gets the autoClear setting, returning true as default if it wasn't set. + * Gets the autoClear setting. + * @returns {boolean} True if auto clear is enabled. Defaults to true. */ - get autoClear() { + get autoClear(): boolean { return this.settings.autoClear ?? true; } /** - * Gets isUnavailable, which is true if no ATIS letter was available in the last VATSIM update. + * Gets isUnavailable. + * @returns {boolean} True if no ATIS letter is available for the station. */ - get isUnavailable() { + get isUnavailable(): boolean { return this._isUnavailable; } @@ -84,15 +86,16 @@ export class AtisLetterController extends BaseController { } /** - * Returns the callsign for the ATIS action. + * Gets the callsign for the ATIS action. + * @returns {string} The callsign, or undefined if no callsign is set. */ - get callsign() { + get callsign(): string | undefined { return this.settings.callsign; } /** - * Returns the currentImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the current image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get currentImagePath(): string { return this._currentImagePath ?? defaultTemplatePath; @@ -106,8 +109,8 @@ export class AtisLetterController extends BaseController { } /** - * Returns the updatedImagePath or the default template path if the user - * didn't specify a custom icon. + * Gets the path to the updated image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get updatedImagePath(): string { return this._updatedImagePath ?? defaultTemplatePath; @@ -121,8 +124,8 @@ export class AtisLetterController extends BaseController { } /** - * Returns the unavailableImagePath or the default unavailable template path - * if the user didn't specify a custom icon. + * Gets the path to the unavailable image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get unavailableImagePath(): string { return this._unavailableImagePath ?? defaultTemplatePath; @@ -136,23 +139,26 @@ export class AtisLetterController extends BaseController { } /** - * Returns the showTitle setting, or true if undefined. + * Gets the showTitle setting. + * @returns {boolean} True if showTitle is enabled. Defaults to true. */ - get showTitle() { + get showTitle(): boolean { return this.settings.showTitle ?? true; } /** - * Returns the showLetter setting, or true if undefined. + * Gets the showLetter setting. + * @returns {boolean} True if showLetter is enabled. Defaults to true. */ - get showLetter() { + get showLetter(): boolean { return this.settings.showLetter ?? true; } /** * Gets the settings. + * @returns {AtisLetterSettings} The settings. */ - get settings() { + get settings(): AtisLetterSettings { if (this._settings === null) { throw new Error("Settings not initialized. This should never happen."); } @@ -161,8 +167,7 @@ export class AtisLetterController extends BaseController { } /** - * Sets the settings. Also updates the private icon paths and - * compiled SVGs. + * Sets the settings. Also updates the private icon paths. */ set settings(newValue: AtisLetterSettings) { this._settings = newValue; @@ -176,8 +181,9 @@ export class AtisLetterController extends BaseController { /** * Gets the isUpdated state on the action. + * @returns {boolean} True if the ATIS is updated. */ - public get isUpdated() { + public get isUpdated(): boolean { return this._isUpdated; } @@ -204,13 +210,14 @@ export class AtisLetterController extends BaseController { /** * Gets the current ATIS letter. + * @returns {string | undefined} The current ATIS letter, or undefined if no letter is set. */ get letter(): string | undefined { return this._letter; } /** - * Sets the current AITS letter. + * Sets the current ATIS letter and updates the display. */ set letter(newLetter: string | undefined) { // This crazy check catches two situations where the state should not show as updated: @@ -227,9 +234,10 @@ export class AtisLetterController extends BaseController { } /** - * Convenience method to return the action's title from settings. + * Gets the action's title from settings. + * @returns { string | undefined } The title, or undefined if none is set. */ - get title() { + get title(): string | undefined { return this.settings.title; } //#endregion From 526d027bf861bdb5cb5dc91893c687c8789f3cda Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 05:36:44 -0800 Subject: [PATCH 2/9] Update baseController --- src/controllers/baseController.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/controllers/baseController.ts b/src/controllers/baseController.ts index 6d82a73..5991e9a 100644 --- a/src/controllers/baseController.ts +++ b/src/controllers/baseController.ts @@ -20,7 +20,7 @@ export abstract class BaseController implements Controller { /** * Initializes the BaseController. - * @param action The Stream Deck icon this wraps + * @param action The Stream Deck action this wraps */ constructor(action: KeyAction | DialAction) { this.action = action; @@ -48,11 +48,11 @@ export abstract class BaseController implements Controller { } /** - * Sets the image on the tracked action. If the image is a stored + * Sets the image on a key action. If the image is a stored * SVG template then the template is populated and used. Otherwise * the path is used directly. - * @param imagePath The path to the image - * @param replacements The replacements to use + * @param imagePath The path to the image. + * @param replacements The replacements to use. */ setImage(imagePath: string, replacements: object) { const generatedSvg = svgManager.renderSvg(imagePath, replacements); @@ -67,6 +67,13 @@ export abstract class BaseController implements Controller { } } + /** + * Sets the feedback image on a dial action. If the image is a stored + * SVG template then the template is populated and used. Otherwise + * the path is used directly. + * @param imagePath The path to the image. + * @param replacements The replacements to use. + */ setFeedbackImage(imagePath: string, replacements: object) { if (!this.action.isDial()) { return; From f462193f4a74acbdd8d39ca991f1e9b388c56257 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 05:44:23 -0800 Subject: [PATCH 3/9] Hotline --- src/controllers/atisLetter.ts | 6 +- src/controllers/hotline.ts | 114 +++++++++++++++++++--------------- 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/controllers/atisLetter.ts b/src/controllers/atisLetter.ts index b2e4d6b..8faa0ed 100644 --- a/src/controllers/atisLetter.ts +++ b/src/controllers/atisLetter.ts @@ -102,7 +102,7 @@ export class AtisLetterController extends BaseController { } /** - * Sets the currentImagePath and re-compiles the SVG template if necessary. + * Sets the currentImagePath. */ set currentImagePath(newValue: string | undefined) { this._currentImagePath = stringOrUndefined(newValue); @@ -117,7 +117,7 @@ export class AtisLetterController extends BaseController { } /** - * Sets the updatedImagePath and re-compiles the SVG template if necessary. + * Sets the updatedImagePath. */ set updatedImagePath(newValue: string | undefined) { this._updatedImagePath = stringOrUndefined(newValue); @@ -132,7 +132,7 @@ export class AtisLetterController extends BaseController { } /** - * Sets the unavailableImagePath and re-compiles the SVG template if necessary. + * Sets the unavailableImagePath. */ set unavailableImagePath(newValue: string | undefined) { this._unavailableImagePath = stringOrUndefined(newValue); diff --git a/src/controllers/hotline.ts b/src/controllers/hotline.ts index d77350d..4e355a4 100644 --- a/src/controllers/hotline.ts +++ b/src/controllers/hotline.ts @@ -1,12 +1,12 @@ import { HotlineSettings } from "@actions/hotline"; import { KeyAction } from "@elgato/streamdeck"; import { Controller } from "@interfaces/controller"; +import trackAudioManager from "@managers/trackAudio"; import TitleBuilder from "@root/utils/titleBuilder"; import { stringOrUndefined } from "@root/utils/utils"; -import { BaseController } from "./baseController"; -import debounce from "debounce"; import { HOTLINE_CONTROLLER_TYPE } from "@utils/controllerTypes"; -import trackAudioManager from "@managers/trackAudio"; +import debounce from "debounce"; +import { BaseController } from "./baseController"; const defaultTemplatePath = "images/actions/hotline/template.svg"; @@ -70,113 +70,114 @@ export class HotlineController extends BaseController { //#region Getters/setters /** - * Convenience method to return the action's title from settings or empty string - * if it is undefined. + * Gets the action's title from settings. + * @returns { string | undefined } The title, or undefined if none is set. */ - get title() { + get title(): string | undefined { return this.settings.title ?? ""; } /** - * Returns the bothActiveImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the both active image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get bothActiveImagePath(): string { return this._bothActiveImagePath ?? defaultTemplatePath; } /** - * Sets the bothActiveImagePath and re-compiles the SVG template if necessary. + * Sets the bothActiveImagePath. */ set bothActiveImagePath(newValue: string | undefined) { this._bothActiveImagePath = stringOrUndefined(newValue); } /** - * Returns the unavailableImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the unavailable image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get unavailableImagePath(): string { return this._unavailableImagePath ?? defaultTemplatePath; } /** - * Sets the unavailableImagePath and re-compiles the SVG template if necessary. + * Sets the unavailableImagePath. */ set unavailableImagePath(newValue: string | undefined) { this._unavailableImagePath = stringOrUndefined(newValue); } /** - * Returns the hotlineActiveImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the hotline active image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get hotlineActiveImagePath(): string { return this._hotlineActiveImagePath ?? defaultTemplatePath; } /** - * Sets the hotlineActiveImagePath and re-compiles the SVG template if necessary. + * Sets the hotlineActiveImagePath. */ set hotlineActiveImagePath(newValue: string | undefined) { this._hotlineActiveImagePath = stringOrUndefined(newValue); } /** - * Returns the listeningImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the listening image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get listeningImagePath(): string { return this._listeningImagePath ?? defaultTemplatePath; } /** - * Sets the listeningImagePath and re-compiles the SVG template if necessary. + * Sets the listeningImagePath. */ set listeningImagePath(newValue: string | undefined) { this._listeningImagePath = stringOrUndefined(newValue); } /** - * Returns the neitherActiveImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the neither active image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get neitherActiveImagePath(): string { return this._neitherActiveImagePath ?? defaultTemplatePath; } /** - * Sets the neitherActiveImagePath and re-compiles the SVG template if necessary. + * Sets the neitherActiveImagePath. */ set neitherActiveImagePath(newValue: string | undefined) { this._neitherActiveImagePath = stringOrUndefined(newValue); } /** - * Returns the receivingImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the receiving image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get receivingImagePath(): string { return this._receivingImagePath ?? defaultTemplatePath; } /** - * Sets the receivingImagePath and re-compiles the SVG template if necessary. + * Sets the receivingImagePath. */ set receivingImagePath(newValue: string | undefined) { this._receivingImagePath = stringOrUndefined(newValue); } /** - * Returns the frequency for the primary callsign. + * Gets the frequency for the primary callsign. + * @returns {number} The frequency or 0 if the frequency isn't set. */ - get primaryFrequency() { + get primaryFrequency(): number { return this._primaryFrequency; } /** * Sets the frequency for the primary callsign and updates the isAvailable - * to true if both primary and hotline frequency are set + * to true if both primary and hotline frequency are set. */ set primaryFrequency(newValue: number) { // This is always done even if the new value is the same as the existing one @@ -190,8 +191,9 @@ export class HotlineController extends BaseController { /** * Gets the frequency for the hotline callsign. + * @returns {number} The frequency or 0 if the frequency isn't set. */ - get hotlineFrequency() { + get hotlineFrequency(): number { return this._hotlineFrequency; } @@ -210,14 +212,15 @@ export class HotlineController extends BaseController { } /** - * True if both the primary and hotline frequencies are available in TrackAudio. + * Gets the isAvailable value. + * @returns {boolean | undefined} True if both the primary and hotline frequencies are available in TrackAudio. */ get isAvailable(): boolean | undefined { return this._isAvailable; } /** - * Sets the isAvailable property and updates the action image accordingly. + * Sets the isAvailable property and updates the action image. */ set isAvailable(newValue: boolean | undefined) { if (this._isAvailable === newValue) { @@ -229,7 +232,8 @@ export class HotlineController extends BaseController { } /** - * Sets whether the hotline frequency is actively receiving a communication. + * Sets whether the hotline frequency is actively receiving a communication + * and updates the action image. */ set isReceiving(newValue: boolean) { // Don't do anything if the state is the same @@ -242,16 +246,18 @@ export class HotlineController extends BaseController { } /** - * True if the hotline frequency is actively receicving a communication. + * Gets the isReceiving property. + * @returns {boolean} True if the hotline frequency is actively receiving a communication. */ - get isReceiving() { + get isReceiving(): boolean { return this._isReceiving; } /** - * True if the station has Tx enabled on the primary frequency. + * Gets the isTxPrimary property. + * @returns {boolean} True if the station has Tx enabled on the primary frequency. */ - get isTxPrimary() { + get isTxPrimary(): boolean { return this._isTxPrimary; } @@ -263,9 +269,10 @@ export class HotlineController extends BaseController { } /** - * True if the station has Tx enabled on the hotline frequency. + * Gets the isTxHotline property. + * @returns {boolean} True if the station has Tx enabled on the hotline frequency. */ - get isTxHotline() { + get isTxHotline(): boolean { return this._isTxHotline; } @@ -277,9 +284,10 @@ export class HotlineController extends BaseController { } /** - * True if the station has Rx enabled on the hotline frequency. + * Gets the isRxHotline property. + * @returns {boolean} True if the station has Rx enabled on the hotline frequency. */ - get isRxHotline() { + get isRxHotline(): boolean { return this._isRxHotline; } @@ -291,44 +299,50 @@ export class HotlineController extends BaseController { } /** - * Convenience property to get the primaryCallsign value of settings. + * Gets the primaryCallsign value from settings. + * @returns {string | undefined} The primary callsign, or undefined if not specified. */ - get primaryCallsign() { + get primaryCallsign(): string | undefined { return this.settings.primaryCallsign; } /** - * Convenience property to get the hotlineCallsign value of settings. + * Gets the hotlineCallsign value from settings. + * @returns {string | undefined} The hotline callsign, or undefined if not specified. */ - get hotlineCallsign() { + get hotlineCallsign(): string | undefined { return this.settings.hotlineCallsign; } /** - * Returns the showTitle setting, or true if undefined. + * Gets the showTitle setting. + * @returns {boolean} True if showTitle is enabled. Defaults to true. */ - get showTitle() { + get showTitle(): boolean { return this.settings.showTitle ?? true; } /** - * Returns the showHotlineCallsign setting, or false if undefined. + * Gets the showHotlineCallsign setting. + * @returns {boolean} True if showHotlineCallsign is enabled. Defaults to true. */ - get showHotlineCallsign() { + get showHotlineCallsign(): boolean { return this.settings.showHotlineCallsign ?? false; } /** - * Returns the showPrimaryCallsign setting, or false if undefined. + * Gets the showPrimaryCallsign setting. + * @returns {boolean} True if showPrimaryCallsign is enabled. Defaults to true. */ - get showPrimaryCallsign() { + get showPrimaryCallsign(): boolean { return this.settings.showPrimaryCallsign ?? false; } /** * Gets the settings. + * @returns {HotlineSettings} The settings. */ - get settings() { + get settings(): HotlineSettings { if (this._settings === null) { throw new Error("Settings not initialized. This should never happen."); } From aa0dfabbccd08a4af73f5e8b753509e53b71f267 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 06:01:44 -0800 Subject: [PATCH 4/9] mainVolume --- src/controllers/atisLetter.ts | 4 ++-- src/controllers/hotline.ts | 4 ++-- src/controllers/mainVolume.ts | 42 ++++++++++++++++++++++------------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/controllers/atisLetter.ts b/src/controllers/atisLetter.ts index 8faa0ed..ea964d3 100644 --- a/src/controllers/atisLetter.ts +++ b/src/controllers/atisLetter.ts @@ -243,7 +243,7 @@ export class AtisLetterController extends BaseController { //#endregion /** - * Sets the image based on the state of the action. + * Sets the displayed image based on the state of the action. */ private refreshImage() { const replacements = { @@ -275,7 +275,7 @@ export class AtisLetterController extends BaseController { } /** - * Sets the title on the action. + * Sets the displayed title based on the state of the action. */ private refreshTitle() { const title = new TitleBuilder(); diff --git a/src/controllers/hotline.ts b/src/controllers/hotline.ts index 4e355a4..9e8ad67 100644 --- a/src/controllers/hotline.ts +++ b/src/controllers/hotline.ts @@ -384,7 +384,7 @@ export class HotlineController extends BaseController { //#endregion /** - * Sets the title on the action. + * Sets the displayed title based on the state of the action. */ private refreshTitle() { const title = new TitleBuilder(); @@ -398,7 +398,7 @@ export class HotlineController extends BaseController { } /** - * Sets the image based on the state of the action. + * Sets the displayed image based on the state of the action. */ private refreshImage() { const replacements = { diff --git a/src/controllers/mainVolume.ts b/src/controllers/mainVolume.ts index fafbbca..134fe75 100644 --- a/src/controllers/mainVolume.ts +++ b/src/controllers/mainVolume.ts @@ -8,9 +8,7 @@ import { stringOrUndefined } from "@utils/utils"; import debounce from "debounce"; import { BaseController } from "./baseController"; -const defaultConnectedTemplatePath = "images/actions/mainVolume/template.svg"; -const defaultNotConnectedTemplatePath = - "images/actions/mainVolume/template.svg"; +const defaultTemplatePath = "images/actions/mainVolume/template.svg"; export class MainVolumeController extends BaseController { type = MAIN_VOLUME_CONTROLLER_TYPE; @@ -25,8 +23,8 @@ export class MainVolumeController extends BaseController { /** * Creates a new MainVolumeController object. - * @param action The dial action associated with the controller - * @param settings: The options for the action + * @param action The dial action associated with the controller. + * @param settings: The options for the action. */ constructor(action: DialAction, settings: MainVolumeSettings) { super(action); @@ -43,42 +41,45 @@ export class MainVolumeController extends BaseController { }, 100); /** - * Gets the connected SVG template path. + * Gets the path to the connected image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get connectedTemplatePath(): string { - return this._connectedTemplatePath ?? defaultConnectedTemplatePath; + return this._connectedTemplatePath ?? defaultTemplatePath; } /** - * Sets the connected SVG template path. + * Sets the connectedTemplatePath. */ set connectedTemplatePath(newValue: string | undefined) { this._connectedTemplatePath = stringOrUndefined(newValue); } /** - * Gets the not connected SVG template path. + * Gets the path to the not connected image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get notConnectedTemplatePath(): string { - return this._notConnectedTemplatePath ?? defaultNotConnectedTemplatePath; + return this._notConnectedTemplatePath ?? defaultTemplatePath; } /** - * Sets the not connected SVG template path. + * Sets the notConnectedTemplatePath. */ set notConnectedTemplatePath(newValue: string | undefined) { this._notConnectedTemplatePath = stringOrUndefined(newValue); } /** - * Gets the output volume. Returns 100 if undefined. + * Gets the output volume. + * @returns {number} The output volume. Defaults to 100. **/ get volume(): number { return this._volume; } /** - * Sets the output volume. + * Sets the output volume and refreshes the action display. **/ set volume(newValue: number) { if (this._volume === newValue) { @@ -94,6 +95,7 @@ export class MainVolumeController extends BaseController { /** * Gets the settings. + * @returns {MainVolumeSettings} The settings. */ get settings(): MainVolumeSettings { if (this._settings === null) { @@ -115,19 +117,26 @@ export class MainVolumeController extends BaseController { } /** - * Convenience property to get the changeAmount value of settings. + * Gets the changeAmount. + * @returns {number} The amount to change the volume on each dial tick. Defaults to 2. */ - get changeAmount() { + get changeAmount(): number { const amount = this.settings.changeAmount ?? 2; return amount > 0 ? amount : 2; } + /** + * Resets the action to defaults and refreshes the display. + */ override reset(): void { this._volume = 100; this.refreshDisplay(); } + /** + * Sets the displayed image based on the state of the action. + */ private refreshImage(): void { const replacements = { volume: this.volume, @@ -141,6 +150,9 @@ export class MainVolumeController extends BaseController { this.setFeedbackImage(templatePath, replacements); } + /** + * Sets the displayed title based on the state of the action. + */ private refreshTitle(): void { if (!trackAudioManager.isVoiceConnected) { this.action From fef7a529cee71bb050085c7adff0a492f413c02a Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 06:06:02 -0800 Subject: [PATCH 5/9] PushToTalk --- src/controllers/pushToTalk.ts | 40 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/controllers/pushToTalk.ts b/src/controllers/pushToTalk.ts index 0aff09b..9d8870d 100644 --- a/src/controllers/pushToTalk.ts +++ b/src/controllers/pushToTalk.ts @@ -3,9 +3,9 @@ import { KeyAction } from "@elgato/streamdeck"; import { Controller } from "@interfaces/controller"; import TitleBuilder from "@root/utils/titleBuilder"; import { stringOrUndefined } from "@root/utils/utils"; -import { BaseController } from "./baseController"; -import debounce from "debounce"; import { PUSH_TO_TALK_CONTROLLER_TYPE } from "@utils/controllerTypes"; +import debounce from "debounce"; +import { BaseController } from "./baseController"; const defaultTemplatePath = "images/actions/pushToTalk/template.svg"; @@ -40,7 +40,7 @@ export class PushToTalkController extends BaseController { }, 100); /** - * Resets the action to its default, disconnected, state. + * Resets the action to its default state. */ public reset() { this.isTransmitting = false; @@ -48,53 +48,56 @@ export class PushToTalkController extends BaseController { //#region Getters and setters /** - * Returns the transmittingImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the transmitting image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get transmittingImagePath(): string { return this._transmittingImagePath ?? defaultTemplatePath; } /** - * Sets the transmittingImagePath and re-compiles the SVG template if necessary. + * Sets the transmittingImagePath. */ set transmittingImagePath(newValue: string | undefined) { this._transmittingImagePath = stringOrUndefined(newValue); } /** - * Returns the notTransmittingImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the not transmitting image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get notTransmittingImagePath(): string { return this._notTransmittingImagePath ?? defaultTemplatePath; } /** - * Sets the notTransmittingImagePath and re-compiles the SVG template if necessary. + * Sets the notTransmittingImagePath. */ set notTransmittingImagePath(newValue: string | undefined) { this._notTransmittingImagePath = stringOrUndefined(newValue); } /** - * Convenience method to return the action's title from settings. + * Gets the action's title from settings. + * @returns { string | undefined } The title, or undefined if none is set. */ - get title() { + get title(): string | undefined { return this.settings.title; } /** - * Returns the showTitle setting, or false if undefined. + * Gets the showTitle setting. + * @returns {boolean} True if showTitle is enabled. Defaults to true. */ - get showTitle() { + get showTitle(): boolean { return this.settings.showTitle ?? false; } /** - * True if push-to-talk is actively transmitting. + * Gets the isTransmitting property. + * @returns {boolean} True if transmitting is active. */ - get isTransmitting() { + get isTransmitting(): boolean { return this._isTransmitting; } @@ -113,8 +116,9 @@ export class PushToTalkController extends BaseController { /** * Gets the settings. + * @returns {PushToTalkSettings} The settings. */ - get settings() { + get settings(): PushToTalkSettings { if (this._settings === null) { throw new Error("Settings not initialized. This should never happen."); } @@ -136,7 +140,7 @@ export class PushToTalkController extends BaseController { //#endregion /** - * Sets the title on the action. + * Sets the displayed title based on the state of the action. */ private refreshTitle() { const title = new TitleBuilder(); @@ -147,7 +151,7 @@ export class PushToTalkController extends BaseController { } /** - * Sets the action image to the correct one for when comms are active. + * Sets the displayed image based on the state of the action. */ private refreshImage() { const replacements = { From 323ddb47256705cc4f5636321d4f37548e112490 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 06:22:42 -0800 Subject: [PATCH 6/9] stationStatus --- src/actions/stationStatus.ts | 26 ++- src/controllers/atisLetter.ts | 8 +- src/controllers/stationStatus.ts | 187 ++++++++++-------- .../streamDeck/stationStatus/addStation.ts | 4 +- .../streamDeck/stationStatus/updateStation.ts | 4 +- 5 files changed, 129 insertions(+), 100 deletions(-) diff --git a/src/actions/stationStatus.ts b/src/actions/stationStatus.ts index 989b89a..3094d6d 100644 --- a/src/actions/stationStatus.ts +++ b/src/actions/stationStatus.ts @@ -9,8 +9,8 @@ import { WillAppearEvent, WillDisappearEvent, } from "@elgato/streamdeck"; -import { handleAddStation } from "@events/streamDeck/stationStatus/addStation"; import { handleRemove } from "@events/streamDeck/remove"; +import { handleAddStation } from "@events/streamDeck/stationStatus/addStation"; import { handleStationStatusLongPress } from "@events/streamDeck/stationStatus/stationStatusLongPress"; import { handleStationStatusShortPress } from "@events/streamDeck/stationStatus/stationStatusShortPress"; import { handleUpdateStation } from "@events/streamDeck/stationStatus/updateStation"; @@ -21,18 +21,21 @@ import debounce from "debounce"; /** * Represents the status of a TrackAudio station */ -export class StationStatus extends SingletonAction { +export class StationStatus extends SingletonAction { private _keyDownStart = 0; - debouncedUpdate = debounce((action: KeyAction, settings: StationSettings) => { - handleUpdateStation(action, settings); - }, 300); + debouncedUpdate = debounce( + (action: KeyAction, settings: StationStatusSettings) => { + handleUpdateStation(action, settings); + }, + 300 + ); // When the action is added to a profile it gets saved in the ActionManager // instance for use elsewhere in the code. The default title is also set // to something useful. override onWillAppear( - ev: WillAppearEvent + ev: WillAppearEvent ): void | Promise { // This should never happen. Typeguard to ensure the rest of the code can just use // KeyAction. @@ -45,7 +48,7 @@ export class StationStatus extends SingletonAction { // When the action is removed from a profile it also gets removed from the ActionManager. override onWillDisappear( - ev: WillDisappearEvent + ev: WillDisappearEvent ): void | Promise { handleRemove(ev.action); } @@ -53,7 +56,7 @@ export class StationStatus extends SingletonAction { // When settings are received the ActionManager is called to update the existing // settings on the saved action. override onDidReceiveSettings( - ev: DidReceiveSettingsEvent + ev: DidReceiveSettingsEvent ): void | Promise { // This should never happen. Typeguard to ensure the rest of the code can just use // KeyAction. @@ -68,7 +71,9 @@ export class StationStatus extends SingletonAction { this._keyDownStart = Date.now(); } - override onKeyUp(ev: KeyUpEvent): Promise | void { + override onKeyUp( + ev: KeyUpEvent + ): Promise | void { const pressLength = Date.now() - this._keyDownStart; if (pressLength > LONG_PRESS_THRESHOLD) { @@ -79,8 +84,9 @@ export class StationStatus extends SingletonAction { } } -export interface StationSettings { +export interface StationStatusSettings { autoSetListen?: boolean; + autoSetSpk?: boolean; autoSetRx?: boolean; blockedCommsImagePath?: string; activeCommsImagePath?: string; diff --git a/src/controllers/atisLetter.ts b/src/controllers/atisLetter.ts index ea964d3..2b1cafb 100644 --- a/src/controllers/atisLetter.ts +++ b/src/controllers/atisLetter.ts @@ -86,8 +86,8 @@ export class AtisLetterController extends BaseController { } /** - * Gets the callsign for the ATIS action. - * @returns {string} The callsign, or undefined if no callsign is set. + * Gets the callsign value from settings. + * @returns {string | undefined} The callsign. Defaults to undefined. */ get callsign(): string | undefined { return this.settings.callsign; @@ -234,8 +234,8 @@ export class AtisLetterController extends BaseController { } /** - * Gets the action's title from settings. - * @returns { string | undefined } The title, or undefined if none is set. + * Gets the title value from settings. + * @returns { string | undefined } The title. Defaults to undefined. */ get title(): string | undefined { return this.settings.title; diff --git a/src/controllers/stationStatus.ts b/src/controllers/stationStatus.ts index 07b0910..1a47a65 100644 --- a/src/controllers/stationStatus.ts +++ b/src/controllers/stationStatus.ts @@ -1,6 +1,7 @@ -import { StationSettings } from "@actions/stationStatus"; +import { StationStatusSettings } from "@actions/stationStatus"; import { KeyAction } from "@elgato/streamdeck"; import { Controller } from "@interfaces/controller"; +import trackAudioManager from "@managers/trackAudio"; import TitleBuilder from "@root/utils/titleBuilder"; import { stringOrUndefined } from "@root/utils/utils"; import { STATION_STATUS_CONTROLLER_TYPE } from "@utils/controllerTypes"; @@ -8,7 +9,6 @@ import mainLogger from "@utils/logger"; import debounce from "debounce"; import { LRUCache } from "lru-cache"; import { BaseController } from "./baseController"; -import trackAudioManager from "@managers/trackAudio"; // Valid values for the ListenTo property. This must match // the list of array property names that come from TrackAudio @@ -33,7 +33,7 @@ export class StationStatusController extends BaseController { private _isReceiving = false; private _isTransmitting = false; private _outputVolume? = 100; - private _settings: StationSettings | null = null; + private _settings: StationStatusSettings | null = null; // This gets initialized in the settings setter so it can be re-created if the // number of callsigns to track changes. @@ -52,7 +52,7 @@ export class StationStatusController extends BaseController { * @param action The callsign for the action * @param settings: The options for the action */ - constructor(action: KeyAction, settings: StationSettings) { + constructor(action: KeyAction, settings: StationStatusSettings) { super(action); this.action = action; @@ -70,90 +70,91 @@ export class StationStatusController extends BaseController { //#region Getters and setters /** - * Returns the mutedImagePath or the default template path if the if - * the user didn't specify a custom icon. + * Gets the path to the muted image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get mutedImagePath(): string { return this._mutedImagePath ?? defaultTemplatePath; } /** - * Returns the notListeningImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the not listening image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get notListeningImagePath(): string { return this._notListeningImagePath ?? defaultTemplatePath; } /** - * Sets the notListeningImagePath and re-compiles the SVG template if necessary. + * Sets the notListeningImagePath. */ set notListeningImagePath(newValue: string | undefined) { this._notListeningImagePath = stringOrUndefined(newValue); } /** - * Returns the listeningImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the listening image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get listeningImagePath(): string { return this._listeningImagePath ?? defaultTemplatePath; } /** - * Sets the listeningImagePath and re-compiles the SVG template if necessary. + * Sets the listeningImagePath. */ set listeningImagePath(newValue: string | undefined) { this._listeningImagePath = stringOrUndefined(newValue); } /** - * Returns the blockingImagePath or the default blocking image path if the - * user didn't specify a custom icon. + * Gets the path to the blocking coms image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get blockedCommsImagePath(): string { return this._blockedCommsImagePath ?? defaultTemplatePath; } /** - * Sets the activeCommsImagePath and re-compiles the SVG template if necessary. + * Sets the blockingComsImagePath. */ set blockedCommsImagePath(newValue: string | undefined) { this._blockedCommsImagePath = stringOrUndefined(newValue); } /** - * Returns the activeCommsImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the active coms image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get activeCommsImagePath(): string { return this._activeCommsImagePath ?? defaultTemplatePath; } /** - * Sets the activeCommsImagePath and re-compiles the SVG template if necessary. + * Sets the activeCommsImagePath. */ set activeCommsImagePath(newValue: string | undefined) { this._activeCommsImagePath = stringOrUndefined(newValue); } /** - * Returns the unavailableImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the unavailable image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get unavailableImagePath(): string { return this._unavailableImagePath ?? defaultTemplatePath; } /** - * Sets the unavailableImagePath and re-compiles the SVG template if necessary. + * Sets the unavailableImagePath. */ set unavailableImagePath(newValue: string | undefined) { this._unavailableImagePath = stringOrUndefined(newValue); } /** - * Gets whether the output is muted. Returns false if undefined. + * Gets the isOutputMuted property. + * @returns {boolean} True if the station is muted. Defaults to false. */ get isOutputMuted(): boolean { return this._isOutputMuted ?? false; @@ -172,8 +173,9 @@ export class StationStatusController extends BaseController { } /** - * Gets the output volume. Returns 100 if undefined. - **/ + * Gets the output volume property. + * @returns {number} The output volume. Defaults to 100. + */ get outputVolume(): number { return this._outputVolume ?? 100; } @@ -191,9 +193,10 @@ export class StationStatusController extends BaseController { } /** - * Gets the frequency. + * Gets the frequency for the station callsign. + * @returns {number} The frequency or 0 if the frequency isn't set. */ - get frequency() { + get frequency(): number { return this._frequency; } @@ -212,11 +215,12 @@ export class StationStatusController extends BaseController { } /** - * Returns the frequency formatted for display. A value of 121900000 - * will be returned as "121.900". If the frequency is undefined or 0 + * Gets the frequency formatted for display. A value of 121900000 + * will be returned as 121.900. If the frequency is undefined or 0 * then an empty string is returned. + * @returns {string} The frequency, or an empty string if no frequency is defined. */ - get formattedFrequency() { + get formattedFrequency(): string { if (this.frequency) { return (this.frequency / 1000000).toFixed(3); } else { @@ -225,24 +229,27 @@ export class StationStatusController extends BaseController { } /** - * Convenience property to get the listenTo value of settings. + * Gets the listenTo value from settings. + * @returns {string} The listen to value. Defaults to "rx". */ - get listenTo() { + get listenTo(): string { return this.settings.listenTo ?? "rx"; } /** - * Convenience property to get the toggleMuteIfPressed value of settings. Defaults to false. + * Gets the toggleMuteOnPress value from settings. + * @returns {boolean} The value. Defaults to false. */ - get toggleMuteOnPress() { + get toggleMuteOnPress(): boolean { return this.settings.toggleMuteOnPress ?? false; } /** - * Returns true if listenTo is rx, xc, or xca, the settings that mean - * rx is active in TrackAudio. + * Gets the isListeningForReceive property. + * @returns {boolean} Returns true if listenTo is rx, xc, or xca, + * the settings that mean rx is active in TrackAudio. */ - get isListeningForReceive() { + get isListeningForReceive(): boolean { return ( this.listenTo === "rx" || this.listenTo === "xc" || @@ -251,10 +258,11 @@ export class StationStatusController extends BaseController { } /** - * Returns true if listenTo is tx, xc or xca, the settings that mean - * tx is active in TrackAudio, and the station in TrackAudio is listening. + * Gets the isListeningForTransmit property. + * @returns {boolean} Returns true if listenTo is tx, xc, or xca, + * the settings that mean tx is active in TrackAudio. */ - get isListeningForTransmit() { + get isListeningForTransmit(): boolean { return ( (this.listenTo === "tx" || this.listenTo === "xc" || @@ -264,80 +272,90 @@ export class StationStatusController extends BaseController { } /** - * Convenience property to get the callsign value of settings. + * Gets the callsign value from settings. + * @returns {string | undefined} The callsign. Defaults to undefined. */ - get callsign() { + get callsign(): string | undefined { return this.settings.callsign; } /** - * Returns the title specified by the user in the property inspector. + * Gets the title value from settings. + * @returns { string | undefined } The title. Defaults to undefined. */ - get title() { + get title(): string | undefined { return this.settings.title; } /** - * Returns the autoSetSpk setting, or false if undefined. + * Gets the autoSetSpk value from settings. + * @returns { boolean } The value. Defaults to false. */ - get autoSetSpk() { + get autoSetSpk(): boolean { return this.settings.autoSetSpk ?? false; } /** - * Returns the autoSetRx setting, or false if undefined. + * Gets the autoSetRx value from settings. + * @returns { boolean } The value. Defaults to false. */ - get autoSetRx() { + get autoSetRx(): boolean { return this.settings.autoSetRx ?? false; } /** - * Returns the showTitle setting, or true if undefined. + * Gets the showTitle value from settings. + * @returns { boolean } The value. Defaults to true. */ - get showTitle() { + get showTitle(): boolean { return this.settings.showTitle ?? true; } /** - * Returns the showCallsign setting, or false if undefined. + * Gets the showCallsign value from settings. + * @returns { boolean } The value. Defaults to false. */ - get showCallsign() { + get showCallsign(): boolean { return this.settings.showCallsign ?? false; } /** - * Returns the showListenTo setting, or false if undefined + * Gets the showLIstenTo value from settings. + * @returns { boolean } The value. Defaults to false. */ - get showListenTo() { + get showListenTo(): boolean { return this.settings.showListenTo ?? false; } /** - * Returns the showFrequency setting, or false if undefined + * Gets the showFrequency value from settings. + * @returns { boolean } The value. Defaults to false. */ - get showFrequency() { + get showFrequency(): boolean { return this.settings.showFrequency ?? false; } /** - * Returns true if the number of last received callsigns to display is greater than 0 + * Gets the showLastReceivedCallsign property. + * @returns { boolean } True if the lastReceivedCallsignCount property is greater than 0. Defaults to false. */ - get showLastReceivedCallsign() { + get showLastReceivedCallsign(): boolean { return (this.settings.lastReceivedCallsignCount ?? 0) > 0; } /** - * Returns the number of minutes to clear callsigns after, or three if it wasn't defined - * by the user in settings. + * Gets the clearAfterInMinutes value from settings. + * @returns { number } The value. Defaults to 3. */ - get clearAfterInMinutes() { + get clearAfterInMinutes(): number { return this.settings.clearAfterInMinutes ?? 3; } /** * Gets the settings. + * @return {StationStatusSettings} The settings. */ - get settings() { + get settings(): StationStatusSettings { if (this._settings === null) { throw new Error("Settings not initialized. This should never happen."); } @@ -348,7 +366,7 @@ export class StationStatusController extends BaseController { /** * Sets the settings. */ - set settings(newValue: StationSettings) { + set settings(newValue: StationStatusSettings) { // Issue 183: Clear the frequency if the callsign changes. if (this._settings && this._settings.callsign !== newValue.callsign) { this.frequency = 0; @@ -385,14 +403,15 @@ export class StationStatusController extends BaseController { } /** - * True if the station is actively receiving. + * Gets the isReceiving property. + * @returns {boolean} True if the station is currently receiving. */ - get isReceiving() { + get isReceiving(): boolean { return this._isReceiving; } /** - * Sets the isReceiving property and updates the action image accordingly. + * Sets the isReceiving property. */ set isReceiving(newValue: boolean) { // Don't do anything if the state is the same @@ -405,14 +424,15 @@ export class StationStatusController extends BaseController { } /** - * True if the station is actively transmitting. + * Gets the isTransmitting property. + * @returns {boolean} True if the station is currently transmitting. */ - get isTransmitting() { + get isTransmitting(): boolean { return this._isTransmitting; } /** - * Sets the isTransmitting property and updates the action image accordingly. + * Sets the isTransmitting property. */ set isTransmitting(newValue: boolean) { // Don't do anything if the state is the same @@ -425,14 +445,15 @@ export class StationStatusController extends BaseController { } /** - * True if the station is being listened to. + * Gets the isListening property. + * @returns {boolean} True if the station is currently listening. */ - get isListening() { + get isListening(): boolean { return this._isListening; } /** - * Sets the isListening property and updates the action image accordingly. + * Sets the isListening property. */ set isListening(newValue: boolean) { // Don't do anything if the state is the same @@ -445,7 +466,8 @@ export class StationStatusController extends BaseController { } /** - * True if the station is available in TrackAudio. + * Gets the isAvailable value. + * @returns {boolean | undefined} True if the station is available in TrackAudio. */ get isAvailable(): boolean | undefined { return this._isAvailable; @@ -463,6 +485,14 @@ export class StationStatusController extends BaseController { this.refreshDisplay(); } + /** + * Gets the lastReceivedCallsign property. + * @returns {string | undefined} The last received callsign. Default is undefined. + */ + get lastReceivedCallsign(): string | undefined { + return this._lastReceivedCallsign; + } + /** * Sets the last received callsign property and updates the action title accordingly. */ @@ -479,17 +509,10 @@ export class StationStatusController extends BaseController { } /** - * Returns the last received callsign. - */ - get lastReceivedCallsign() { - return this._lastReceivedCallsign; - } - - /** - * Returns an array of received callsigns, up to the length specified by the user in the - * action's settings. + * Gets the lastReceivedCallsignHistory property, up to the length specified by the user in settings. + * @returns {string[]} An array of callsigns. Default is []. */ - get lastReceivedCallsignHistory() { + get lastReceivedCallsignHistory(): string[] { const entries = this._lastReceivedCallsignHistory ? [...this._lastReceivedCallsignHistory.values()] : []; diff --git a/src/events/streamDeck/stationStatus/addStation.ts b/src/events/streamDeck/stationStatus/addStation.ts index 67db193..dead2b6 100644 --- a/src/events/streamDeck/stationStatus/addStation.ts +++ b/src/events/streamDeck/stationStatus/addStation.ts @@ -1,4 +1,4 @@ -import { StationSettings } from "@actions/stationStatus"; +import { StationStatusSettings } from "@actions/stationStatus"; import { StationStatusController } from "@controllers/stationStatus"; import { KeyAction } from "@elgato/streamdeck"; import actionManager from "@managers/action"; @@ -11,7 +11,7 @@ import actionManager from "@managers/action"; */ export const handleAddStation = ( action: KeyAction, - settings: StationSettings + settings: StationStatusSettings ) => { const controller = new StationStatusController(action, settings); diff --git a/src/events/streamDeck/stationStatus/updateStation.ts b/src/events/streamDeck/stationStatus/updateStation.ts index c25978e..76a0068 100644 --- a/src/events/streamDeck/stationStatus/updateStation.ts +++ b/src/events/streamDeck/stationStatus/updateStation.ts @@ -1,4 +1,4 @@ -import { StationSettings } from "@actions/stationStatus"; +import { StationStatusSettings } from "@actions/stationStatus"; import { KeyAction } from "@elgato/streamdeck"; import actionManager from "@managers/action"; @@ -11,7 +11,7 @@ import actionManager from "@managers/action"; */ export const handleUpdateStation = ( action: KeyAction, - settings: StationSettings + settings: StationStatusSettings ) => { const savedAction = actionManager .getStationStatusControllers() From 7619b73a771fc1d79b4b4f2f6df02030968e9f39 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 06:26:31 -0800 Subject: [PATCH 7/9] stationVolume --- src/controllers/stationVolume.ts | 45 +++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/controllers/stationVolume.ts b/src/controllers/stationVolume.ts index 791ac95..d49b6f4 100644 --- a/src/controllers/stationVolume.ts +++ b/src/controllers/stationVolume.ts @@ -45,7 +45,8 @@ export class StationVolumeController extends BaseController { }, 100); /** - * Gets the not muted SVG template path. + * Gets the path to the not muted image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get notMutedTemplatePath(): string { return this._notMutedTemplatePath ?? defaultTemplatePath; @@ -59,7 +60,8 @@ export class StationVolumeController extends BaseController { } /** - * Gets the muted SVG template path. + * Gets the path to the muted image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get mutedTemplatePath(): string { return this._mutedTemplatePath ?? defaultTemplatePath; @@ -73,7 +75,8 @@ export class StationVolumeController extends BaseController { } /** - * Gets the unavailable SVG template path. + * Gets the path to the unavailable image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get unavailableTemplatePath(): string { return this._unavailableTemplatePath ?? defaultTemplatePath; @@ -87,8 +90,9 @@ export class StationVolumeController extends BaseController { } /** - * Gets the output volume. Returns 100 if undefined. - **/ + * Gets the output volume property. + * @returns {number} The output volume. Defaults to 100. + */ get outputVolume(): number { return this._outputVolume ?? 100; } @@ -109,7 +113,8 @@ export class StationVolumeController extends BaseController { } /** - * Gets whether the output is muted. Returns false if undefined. + * Gets the isOutputMuted property. + * @returns {boolean} True if the station is muted. Defaults to false. */ get isOutputMuted(): boolean { return this._isOutputMuted ?? false; @@ -129,6 +134,7 @@ export class StationVolumeController extends BaseController { /** * Gets the settings. + * @returns {StationVolumeSettings} The settings. */ get settings(): StationVolumeSettings { if (this._settings === null) { @@ -156,16 +162,18 @@ export class StationVolumeController extends BaseController { } /** - * Convenience property to get the callsign value of settings. + * Gets the callsign value from settings. + * @returns {string | undefined} The callsign. Defaults to undefined. */ - get callsign() { + get callsign(): string | undefined { return this.settings.callsign; } /** - * Gets the frequency. + * Gets the frequency for the station callsign. + * @returns {number} The frequency or 0 if the frequency isn't set. */ - get frequency() { + get frequency(): number { return this._frequency; } @@ -184,7 +192,8 @@ export class StationVolumeController extends BaseController { } /** - * True if the station is available in TrackAudio. + * Gets the isAvailable value. + * @returns {boolean | undefined} True if the station is available in TrackAudio. */ get isAvailable(): boolean | undefined { return this._isAvailable; @@ -203,13 +212,17 @@ export class StationVolumeController extends BaseController { } /** - * Convenience property to get the changeAmount value of settings. + * Gets the changeAmount. + * @returns {number} The amount to change the volume on each dial tick. Defaults to 2. */ - get changeAmount() { + get changeAmount(): number { const amount = this.settings.changeAmount ?? 2; return amount > 0 ? amount : 2; } + /** + * Resets the action to defaults and refreshes the display. + */ override reset(): void { this._isAvailable = undefined; this._isOutputMuted = false; @@ -219,6 +232,9 @@ export class StationVolumeController extends BaseController { this.refreshDisplay(); } + /** + * Sets the displayed image based on the state of the action. + */ private refreshImage(): void { const replacements = { volume: this.outputVolume, @@ -255,6 +271,9 @@ export class StationVolumeController extends BaseController { }); } + /** + * Sets the displayed title based on the state of the action. + */ private refreshTitle(): void { if (!trackAudioManager.isVoiceConnected || !this.isAvailable) { this.action From 2ee4e58e5caf1d1205064cd644faab2d33f43b43 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 06:30:26 -0800 Subject: [PATCH 8/9] The rest. Phew. --- src/controllers/atisLetter.ts | 2 +- src/controllers/hotline.ts | 2 +- src/controllers/mainVolume.ts | 18 ++++++------- src/controllers/stationStatus.ts | 3 +-- src/controllers/stationVolume.ts | 24 ++++++++--------- src/controllers/trackAudioStatus.ts | 41 ++++++++++++++++++----------- 6 files changed, 49 insertions(+), 41 deletions(-) diff --git a/src/controllers/atisLetter.ts b/src/controllers/atisLetter.ts index 2b1cafb..aacb9ea 100644 --- a/src/controllers/atisLetter.ts +++ b/src/controllers/atisLetter.ts @@ -45,7 +45,7 @@ export class AtisLetterController extends BaseController { }); /** - * Resets the action to its default, disconnected, state. + * Resets the action to its default state. */ public reset() { this._letter = undefined; diff --git a/src/controllers/hotline.ts b/src/controllers/hotline.ts index 9e8ad67..7e4d3b9 100644 --- a/src/controllers/hotline.ts +++ b/src/controllers/hotline.ts @@ -53,7 +53,7 @@ export class HotlineController extends BaseController { }, 100); /** - * Resets the action to its default, disconnected, state. + * Resets the action to its default state. */ public reset() { this._isReceiving = false; diff --git a/src/controllers/mainVolume.ts b/src/controllers/mainVolume.ts index 134fe75..6b20d0c 100644 --- a/src/controllers/mainVolume.ts +++ b/src/controllers/mainVolume.ts @@ -40,6 +40,15 @@ export class MainVolumeController extends BaseController { this.refreshImage(); }, 100); + /** + * Resets the action to its default state. + */ + override reset(): void { + this._volume = 100; + + this.refreshDisplay(); + } + /** * Gets the path to the connected image template. * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. @@ -125,15 +134,6 @@ export class MainVolumeController extends BaseController { return amount > 0 ? amount : 2; } - /** - * Resets the action to defaults and refreshes the display. - */ - override reset(): void { - this._volume = 100; - - this.refreshDisplay(); - } - /** * Sets the displayed image based on the state of the action. */ diff --git a/src/controllers/stationStatus.ts b/src/controllers/stationStatus.ts index 1a47a65..0455936 100644 --- a/src/controllers/stationStatus.ts +++ b/src/controllers/stationStatus.ts @@ -538,8 +538,7 @@ export class StationStatusController extends BaseController { } /** - * Resets the action to the initial display state: no last received callsign - * and no active coms image. + * Resets the action to its default state. */ public reset() { this._lastReceivedCallsign = undefined; // This also clears _lastReceivedCallsignHistory diff --git a/src/controllers/stationVolume.ts b/src/controllers/stationVolume.ts index d49b6f4..6df11f7 100644 --- a/src/controllers/stationVolume.ts +++ b/src/controllers/stationVolume.ts @@ -44,6 +44,18 @@ export class StationVolumeController extends BaseController { this.refreshImage(); }, 100); + /** + * Resets the action to its default state. + */ + override reset(): void { + this._isAvailable = undefined; + this._isOutputMuted = false; + this._frequency = 0; + this._outputVolume = 100; + + this.refreshDisplay(); + } + /** * Gets the path to the not muted image template. * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. @@ -220,18 +232,6 @@ export class StationVolumeController extends BaseController { return amount > 0 ? amount : 2; } - /** - * Resets the action to defaults and refreshes the display. - */ - override reset(): void { - this._isAvailable = undefined; - this._isOutputMuted = false; - this._frequency = 0; - this._outputVolume = 100; - - this.refreshDisplay(); - } - /** * Sets the displayed image based on the state of the action. */ diff --git a/src/controllers/trackAudioStatus.ts b/src/controllers/trackAudioStatus.ts index 8dff422..00bdee6 100644 --- a/src/controllers/trackAudioStatus.ts +++ b/src/controllers/trackAudioStatus.ts @@ -25,77 +25,85 @@ export class TrackAudioStatusController extends BaseController { /** * Creates a new TrackAudioStatusController. - * @param action The Stream Deck action object + * @param action The Stream Deck action object. */ constructor(action: KeyAction, settings: TrackAudioStatusSettings) { super(action); this.settings = settings; } + /** + * Refreshes the title and image on the action. + */ public override refreshDisplay = debounce(() => { this.refreshTitle(); this.refreshImage(); }, 100); + /** + * Resets the action to its default state. + */ public reset() { this.refreshDisplay(); } //#region Getters and setters /** - * Returns the showTitle setting, or false if undefined. + * Gets the showTitle value from settings. + * @returns { boolean } The value. Defaults to true. */ - get showTitle() { + get showTitle(): boolean { return this.settings.showTitle ?? false; } /** - * Convenience method to return the action's title from settings. + * Gets the title value from settings. + * @returns { string | undefined } The title. Defaults to undefined. */ - get title() { + get title(): string | undefined { return this.settings.title; } /** - * Returns the notConnectedImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the not connected image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get notConnectedImagePath(): string { return this._notConnectedImagePath ?? defaultTemplatePath; } /** - * Sets the notConnectedImagePath and re-compiles the SVG template if necessary. + * Sets the notConnectedImagePath. */ set notConnectedImagePath(newValue: string | undefined) { this._notConnectedImagePath = stringOrUndefined(newValue); } /** - * Returns the connectedImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the connected image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get connectedImagePath(): string { return this._connectedImagePath ?? defaultTemplatePath; } /** - * Sets the notConnectedImagePath and re-compiles the SVG template if necessary. + * Sets the connectedImagePath. */ set connectedImagePath(newValue: string | undefined) { this._connectedImagePath = stringOrUndefined(newValue); } /** - * Returns the voiceConnectedImagePath or the default template path if the - * user didn't specify a custom icon. + * Gets the path to the voice connected image template. + * @returns {string} The path specified by the user, or the defaultTemplatePath if none was specified. */ get voiceConnectedImagePath(): string { return this._voiceConnectedImagePath ?? defaultTemplatePath; } /** - * Sets the notConnectedImagePath and re-compiles the SVG template if necessary. + * Sets the voiceConnectedImagePath. */ set voiceConnectedImagePath(newValue: string | undefined) { this._voiceConnectedImagePath = stringOrUndefined(newValue); @@ -103,6 +111,7 @@ export class TrackAudioStatusController extends BaseController { /** * Gets the settings. + * @returns {TrackAudioStatusSettings} The settings. */ get settings() { if (this._settings === null) { @@ -130,7 +139,7 @@ export class TrackAudioStatusController extends BaseController { //#endregion /** - * Sets the title on the action. + * Sets the displayed title based on the state of the action. */ private refreshTitle() { const title = new TitleBuilder(); @@ -141,7 +150,7 @@ export class TrackAudioStatusController extends BaseController { } /** - * Sets the action image based on the isConnected state + * Sets the displayed image based on the state of the action. */ private refreshImage() { const replacements = { From fb277a829fc51310e3372ee29579ad9584c5df9f Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 14 Jan 2025 06:44:56 -0800 Subject: [PATCH 9/9] Address PR feedback --- src/controllers/atisLetter.ts | 1 + src/controllers/hotline.ts | 7 ++++--- src/controllers/mainVolume.ts | 1 + src/controllers/pushToTalk.ts | 1 + src/controllers/stationStatus.ts | 1 + src/controllers/stationVolume.ts | 1 + src/controllers/trackAudioStatus.ts | 2 ++ 7 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/controllers/atisLetter.ts b/src/controllers/atisLetter.ts index aacb9ea..357148b 100644 --- a/src/controllers/atisLetter.ts +++ b/src/controllers/atisLetter.ts @@ -38,6 +38,7 @@ export class AtisLetterController extends BaseController { /** * Refreshes the title and image on the action. + * @remarks This method is debounced with a 100ms delay to prevent excessive updates. */ public override refreshDisplay = debounce(() => { this.refreshTitle(); diff --git a/src/controllers/hotline.ts b/src/controllers/hotline.ts index 7e4d3b9..644f19c 100644 --- a/src/controllers/hotline.ts +++ b/src/controllers/hotline.ts @@ -45,7 +45,8 @@ export class HotlineController extends BaseController { } /** - * Updates the title and image on the action. + * Refreshes the title and image on the action. + * @remarks This method is debounced with a 100ms delay to prevent excessive updates. */ public override refreshDisplay = debounce(() => { this.refreshTitle(); @@ -71,10 +72,10 @@ export class HotlineController extends BaseController { //#region Getters/setters /** * Gets the action's title from settings. - * @returns { string | undefined } The title, or undefined if none is set. + * @returns { string | undefined } The title. Defaults to undefined. */ get title(): string | undefined { - return this.settings.title ?? ""; + return this.settings.title; } /** diff --git a/src/controllers/mainVolume.ts b/src/controllers/mainVolume.ts index 6b20d0c..555f213 100644 --- a/src/controllers/mainVolume.ts +++ b/src/controllers/mainVolume.ts @@ -34,6 +34,7 @@ export class MainVolumeController extends BaseController { /** * Refreshes the title and image on the action. + * @remarks This method is debounced with a 100ms delay to prevent excessive updates. */ public override refreshDisplay = debounce(() => { this.refreshTitle(); diff --git a/src/controllers/pushToTalk.ts b/src/controllers/pushToTalk.ts index 9d8870d..12389c7 100644 --- a/src/controllers/pushToTalk.ts +++ b/src/controllers/pushToTalk.ts @@ -33,6 +33,7 @@ export class PushToTalkController extends BaseController { /** * Refreshes the title and image on the action. + * @remarks This method is debounced with a 100ms delay to prevent excessive updates. */ public override refreshDisplay = debounce(() => { this.refreshTitle(); diff --git a/src/controllers/stationStatus.ts b/src/controllers/stationStatus.ts index 0455936..0441862 100644 --- a/src/controllers/stationStatus.ts +++ b/src/controllers/stationStatus.ts @@ -61,6 +61,7 @@ export class StationStatusController extends BaseController { /** * Refreshes the title and image on the action. + * @remarks This method is debounced with a 100ms delay to prevent excessive updates. */ public override refreshDisplay = debounce(() => { logger.debug(`Refreshing display for ${this.callsign ?? ""}`); diff --git a/src/controllers/stationVolume.ts b/src/controllers/stationVolume.ts index 6df11f7..4247049 100644 --- a/src/controllers/stationVolume.ts +++ b/src/controllers/stationVolume.ts @@ -38,6 +38,7 @@ export class StationVolumeController extends BaseController { /** * Refreshes the title and image on the action. + * @remarks This method is debounced with a 100ms delay to prevent excessive updates. */ public override refreshDisplay = debounce(() => { this.refreshTitle(); diff --git a/src/controllers/trackAudioStatus.ts b/src/controllers/trackAudioStatus.ts index 00bdee6..d7d0310 100644 --- a/src/controllers/trackAudioStatus.ts +++ b/src/controllers/trackAudioStatus.ts @@ -26,6 +26,7 @@ export class TrackAudioStatusController extends BaseController { /** * Creates a new TrackAudioStatusController. * @param action The Stream Deck action object. + * @param settings The settings for configuring the track audio status. */ constructor(action: KeyAction, settings: TrackAudioStatusSettings) { super(action); @@ -34,6 +35,7 @@ export class TrackAudioStatusController extends BaseController { /** * Refreshes the title and image on the action. + * @remarks This method is debounced with a 100ms delay to prevent excessive updates. */ public override refreshDisplay = debounce(() => { this.refreshTitle();