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

Fix state problems with main volume dial #389

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"svg.preview.background": "editor",
"cSpell.words": [
"ATIS",
"Autopurge",
"Callsign",
"callsigns",
Expand All @@ -31,6 +32,7 @@
"stationvolume",
"streamdeck",
"trackaudio",
"Typeguard"
"Typeguard",
"vatsim"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 32 additions & 5 deletions src/controllers/mainVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { handleAsyncException } from "@utils/handleAsyncException";
import { stringOrUndefined } from "@utils/utils";
import debounce from "debounce";
import { BaseController } from "./baseController";
import mainLogger from "@utils/logger";

const logger = mainLogger.child({ service: "mainVolumeController" });

const defaultConnectedTemplatePath = "images/actions/mainVolume/template.svg";
const defaultNotConnectedTemplatePath =
Expand Down Expand Up @@ -134,28 +137,52 @@ export class MainVolumeController extends BaseController {
state: trackAudioManager.isVoiceConnected ? "connected" : "notConnected",
};

const templatePath = trackAudioManager.isConnected
const templatePath = trackAudioManager.isVoiceConnected
? this.connectedTemplatePath
: this.notConnectedTemplatePath;

this.setFeedbackImage(templatePath, replacements);
}

private refreshTitle(): void {
const color = trackAudioManager.isVoiceConnected ? "white" : "grey";
logger.info(
`mainVolume refresh title, isVoiceConnected is ${
trackAudioManager.isConnected ? "true" : "false"
}`
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistent connection check in logging.

The logging message uses isConnected while the code logic uses isVoiceConnected. This inconsistency could lead to confusing logs.

-      `mainVolume refresh title, isVoiceConnected is ${
-        trackAudioManager.isConnected ? "true" : "false"
-      }`
+      `mainVolume refresh title, isVoiceConnected is ${
+        trackAudioManager.isVoiceConnected ? "true" : "false"
+      }`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logger.info(
`mainVolume refresh title, isVoiceConnected is ${
trackAudioManager.isConnected ? "true" : "false"
}`
);
logger.info(
`mainVolume refresh title, isVoiceConnected is ${
trackAudioManager.isVoiceConnected ? "true" : "false"
}`
);

if (!trackAudioManager.isVoiceConnected) {
this.action
.setFeedback({
title: {
color: "grey",
},
indicator: {
value: 0,
bar_fill_c: "grey",
},
value: {
value: "",
color: "grey",
},
})
.catch((error: unknown) => {
handleAsyncException("Unable to set dial feedback: ", error);
});
return;
}

this.action
.setFeedback({
title: {
color: color,
color: "white",
},
indicator: {
value: this.volume,
color,
bar_fill_c: "white",
},
value: {
value: `${this.volume.toString()}%`,
color,
color: "white",
},
})
.catch((error: unknown) => {
Expand Down
6 changes: 1 addition & 5 deletions src/controllers/stationVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ export class StationVolumeController extends BaseController {
}

private refreshTitle(): void {
if (
!trackAudioManager.isConnected ||
!trackAudioManager.isVoiceConnected ||
!this.isAvailable
) {
if (!trackAudioManager.isVoiceConnected || !this.isAvailable) {
this.action
.setFeedback({
title: {
Expand Down
1 change: 0 additions & 1 deletion src/events/trackAudio/connected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ export const handleConnected = () => {
});

trackAudioManager.refreshVoiceConnectedState(); // This will force an update of station states as well if voice is connected.
trackAudioManager.refreshMainVolume(); // This will force an update of the main volume knobs
};
1 change: 1 addition & 0 deletions src/events/trackAudio/mainVolumeChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const handleMainVolumeChange = (data: MainVolumeChange) => {

try {
actionManager.getMainVolumeControllers().forEach((entry) => {
logger.info(`Setting mainVolume to ${data.value.volume.toString()}`);
entry.volume = data.value.volume;
});
} catch (error: unknown) {
Expand Down
1 change: 1 addition & 0 deletions src/events/trackAudio/voiceConnectedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const handleVoiceConnectedState = async (data: VoiceConnectedState) => {

if (data.value.connected) {
trackAudioManager.refreshStationStates();
trackAudioManager.refreshMainVolume(); // This will force an update of the main volume knobs

// Only start polling VATSIM if there are ATIS letters.
if (actionManager.getAtisLetterControllers().length > 0) {
Expand Down