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 @@ -11,7 +11,7 @@
import { ToastContainer } from 'react-toastify';
import { extractExtensionName } from './components/settings/extensions/utils';
import { GoosehintsModal } from './components/GoosehintsModal';
import { SessionDetails, fetchSessionDetails } from './sessions';

Check warning on line 14 in ui/desktop/src/App.tsx

View workflow job for this annotation

GitHub Actions / Lint Electron Desktop App

'fetchSessionDetails' is defined but never used. Allowed unused vars must match /^_/u

import WelcomeView from './components/WelcomeView';
import ChatView from './components/ChatView';
Expand Down Expand Up @@ -44,7 +44,7 @@
| {
resumedSession?: SessionDetails;
}
| Record<string, any>;

Check warning on line 47 in ui/desktop/src/App.tsx

View workflow job for this annotation

GitHub Actions / Lint Electron Desktop App

Unexpected any. Specify a different type
};

export default function App() {
Expand All @@ -62,7 +62,7 @@

const { switchModel } = useModel();
const { addRecentModel } = useRecentModels();
const setView = (view: View, viewOptions: Record<any, any> = {}) => {

Check warning on line 65 in ui/desktop/src/App.tsx

View workflow job for this annotation

GitHub Actions / Lint Electron Desktop App

Unexpected any. Specify a different type

Check warning on line 65 in ui/desktop/src/App.tsx

View workflow job for this annotation

GitHub Actions / Lint Electron Desktop App

Unexpected any. Specify a different type
setInternalView({ view, viewOptions });
};

Expand All @@ -74,8 +74,10 @@
return `${cmd} ${args.join(' ')}`.trim();
}

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

useEffect(() => {
const handleAddExtension = (_: any, link: string) => {

Check warning on line 80 in ui/desktop/src/App.tsx

View workflow job for this annotation

GitHub Actions / Lint Electron Desktop App

Unexpected any. Specify a different type
const command = extractCommand(link);
const extName = extractExtensionName(link);
window.electron.logInfo(`Adding extension from deep link ${link}`);
Expand Down Expand Up @@ -150,12 +152,12 @@
};

setupStoredProvider();
}, []);

Check warning on line 155 in ui/desktop/src/App.tsx

View workflow job for this annotation

GitHub Actions / Lint Electron Desktop App

React Hook useEffect has missing dependencies: 'addRecentModel' and 'switchModel'. Either include them or remove the dependency array

const { chat, setChat } = useChat({ setView, setIsLoadingSession });

useEffect(() => {
const handleFatalError = (_: any, errorMessage: string) => {

Check warning on line 160 in ui/desktop/src/App.tsx

View workflow job for this annotation

GitHub Actions / Lint Electron Desktop App

Unexpected any. Specify a different type
setFatalError(errorMessage);
};

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
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
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
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
Loading