TeaSpeak-Client/modules/core/MultiInstanceHandler.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-10-01 04:56:22 -04:00
import { app } from "electron";
2020-12-02 12:32:58 -05:00
import {getMainWindow} from "./windows/main-window/controller/MainWindow";
2020-10-01 04:56:22 -04:00
export function handleSecondInstanceCall(argv: string[], _workingDirectory: string) {
const original_args = argv.slice(1).filter(e => !e.startsWith("--original-process-start-time=") && e != "--allow-file-access-from-files");
console.log("Second instance: %o", original_args);
2020-12-02 12:32:58 -05:00
const mainWindow = getMainWindow()
2020-10-01 04:56:22 -04:00
if(!mainWindow) {
console.warn("Ignoring second instance call because we haven't yet started");
return;
}
2020-10-01 04:56:22 -04:00
mainWindow.focus();
2019-11-24 12:38:50 -05:00
execute_connect_urls(original_args);
}
2019-11-24 12:38:50 -05:00
export function execute_connect_urls(argv: string[]) {
2020-12-02 12:32:58 -05:00
const connectUrls = argv.filter(e => e.startsWith("teaclient://"));
for(const url of connectUrls) {
2019-11-24 12:38:50 -05:00
console.log("Received connect url: %s", url);
2020-12-02 12:32:58 -05:00
getMainWindow().webContents.send('connect', url);
}
2020-10-01 04:56:22 -04:00
}
export function initializeSingleInstance() : boolean {
if(!app.requestSingleInstanceLock()) {
return false;
}
app.on('second-instance', (event, argv, workingDirectory) => handleSecondInstanceCall(argv, workingDirectory));
return true;
}