Skip to content

Commit

Permalink
Merge branch 'main' into neilenns/kSetStationStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
neilenns committed May 26, 2024
2 parents bc1ef7a + 2c0c17a commit b623b60
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 15 deletions.
18 changes: 14 additions & 4 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"i": "^0.3.7",
"npm": "^10.5.1",
"react": "^18.2.0",
"react-bootstrap-icons": "^1.11.4",
"react-dom": "^18.2.0",
"sass": "^1.74.1",
"styled-components": "^5.3.11",
Expand Down
11 changes: 11 additions & 0 deletions src/app/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "../helpers/CallsignHelper";
import useUtilStore from "../store/utilStore";
import { Configuration } from "../../config";
import { FullscreenExit } from "react-bootstrap-icons";

const Navbar: React.FC = () => {
const [showModal, setShowModal] = useState(false);
Expand Down Expand Up @@ -204,6 +205,16 @@ const Navbar: React.FC = () => {
onWheel={handleRadioGainMouseWheel}
value={radioGain}
></input>
<button
className="btn btn-primary m-2 hide-gain-value"
style={{ lineHeight: 0, fontSize: "14px" }}
onClick={() => void window.api.toggleMiniMode()}
>
<FullscreenExit
title={"Mini mode"}
style={{ strokeWidth: "0.5px", stroke: "white" }}
/>
</button>
{platform === "linux" && (
<button
className="btn btn-danger m-2 hide-gain-value"
Expand Down
57 changes: 46 additions & 11 deletions src/app/components/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
setOnSpeaker,
selectRadio,
removeRadio,
setPendingDeletion,
] = useRadioState((state) => [
state.setRx,
state.setTx,
Expand All @@ -26,6 +27,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
state.setOnSpeaker,
state.selectRadio,
state.removeRadio,
state.setPendingDeletion,
]);

const isATC = useSessionStore((state) => state.isAtc);
Expand All @@ -48,7 +50,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
newState ? radio.tx : false,
newState ? radio.xc : false,
radio.onSpeaker,
newState ? radio.crossCoupleAcross : false,
newState ? radio.crossCoupleAcross : false
)
.then((ret) => {
if (!ret) {
Expand All @@ -61,7 +63,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
setXc(radio.frequency, newState ? radio.xc : false);
setCrossCoupleAcross(
radio.frequency,
newState ? radio.crossCoupleAcross : false,
newState ? radio.crossCoupleAcross : false
);
})
.catch((err: unknown) => {
Expand All @@ -79,7 +81,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
newState,
!newState ? false : radio.xc, // If tx is false, xc must be false
radio.onSpeaker,
!newState ? false : radio.crossCoupleAcross, // If tx is false, crossCoupleAcross must be false
!newState ? false : radio.crossCoupleAcross // If tx is false, crossCoupleAcross must be false
)
.then((ret) => {
if (!ret) {
Expand All @@ -91,7 +93,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
setXc(radio.frequency, !newState ? false : radio.xc);
setCrossCoupleAcross(
radio.frequency,
!newState ? false : radio.crossCoupleAcross,
!newState ? false : radio.crossCoupleAcross
);
})
.catch((err: unknown) => {
Expand All @@ -108,7 +110,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
newState ? true : radio.tx, // If xc is true, tx must be true
newState,
radio.onSpeaker,
false, // If xc is true, crossCoupleAcross must be false
false // If xc is true, crossCoupleAcross must be false
)
.then((ret) => {
if (!ret) {
Expand All @@ -134,7 +136,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
newState ? true : radio.tx, // If crossCoupleAcross is true, tx must be true
false, // If crossCoupleAcross is true, xc must be false
radio.onSpeaker,
newState,
newState
)
.then((ret) => {
if (!ret) {
Expand All @@ -160,7 +162,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
radio.tx,
radio.xc,
newState,
radio.crossCoupleAcross,
radio.crossCoupleAcross
)
.then((ret) => {
if (!ret) {
Expand All @@ -175,6 +177,33 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
});
};

const awaitEndOfRxForDeletion = (frequency: number): void => {
const interval = setInterval(
(frequency: number) => {
const radio = useRadioState
.getState()
.radios.find((r) => r.frequency === frequency);
if (!radio) {
clearInterval(interval);
return;
}

if (!radio.currentlyRx && !radio.currentlyTx) {
void window.api.removeFrequency(radio.frequency);
removeRadio(radio.frequency);
clearInterval(interval);
}
},
60,
frequency
);

// Clear the interval after 5 seconds
setTimeout(() => {
clearInterval(interval);
}, 10000);
};

return (
<>
<div className="col-4 radio">
Expand All @@ -183,6 +212,12 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
className="btn btn-no-interact"
style={{ height: "100%", marginBottom: "4%" }}
onClick={clickRadioHeader}
onKeyDown={(e) => {
if (e.key === "Delete" || e.key === "Backspace") {
awaitEndOfRxForDeletion(radio.frequency);
setPendingDeletion(radio.frequency, true);
}
}}
>
{radio.humanFrequency}
<br />
Expand All @@ -193,7 +228,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
"btn",
!radio.xc && !radio.crossCoupleAcross && "btn-primary",
radio.xc && "btn-success",
radio.crossCoupleAcross && "btn-warning",
radio.crossCoupleAcross && "btn-warning"
)}
style={{ width: "45%", height: "100%", marginTop: "4%" }}
onClick={clickXc}
Expand All @@ -206,7 +241,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
className={clsx(
"btn",
!radio.onSpeaker && "btn-primary",
radio.onSpeaker && "btn-success",
radio.onSpeaker && "btn-success"
)}
style={{
width: "45%",
Expand All @@ -232,7 +267,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
"btn",
!radio.rx && "btn-primary",
radio.rx && radio.currentlyRx && "btn-warning",
radio.rx && !radio.currentlyRx && "btn-success",
radio.rx && !radio.currentlyRx && "btn-success"
)}
style={{ width: "100%", height: "100%" }}
onClick={clickRx}
Expand All @@ -244,7 +279,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
"btn",
!radio.tx && "btn-primary",
radio.tx && radio.currentlyTx && "btn-warning",
radio.tx && !radio.currentlyTx && "btn-success",
radio.tx && !radio.currentlyTx && "btn-success"
)}
style={{ width: "100%", height: "100%", marginTop: "8%" }}
onClick={clickTx}
Expand Down
2 changes: 2 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
http-equiv="Content-Security-Policy"
content="script-src 'self' 'unsafe-inline'"
/>
<link rel="preload" href="<%=require('./app/assets/fonts/UbuntuMono-R.ttf')%>" as="font" crossorigin="anonymous">
<link rel="preload" href="<%=require('./app/assets/fonts/UbuntuMono-B.ttf')%>" as="font" crossorigin="anonymous">
</head>

<body>
Expand Down
29 changes: 29 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let version: string;
let mainWindow: BrowserWindow;

const defaultWindowSize = { width: 800, height: 660 };
const savedLastWindowSize = { width: 800, height: 660 };

let currentConfiguration: Configuration = {
audioApi: -1,
Expand Down Expand Up @@ -58,6 +59,19 @@ const setAudioSettings = () => {
TrackAudioAfv.SetHardwareType(currentConfiguration.hardwareType || 0);
};

const toggleMiniMode = () => {
if (
mainWindow.getSize()[0] == mainWindow.getMinimumSize()[0] &&
mainWindow.getSize()[1] == mainWindow.getMinimumSize()[1]
) {
mainWindow.setSize(savedLastWindowSize.width, savedLastWindowSize.height);
return;
}
savedLastWindowSize.width = mainWindow.getSize()[0];
savedLastWindowSize.height = mainWindow.getSize()[1];
mainWindow.setSize(1, 1);
};

const restoreWindowBounds = (win: BrowserWindow) => {
const savedBounds = store.get("bounds");
const boundsRectangle = savedBounds as Rectangle;
Expand Down Expand Up @@ -130,6 +144,17 @@ const createWindow = (): void => {

store.set("bounds", mainWindow.getBounds());
});

mainWindow.webContents.on("before-input-event", (e, input) => {
if (
input.key.toLowerCase() === "m" &&
input.type === "keyDown" &&
(input.control || input.meta)
) {
toggleMiniMode();
e.preventDefault();
}
});
};

// This method will be called when Electron has finished
Expand Down Expand Up @@ -261,6 +286,10 @@ ipcMain.handle("set-audio-api", (_, apiId: number) => {
saveConfig();
});

ipcMain.handle("toggle-mini-mode", () => {
toggleMiniMode();
});

//
// AFV login settings
//
Expand Down
2 changes: 2 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const IElectronAPI = {

RequestPttKeyName: () => ipcRenderer.invoke("request-ptt-key-name"),

toggleMiniMode: () => ipcRenderer.invoke("toggle-mini-mode"),

dialog: (
type: "none" | "info" | "error" | "question" | "warning",
title: string,
Expand Down

0 comments on commit b623b60

Please sign in to comment.