refactor: change open recipe in new window to pass recipe id (#7392)

This commit is contained in:
Zane
2026-02-23 07:24:00 -08:00
committed by GitHub
parent 33af64406b
commit ffed9dfc4f
12 changed files with 162 additions and 198 deletions
+94 -106
View File
@@ -158,17 +158,12 @@ if (process.platform !== 'darwin') {
const deeplinkData = parseRecipeDeeplink(protocolUrl);
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
createChat(
app,
undefined,
openDir || undefined,
undefined,
undefined,
undefined,
deeplinkData?.config,
scheduledJobId || undefined,
deeplinkData?.parameters
);
await createChat(app, {
dir: openDir || undefined,
recipeDeeplink: deeplinkData?.config,
scheduledJobId: scheduledJobId || undefined,
recipeParameters: deeplinkData?.parameters,
});
});
return; // Skip the rest of the handler
}
@@ -217,7 +212,7 @@ async function handleProtocolUrl(url: string) {
const targetWindow =
existingWindows.length > 0
? existingWindows[0]
: await createChat(app, undefined, openDir || undefined);
: await createChat(app, { dir: openDir || undefined });
await processProtocolUrl(parsedUrl, targetWindow);
} else {
// For other URL types, reuse existing window if available
@@ -229,7 +224,7 @@ async function handleProtocolUrl(url: string) {
}
firstOpenWindow.focus();
} else {
firstOpenWindow = await createChat(app, undefined, openDir || undefined);
firstOpenWindow = await createChat(app, { dir: openDir || undefined });
}
if (firstOpenWindow) {
@@ -258,17 +253,12 @@ async function processProtocolUrl(parsedUrl: URL, window: BrowserWindow) {
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
// Create a new window and ignore the passed-in window
createChat(
app,
undefined,
openDir || undefined,
undefined,
undefined,
undefined,
deeplinkData?.config,
scheduledJobId || undefined,
deeplinkData?.parameters
);
await createChat(app, {
dir: openDir || undefined,
recipeDeeplink: deeplinkData?.config,
scheduledJobId: scheduledJobId || undefined,
recipeParameters: deeplinkData?.parameters,
});
pendingDeepLink = null;
}
}
@@ -296,17 +286,12 @@ app.on('open-url', async (_event, url) => {
}
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
await createChat(
app,
undefined,
openDir || undefined,
undefined,
undefined,
undefined,
deeplinkData?.config,
scheduledJobId || undefined,
deeplinkData?.parameters
);
await createChat(app, {
dir: openDir || undefined,
recipeDeeplink: deeplinkData?.config,
scheduledJobId: scheduledJobId || undefined,
recipeParameters: deeplinkData?.parameters,
});
windowDeeplinkURL = null;
return;
}
@@ -329,7 +314,7 @@ app.on('open-url', async (_event, url) => {
}
} else {
openUrlHandledLaunch = true;
firstOpenWindow = await createChat(app, undefined, openDir || undefined);
firstOpenWindow = await createChat(app, { dir: openDir || undefined });
}
}
});
@@ -380,7 +365,7 @@ async function handleFileOpen(filePath: string) {
addRecentDir(targetDir);
// Create new window for the directory
const newWindow = await createChat(app, undefined, targetDir);
const newWindow = await createChat(app, { dir: targetDir });
// Focus the new window
if (newWindow) {
@@ -478,17 +463,28 @@ const windowPowerSaveBlockers = new Map<number, number>(); // windowId -> blocke
// Track pending initial messages per window
const pendingInitialMessages = new Map<number, string>(); // windowId -> initialMessage
const createChat = async (
app: App,
initialMessage?: string,
dir?: string,
_version?: string,
resumeSessionId?: string,
viewType?: string,
recipeDeeplink?: string, // Raw deeplink decoded on server
scheduledJobId?: string, // Scheduled job ID if applicable
recipeParameters?: Record<string, string> // Recipe parameter values from deeplink URL
) => {
interface CreateChatOptions {
initialMessage?: string;
dir?: string;
resumeSessionId?: string;
viewType?: string;
recipeDeeplink?: string;
recipeId?: string;
scheduledJobId?: string;
recipeParameters?: Record<string, string>;
}
const createChat = async (app: App, options: CreateChatOptions = {}) => {
const {
initialMessage,
dir,
resumeSessionId,
viewType,
recipeDeeplink,
recipeId,
scheduledJobId,
recipeParameters,
} = options;
const settings = getSettings();
const serverSecret = getServerSecret(settings);
@@ -548,6 +544,7 @@ const createChat = async (
GOOSE_BASE_URL_SHARE: baseUrlShare,
GOOSE_VERSION: version,
recipeDeeplink: recipeDeeplink,
recipeId: recipeId,
recipeParameters: recipeParameters,
scheduledJobId: scheduledJobId,
SECURITY_ML_MODEL_MAPPING: process.env.SECURITY_ML_MODEL_MAPPING,
@@ -590,7 +587,7 @@ const createChat = async (
}
});
mainWindow.destroy();
return createChat(app, initialMessage, dir);
return createChat(app, { initialMessage, dir });
}
} else {
dialog.showMessageBoxSync({
@@ -720,7 +717,10 @@ const createChat = async (
if (viewType) {
appPath = routeMap[viewType] || '/';
}
if (appPath === '/' && (recipeDeeplink !== undefined || initialMessage)) {
if (
appPath === '/' &&
(recipeDeeplink !== undefined || recipeId !== undefined || initialMessage)
) {
appPath = '/pair';
}
@@ -931,7 +931,7 @@ const showWindow = async () => {
log.info('No windows are open, creating a new one...');
const recentDirs = loadRecentDirs();
const openDir = recentDirs.length > 0 ? recentDirs[0] : null;
await createChat(app, undefined, openDir || undefined);
await createChat(app, { dir: openDir || undefined });
return;
}
@@ -963,8 +963,8 @@ const buildRecentFilesMenu = () => {
const recentDirs = loadRecentDirs();
return recentDirs.map((dir) => ({
label: dir,
click: () => {
createChat(app, undefined, dir);
click: async () => {
await createChat(app, { dir });
},
}));
};
@@ -1052,18 +1052,11 @@ const openDirectoryDialog = async (): Promise<OpenDialogReturnValue> => {
if (windowDeeplinkURL) {
deeplinkData = parseRecipeDeeplink(windowDeeplinkURL);
}
// Create a new window with the selected directory
await createChat(
app,
undefined,
dirToAdd,
undefined,
undefined,
undefined,
deeplinkData?.config,
undefined,
deeplinkData?.parameters
);
await createChat(app, {
dir: dirToAdd,
recipeDeeplink: deeplinkData?.config,
recipeParameters: deeplinkData?.parameters,
});
}
return result;
};
@@ -1615,7 +1608,7 @@ ipcMain.handle('get-allowed-extensions', async () => {
const createNewWindow = async (app: App, dir?: string | null) => {
const recentDirs = loadRecentDirs();
const openDir = dir || (recentDirs.length > 0 ? recentDirs[0] : undefined);
return await createChat(app, undefined, openDir);
return await createChat(app, { dir: openDir });
};
const focusWindow = () => {
@@ -2032,48 +2025,43 @@ async function appMain() {
}
});
ipcMain.on(
'create-chat-window',
(event, query, dir, version, resumeSessionId, viewType, recipeDeeplink) => {
if (!dir?.trim()) {
const recentDirs = loadRecentDirs();
dir = recentDirs.length > 0 ? recentDirs[0] : undefined;
}
ipcMain.on('create-chat-window', (event, options = {}) => {
const { query, dir, resumeSessionId, viewType, recipeId } = options;
const isFromLauncher = query && !resumeSessionId && !viewType && !recipeDeeplink;
if (isFromLauncher) {
const senderWindow = BrowserWindow.fromWebContents(event.sender);
const launcherWindowId = senderWindow?.id;
const allWindows = BrowserWindow.getAllWindows();
const existingWindows = allWindows.filter(
(win) => !win.isDestroyed() && win.id !== launcherWindowId
);
if (existingWindows.length > 0) {
const targetWindow = existingWindows[0];
targetWindow.show();
targetWindow.focus();
targetWindow.webContents.send('set-initial-message', query);
return;
}
}
// Otherwise, create a new window
createChat(
app,
query,
dir,
version,
resumeSessionId,
viewType,
recipeDeeplink,
undefined,
undefined
);
let resolvedDir = dir;
if (!resolvedDir?.trim()) {
const recentDirs = loadRecentDirs();
resolvedDir = recentDirs.length > 0 ? recentDirs[0] : undefined;
}
);
const isFromLauncher = query && !resumeSessionId && !viewType && !recipeId;
if (isFromLauncher) {
const senderWindow = BrowserWindow.fromWebContents(event.sender);
const launcherWindowId = senderWindow?.id;
const allWindows = BrowserWindow.getAllWindows();
const existingWindows = allWindows.filter(
(win) => !win.isDestroyed() && win.id !== launcherWindowId
);
if (existingWindows.length > 0) {
const targetWindow = existingWindows[0];
targetWindow.show();
targetWindow.focus();
targetWindow.webContents.send('set-initial-message', query);
return;
}
}
createChat(app, {
initialMessage: query,
dir: resolvedDir,
resumeSessionId,
viewType,
recipeId,
});
});
ipcMain.on('close-window', (event) => {
const window = BrowserWindow.fromWebContents(event.sender);