Skip to content

Commit

Permalink
Only show close confirmation popup if connected
Browse files Browse the repository at this point in the history
  • Loading branch information
pierr3 committed Apr 24, 2024
1 parent fe16df9 commit 7227976
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
7 changes: 7 additions & 0 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ Napi::String Version(const Napi::CallbackInfo &info) {
return Napi::String::New(env, VERSION.to_string());
}

Napi::Boolean IsConnected(const Napi::CallbackInfo &info) {
return Napi::Boolean::New(info.Env(), mClient->IsVoiceConnected());
}

static void HandleAfvEvents(afv_native::ClientEventType eventType, void *data,
void *data2) {
if (!callbackAvailable) {
Expand Down Expand Up @@ -597,6 +601,9 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "Bootstrap"),
Napi::Function::New(env, Bootstrap));

exports.Set(Napi::String::New(env, "IsConnected"),
Napi::Function::New(env, IsConnected));

exports.Set(Napi::String::New(env, "Exit"), Napi::Function::New(env, Exit));

return exports;
Expand Down
4 changes: 3 additions & 1 deletion backend/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ declare namespace TrackAudioAfv {
rx: boolean,
tx: boolean,
xc: boolean,
onSpeaker: boolean
onSpeaker: boolean,
crossCoupleAcross: boolean
): Promise<boolean>;

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

export function IsConnected(): boolean;
export function Bootstrap(resourcePath: string): Promise<boolean>;
export function Exit(): void;
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 19 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ const createWindow = (): void => {
}

mainWindow.on("close", (e) => {
const response = dialog.showMessageBoxSync(mainWindow, {
type: "question",
buttons: ["Yes", "No"],
title: "Confirm",
message: "Are you sure you want to quit?",
});

if (response == 1) {
e.preventDefault();
if (TrackAudioAfv.IsConnected()) {
const response = dialog.showMessageBoxSync(mainWindow, {
type: "question",
buttons: ["Yes", "No"],
title: "Confirm",
message: "Are you sure you want to quit?",
});

if (response == 1) {
e.preventDefault();
}
}
});
};
Expand Down Expand Up @@ -264,7 +266,14 @@ ipcMain.handle(
onSpeaker: boolean,
crossCoupleAcross: boolean
) => {
return TrackAudioAfv.SetFrequencyState(frequency, rx, tx, xc, onSpeaker, crossCoupleAcross);
return TrackAudioAfv.SetFrequencyState(
frequency,
rx,
tx,
xc,
onSpeaker,
crossCoupleAcross
);
}
);

Expand Down

0 comments on commit 7227976

Please sign in to comment.