TeaSpeak-Client/modules/renderer/index.ts

168 lines
5.2 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";
import * as path from "path";
/* first of all setup crash handler */
{
const is_electron_run = process.argv[0].endsWith("electron") || process.argv[0].endsWith("electron.exe");
crash_handler.initialize_handler("renderer", is_electron_run);
}
RequireProxy.initialize(path.join(__dirname, "backend-impl"));
/* --------------- main initialize --------------- */
import {Arguments, parse_arguments, process_args} from "../shared/process-arguments";
import * as electron from "electron";
import {remote} from "electron";
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
});
loader.register_task(loader.Stage.INITIALIZING, {
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 => {
2019-10-25 19:51:40 -04:00
if(!process_args.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");
}
};
if(window.impl_display_critical_error)
window.impl_display_critical_error = _impl;
else
window.displayCriticalError = _impl;
},
priority: 100
});
loader.register_task(loader.Stage.INITIALIZING, {
name: "teaclient initialize arguments",
function: async () => {
parse_arguments();
if(process_args.has_value(Arguments.DUMMY_CRASH_RENDERER))
crash_handler.handler.crash();
/* loader url setup */
{
const baseUrl = process_args.value(Arguments.SERVER_URL);
2020-08-21 07:37:10 -04:00
console.error(process_args.value(Arguments.UPDATER_UI_LOAD_TYPE));
if(typeof baseUrl === "string" && parseFloat((process_args.value(Arguments.UPDATER_UI_LOAD_TYPE)?.toString() || "").trim()) === 3) {
loader.config.baseUrl = baseUrl;
}
}
},
priority: 110
});
loader.register_task(loader.Stage.INITIALIZING, {
name: 'gdb-waiter',
function: async () => {
if(process_args.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);
});
2019-10-25 19:51:40 -04:00
}
},
priority: 100
});
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 {
await import("./version");
await import("./MenuBarHandler");
await import("./context-menu");
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("./UnloadHandler");
} 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
});
2019-10-27 17:50:25 -04:00
export async function initialize() { }