Skip to content

Commit

Permalink
fix: reload doesn't crash the app
Browse files Browse the repository at this point in the history
  • Loading branch information
nahiyankhan committed Feb 1, 2025
1 parent 5f6c85d commit 3db1b84
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ui/desktop/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<title>Goose</title>
<link href="/src/styles/main.css" rel="stylesheet" />
<link href="./src/styles/main.css" rel="stylesheet" />
</head>
<script>
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
Expand All @@ -19,6 +19,6 @@
</script>
<body>
<div id="root"></div>
<script type="module" src="/src/renderer.tsx"></script>
<script type="module" src="./src/renderer.tsx"></script>
</body>
</html>
34 changes: 29 additions & 5 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,28 @@ const createChat = async (app, query?: string, dir?: string, version?: string) =
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
mainWindow.loadURL(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}${queryParam}`);
} else {
mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`), {
search: queryParam.slice(1),
});
// In production, we need to use a proper file protocol URL with correct base path
const indexPath = path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`);
console.log('Loading production path:', indexPath);
mainWindow
.loadFile(indexPath, {
search: queryParam ? queryParam.slice(1) : undefined,
})
.catch((err) => {
console.error('Failed to load window:', err);
// Try alternative path if first attempt fails
const altPath = path.join(
app.getAppPath(),
'out',
'renderer',
MAIN_WINDOW_VITE_NAME,
'index.html'
);
console.log('Trying alternative path:', altPath);
return mainWindow.loadFile(altPath, {
search: queryParam ? queryParam.slice(1) : undefined,
});
});
}

// DevTools shortcut management
Expand All @@ -206,14 +225,19 @@ const createChat = async (app, query?: string, dir?: string, version?: string) =
globalShortcut.unregister('Alt+Command+I');
};

// Register shortcut when window is focused
// Register shortcuts when window is focused
mainWindow.on('focus', () => {
registerDevToolsShortcut(mainWindow);
// Register reload shortcut
globalShortcut.register('CommandOrControl+R', () => {
mainWindow.reload();
});
});

// Unregister shortcut when window loses focus
// Unregister shortcuts when window loses focus
mainWindow.on('blur', () => {
unregisterDevToolsShortcut();
globalShortcut.unregister('CommandOrControl+R');
});

windowMap.set(windowId, mainWindow);
Expand Down
2 changes: 1 addition & 1 deletion ui/desktop/src/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter as Router } from 'react-router-dom';
import { HashRouter as Router } from 'react-router-dom';
import App from './App';

// Error Boundary Component
Expand Down
1 change: 1 addition & 0 deletions ui/desktop/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { resolve } from 'path';
// https://vitejs.dev/config
export default defineConfig({
plugins: [react()],
base: './',
build: {
rollupOptions: {
input: {
Expand Down

0 comments on commit 3db1b84

Please sign in to comment.