TeaSpeak-Client/modules/renderer/index.ts

181 lines
5.8 KiB
TypeScript
Raw Normal View History

/* --------------- bootstrap --------------- */
import * as RequireProxy from "./RequireProxy";
2019-10-25 19:51:40 -04:00
import * as crash_handler from "../crash_handler";
2020-10-01 04:56:22 -04:00
import {Arguments, parseProcessArguments, processArguments} from "../shared/process-arguments";
2019-10-25 19:51:40 -04:00
import * as path from "path";
2020-08-22 15:33:30 -04:00
import * as electron from "electron";
import {remote} from "electron";
/*
2020-10-01 04:56:22 -04:00
import * as Sentry from "@sentry/electron";
2020-08-22 15:33:30 -04:00
Sentry.init({
dsn: "https://72b9f40ce6894b179154e7558f1aeb87@o437344.ingest.sentry.io/5399791",
appName: "TeaSpeak - Client",
release: "TeaClient@" + electron.remote.app.getVersion()
});
*/
2019-10-25 19:51:40 -04:00
/* first of all setup crash handler */
2020-10-01 04:56:22 -04:00
parseProcessArguments();
if(!processArguments.has_flag(Arguments.NO_CRASH_RENDERER)) {
2019-10-25 19:51:40 -04:00
const is_electron_run = process.argv[0].endsWith("electron") || process.argv[0].endsWith("electron.exe");
crash_handler.initialize_handler("renderer", is_electron_run);
}
2020-10-01 04:56:22 -04:00
RequireProxy.initialize(path.join(__dirname, "backend-impl"), "client-app");
/* --------------- main initialize --------------- */
import * as loader from "tc-loader";
import ipcRenderer = electron.ipcRenderer;
/* some decls */
declare global {
interface Window {
$: any;
jQuery: any;
jsrender: any;
2019-10-25 19:51:40 -04:00
impl_display_critical_error: any;
displayCriticalError: any;
teaclient_initialize: any;
}
2019-10-25 19:51:40 -04:00
}
/* we use out own jquery resource */
loader.register_task(loader.Stage.JAVASCRIPT, {
name: "teaclient jquery",
function: async () => {
window.$ = require("jquery");
window.jQuery = window.$;
Object.assign(window.$, window.jsrender = require('jsrender'));
},
priority: 80
});
2020-10-05 09:10:49 -04:00
loader.register_task(loader.Stage.SETUP, {
name: "teaclient initialize persistent storage",
function: async () => {
const storage = require("./PersistentLocalStorage");
await storage.initialize();
},
priority: 90
});
loader.register_task(loader.Stage.INITIALIZING, {
name: "teaclient initialize logging",
function: async () => {
2020-08-21 07:37:10 -04:00
(await import("./Logger")).setup();
},
priority: 80
});
loader.register_task(loader.Stage.INITIALIZING, {
name: "teaclient initialize error",
function: async () => {
const _impl = message => {
2020-10-01 04:56:22 -04:00
if(!processArguments.has_flag(Arguments.DEBUG)) {
console.error("Displaying critical error: %o", message);
message = message.replace(/<br>/i, "\n");
const win = remote.getCurrentWindow();
remote.dialog.showMessageBox({
type: "error",
buttons: ["exit"],
title: "A critical error happened!",
message: message
2019-10-25 19:51:40 -04:00
});
win.close();
} else {
console.error("Received critical error: %o", message);
console.error("Ignoring error due to the debug mode");
}
};
2020-10-01 04:56:22 -04:00
if(window.impl_display_critical_error) {
window.impl_display_critical_error = _impl;
2020-10-01 04:56:22 -04:00
} else {
window.displayCriticalError = _impl;
2020-10-01 04:56:22 -04:00
}
},
priority: 100
});
loader.register_task(loader.Stage.INITIALIZING, {
name: "teaclient initialize arguments",
function: async () => {
2020-10-01 04:56:22 -04:00
if(processArguments.has_value(Arguments.DUMMY_CRASH_RENDERER))
crash_handler.handler.crash();
/* loader url setup */
{
2020-10-01 04:56:22 -04:00
const baseUrl = processArguments.value(Arguments.SERVER_URL);
console.error(processArguments.value(Arguments.UPDATER_UI_LOAD_TYPE));
if(typeof baseUrl === "string" && parseFloat((processArguments.value(Arguments.UPDATER_UI_LOAD_TYPE)?.toString() || "").trim()) === 3) {
loader.config.baseUrl = baseUrl;
}
}
},
priority: 110
});
loader.register_task(loader.Stage.JAVASCRIPT, {
name: 'gdb-waiter',
function: async () => {
2020-10-01 04:56:22 -04:00
if(processArguments.has_flag(Arguments.DEV_TOOLS_GDB)) {
console.log("Process ID: %d", process.pid);
await new Promise(resolve => {
console.log("Waiting for continue!");
const listener = () => {
console.log("Continue");
document.removeEventListener('click', listener);
resolve();
};
document.addEventListener('click', listener);
});
console.log("Awaited");
2019-10-25 19:51:40 -04:00
}
},
priority: 10000
});
loader.register_task(loader.Stage.LOADED, {
name: "argv connect",
function: async () => {
ipcRenderer.send('basic-action', "parse-connect-arguments");
},
priority: 0
});
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "teaclient load adapters",
function: async () => {
/* all files which replaces a native driver */
2019-10-25 19:51:40 -04:00
try {
2020-10-05 09:10:49 -04:00
await import("./MenuBar");
2020-10-01 04:56:22 -04:00
await import("./ContextMenu");
await import("./SingleInstanceHandler");
await import("./IconHelper");
await import("./connection/FileTransfer");
2020-08-21 07:37:10 -04:00
await import("./hooks/AudioInput");
await import("./hooks/ExternalModal");
await import("./hooks/ServerConnection");
await import("./hooks/ChangeLogClient");
2020-10-05 09:10:49 -04:00
await import("./hooks/Backend");
await import("./hooks/MenuBar");
2020-11-29 15:06:57 -05:00
await import("./hooks/Video");
2020-08-21 07:37:10 -04:00
await import("./UnloadHandler");
2020-09-24 16:06:52 -04:00
await import("./WindowsTrayHandler");
} catch (error) {
console.log(error);
window.displayCriticalError("Failed to load native extensions: " + error);
2019-10-25 19:51:40 -04:00
throw error;
}
remote.getCurrentWindow().on('focus', () => remote.getCurrentWindow().flashFrame(false));
},
priority: 60
2020-10-01 04:56:22 -04:00
});