2020-04-01 15:56:23 -04:00
|
|
|
import {createErrorModal} from "tc-shared/ui/elements/Modal";
|
2019-10-27 17:39:59 -04:00
|
|
|
|
|
|
|
import * as electron from "electron";
|
2020-04-01 15:56:23 -04:00
|
|
|
import {tr, tra} from "tc-shared/i18n/localize";
|
|
|
|
import {handle_connect_request} from "tc-shared/main";
|
2020-09-24 16:06:52 -04:00
|
|
|
import {server_connections} from "tc-shared/ConnectionManager";
|
2019-10-27 17:39:59 -04:00
|
|
|
|
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();
|
2020-09-24 16:06:52 -04:00
|
|
|
if(connection.connected) {
|
2020-05-19 05:28:51 -04:00
|
|
|
connection = server_connections.spawn_server_connection();
|
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)
|
|
|
|
}
|