From 45923995674d722c1eed49fbfcc2677b0eb5a657 Mon Sep 17 00:00:00 2001 From: Neil Enns Date: Wed, 14 Aug 2024 15:18:53 -0700 Subject: [PATCH] Add option to control how long callsigns stay on the action Fixes #242 --- README.md | 31 ++++++++++--------- .../pi/stationStatus.html | 14 +++++++++ src/actions/stationStatus.ts | 13 ++++---- src/controllers/stationStatus.ts | 12 +++++-- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3f03a24..1aea8fc 100644 --- a/README.md +++ b/README.md @@ -52,21 +52,22 @@ configure the station status action like this to show that RX is enabled and the ### Station status settings -| Setting | Description | Default | -| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | -| Title | The title to show on the action. Optional. | Station callsign and listen to value | -| Callsign | The callsign for the station you want to display status for. Required. | | -| Listen to | What status to display on the button, either RX, TX, or XCA. Required. | RX | -| Show last callsigns | Sets the number of last received callsigns to display, newest to oldest, and will age off after five minutes. Only supported when listen to is set to `RX` or `XCA`. If set to `0` no last received callsigns will be shown. | `0` | -| Active comms | The image to display when a transmission is actively taking place. Optional. | ![Orange background](docs/images/stationstatus-receiving.png) | -| Listening | The image to display when the station is active. Optional. | ![Green background](docs/images/stationstatus-listening.png) | -| Not listening | The image to display when the station is not currently active. Optional. | ![Black background](docs/images/stationstatus-notlistening.png) | -| Unavailable | The image to display when the station is not added in TrackAudio. Optional, defaults to a warning icon. | ![Warning icon](docs/images/stationstatus-unavailable.png) | -| Show callsign | Show the callsign on the action. | false | -| Show frequency | Show the callsign's frequency on the action. | false | -| Show last received callsign | Show the last received callsign on the action. | true | -| Show listen to | Show the listen to value on the action. | false | -| Show title | Show the title on the action. | true | +| Setting | Description | Default | +| ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | +| Title | The title to show on the action. Optional. | Station callsign and listen to value | +| Callsign | The callsign for the station you want to display status for. Required. | | +| Listen to | What status to display on the button, either RX, TX, or XCA. Required. | RX | +| Show last callsigns | Sets the number of last received callsigns to display, newest to oldest, and will age off after five minutes. Only supported when listen to is set to `RX` or `XCA`. If set to `0` no last received callsigns will be shown. | `0` | +| Active comms | The image to display when a transmission is actively taking place. Optional. | ![Orange background](docs/images/stationstatus-receiving.png) | +| Listening | The image to display when the station is active. Optional. | ![Green background](docs/images/stationstatus-listening.png) | +| Not listening | The image to display when the station is not currently active. Optional. | ![Black background](docs/images/stationstatus-notlistening.png) | +| Unavailable | The image to display when the station is not added in TrackAudio. Optional, defaults to a warning icon. | ![Warning icon](docs/images/stationstatus-unavailable.png) | +| Show callsign | Show the callsign on the action. | false | +| Show frequency | Show the callsign's frequency on the action. | false | +| Show last received callsign | Show the last received callsign on the action. | true | +| Show listen to | Show the listen to value on the action. | false | +| Show title | Show the title on the action. | true | +| Clear callsigns after (minutes) | How long to leave callsigns displayed before they age off. Set to 0 to persist callsigns until they are pushed by newer callsigns. | 3 minutes | ## Configuring a hotline action diff --git a/com.neil-enns.trackaudio.sdPlugin/pi/stationStatus.html b/com.neil-enns.trackaudio.sdPlugin/pi/stationStatus.html index e4c512f..6798524 100644 --- a/com.neil-enns.trackaudio.sdPlugin/pi/stationStatus.html +++ b/com.neil-enns.trackaudio.sdPlugin/pi/stationStatus.html @@ -91,6 +91,20 @@ label="Show title" default="true" > + + + + diff --git a/src/actions/stationStatus.ts b/src/actions/stationStatus.ts index 0eff0c9..90603cf 100644 --- a/src/actions/stationStatus.ts +++ b/src/actions/stationStatus.ts @@ -45,16 +45,17 @@ export class StationStatus extends SingletonAction { } export interface StationSettings { - title?: string; + clearAfterInMinutes?: number; + activeCommsImagePath?: string; callsign?: string; + lastReceivedCallsignCount?: number; + listeningImagePath?: string; listenTo: ListenTo | null; notListeningImagePath?: string; - listeningImagePath?: string; - activeCommsImagePath?: string; - unavailableImagePath?: string; - showTitle?: boolean; showCallsign?: boolean; showFrequency?: boolean; showListenTo?: boolean; - lastReceivedCallsignCount?: number; + showTitle?: boolean; + title?: string; + unavailableImagePath?: string; } diff --git a/src/controllers/stationStatus.ts b/src/controllers/stationStatus.ts index b1a5fd6..c4d71cf 100644 --- a/src/controllers/stationStatus.ts +++ b/src/controllers/stationStatus.ts @@ -232,6 +232,14 @@ export class StationStatusController extends BaseController { 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. + */ + get clearAfterInMinutes() { + return this.settings.clearAfterInMinutes ?? 3; + } + /** * Gets the settings. */ @@ -254,11 +262,11 @@ export class StationStatusController extends BaseController { this._settings = newValue; - // Recreate the last received callsign cache with the new length + // Recreate the last received callsign cache with the new length and TTL if ((this._settings.lastReceivedCallsignCount ?? 0) > 0) { this._lastReceivedCallsignHistory = new LRUCache({ max: this._settings.lastReceivedCallsignCount, - ttl: 1000 * 60 * 5, // 10 seconds + ttl: this.clearAfterInMinutes * 60 * 1000, // Convert minutes to milliseconds. If this is zero it automatically disables TTL. ttlAutopurge: true, allowStale: false, disposeAfter: (