Make shortcut work

This commit is contained in:
Joey Yakimowich-Payne 2025-08-09 12:31:51 -06:00
commit a112f61c05
3 changed files with 30 additions and 5 deletions

View file

@ -2,14 +2,27 @@
// Handle keyboard shortcut // Handle keyboard shortcut
chrome.commands.onCommand.addListener(async (command) => { chrome.commands.onCommand.addListener(async (command) => {
console.log('Command received:', command);
if (command === 'activate-selector') { if (command === 'activate-selector') {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (tab && tab.url && !tab.url.startsWith('chrome://') && !tab.url.startsWith('chrome-extension://')) { if (
tab &&
tab.url &&
!tab.url.startsWith('chrome://') &&
!tab.url.startsWith('chrome-extension://') &&
!tab.url.startsWith('edge://') &&
!tab.url.startsWith('about:') &&
tab.url !== 'chrome://newtab/' &&
tab.url !== 'edge://newtab/'
) {
try { try {
await chrome.tabs.sendMessage(tab.id, { action: 'activateFromShortcut' }); await chrome.tabs.sendMessage(tab.id, { action: 'activateFromShortcut' });
} catch (error) { } catch (error) {
console.log('Could not activate selector on this page:', error); console.log(
'Could not activate selector on this page:',
error && error.message ? error.message : error
);
} }
} }
} }
@ -20,4 +33,15 @@ chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') { if (details.reason === 'install') {
console.log('Full Screenshot Selector installed'); console.log('Full Screenshot Selector installed');
} }
// Log available commands and their current shortcuts to help debug
chrome.commands.getAll((commands) => {
console.log('Registered commands:', commands);
});
});
// Also log commands on service worker startup (in case it wakes up later)
chrome.runtime.onStartup?.addListener(() => {
chrome.commands.getAll((commands) => {
console.log('Registered commands (onStartup):', commands);
});
}); });

View file

@ -6,6 +6,7 @@
"permissions": [ "permissions": [
"activeTab", "activeTab",
"tabs",
"storage" "storage"
], ],
@ -35,8 +36,8 @@
"commands": { "commands": {
"activate-selector": { "activate-selector": {
"suggested_key": { "suggested_key": {
"default": "Ctrl+Shift+S", "default": "Alt+Shift+S",
"mac": "Command+Shift+S" "mac": "Alt+Shift+S"
}, },
"description": "Activate screenshot selector" "description": "Activate screenshot selector"
} }

View file

@ -135,7 +135,7 @@
<div id="status" class="status" style="display: none;"></div> <div id="status" class="status" style="display: none;"></div>
<div class="shortcut-info"> <div class="shortcut-info">
💡 Tip: Use <strong>Ctrl+Shift+S</strong> (or Cmd+Shift+S on Mac) to quickly activate 💡 Tip: Use <strong>Alt+Shift+S</strong> (or Option+Shift+S on Mac) to quickly activate
</div> </div>
<script src="popup.js"></script> <script src="popup.js"></script>