+7
-100
@@ -194,102 +194,9 @@ const createChat = async (app, query?: string, dir?: string, version?: string) =
|
|||||||
globalShortcut.unregister('Alt+Command+I');
|
globalShortcut.unregister('Alt+Command+I');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Install MCP Extension shortcut
|
|
||||||
const registerMCPExtensionsShortcut = () => {
|
|
||||||
globalShortcut.register('Shift+Command+Y', () => {
|
|
||||||
const defaultUrl =
|
|
||||||
'goose://extension?cmd=npx&arg=-y&arg=%40modelcontextprotocol%2Fserver-github&id=github&name=GitHub&description=Repository%20management%2C%20file%20operations%2C%20and%20GitHub%20API%20integration&env=GITHUB_TOKEN%3DGitHub%20personal%20access%20token';
|
|
||||||
|
|
||||||
const result = dialog.showMessageBoxSync({
|
|
||||||
type: 'question',
|
|
||||||
buttons: ['Install', 'Edit URL', 'Cancel'],
|
|
||||||
defaultId: 0,
|
|
||||||
cancelId: 2,
|
|
||||||
title: 'Install MCP Extension',
|
|
||||||
message: 'Install MCP Extension',
|
|
||||||
detail: `Current extension URL:\n\n${defaultUrl}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result === 0) {
|
|
||||||
// User clicked Install
|
|
||||||
const mockEvent = {
|
|
||||||
preventDefault: () => {
|
|
||||||
console.log('Default handling prevented.');
|
|
||||||
},
|
|
||||||
};
|
|
||||||
app.emit('open-url', mockEvent, defaultUrl);
|
|
||||||
} else if (result === 1) {
|
|
||||||
// User clicked Edit URL
|
|
||||||
// Create a simple input dialog
|
|
||||||
const win = new BrowserWindow({
|
|
||||||
width: 800,
|
|
||||||
height: 120,
|
|
||||||
frame: false,
|
|
||||||
transparent: false,
|
|
||||||
resizable: false,
|
|
||||||
minimizable: false,
|
|
||||||
maximizable: false,
|
|
||||||
parent: BrowserWindow.getFocusedWindow(),
|
|
||||||
modal: true,
|
|
||||||
show: false,
|
|
||||||
webPreferences: {
|
|
||||||
nodeIntegration: true,
|
|
||||||
contextIsolation: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
win.loadURL(`data:text/html,
|
|
||||||
<html>
|
|
||||||
<body style="margin: 20px; font-family: system-ui;">
|
|
||||||
<input type="text" id="url" value="${defaultUrl}" style="width: 100%; padding: 8px; margin-bottom: 10px;">
|
|
||||||
<div style="text-align: right;">
|
|
||||||
<button onclick="window.close()" style="margin-right: 10px;">Cancel</button>
|
|
||||||
<button onclick="submit()" style="min-width: 80px;">Install</button>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
function submit() {
|
|
||||||
require('electron').ipcRenderer.send('install-extension-url', document.getElementById('url').value);
|
|
||||||
}
|
|
||||||
// Handle Enter key
|
|
||||||
document.getElementById('url').addEventListener('keypress', (e) => {
|
|
||||||
if (e.key === 'Enter') submit();
|
|
||||||
});
|
|
||||||
// Focus the input
|
|
||||||
document.getElementById('url').focus();
|
|
||||||
document.getElementById('url').select();
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`);
|
|
||||||
|
|
||||||
win.once('ready-to-show', () => {
|
|
||||||
win.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle the URL submission
|
|
||||||
ipcMain.once('install-extension-url', (event, url) => {
|
|
||||||
win.close();
|
|
||||||
const mockEvent = {
|
|
||||||
preventDefault: () => {
|
|
||||||
console.log('Default handling prevented.');
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (url && url.trim()) {
|
|
||||||
app.emit('open-url', mockEvent, url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const unRegisterMCPExtensionsShortcut = () => {
|
|
||||||
globalShortcut.unregister('Shift+Command+Y');
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register shortcuts when window is focused
|
// Register shortcuts when window is focused
|
||||||
mainWindow.on('focus', () => {
|
mainWindow.on('focus', () => {
|
||||||
registerDevToolsShortcut(mainWindow);
|
registerDevToolsShortcut(mainWindow);
|
||||||
registerMCPExtensionsShortcut();
|
|
||||||
// Register reload shortcut
|
// Register reload shortcut
|
||||||
globalShortcut.register('CommandOrControl+R', () => {
|
globalShortcut.register('CommandOrControl+R', () => {
|
||||||
mainWindow.reload();
|
mainWindow.reload();
|
||||||
@@ -299,7 +206,6 @@ const createChat = async (app, query?: string, dir?: string, version?: string) =
|
|||||||
// Unregister shortcuts when window loses focus
|
// Unregister shortcuts when window loses focus
|
||||||
mainWindow.on('blur', () => {
|
mainWindow.on('blur', () => {
|
||||||
unregisterDevToolsShortcut();
|
unregisterDevToolsShortcut();
|
||||||
unRegisterMCPExtensionsShortcut();
|
|
||||||
globalShortcut.unregister('CommandOrControl+R');
|
globalShortcut.unregister('CommandOrControl+R');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -477,7 +383,8 @@ app.whenReady().then(async () => {
|
|||||||
const appMenu = menu.items.find((item) => item.label === 'Goose');
|
const appMenu = menu.items.find((item) => item.label === 'Goose');
|
||||||
// add Settings to app menu after About
|
// add Settings to app menu after About
|
||||||
appMenu.submenu.insert(1, new MenuItem({ type: 'separator' }));
|
appMenu.submenu.insert(1, new MenuItem({ type: 'separator' }));
|
||||||
appMenu.submenu.insert(1,
|
appMenu.submenu.insert(
|
||||||
|
1,
|
||||||
new MenuItem({
|
new MenuItem({
|
||||||
label: 'Settings',
|
label: 'Settings',
|
||||||
accelerator: 'CmdOrCtrl+,',
|
accelerator: 'CmdOrCtrl+,',
|
||||||
@@ -645,16 +552,16 @@ app.whenReady().then(async () => {
|
|||||||
exec(`cat ${filePath}`, (error, stdout, stderr) => {
|
exec(`cat ${filePath}`, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
// File not found
|
// File not found
|
||||||
resolve({ file: "", filePath, error: null, found: false });
|
resolve({ file: '', filePath, error: null, found: false });
|
||||||
}
|
}
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.error('Error output:', stderr);
|
console.error('Error output:', stderr);
|
||||||
resolve({ file: "", filePath, error, found: false });
|
resolve({ file: '', filePath, error, found: false });
|
||||||
}
|
}
|
||||||
resolve({ file: stdout, filePath, error: null, found: true });
|
resolve({ file: stdout, filePath, error: null, found: true });
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
ipcMain.handle('write-file', (event, filePath, content) => {
|
ipcMain.handle('write-file', (event, filePath, content) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@@ -681,4 +588,4 @@ app.on('window-all-closed', () => {
|
|||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user