From c874aa1d3998ef77729fcba7d383dc9951ecb12d Mon Sep 17 00:00:00 2001 From: Mohan Date: Tue, 10 Sep 2024 23:28:59 +0530 Subject: [PATCH] fix: Release 0.1.0-rc126 issues (#342) * Refactor SetupWelcome component to handle account setup state correctly * feat: trigger IPC call on app load (with commented code) * feat: remove all comments from main.js --- electron/main.js | 19 ++++++++++++++---- electron/preload.js | 2 ++ .../components/SetupPage/SetupWelcome.tsx | 20 ++++++++++++++----- frontend/context/ElectronApiProvider.tsx | 3 +++ frontend/pages/index.tsx | 4 ++++ 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/electron/main.js b/electron/main.js index a1035a22..5216987e 100644 --- a/electron/main.js +++ b/electron/main.js @@ -57,8 +57,12 @@ let appConfig = { }, }; +/** + * @type {BrowserWindow} + */ +let mainWindow; + let tray, - mainWindow, splashWindow, operateDaemon, operateDaemonPid, @@ -243,6 +247,14 @@ const createMainWindow = async () => { showNotification(title, description || undefined); }); + // if app (ie. mainWindow) is loaded, destroy splash window. + ipcMain.on('is-app-loaded', (_event, isLoaded) => { + if (isLoaded && splashWindow) { + splashWindow.destroy(); + splashWindow = null; + } + }); + mainWindow.webContents.on('did-fail-load', () => { mainWindow.webContents.reloadIgnoringCache(); }); @@ -261,7 +273,7 @@ const createMainWindow = async () => { event.preventDefault(); mainWindow.hide(); }); - + try { logger.electron('Setting up store IPC'); await setupStoreIpc(ipcMain, mainWindow); @@ -337,7 +349,6 @@ async function launchDaemon() { } async function launchDaemonDev() { - const check = new Promise(function (resolve, _reject) { operateDaemon = spawn('poetry', [ 'run', @@ -503,7 +514,6 @@ ipcMain.on('check', async function (event, _argument) { event.sender.send('response', 'Launching App'); await createMainWindow(); createTray(); - splashWindow.destroy(); } catch (e) { logger.electron(e); new Notification({ @@ -522,6 +532,7 @@ app.on('ready', async () => { path.join(__dirname, 'assets/icons/splash-robot-head-dock.png'), ); } + createSplashWindow(); }); diff --git a/electron/preload.js b/electron/preload.js index 2878e232..562f49c7 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -1,6 +1,8 @@ const { contextBridge, ipcRenderer } = require('electron/renderer'); contextBridge.exposeInMainWorld('electronAPI', { + setIsAppLoaded: (isAppLoaded) => + ipcRenderer.send('is-app-loaded', isAppLoaded), closeApp: () => ipcRenderer.send('close-app'), minimizeApp: () => ipcRenderer.send('minimize-app'), setTrayIcon: (status) => ipcRenderer.send('tray', status), diff --git a/frontend/components/SetupPage/SetupWelcome.tsx b/frontend/components/SetupPage/SetupWelcome.tsx index b12c2ebf..9d3c3b3d 100644 --- a/frontend/components/SetupPage/SetupWelcome.tsx +++ b/frontend/components/SetupPage/SetupWelcome.tsx @@ -39,12 +39,13 @@ export const SetupWelcome = () => { case true: setIsSetup(AccountIsSetup.True); break; - case false: + case false: { // Reset persistent state // if creating new account electronApi.store?.clear?.(); setIsSetup(AccountIsSetup.False); break; + } default: setIsSetup(AccountIsSetup.Error); break; @@ -64,18 +65,27 @@ export const SetupWelcome = () => { return ; case AccountIsSetup.Loading: return ( - + ); - default: + case AccountIsSetup.Error: return ( - + - Error determining account setup state. + Unable to determine the account setup status, please try again. ); + default: + return null; } }, [isSetup]); diff --git a/frontend/context/ElectronApiProvider.tsx b/frontend/context/ElectronApiProvider.tsx index 01f85bdf..7927bf7d 100644 --- a/frontend/context/ElectronApiProvider.tsx +++ b/frontend/context/ElectronApiProvider.tsx @@ -4,6 +4,7 @@ import { createContext, PropsWithChildren } from 'react'; import { ElectronStore, ElectronTrayIconStatus } from '@/types/ElectronApi'; type ElectronApiContextProps = { + setIsAppLoaded?: (isLoaded: boolean) => void; closeApp?: () => void; minimizeApp?: () => void; setTrayIcon?: (status: ElectronTrayIconStatus) => void; @@ -33,6 +34,7 @@ type ElectronApiContextProps = { }; export const ElectronApiContext = createContext({ + setIsAppLoaded: () => false, closeApp: () => {}, minimizeApp: () => {}, setTrayIcon: () => {}, @@ -70,6 +72,7 @@ export const ElectronApiProvider = ({ children }: PropsWithChildren) => { return ( { + // Notify the main process that the app is loaded + electronApi?.setIsAppLoaded?.(true); + + // Set the app height to the body scroll height function updateAppHeight() { const bodyElement = document.querySelector('body'); if (bodyElement) {