chore: Make debug MCP install keyboard shortcut only (#742)

This commit is contained in:
Alex Hancock
2025-01-25 22:17:09 -05:00
committed by GitHub
parent d1ee6f601e
commit 9e3b2d1edb
+80 -85
View File
@@ -426,96 +426,91 @@ app.whenReady().then(async () => {
}) })
); );
fileMenu.submenu.append( // Register global shortcut for Install MCP Extension
new MenuItem({ globalShortcut.register('Shift+Command+Y', () => {
label: 'Install MCP Extension', const defaultUrl =
accelerator: 'Shift+Command+Y', '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';
click() {
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({ const result = dialog.showMessageBoxSync({
type: 'question', type: 'question',
buttons: ['Install', 'Edit URL', 'Cancel'], buttons: ['Install', 'Edit URL', 'Cancel'],
defaultId: 0, defaultId: 0,
cancelId: 2, cancelId: 2,
title: 'Install MCP Extension', title: 'Install MCP Extension',
message: 'Install MCP Extension', message: 'Install MCP Extension',
detail: `Current extension URL:\n\n${defaultUrl}`, detail: `Current extension URL:\n\n${defaultUrl}`,
}); });
if (result === 0) { if (result === 0) {
// User clicked Install // User clicked Install
const mockEvent = { const mockEvent = {
preventDefault: () => { preventDefault: () => {
console.log('Default handling prevented.'); console.log('Default handling prevented.');
}, },
}; };
app.emit('open-url', mockEvent, defaultUrl); app.emit('open-url', mockEvent, defaultUrl);
} else if (result === 1) { } else if (result === 1) {
// User clicked Edit URL // User clicked Edit URL
// Create a simple input dialog // Create a simple input dialog
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 120, height: 120,
frame: false, frame: false,
transparent: false, transparent: false,
resizable: false, resizable: false,
minimizable: false, minimizable: false,
maximizable: false, maximizable: false,
parent: BrowserWindow.getFocusedWindow(), parent: BrowserWindow.getFocusedWindow(),
modal: true, modal: true,
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false, contextIsolation: false,
}, },
}); });
win.loadURL(`data:text/html, win.loadURL(`data:text/html,
<html> <html>
<body style="margin: 20px; font-family: system-ui;"> <body style="margin: 20px; font-family: system-ui;">
<input type="text" id="url" value="${defaultUrl}" style="width: 100%; padding: 8px; margin-bottom: 10px;"> <input type="text" id="url" value="${defaultUrl}" style="width: 100%; padding: 8px; margin-bottom: 10px;">
<div style="text-align: right;"> <div style="text-align: right;">
<button onclick="window.close()" style="margin-right: 10px;">Cancel</button> <button onclick="window.close()" style="margin-right: 10px;">Cancel</button>
<button onclick="submit()" style="min-width: 80px;">Install</button> <button onclick="submit()" style="min-width: 80px;">Install</button>
</div> </div>
<script> <script>
function submit() { function submit() {
require('electron').ipcRenderer.send('install-extension-url', document.getElementById('url').value); 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);
} }
}); // 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);
} }
}, });
}) }
); });
} }
Menu.setApplicationMenu(menu); Menu.setApplicationMenu(menu);