TeaSpeak-Client/modules/renderer/SingleInstanceHandler.ts
2020-09-24 22:06:52 +02:00

41 lines
1.5 KiB
TypeScript

import {createErrorModal} from "tc-shared/ui/elements/Modal";
import * as electron from "electron";
import {tr, tra} from "tc-shared/i18n/localize";
import {handle_connect_request} from "tc-shared/main";
import {server_connections} from "tc-shared/ConnectionManager";
electron.ipcRenderer.on('connect', (event, url) => handle_native_connect_request(url));
function handle_native_connect_request(url_string: string) {
console.log(tr("Received connect event to %s"), url_string);
if(!url_string.toLowerCase().startsWith("teaclient://")) {
createErrorModal(tr("Failed to parse connect URL"), tra("Failed to parse connect URL (Unknown protocol).{:br:}URL: {}", url_string)).open();
return;
}
let url: URL;
try {
url = new URL("https://" + url_string.substring(10));
} catch(error) {
createErrorModal(tr("Failed to parse connect URL"), tra("Failed to parse connect URL.{:br:}URL: {}", url_string)).open();
return;
}
let connection = server_connections.active_connection();
if(connection.connected) {
connection = server_connections.spawn_server_connection();
}
handle_connect_request({
address: url.host + ":" + (url.searchParams.has("port") ? url.searchParams.get("port") : "9987"),
password: {
value: url.password,
hashed: (url.searchParams.get("password_raw") || "0") == "0"
},
profile: url.searchParams.get("profile"),
username: url.searchParams.get("username")
}, connection)
}