Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into fix/switch-back-to…
Browse files Browse the repository at this point in the history
…-beta
  • Loading branch information
truemiller committed Sep 11, 2024
2 parents 4cbf42a + c874aa1 commit 16bfb0a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
19 changes: 15 additions & 4 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ let appConfig = {
},
};

/**
* @type {BrowserWindow}
*/
let mainWindow;

let tray,
mainWindow,
splashWindow,
operateDaemon,
operateDaemonPid,
Expand Down Expand Up @@ -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();
});
Expand All @@ -261,7 +273,7 @@ const createMainWindow = async () => {
event.preventDefault();
mainWindow.hide();
});

try {
logger.electron('Setting up store IPC');
await setupStoreIpc(ipcMain, mainWindow);
Expand Down Expand Up @@ -337,7 +349,6 @@ async function launchDaemon() {
}

async function launchDaemonDev() {

const check = new Promise(function (resolve, _reject) {
operateDaemon = spawn('poetry', [
'run',
Expand Down Expand Up @@ -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({
Expand All @@ -522,6 +532,7 @@ app.on('ready', async () => {
path.join(__dirname, 'assets/icons/splash-robot-head-dock.png'),
);
}

createSplashWindow();
});

Expand Down
2 changes: 2 additions & 0 deletions electron/preload.js
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
20 changes: 15 additions & 5 deletions frontend/components/SetupPage/SetupWelcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,18 +65,27 @@ export const SetupWelcome = () => {
return <SetupWelcomeCreate />;
case AccountIsSetup.Loading:
return (
<Flex justify="center">
<Flex
justify="center"
align="center"
style={{ height: 140, marginBottom: 32 }}
>
<Spin />
</Flex>
);
default:
case AccountIsSetup.Error:
return (
<Flex justify="center">
<Flex
justify="center"
style={{ margin: '32px 0', textAlign: 'center' }}
>
<Typography.Text>
Error determining account setup state.
Unable to determine the account setup status, please try again.
</Typography.Text>
</Flex>
);
default:
return null;
}
}, [isSetup]);

Expand Down
3 changes: 3 additions & 0 deletions frontend/context/ElectronApiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,6 +34,7 @@ type ElectronApiContextProps = {
};

export const ElectronApiContext = createContext<ElectronApiContextProps>({
setIsAppLoaded: () => false,
closeApp: () => {},
minimizeApp: () => {},
setTrayIcon: () => {},
Expand Down Expand Up @@ -70,6 +72,7 @@ export const ElectronApiProvider = ({ children }: PropsWithChildren) => {
return (
<ElectronApiContext.Provider
value={{
setIsAppLoaded: getElectronApiFunction('setIsAppLoaded'),
closeApp: getElectronApiFunction('closeApp'),
minimizeApp: getElectronApiFunction('minimizeApp'),
setTrayIcon: getElectronApiFunction('setTrayIcon'),
Expand Down
4 changes: 4 additions & 0 deletions frontend/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default function Home() {
const electronApi = useElectronApi();

useEffect(() => {
// 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) {
Expand Down

0 comments on commit 16bfb0a

Please sign in to comment.