TeaSpeak-Client/modules/core/main-window/index.ts

110 lines
3.7 KiB
TypeScript
Raw Normal View History

2020-12-02 12:08:49 -05:00
import {BrowserWindow, app, dialog, MessageBoxOptions} from "electron";
2019-10-25 19:51:40 -04:00
import * as path from "path";
export let is_debug: boolean;
export let allow_dev_tools: boolean;
2020-10-01 04:56:22 -04:00
import {Arguments, processArguments} from "../../shared/process-arguments";
2020-12-02 12:08:49 -05:00
import {
getLoaderWindow,
hideAppLoaderWindow,
setAppLoaderStatus,
showAppLoaderWindow
} from "../windows/app-loader/controller/AppLoader";
import {loadUiPack} from "../ui-loader/Loader";
import {loadLocalUiCache} from "../ui-loader/Cache";
2020-12-02 12:32:58 -05:00
import {closeMainWindow, showMainWindow} from "../windows/main-window/controller/MainWindow";
2020-12-02 12:08:49 -05:00
import {showUpdateWindow} from "../windows/client-updater/controller/ClientUpdate";
import {
currentClientVersion,
availableClientUpdate,
setClientUpdateChannel,
initializeAppUpdater
} from "../app-updater";
import * as app_updater from "../app-updater";
2020-12-02 12:32:58 -05:00
import {referenceApp} from "../AppInstance";
2020-10-01 04:56:22 -04:00
2020-12-02 12:08:49 -05:00
export async function execute() {
2019-10-25 19:51:40 -04:00
console.log("Main app executed!");
2020-10-01 04:56:22 -04:00
is_debug = processArguments.has_flag(...Arguments.DEBUG);
allow_dev_tools = processArguments.has_flag(...Arguments.DEV_TOOLS);
2019-10-25 19:51:40 -04:00
if(is_debug) {
console.log("Enabled debug!");
2020-10-01 04:56:22 -04:00
console.log("Arguments: %o", processArguments);
2019-10-25 19:51:40 -04:00
}
2020-12-02 12:08:49 -05:00
setAppLoaderStatus("Bootstrapping", 0);
await showAppLoaderWindow();
await initializeAppUpdater();
/* TODO: Remove this (currently required somewhere within the renderer) */
const version = await app_updater.currentClientVersion();
global["app_version_client"] = version.toString();
setAppLoaderStatus("Checking for updates", .1);
try {
if(processArguments.has_value(Arguments.UPDATER_CHANNEL)) {
setClientUpdateChannel(processArguments.value(Arguments.UPDATER_CHANNEL));
}
const newVersion = await availableClientUpdate();
if(newVersion) {
setAppLoaderStatus("Awaiting update", .15);
const result = await dialog.showMessageBox(getLoaderWindow(), {
buttons: ["Update now", "No thanks"],
title: "Update available!",
message:
"There is an update available!\n" +
"Should we update now?\n" +
"\n" +
"Current version: " + (await currentClientVersion()).toString() + "\n" +
"Target version: " + newVersion.version.toString(true)
} as MessageBoxOptions);
if(result.response === 0) {
/* TODO: Execute update! */
await showUpdateWindow();
hideAppLoaderWindow();
return;
2019-10-25 19:51:40 -04:00
}
}
2020-12-02 12:08:49 -05:00
} catch (error) {
console.warn("Failed to check for a client update: %o", error);
}
setAppLoaderStatus("Initialize backend", .2);
2019-10-25 19:51:40 -04:00
2020-12-02 12:08:49 -05:00
console.log("Setting up render backend");
require("../render-backend");
2019-10-25 19:51:40 -04:00
2020-12-02 12:08:49 -05:00
let uiEntryPoint;
try {
setAppLoaderStatus("Loading ui cache", .25);
await loadLocalUiCache();
uiEntryPoint = await loadUiPack((message, index) => {
setAppLoaderStatus(message, index * .75 + .25);
});
} catch (error) {
hideAppLoaderWindow();
console.error("Failed to load ui: %o", error);
2019-10-25 19:51:40 -04:00
2020-12-02 12:32:58 -05:00
closeMainWindow(true);
2020-12-02 12:08:49 -05:00
await dialog.showMessageBox({
type: "error",
buttons: ["exit"],
title: "A critical error happened while loading TeaClient!",
message: (error || "no error").toString()
});
return;
}
if(!uiEntryPoint) {
throw "missing ui entry point";
}
setAppLoaderStatus("Starting client", 100);
await showMainWindow(uiEntryPoint);
hideAppLoaderWindow();
2019-10-25 19:51:40 -04:00
}