2019-06-26 16:09:01 -04:00
|
|
|
import * as electron from "electron";
|
|
|
|
import * as path from "path";
|
|
|
|
import {screen} from "electron";
|
|
|
|
|
|
|
|
import {Arguments, process_args} from "../../shared/process-arguments";
|
|
|
|
import * as loader from "./loader";
|
|
|
|
import * as updater from "../app-updater";
|
2019-06-30 11:24:10 -04:00
|
|
|
import * as winmgr from "../window";
|
|
|
|
import {main_window} from "../main_window";
|
2019-06-26 16:09:01 -04:00
|
|
|
|
|
|
|
export namespace ui {
|
|
|
|
let gui: electron.BrowserWindow;
|
|
|
|
let promise: Promise<String>;
|
|
|
|
let resolve: any;
|
|
|
|
let reject: any;
|
|
|
|
|
|
|
|
export function running() : boolean {
|
|
|
|
return promise !== undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function cancel() : boolean {
|
|
|
|
if(resolve)
|
|
|
|
resolve();
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function cleanup() {
|
|
|
|
if(gui) {
|
2019-06-30 11:24:10 -04:00
|
|
|
promise = undefined;
|
|
|
|
resolve = undefined;
|
|
|
|
|
2019-06-26 16:09:01 -04:00
|
|
|
gui.destroy();
|
|
|
|
gui = undefined;
|
|
|
|
|
|
|
|
reject = error => {
|
|
|
|
if(error)
|
|
|
|
console.error("Received error from loader after it had been closed... Error: %o", error);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function load_files() {
|
|
|
|
const channel = await updater.selected_channel();
|
|
|
|
try {
|
|
|
|
const entry_point = await loader.load_files(channel, (status, index) => {
|
|
|
|
if(gui) {
|
|
|
|
gui.webContents.send('progress-update', index);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const resolved = () => {
|
|
|
|
resolve(entry_point);
|
|
|
|
|
|
|
|
promise = undefined;
|
|
|
|
resolve = undefined;
|
|
|
|
reject = error => {
|
|
|
|
if(error)
|
|
|
|
console.error("Received error from loader after it had been closed... Error: %o", error);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if(!process_args.has_flag(...Arguments.DISABLE_ANIMATION))
|
|
|
|
setTimeout(resolved, 250);
|
|
|
|
else
|
|
|
|
setImmediate(resolved);
|
|
|
|
} catch (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function show_await_update() {
|
|
|
|
if(gui)
|
|
|
|
gui.webContents.send('await-update');
|
|
|
|
}
|
|
|
|
|
2019-06-30 11:24:10 -04:00
|
|
|
function spawn_gui() {
|
2019-06-26 16:09:01 -04:00
|
|
|
console.log("Spawn window!");
|
2019-06-30 11:24:10 -04:00
|
|
|
let dev_tools = false;
|
2019-06-26 16:09:01 -04:00
|
|
|
|
2019-06-30 11:24:10 -04:00
|
|
|
const WINDOW_WIDTH = 340 + (dev_tools ? 1000 : 0);
|
|
|
|
const WINDOW_HEIGHT = 400 + (process.platform == "win32" ? 40 : 0);
|
2019-06-26 16:09:01 -04:00
|
|
|
|
|
|
|
let bounds = screen.getPrimaryDisplay().bounds;
|
2019-06-30 11:24:10 -04:00
|
|
|
let x = bounds.x + (bounds.width - WINDOW_WIDTH) / 2;
|
|
|
|
let y = bounds.y + (bounds.height - WINDOW_HEIGHT) / 2;
|
|
|
|
console.log("Bounds: %o; Move loader window to %ox%o", bounds, x, y);
|
2019-06-26 16:09:01 -04:00
|
|
|
|
|
|
|
gui = new electron.BrowserWindow({
|
2019-06-30 11:24:10 -04:00
|
|
|
width: WINDOW_WIDTH,
|
|
|
|
height: WINDOW_HEIGHT,
|
|
|
|
frame: dev_tools,
|
2019-06-26 16:09:01 -04:00
|
|
|
resizable: dev_tools,
|
|
|
|
show: false,
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
|
|
|
|
webPreferences: {
|
|
|
|
webSecurity: false,
|
2019-06-30 11:24:10 -04:00
|
|
|
nodeIntegrationInWorker: false,
|
|
|
|
nodeIntegration: true
|
2019-06-26 16:09:01 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
gui.setMenu(null);
|
|
|
|
gui.loadFile(path.join(path.dirname(module.filename), "ui", "loading_screen.html"));
|
2019-06-30 11:24:10 -04:00
|
|
|
gui.on('closed', () => {
|
|
|
|
if(resolve)
|
|
|
|
resolve();
|
|
|
|
gui = undefined;
|
|
|
|
cleanup();
|
|
|
|
});
|
2019-06-26 16:09:01 -04:00
|
|
|
|
|
|
|
gui.on('ready-to-show', () => {
|
|
|
|
gui.show();
|
2019-06-30 11:24:10 -04:00
|
|
|
gui.setPosition(x, y);
|
|
|
|
winmgr.apply_bounds('ui-load-window', gui, undefined, { apply_size: false }).then(() => {
|
|
|
|
winmgr.track_bounds('ui-load-window', gui);
|
|
|
|
|
|
|
|
const call_loader = () => load_files().catch(reject);
|
|
|
|
if(!process_args.has_flag(...Arguments.DISABLE_ANIMATION))
|
|
|
|
setTimeout(call_loader, 1000);
|
|
|
|
else
|
|
|
|
setImmediate(call_loader);
|
|
|
|
|
|
|
|
if(dev_tools)
|
|
|
|
gui.webContents.openDevTools();
|
|
|
|
});
|
2019-06-26 16:09:01 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function execute_loader() : Promise<String> {
|
|
|
|
return promise = new Promise((_resolve, _reject) => {
|
|
|
|
resolve = _resolve;
|
|
|
|
reject = _reject || (error => {
|
|
|
|
console.error("Failed to load UI files! Error: %o", error)
|
|
|
|
});
|
|
|
|
|
2019-06-30 11:24:10 -04:00
|
|
|
spawn_gui();
|
2019-06-26 16:09:01 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function preloading_page(entry_point: string) : string {
|
|
|
|
global["browser-root"] = entry_point; /* setup entry point */
|
|
|
|
|
|
|
|
return path.join(path.dirname(module.filename), "ui", "preload_page.html");
|
|
|
|
}
|
|
|
|
}
|