Skip to content

Commit

Permalink
Initial work of porting add-on to WebExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronraimist committed May 19, 2017
1 parent 50635b8 commit 55fe996
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Everyday, I quit Firefox accidentally at least once. Finally wrote this one to
Everyday, I quit Firefox accidentally at least once. Finally wrote this one to
stop doing that! Catches Ctrl-Q and shows a small panel that asks you press it
again within another second to quit firefox.

Expand Down
2 changes: 0 additions & 2 deletions doc/main.md

This file was deleted.

74 changes: 24 additions & 50 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,31 @@
// Define keyboard shortcuts for showing and hiding a custom panel.
var { Cc, Ci } = require("chrome");
var { Hotkey } = require("sdk/hotkeys");
var panel = require("sdk/panel");
var timers = require("sdk/timers");
var data = require("sdk/self").data;
var runtime = require("sdk/system/runtime");
var osString = runtime.OS;
var osWarnFile;
var hasWarned;

// Load the right warning
if (osString === "Darwin") {
osWarnFile = "warnmac.html";
} else {
osWarnFile = "warn.html";
}
var quitNotification = "quit-notification";

// Create the panel to show the warning
var myPanel = panel.Panel({
width: 300,
height: 80,
contentURL: data.url(osWarnFile),
});
browser.commands.onCommand.addListener(listener);

// Display the warning
function showPanel() {
myPanel.show();
timers.setTimeout(function() {
myPanel.hide();
}, 2000);
}
function listener(command) {
if (hasWarned) {
browser.commands.onCommand.removeListener(listener);

var pressButton = function() {
// We're already showing the warning
if (myPanel.isShowing) {
myPanel.hide();
Cc['@mozilla.org/toolkit/app-startup;1']
.getService(Ci.nsIAppStartup)
.quit(Ci.nsIAppStartup.eAttemptQuit)
}
// Show the warning since we didn't quit yet
showPanel();
};
return;
}

// Handle the keypress
var AccelQ = Hotkey({
combo: "accel-q",
onPress: function() {
pressButton();
if (command == "prevent-quit-mac") {
browser.notifications.create(quitNotification, {
"type": "basic",
"title": "Firefox was prevented from quitting",
"message": "Press ⌘-Q or ⌘-Shift-W again to quit."
});
}
});
var AccelShiftW = Hotkey({
combo: "accel-shift-w",
onPress: function() {
pressButton();

if (command == "prevent-quit") {
browser.notifications.create(quitNotification, {
"type": "basic",
"title": "Firefox was prevented from quitting",
"message": "Press Control-Q or Control-Shift-W again to quit."
});
}
});

hasWarned = true;
}
34 changes: 34 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"applications": {
"gecko": {
"strict_min_version": "48.0"
}
},
"author": "Nigel Babu",
"background": {
"scripts": [ "index.js" ]
},
"commands": {
"prevent-quit-mac": {
"description": "Send a 'prevent-quit-mac' event to the extension",
"suggested_key": {
"mac": "Command+Q"
}
},
"prevent-quit": {
"description": "Send a 'prevent-quit' event to the extension",
"suggested_key": {
"default": "Ctrl+Q"
}
}
},
"description": "Warn before quitting Firefox",
"homepage_url": "https://github.com/nigelbabu/warn-before-quit",
"license": "MIT",
"manifest_version": 2,
"name": "Warn Before Quit",
"permissions": [
"notifications"
],
"version": "1.0.0"
}
19 changes: 0 additions & 19 deletions package.json

This file was deleted.

0 comments on commit 55fe996

Please sign in to comment.