TeaSpeak-Client/modules/renderer/SingleInstanceHandler.ts

41 lines
1.5 KiB
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";
2020-09-24 16:06:52 -04:00
import {server_connections} from "tc-shared/ConnectionManager";
import {handle_connect_request} 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(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.getActiveConnectionHandler();
2020-09-24 16:06:52 -04:00
if(connection.connected) {
connection = server_connections.spawnConnectionHandler();
2020-09-24 16:06:52 -04:00
}
2019-11-24 12:38:50 -05:00
handle_connect_request({
2020-05-19 05:28:51 -04:00
address: url.host + ":" + (url.searchParams.has("port") ? url.searchParams.get("port") : "9987"),
2019-11-24 12:38:50 -05:00
password: {
value: url.password,
hashed: (url.searchParams.get("password_raw") || "0") == "0"
},
profile: url.searchParams.get("profile"),
username: url.searchParams.get("username")
}, connection)
}