Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export default function App() {
return `${cmd} ${args.join(' ')}`.trim();
}

useEffect(() => window.electron.reactReady(), []);

useEffect(() => {
const handleAddExtension = (_: any, link: string) => {
const command = extractCommand(link);
Expand Down
29 changes: 15 additions & 14 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,25 @@ if (started) app.quit();
app.setAsDefaultProtocolClient('goose');

// Triggered when the user opens "goose://..." links
let firstOpenWindow: BrowserWindow;
let pendingDeepLink = null; // Store deep link if sent before React is ready
app.on('open-url', async (event, url) => {
event.preventDefault();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is ok to remove this? (actually never sure why it was there in the first place)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to test deep links without packaging the app, just the regular npm start dev mode environment.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH WOW - @matthewdiamant I wish I had known this months ago!

pendingDeepLink = url;

// Get existing window or create new one
let targetWindow: BrowserWindow;
const existingWindows = BrowserWindow.getAllWindows();

if (existingWindows.length > 0) {
targetWindow = existingWindows[0];
if (targetWindow.isMinimized()) targetWindow.restore();
targetWindow.focus();
firstOpenWindow = existingWindows[0];
if (firstOpenWindow.isMinimized()) firstOpenWindow.restore();
firstOpenWindow.focus();
} else {
const recentDirs = loadRecentDirs();
const openDir = recentDirs.length > 0 ? recentDirs[0] : null;
targetWindow = await createChat(app, undefined, openDir);
firstOpenWindow = await createChat(app, undefined, openDir);
}

// Wait for window to be ready before sending the extension URL
if (!targetWindow.webContents.isLoading()) {
targetWindow.webContents.send('add-extension', url);
} else {
targetWindow.webContents.once('did-finish-load', () => {
targetWindow.webContents.send('add-extension', url);
});
}
firstOpenWindow.webContents.send('add-extension', pendingDeepLink);
});

declare var MAIN_WINDOW_VITE_DEV_SERVER_URL: string;
Expand Down Expand Up @@ -332,6 +326,13 @@ process.on('unhandledRejection', (error) => {
handleFatalError(error instanceof Error ? error : new Error(String(error)));
});

ipcMain.on('react-ready', (event) => {
if (pendingDeepLink) {
firstOpenWindow.webContents.send('add-extension', pendingDeepLink);
pendingDeepLink = null;
}
});

// Add file/directory selection handler
ipcMain.handle('select-file-or-directory', async () => {
const result = await dialog.showOpenDialog({
Expand Down
2 changes: 2 additions & 0 deletions ui/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const config = JSON.parse(process.argv.find((arg) => arg.startsWith('{')) || '{}

// Define the API types in a single place
type ElectronAPI = {
reactReady: () => void;
getConfig: () => Record<string, any>;
hideWindow: () => void;
directoryChooser: (replace: string) => void;
Expand Down Expand Up @@ -44,6 +45,7 @@ type AppConfigAPI = {
};

const electronAPI: ElectronAPI = {
reactReady: () => ipcRenderer.send('react-ready'),
getConfig: () => config,
hideWindow: () => ipcRenderer.send('hide-window'),
directoryChooser: (replace: string) => ipcRenderer.send('directory-chooser', replace),
Expand Down