Skip to content

Commit

Permalink
Merge pull request #266 from KingfuChan/complement-callsign-for-ws
Browse files Browse the repository at this point in the history
Complement callsign for ws `kStationStateUpdate` message
  • Loading branch information
pierr3 authored Jan 27, 2025
2 parents 05f439e + 7bd2c42 commit cc4e9be
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 17 deletions.
22 changes: 12 additions & 10 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ void RemoveFrequency(const Napi::CallbackInfo& info)
RadioState newState {};

newState.frequency = info[0].As<Napi::Number>().Int32Value();
auto callsign = info.Length() > 1 ? info[1].As<Napi::String>().Utf8Value() : "";
newState.rx = false;
newState.tx = false;
newState.xc = false;
Expand All @@ -225,7 +226,7 @@ void RemoveFrequency(const Napi::CallbackInfo& info)
newState.isOutputMuted = false;
newState.outputVolume = 100;

RadioHelper::SetRadioState(MainThreadShared::mApiServer, newState, "", false);
RadioHelper::SetRadioState(MainThreadShared::mApiServer, newState, callsign, false);
mClient->RemoveFrequency(newState.frequency);

MainThreadShared::mApiServer->publishFrequencyRemoved(newState.frequency);
Expand All @@ -237,19 +238,20 @@ Napi::Boolean SetFrequencyState(const Napi::CallbackInfo& info)
{
RadioState newState {};

newState.frequency = info[0].As<Napi::Number>().Int32Value();
newState.rx = info[1].As<Napi::Boolean>().Value();
newState.tx = info[2].As<Napi::Boolean>().Value();
newState.xc = info[3].As<Napi::Boolean>().Value();
auto callsign = info[0].As<Napi::String>().Utf8Value();
newState.frequency = info[1].As<Napi::Number>().Int32Value();
newState.rx = info[2].As<Napi::Boolean>().Value();
newState.tx = info[3].As<Napi::Boolean>().Value();
newState.xc = info[4].As<Napi::Boolean>().Value();
// Note the negation here, as the API uses the opposite of what is saved internally
newState.headset = !info[4].As<Napi::Boolean>().Value();
newState.xca = info[5].As<Napi::Boolean>().Value(); // Not used
newState.isOutputMuted = info.Length() > 6 ? info[6].As<Napi::Boolean>().Value() : false;
newState.outputVolume = info.Length() > 7 ? info[7].As<Napi::Number>().FloatValue() : 100;
newState.headset = !info[5].As<Napi::Boolean>().Value();
newState.xca = info[6].As<Napi::Boolean>().Value(); // Not used
newState.isOutputMuted = info.Length() > 7 ? info[7].As<Napi::Boolean>().Value() : false;
newState.outputVolume = info.Length() > 8 ? info[8].As<Napi::Number>().FloatValue() : 100;

// SetGuardAndUnicomTransceivers();

auto result = RadioHelper::SetRadioState(MainThreadShared::mApiServer, newState, "");
auto result = RadioHelper::SetRadioState(MainThreadShared::mApiServer, newState, callsign);
return Napi::Boolean::New(info.Env(), result);
}

Expand Down
6 changes: 5 additions & 1 deletion backend/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ declare namespace TrackAudioAfv {
callign: string,
outputVolume?: number,
): Promise<boolean>;
export function RemoveFrequency(frequency: number): void;
export function RemoveFrequency(
frequency: number,
callsign?: string,
): void;
export function IsFrequencyActive(frequency: number): boolean;

export function GetStation(callsign: string): void;
export function RefreshStation(callsign: string): void;

export function SetFrequencyState(
callsign: string,
frequency: number,
rx: boolean,
tx: boolean,
Expand Down
14 changes: 11 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,21 @@ ipcMain.handle(
}
);

