forked from nigelbabu/warn-before-quit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work of porting add-on to WebExtensions
- Loading branch information
1 parent
50635b8
commit 55fe996
Showing
5 changed files
with
59 additions
and
72 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
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; | ||
} |
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
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" | ||
} |
This file was deleted.
Oops, something went wrong.