TeaSpeak-Client/modules/renderer/app_backend.ts

40 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";
import {server_connections} from "tc-shared/ui/frames/connection_handlers";
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;
}
2020-05-19 05:28:51 -04:00
let connection = server_connections.active_connection();
2019-11-24 12:38:50 -05:00
if(connection.connected)
2020-05-19 05:28:51 -04:00
connection = server_connections.spawn_server_connection();
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)
}