ipcMain.handle('audio-remove-frequency', (_, frequency: number) => {
TrackAudioAfv.RemoveFrequency(frequency);
});
ipcMain.handle(
'audio-remove-frequency',
(_, frequency: number, callsign?: string) => {
if (callsign) {
TrackAudioAfv.RemoveFrequency(frequency, callsign);
}
TrackAudioAfv.RemoveFrequency(frequency);
}
);

ipcMain.handle(
'audio-set-frequency-state',
(
_,
callsign: string,
frequency: number,
rx: boolean,
tx: boolean,
Expand All @@ -596,6 +603,7 @@ ipcMain.handle(
outputVolume?: number
) => {
return TrackAudioAfv.SetFrequencyState(
callsign,
frequency,
rx,
tx,
Expand Down
12 changes: 11 additions & 1 deletion src/preload/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ export const api = {

addFrequency: (frequency: number, callsign: string, outputVolume?: number) =>
ipcRenderer.invoke('audio-add-frequency', frequency, callsign, outputVolume),
removeFrequency: (frequency: number) => ipcRenderer.invoke('audio-remove-frequency', frequency),
removeFrequency: (
frequency: number,
callsign?: string
) =>
ipcRenderer.invoke(
'audio-remove-frequency',
frequency,
callsign
),
IsFrequencyActive: (frequency: number) =>
ipcRenderer.invoke('audio-is-frequency-active', frequency),
setFrequencyState: (
callsign: string,
frequency: number,
rx: boolean,
tx: boolean,
Expand All @@ -78,6 +87,7 @@ export const api = {
) =>
ipcRenderer.invoke(
'audio-set-frequency-state',
callsign,
frequency,
rx,
tx,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/delete-multiple-radios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const DeleteMultipleRadios: React.FC = () => {
}

if (!radio.currentlyRx && !radio.currentlyTx) {
void window.api.removeFrequency(radio.frequency);
void window.api.removeFrequency(radio.frequency, radio.callsign);
removeRadio(radio.frequency);
clearInterval(interval);
}
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/src/components/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
const newState = !radio.isOutputMuted;
window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
radio.rx,
radio.tx,
Expand Down Expand Up @@ -195,6 +196,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {

window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
newState,
newState ? radio.tx : false,
Expand Down Expand Up @@ -230,6 +232,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {

window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
newState ? true : radio.rx,
newState,
Expand Down Expand Up @@ -263,6 +266,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
const newState = !radio.xc;
window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
newState ? true : radio.rx,
newState ? true : radio.tx,
Expand Down Expand Up @@ -296,6 +300,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
const newState = !radio.crossCoupleAcross;
window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
newState ? true : radio.rx,
newState ? true : radio.tx,
Expand Down Expand Up @@ -329,6 +334,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
const newState = !radio.onSpeaker;
window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
radio.rx,
radio.tx,
Expand Down Expand Up @@ -370,7 +376,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
}

if (!radio.currentlyRx && !radio.currentlyTx) {
void window.api.removeFrequency(radio.frequency);
void window.api.removeFrequency(radio.frequency, radio.callsign);
removeRadio(radio.frequency);
clearInterval(interval);
}
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/src/components/radio/unicom-guard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const UnicomGuardBar = () => {

window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
newState,
newState ? radio.tx : false,
Expand Down Expand Up @@ -105,6 +106,7 @@ const UnicomGuardBar = () => {

window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
newState ? true : radio.rx, // If tx is true, rx must be true
newState,
Expand Down Expand Up @@ -139,6 +141,7 @@ const UnicomGuardBar = () => {
const newState = !radio.onSpeaker;
window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
radio.rx,
radio.tx,
Expand Down Expand Up @@ -174,6 +177,7 @@ const UnicomGuardBar = () => {
const newState = !radio.isOutputMuted;
window.api
.setFrequencyState(
radio.callsign,
radio.frequency,
radio.rx,
radio.tx,
Expand Down

0 comments on commit cc4e9be

Please sign in to comment.