From 09ce3de108882261a0830f3852c4e8575136838c Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Thu, 1 Aug 2024 01:12:30 -0700 Subject: [PATCH] fix: change emain imports for windows build --- emain/emain.ts | 139 ++++++++++++------------------------------------- 1 file changed, 32 insertions(+), 107 deletions(-) diff --git a/emain/emain.ts b/emain/emain.ts index 28cf342c6..cf6352cf3 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -1,8 +1,8 @@ // Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import { initGlobal } from "@/app/store/global"; -import { WaveDevVarName, WaveDevViteVarName } from "@/util/isdev"; +import { initGlobal } from "../frontend/app/store/global"; +import { WaveDevVarName, WaveDevViteVarName } from "../frontend/util/isdev"; import * as electron from "electron"; import { autoUpdater } from "electron-updater"; import fs from "fs"; @@ -34,7 +34,6 @@ const waveSrvReady: Promise = new Promise((resolve, _) => { }); let globalIsQuitting = false; let globalIsStarting = true; -let globalIsRelaunching = false; const isDev = !electronApp.isPackaged; const isDevVite = isDev && process.env.ELECTRON_RENDERER_URL; @@ -215,8 +214,7 @@ async function handleWSEvent(evtMsg: WSEventType) { return; } const clientData = await services.ClientService.GetClientData(); - const settings = await services.FileService.GetSettingsConfig(); - const newWin = createBrowserWindow(clientData.oid, windowData, settings); + const newWin = createBrowserWindow(clientData.oid, windowData); await newWin.readyPromise; newWin.show(); } else if (evtMsg.eventtype == "electron:closewindow") { @@ -292,39 +290,15 @@ function shFrameNavHandler(event: Electron.Event 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; - } - } +function createBrowserWindow(clientId: string, waveWindow: WaveWindow): WaveBrowserWindow { let winBounds = { - x: winPosX, - y: winPosY, - width: winWidth, - height: winHeight, + x: waveWindow.pos.x, + y: waveWindow.pos.y, + width: waveWindow.winsize.width, + height: waveWindow.winsize.height, }; winBounds = ensureBoundsAreVisible(winBounds); - const winOpts: Electron.BrowserWindowConstructorOptions = { + const bwin = new electron.BrowserWindow({ titleBarStyle: "hiddenInset", x: winBounds.x, y: winBounds.y, @@ -342,26 +316,8 @@ function createBrowserWindow( }, show: false, autoHideMenuBar: true, - }; - 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); + backgroundColor: "#000000", + }); (bwin as any).waveWindowId = waveWindow.oid; let readyResolve: (value: void) => void; (bwin as any).readyPromise = new Promise((resolve, _) => { @@ -563,8 +519,7 @@ electron.ipcMain.on("getEnv", (event, varName) => { async function createNewWaveWindow() { const clientData = await services.ClientService.GetClientData(); const newWindow = await services.ClientService.MakeWindow(); - const settings = await services.FileService.GetSettingsConfig(); - const newBrowserWindow = createBrowserWindow(clientData.oid, newWindow, settings); + const newBrowserWindow = createBrowserWindow(clientData.oid, newWindow); newBrowserWindow.show(); } @@ -608,7 +563,6 @@ function makeAppMenu() { }, { role: "close", - accelerator: "", // clear the accelerator click: () => { electron.BrowserWindow.getFocusedWindow()?.close(); }, @@ -662,12 +616,6 @@ function makeAppMenu() { { role: "forceReload", }, - { - label: "Relaunch All Windows", - click: () => { - relaunchBrowserWindows(); - }, - }, { role: "toggleDevTools", }, @@ -690,14 +638,6 @@ function makeAppMenu() { role: "togglefullscreen", }, ]; - const windowMenu: Electron.MenuItemConstructorOptions[] = [ - { role: "minimize", accelerator: "" }, - { role: "zoom" }, - { type: "separator" }, - { role: "front" }, - { type: "separator" }, - { role: "window" }, - ]; const menuTemplate: Electron.MenuItemConstructorOptions[] = [ { role: "appMenu", @@ -716,7 +656,6 @@ function makeAppMenu() { }, { role: "windowMenu", - submenu: windowMenu, }, ]; const menu = electron.Menu.buildFromTemplate(menuTemplate); @@ -724,9 +663,6 @@ function makeAppMenu() { } electronApp.on("window-all-closed", () => { - if (globalIsRelaunching) { - return; - } if (unamePlatform !== "darwin") { electronApp.quit(); } @@ -921,36 +857,6 @@ async function configureAutoUpdater() { } // ====== 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() { const startTs = Date.now(); const instanceLock = electronApp.requestSingleInstanceLock(); @@ -971,8 +877,27 @@ async function appMain() { } const ready = await waveSrvReady; 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(); - 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(); globalIsStarting = false;