Skip to content

Commit 7227976

Browse files
committed
Only show close confirmation popup if connected
1 parent fe16df9 commit 7227976

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

backend/src/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ Napi::String Version(const Napi::CallbackInfo &info) {
281281
return Napi::String::New(env, VERSION.to_string());
282282
}
283283

284+
Napi::Boolean IsConnected(const Napi::CallbackInfo &info) {
285+
return Napi::Boolean::New(info.Env(), mClient->IsVoiceConnected());
286+
}
287+
284288
static void HandleAfvEvents(afv_native::ClientEventType eventType, void *data,
285289
void *data2) {
286290
if (!callbackAvailable) {
@@ -597,6 +601,9 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
597601
exports.Set(Napi::String::New(env, "Bootstrap"),
598602
Napi::Function::New(env, Bootstrap));
599603

604+
exports.Set(Napi::String::New(env, "IsConnected"),
605+
Napi::Function::New(env, IsConnected));
606+
600607
exports.Set(Napi::String::New(env, "Exit"), Napi::Function::New(env, Exit));
601608

602609
return exports;

backend/types/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ declare namespace TrackAudioAfv {
5151
rx: boolean,
5252
tx: boolean,
5353
xc: boolean,
54-
onSpeaker: boolean
54+
onSpeaker: boolean,
55+
crossCoupleAcross: boolean
5556
): Promise<boolean>;
5657

5758
export function GetFrequencyState(frequency: number): Promise<{
@@ -72,6 +73,7 @@ declare namespace TrackAudioAfv {
7273
func: (arg: string, arg2: string, arg3: string) => void
7374
): void;
7475

76+
export function IsConnected(): boolean;
7577
export function Bootstrap(resourcePath: string): Promise<boolean>;
7678
export function Exit(): void;
7779
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,17 @@ const createWindow = (): void => {
114114
}
115115

116116
mainWindow.on("close", (e) => {
117-
const response = dialog.showMessageBoxSync(mainWindow, {
118-
type: "question",
119-
buttons: ["Yes", "No"],
120-
title: "Confirm",
121-
message: "Are you sure you want to quit?",
122-
});
123-
124-
if (response == 1) {
125-
e.preventDefault();
117+
if (TrackAudioAfv.IsConnected()) {
118+
const response = dialog.showMessageBoxSync(mainWindow, {
119+
type: "question",
120+
buttons: ["Yes", "No"],
121+
title: "Confirm",
122+
message: "Are you sure you want to quit?",
123+
});
124+
125+
if (response == 1) {
126+
e.preventDefault();
127+
}
126128
}
127129
});
128130
};
@@ -264,7 +266,14 @@ ipcMain.handle(
264266
onSpeaker: boolean,
265267
crossCoupleAcross: boolean
266268
) => {
267-
return TrackAudioAfv.SetFrequencyState(frequency, rx, tx, xc, onSpeaker, crossCoupleAcross);
269+
return TrackAudioAfv.SetFrequencyState(
270+
frequency,
271+
rx,
272+
tx,
273+
xc,
274+
onSpeaker,
275+
crossCoupleAcross
276+
);
268277
}
269278
);
270279

0 commit comments

Comments
 (0)