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";
|
2021-02-20 12:50:18 -05:00
|
|
|
import {handleNativeConnectRequest} from "tc-shared/main";
|
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));
|
|
|
|
|
2021-02-20 12:50:18 -05:00
|
|
|
function handle_native_connect_request(urlString: string) {
|
|
|
|
console.log(tr("Received connect event to %s"), urlString);
|
2019-11-24 12:38:50 -05:00
|
|
|
|
|
|
|
|
2021-02-20 12:50:18 -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 {
|
2021-02-20 12:50:18 -05:00
|
|
|
url = new URL("https://" + urlString.substring(10));
|
2019-11-24 12:38:50 -05:00
|
|
|
} catch(error) {
|
2021-02-20 12:50:18 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-20 12:50:18 -05:00
|
|
|
handleNativeConnectRequest(url);
|
2019-11-24 12:38:50 -05:00
|
|
|
}
|