Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move class types to constants #363

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/controllers/atisLetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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";

const defaultTemplatePath = "images/actions/atisLetter/template.svg";

Expand All @@ -13,7 +14,7 @@ const defaultTemplatePath = "images/actions/atisLetter/template.svg";
* state and Stream Deck action for an individual action in a profile.
*/
export class AtisLetterController extends BaseController {
type = "AtisLetterController";
type = ATIS_LETTER_CONTROLLER_TYPE;

private _autoClearTimeout?: NodeJS.Timeout;
private _isUnavailable = false;
Expand Down Expand Up @@ -279,12 +280,12 @@ export class AtisLetterController extends BaseController {
}

/*
* Typeguard for HotlineController.
* Typeguard for AtisLetterController.
* @param action The action
* @returns True if the action is a HotlineController
* @returns True if the action is an AtisLetterController
*/
export function isAtisLetterController(
action: Controller
): action is AtisLetterController {
return action.type === "AtisLetterController";
return action.type === ATIS_LETTER_CONTROLLER_TYPE;
}
5 changes: 3 additions & 2 deletions src/controllers/hotline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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";

const defaultTemplatePath = "images/actions/hotline/template.svg";

Expand All @@ -13,7 +14,7 @@ const defaultTemplatePath = "images/actions/hotline/template.svg";
* state and Stream Deck action for an individual action in a profile.
*/
export class HotlineController extends BaseController {
type = "HotlineController";
type = HOTLINE_CONTROLLER_TYPE;

private _settings: HotlineSettings | null = null;

Expand Down Expand Up @@ -453,5 +454,5 @@ export class HotlineController extends BaseController {
export function isHotlineController(
action: Controller
): action is HotlineController {
return action.type === "HotlineController";
return action.type === HOTLINE_CONTROLLER_TYPE;
}
5 changes: 3 additions & 2 deletions src/controllers/pushToTalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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";

const defaultTemplatePath = "images/actions/pushToTalk/template.svg";

Expand All @@ -13,7 +14,7 @@ const defaultTemplatePath = "images/actions/pushToTalk/template.svg";
* state and Stream Deck action for an individual action in a profile.
*/
export class PushToTalkController extends BaseController {
type = "PushToTalkController";
type = PUSH_TO_TALK_CONTROLLER_TYPE;

private _settings: PushToTalkSettings | null = null;
private _isTransmitting = false;
Expand Down Expand Up @@ -176,5 +177,5 @@ export class PushToTalkController extends BaseController {
export function isPushToTalkController(
action: Controller
): action is PushToTalkController {
return action.type === "PushToTalkController";
return action.type === PUSH_TO_TALK_CONTROLLER_TYPE;
}
5 changes: 3 additions & 2 deletions src/controllers/stationStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LRUCache } from "lru-cache";
import { BaseController } from "./baseController";
import debounce from "debounce";
import mainLogger from "@utils/logger";
import { STATION_STATUS_CONTROLLER_TYPE } from "@utils/controllerTypes";

// Valid values for the ListenTo property. This must match
// the list of array property names that come from TrackAudio
Expand All @@ -22,7 +23,7 @@ const defaultTemplatePath = "images/actions/stationStatus/template.svg";
* state and Stream Deck action for an individual action in a profile.
*/
export class StationStatusController extends BaseController {
type = "StationStatusController";
type = STATION_STATUS_CONTROLLER_TYPE;

private _frequency = 0;
private _isAvailable: boolean | undefined = undefined;
Expand Down Expand Up @@ -622,5 +623,5 @@ export class StationStatusController extends BaseController {
export function isStationStatusController(
action: Controller
): action is StationStatusController {
return action.type === "StationStatusController";
return action.type === STATION_STATUS_CONTROLLER_TYPE;
}
5 changes: 3 additions & 2 deletions src/controllers/stationVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { Controller } from "@interfaces/controller";
import { stringOrUndefined } from "@utils/utils";
import { handleAsyncException } from "@utils/handleAsyncException";
import debounce from "debounce";
import { STATION_VOLUME_CONTROLLER_TYPE } from "@utils/controllerTypes";

const defaultTemplatePath = "images/actions/stationVolume/template.svg";

export class StationVolumeController extends BaseController {
type = "StationVolumeController";
type = STATION_VOLUME_CONTROLLER_TYPE;

declare action: DialAction; // This ensures action from the base class is always a DialAction

Expand Down Expand Up @@ -302,5 +303,5 @@ export class StationVolumeController extends BaseController {
export function isStationVolumeController(
action: Controller
): action is StationVolumeController {
return action.type === "StationVolumeController";
return action.type === STATION_VOLUME_CONTROLLER_TYPE;
}
5 changes: 3 additions & 2 deletions src/controllers/trackAudioStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TitleBuilder from "@root/utils/titleBuilder";
import { stringOrUndefined } from "@root/utils/utils";
import { BaseController } from "./baseController";
import debounce from "debounce";
import { TRACKAUDIO_STATUS_CONTROLLER_TYPE } from "@utils/controllerTypes";

const defaultTemplatePath = "images/actions/trackAudioStatus/template.svg";

Expand All @@ -13,7 +14,7 @@ const defaultTemplatePath = "images/actions/trackAudioStatus/template.svg";
* state and Stream Deck action for an individual action in a profile.
*/
export class TrackAudioStatusController extends BaseController {
type = "TrackAudioStatusController";
type = TRACKAUDIO_STATUS_CONTROLLER_TYPE;

private _isConnected = false;
private _isVoiceConnected = false;
Expand Down Expand Up @@ -226,5 +227,5 @@ export class TrackAudioStatusController extends BaseController {
export function isTrackAudioStatusController(
action: Controller
): action is TrackAudioStatusController {
return action.type === "TrackAudioStatusController";
return action.type === TRACKAUDIO_STATUS_CONTROLLER_TYPE;
}
6 changes: 6 additions & 0 deletions src/utils/controllerTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const ATIS_LETTER_CONTROLLER_TYPE = "AtisLetterController";
export const HOTLINE_CONTROLLER_TYPE = "HotlineController";
export const PUSH_TO_TALK_CONTROLLER_TYPE = "PushToTalkController";
export const STATION_STATUS_CONTROLLER_TYPE = "StationStatusController";
export const STATION_VOLUME_CONTROLLER_TYPE = "StationVolumeController";
export const TRACKAUDIO_STATUS_CONTROLLER_TYPE = "TrackAudioStatusController";