diff --git a/backend/src/main.cpp b/backend/src/main.cpp index b08c366..a202359 100644 --- a/backend/src/main.cpp +++ b/backend/src/main.cpp @@ -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) { @@ -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; diff --git a/backend/types/index.d.ts b/backend/types/index.d.ts index 53c03f9..427a863 100644 --- a/backend/types/index.d.ts +++ b/backend/types/index.d.ts @@ -51,7 +51,8 @@ declare namespace TrackAudioAfv { rx: boolean, tx: boolean, xc: boolean, - onSpeaker: boolean + onSpeaker: boolean, + crossCoupleAcross: boolean ): Promise; export function GetFrequencyState(frequency: number): Promise<{ @@ -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; export function Exit(): void; } diff --git a/package-lock.json b/package-lock.json index 653b93b..d52a254 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13905,7 +13905,7 @@ "node_modules/trackaudio-afv": { "version": "1.0.0", "resolved": "file:backend/trackaudio-afv-1.0.0.tgz", - "integrity": "sha512-GY9GmGdHfdBgr5grgW0gYpgQqRGfET5GbAB5t1pxStX7V4kSSp9aVDszmSg9RauOmLsaGyxD3F7RxJ4x7ZTO/g==", + "integrity": "sha512-vdJiUd1bpUuJRWsACR2sruRMKh222HJR5ZAeRLHXmdgLKBUHK8kO8ODXgFF8M+YY+kDdd9TGxHoKhp+P6HFazA==", "dependencies": { "bindings": "^1.5.0", "node-addon-api": "^1.1.0" diff --git a/src/index.ts b/src/index.ts index 4df2b19..391608a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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(); + } } }); }; @@ -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 + ); } );