[chore] add routes for IPCs + migrate all old ipc.send to sendV2 + remove some dead code

This commit is contained in:
MathieuG-P
2024-03-20 19:00:35 +01:00
parent 031c9044a1
commit 169a6e99b0
58 changed files with 645 additions and 1022 deletions
@@ -0,0 +1,16 @@
import { useConstant } from "./use-constant.hook";
export function useWindowArgs<Key extends string>(...keys: Key[]): Record<Key, string|undefined> {
const getArgs = (...keys: Key[]) => {
const url = new URLSearchParams(window.location.search);
const result = {} as Record<Key, string>;
keys.forEach(key => {
result[key] = url.get(key) || undefined;
});
return result;
}
return useConstant(() => getArgs(...keys));
}
@@ -0,0 +1,17 @@
import { IpcService } from "renderer/services/ipc.service";
import { useService } from "./use-service.hook";
import { useConstant } from "./use-constant.hook";
import { lastValueFrom } from "rxjs";
export function useWindowControls() {
const ipc = useService(IpcService);
const { close, maximise, minimise, unmaximise } = useConstant(() => ({
close: () => lastValueFrom(ipc.sendV2("close-window")),
maximise: () => lastValueFrom(ipc.sendV2("maximise-window")),
minimise: () => lastValueFrom(ipc.sendV2("minimise-window")),
unmaximise: () => lastValueFrom(ipc.sendV2("unmaximise-window"))
}));
return { close, maximise, minimise, unmaximise };
}