Last active
March 3, 2022 16:07
-
-
Save Moizsohail/b8ea7fd911aad0fce9791963df10a53d to your computer and use it in GitHub Desktop.
Chrome Extension In React With NPM Modules: Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sendMessage } from "../messaging"; | |
import { MessageTypes } from "../types"; | |
try { | |
chrome.commands.onCommand.addListener((command) => { | |
if (command === "execute") { | |
sendMessage(MessageTypes.shortcutExecute); | |
} | |
}); | |
// this is to check if there are any conflicts in your | |
// keyboard shorcut. If there are conflicts they won't be set | |
//A simple solution in this case will be to select another shortcut | |
// in the manifest.json | |
const checkCommandShortcuts = () => { | |
chrome.commands.getAll((commands) => { | |
let missingShortcuts = []; | |
for (let { name, shortcut } of commands) { | |
if (shortcut === "") { | |
missingShortcuts.push(name); | |
} | |
} | |
if (missingShortcuts.length > 0) { | |
console.log("Shortcuts not set", missingShortcuts); | |
} | |
}); | |
}; | |
chrome.runtime.onInstalled.addListener((reason) => { | |
console.log(reason, chrome.runtime.OnInstalledReason.INSTALL); | |
if (reason.reason === chrome.runtime.OnInstalledReason.UPDATE) { | |
checkCommandShortcuts(); | |
} | |
}); | |
} catch (e) { | |
console.error(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment