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
32 changes: 32 additions & 0 deletions src/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,37 @@
"optional": ["personallyIdentifyingInfo", "authenticationInfo", "personalCommunications", "websiteContent", "technicalAndInteraction"]
}
}
},
"commands": {
"_execute_sidebar_action": {
"suggested_key": {
"default": "Alt+Shift+W"
},
"description": "Open WebBrain panel"
},
"switch-to-ask": {
"suggested_key": {
"default": "Ctrl+Shift+A"
},
"description": "Switch to Ask mode"
},
"switch-to-act": {
"suggested_key": {
"default": "Ctrl+Shift+X"
},
"description": "Switch to Act mode"
},
"switch-to-dev": {
"suggested_key": {
"default": "Ctrl+Shift+D"
},
"description": "Switch to Dev mode"
},
"focus-input": {
"suggested_key": {
"default": "Ctrl+Period"
},
"description": "Focus the input"
}
}
}
15 changes: 15 additions & 0 deletions src/firefox/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2890,3 +2890,18 @@ async function handleMessage(msg, sender) {
throw new Error(`Unknown action: ${msg.action}`);
}
}

// --- Keyboard shortcuts (browser.commands) ---
// Firefox requires a "commands" manifest entry for browser-level keyboard shortcuts
// to work. Custom commands fire here in the background script; we dispatch them via
// storage.onChanged so the side panel (and any other extension page) can react
// reliably — runtime.sendMessage can miss a sidepanel that isn't fully loaded.
browser.commands.onCommand.addListener(async (command) => {
// _execute_sidebar_action is handled natively by Firefox — no need to forward
if (command === '_execute_sidebar_action') return;
try {
await browser.storage.local.set({ _wb_cmd: { command, ts: Date.now() } });
} catch (err) {
console.error('[WebBrain] failed to dispatch command:', command, err);
}
});
29 changes: 29 additions & 0 deletions src/firefox/src/ui/sidepanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7870,6 +7870,35 @@ browser.runtime.onMessage.addListener((msg) => {
acceptContextMenuPrompt(msg.prompt || msg);
});

// --- Keyboard shortcut commands from background script ---
// Firefox browser.commands custom shortcuts fire in the background script
// (browser.commands.onCommand). The background dispatches them via
// storage.local so the side panel can receive them reliably even when
// runtime.sendMessage would miss the panel.
browser.storage.onChanged.addListener((changes) => {
if (!changes._wb_cmd?.newValue) return;
const { command } = changes._wb_cmd.newValue;
switch (command) {
case 'switch-to-ask':
if (!isProcessing) setMode('ask');
break;
case 'switch-to-act':
if (!isProcessing) ensureActMode();
break;
case 'switch-to-dev':
if (!isProcessing) ensureDevMode();
break;
case 'focus-input':
// Firefox won't allow inputEl.focus() if the sidebar panel doesn't
// have focus — window.focus() acquires it first so the input focus
// actually takes effect.
window.focus();
inputEl.focus();
inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length);
break;
}
});

browser.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
if (msg?.target !== 'sidepanel'
|| msg.action !== 'tab_chat_handoff_request'
Expand Down