TeaSpeak-Client/modules/renderer/SingleInstanceHandler.ts

27 lines
958 B
TypeScript
Raw Normal View History

import {createErrorModal} from "tc-shared/ui/elements/Modal";
import * as electron from "electron";
import {tr, tra} from "tc-shared/i18n/localize";
import {handleNativeConnectRequest} from "tc-shared/main";
2019-11-24 12:38:50 -05:00
electron.ipcRenderer.on('connect', (event, url) => handle_native_connect_request(url));
function handle_native_connect_request(urlString: string) {
console.log(tr("Received connect event to %s"), urlString);
2019-11-24 12:38:50 -05:00
if(!urlString.toLowerCase().startsWith("teaclient://")) {
createErrorModal(tr("Failed to parse connect URL"), tra("Failed to parse connect URL (Unknown protocol).{:br:}URL: {}", urlString)).open();
2019-11-24 12:38:50 -05:00
return;
}
let url: URL;
try {
url = new URL("https://" + urlString.substring(10));
2019-11-24 12:38:50 -05:00
} catch(error) {
createErrorModal(tr("Failed to parse connect URL"), tra("Failed to parse connect URL.{:br:}URL: {}", urlString)).open();
2019-11-24 12:38:50 -05:00
return;
}
handleNativeConnectRequest(url);
2019-11-24 12:38:50 -05:00
}