fix: change emain imports for windows build

This commit is contained in:
Sylvia Crowe 2024-08-01 01:12:30 -07:00
parent 7cba3c46d4
commit 09ce3de108

View File

@ -1,8 +1,8 @@
// Copyright 2024, Command Line Inc. // Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { initGlobal } from "@/app/store/global"; import { initGlobal } from "../frontend/app/store/global";
import { WaveDevVarName, WaveDevViteVarName } from "@/util/isdev"; import { WaveDevVarName, WaveDevViteVarName } from "../frontend/util/isdev";
import * as electron from "electron"; import * as electron from "electron";
import { autoUpdater } from "electron-updater"; import { autoUpdater } from "electron-updater";
import fs from "fs"; import fs from "fs";
@ -34,7 +34,6 @@ const waveSrvReady: Promise<boolean> = new Promise((resolve, _) => {
}); });
let globalIsQuitting = false; let globalIsQuitting = false;
let globalIsStarting = true; let globalIsStarting = true;
let globalIsRelaunching = false;
const isDev = !electronApp.isPackaged; const isDev = !electronApp.isPackaged;
const isDevVite = isDev && process.env.ELECTRON_RENDERER_URL; const isDevVite = isDev && process.env.ELECTRON_RENDERER_URL;
@ -215,8 +214,7 @@ async function handleWSEvent(evtMsg: WSEventType) {
return; return;
} }
const clientData = await services.ClientService.GetClientData(); const clientData = await services.ClientService.GetClientData();
const settings = await services.FileService.GetSettingsConfig(); const newWin = createBrowserWindow(clientData.oid, windowData);
const newWin = createBrowserWindow(clientData.oid, windowData, settings);
await newWin.readyPromise; await newWin.readyPromise;
newWin.show(); newWin.show();
} else if (evtMsg.eventtype == "electron:closewindow") { } else if (evtMsg.eventtype == "electron:closewindow") {
@ -292,39 +290,15 @@ function shFrameNavHandler(event: Electron.Event<Electron.WebContentsWillFrameNa
// note, this does not *show* the window. // note, this does not *show* the window.
// to show, await win.readyPromise and then win.show() // to show, await win.readyPromise and then win.show()
function createBrowserWindow( function createBrowserWindow(clientId: string, waveWindow: WaveWindow): WaveBrowserWindow {
clientId: string,
waveWindow: WaveWindow,
settings: SettingsConfigType
): WaveBrowserWindow {
let winWidth = waveWindow?.winsize?.width;
let winHeight = waveWindow?.winsize?.height;
let winPosX = waveWindow.pos.x;
let winPosY = waveWindow.pos.y;
if (winWidth == null || winWidth == 0) {
const primaryDisplay = electron.screen.getPrimaryDisplay();
const { width } = primaryDisplay.workAreaSize;
winWidth = width - winPosX - 100;
if (winWidth > 2000) {
winWidth = 2000;
}
}
if (winHeight == null || winHeight == 0) {
const primaryDisplay = electron.screen.getPrimaryDisplay();
const { height } = primaryDisplay.workAreaSize;
winHeight = height - winPosY - 100;
if (winHeight > 1200) {
winHeight = 1200;
}
}
let winBounds = { let winBounds = {
x: winPosX, x: waveWindow.pos.x,
y: winPosY, y: waveWindow.pos.y,
width: winWidth, width: waveWindow.winsize.width,
height: winHeight, height: waveWindow.winsize.height,
}; };
winBounds = ensureBoundsAreVisible(winBounds); winBounds = ensureBoundsAreVisible(winBounds);
const winOpts: Electron.BrowserWindowConstructorOptions = { const bwin = new electron.BrowserWindow({
titleBarStyle: "hiddenInset", titleBarStyle: "hiddenInset",
x: winBounds.x, x: winBounds.x,
y: winBounds.y, y: winBounds.y,
@ -342,26 +316,8 @@ function createBrowserWindow(
}, },
show: false, show: false,
autoHideMenuBar: true, autoHideMenuBar: true,
}; backgroundColor: "#000000",
const isTransparent = settings?.window?.transparent ?? false; });
const isBlur = !isTransparent && (settings?.window?.blur ?? false);
if (isTransparent) {
winOpts.transparent = true;
} else if (isBlur) {
switch (unamePlatform) {
case "win32": {
winOpts.backgroundMaterial = "acrylic";
break;
}
case "darwin": {
winOpts.vibrancy = "fullscreen-ui";
break;
}
}
} else {
winOpts.backgroundColor = "#222222";
}
const bwin = new electron.BrowserWindow(winOpts);
(bwin as any).waveWindowId = waveWindow.oid; (bwin as any).waveWindowId = waveWindow.oid;
let readyResolve: (value: void) => void; let readyResolve: (value: void) => void;
(bwin as any).readyPromise = new Promise((resolve, _) => { (bwin as any).readyPromise = new Promise((resolve, _) => {
@ -563,8 +519,7 @@ electron.ipcMain.on("getEnv", (event, varName) => {
async function createNewWaveWindow() { async function createNewWaveWindow() {
const clientData = await services.ClientService.GetClientData(); const clientData = await services.ClientService.GetClientData();
const newWindow = await services.ClientService.MakeWindow(); const newWindow = await services.ClientService.MakeWindow();
const settings = await services.FileService.GetSettingsConfig(); const newBrowserWindow = createBrowserWindow(clientData.oid, newWindow);
const newBrowserWindow = createBrowserWindow(clientData.oid, newWindow, settings);
newBrowserWindow.show(); newBrowserWindow.show();
} }
@ -608,7 +563,6 @@ function makeAppMenu() {
}, },
{ {
role: "close", role: "close",
accelerator: "", // clear the accelerator
click: () => { click: () => {
electron.BrowserWindow.getFocusedWindow()?.close(); electron.BrowserWindow.getFocusedWindow()?.close();
}, },
@ -662,12 +616,6 @@ function makeAppMenu() {
{ {
role: "forceReload", role: "forceReload",
}, },
{
label: "Relaunch All Windows",
click: () => {
relaunchBrowserWindows();
},
},
{ {
role: "toggleDevTools", role: "toggleDevTools",
}, },
@ -690,14 +638,6 @@ function makeAppMenu() {
role: "togglefullscreen", role: "togglefullscreen",
}, },
]; ];
const windowMenu: Electron.MenuItemConstructorOptions[] = [
{ role: "minimize", accelerator: "" },
{ role: "zoom" },
{ type: "separator" },
{ role: "front" },
{ type: "separator" },
{ role: "window" },
];
const menuTemplate: Electron.MenuItemConstructorOptions[] = [ const menuTemplate: Electron.MenuItemConstructorOptions[] = [
{ {
role: "appMenu", role: "appMenu",
@ -716,7 +656,6 @@ function makeAppMenu() {
}, },
{ {
role: "windowMenu", role: "windowMenu",
submenu: windowMenu,
}, },
]; ];
const menu = electron.Menu.buildFromTemplate(menuTemplate); const menu = electron.Menu.buildFromTemplate(menuTemplate);
@ -724,9 +663,6 @@ function makeAppMenu() {
} }
electronApp.on("window-all-closed", () => { electronApp.on("window-all-closed", () => {
if (globalIsRelaunching) {
return;
}
if (unamePlatform !== "darwin") { if (unamePlatform !== "darwin") {
electronApp.quit(); electronApp.quit();
} }
@ -921,36 +857,6 @@ async function configureAutoUpdater() {
} }
// ====== AUTO-UPDATER ====== // // ====== AUTO-UPDATER ====== //
async function relaunchBrowserWindows() {
globalIsRelaunching = true;
const windows = electron.BrowserWindow.getAllWindows();
for (const window of windows) {
window.removeAllListeners();
window.close();
}
globalIsRelaunching = false;
const clientData = await services.ClientService.GetClientData();
const settings = await services.FileService.GetSettingsConfig();
const wins: WaveBrowserWindow[] = [];
for (const windowId of clientData.windowids.slice().reverse()) {
const windowData: WaveWindow = (await services.ObjectService.GetObject("window:" + windowId)) as WaveWindow;
if (windowData == null) {
services.WindowService.CloseWindow(windowId).catch((e) => {
/* ignore */
});
continue;
}
const win = createBrowserWindow(clientData.oid, windowData, settings);
wins.push(win);
}
for (const win of wins) {
await win.readyPromise;
console.log("show", win.waveWindowId);
win.show();
}
}
async function appMain() { async function appMain() {
const startTs = Date.now(); const startTs = Date.now();
const instanceLock = electronApp.requestSingleInstanceLock(); const instanceLock = electronApp.requestSingleInstanceLock();
@ -971,8 +877,27 @@ async function appMain() {
} }
const ready = await waveSrvReady; const ready = await waveSrvReady;
console.log("wavesrv ready signal received", ready, Date.now() - startTs, "ms"); console.log("wavesrv ready signal received", ready, Date.now() - startTs, "ms");
console.log("get client data");
const clientData = await services.ClientService.GetClientData();
console.log("client data ready");
await electronApp.whenReady(); await electronApp.whenReady();
relaunchBrowserWindows(); const wins: WaveBrowserWindow[] = [];
for (const windowId of clientData.windowids.slice().reverse()) {
const windowData: WaveWindow = (await services.ObjectService.GetObject("window:" + windowId)) as WaveWindow;
if (windowData == null) {
services.WindowService.CloseWindow(windowId).catch((e) => {
/* ignore */
});
continue;
}
const win = createBrowserWindow(clientData.oid, windowData);
wins.push(win);
}
for (const win of wins) {
await win.readyPromise;
console.log("show", win.waveWindowId);
win.show();
}
configureAutoUpdater(); configureAutoUpdater();
globalIsStarting = false; globalIsStarting = false;