mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 22:28:59 +02:00
Checking extension.shutdownReason for any purpose other than detecting app shutdown is unreliable, since actions such as disabing, uninstalling, etc. may happen ito an extension after it has shut down. Remove the temptation for api authors to write incorrect code by removing extension.shutdownReason and replacing it with an isAppShutdown boolean passed to shutdown handlers. Differential Revision: https://phabricator.services.mozilla.com/D30605 --HG-- extra : rebase_source : 07ff7710757150d011fec6bc3ed134c6509e9a12
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
/* vim: set sts=2 sw=2 et tw=80: */
|
|
"use strict";
|
|
|
|
ChromeUtils.defineModuleGetter(this, "ExtensionShortcuts",
|
|
"resource://gre/modules/ExtensionShortcuts.jsm");
|
|
|
|
this.commands = class extends ExtensionAPI {
|
|
static onUninstall(extensionId) {
|
|
return ExtensionShortcuts.removeCommandsFromStorage(extensionId);
|
|
}
|
|
|
|
async onManifestEntry(entryName) {
|
|
let shortcuts = new ExtensionShortcuts({
|
|
extension: this.extension,
|
|
onCommand: (name) => this.emit("command", name),
|
|
});
|
|
this.extension.shortcuts = shortcuts;
|
|
await shortcuts.loadCommands();
|
|
await shortcuts.register();
|
|
}
|
|
|
|
onShutdown() {
|
|
this.extension.shortcuts.unregister();
|
|
}
|
|
|
|
getAPI(context) {
|
|
return {
|
|
commands: {
|
|
getAll: () => this.extension.shortcuts.allCommands(),
|
|
update: (args) => this.extension.shortcuts.updateCommand(args),
|
|
reset: (name) => this.extension.shortcuts.resetCommand(name),
|
|
onCommand: new EventManager({
|
|
context,
|
|
name: "commands.onCommand",
|
|
inputHandling: true,
|
|
register: fire => {
|
|
let listener = (eventName, commandName) => {
|
|
fire.async(commandName);
|
|
};
|
|
this.on("command", listener);
|
|
return () => {
|
|
this.off("command", listener);
|
|
};
|
|
},
|
|
}).api(),
|
|
},
|
|
};
|
|
}
|
|
};
|