Skip to content

Commit

Permalink
An option to control whether automatic updates get installed.
Browse files Browse the repository at this point in the history
Fixes #1455
  • Loading branch information
Anthony Lieuallen committed Feb 16, 2012
1 parent 77f6c1d commit 2109ae7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
11 changes: 10 additions & 1 deletion content/addons.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Components.utils.import('resource://greasemonkey/prefmanager.js');
Components.utils.import('resource://greasemonkey/util.js');

// Globals.
Expand Down Expand Up @@ -139,6 +140,7 @@ var observer = {
}
break;
case 'move':
if ('updates' == aView) break;
gUserscriptsView.removeChild(node);
gUserscriptsView.insertBefore(node, gUserscriptsView.childNodes[data]);
greasemonkeyAddons.reselectLastSelected();
Expand Down Expand Up @@ -419,7 +421,8 @@ var greasemonkeyAddons = {
GM_config.uninstall(script);
break;
case 'cmd_userscript_checkUpdate':
script.checkForRemoteUpdate(true);
script.checkForRemoteUpdate(true,
GM_util.hitch(this, this.conditionalInstallUpdate, script));
break;
case 'cmd_userscript_installUpdate':
script.installUpdate();
Expand All @@ -431,6 +434,12 @@ var greasemonkeyAddons = {
}
},

conditionalInstallUpdate: function(aScript, aAvailable, aListener) {
if (GM_prefRoot.getValue('autoInstallUpdates')) {
aScript.handleRemoteUpdate(aAvailable, aListener);
}
},

buildContextMenu: function(aEvent) {
var script = greasemonkeyAddons.findSelectedScript();
if (!script) {
Expand Down
5 changes: 5 additions & 0 deletions content/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function GM_loadOptions() {

document.getElementById('check-update')
.checked = GM_prefRoot.getValue('enableUpdateChecking');
document.getElementById('auto-install-updates')
.checked = GM_prefRoot.getValue('autoInstallUpdates');
document.getElementById('secure-update')
.checked = GM_prefRoot.getValue('requireSecureUpdates');

Expand All @@ -27,6 +29,8 @@ function GM_saveOptions(checkbox) {
document.getElementById('globalExcludes').pages;
GM_prefRoot.setValue('enableUpdateChecking',
!!document.getElementById('check-update').checked);
GM_prefRoot.setValue('autoInstallUpdates',
!!document.getElementById('auto-install-updates').checked);
GM_prefRoot.setValue('requireSecureUpdates',
!!document.getElementById('secure-update').checked);
GM_prefRoot.setValue("minDaysBetweenUpdateChecks", GM_getMinUpdateDays());
Expand All @@ -38,6 +42,7 @@ function GM_getMinUpdateDays() {

function GM_onChangeUpdateChecking() {
var enabled = document.getElementById('check-update').checked;
document.getElementById('auto-install-updates').disabled = !enabled;
document.getElementById('secure-update').disabled = !enabled;
document.getElementById('slide-updateInterval').disabled = !enabled;
document.getElementById('label-slide-updateInterval').disabled = !enabled;
Expand Down
6 changes: 2 additions & 4 deletions content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@
<caption label="&UpdateChecking;" />
<checkbox id="check-update" label="&EnableUpdateChecking;"
oncommand="GM_onChangeUpdateChecking()" />
<hbox>
<separator orient="vertical" />
<checkbox id="secure-update" label="&RequireSecureUpdates;" />
</hbox>
<checkbox id="auto-install-updates" label="&AutoInstallUpdates;" />
<checkbox id="secure-update" label="&RequireSecureUpdates;" />
<label value="&UpdateInterval;" control="slide-updateInterval"
id="label-slide-updateInterval" />
<hbox>
Expand Down
1 change: 1 addition & 0 deletions defaults/preferences/greasemonkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pref("greasemonkey.enableScriptRefreshing", true);
pref("greasemonkey.uninstallPreferences", true);
pref("greasemonkey.enableUpdateChecking", false);
pref("greasemonkey.minDaysBetweenUpdateChecks", 7);
pref("greasemonkey.autoInstallUpdates", true);
pref("greasemonkey.requireSecureUpdates", true);
pref("greasemonkey.haveInsertedToolbarbutton", false);
pref("greasemonkey.logChrome", false);
1 change: 1 addition & 0 deletions locale/en-US/greasemonkey.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<!ENTITY UpdateChecking "Update Checking">
<!ENTITY EnableUpdateChecking "Enable automatic update checking of scripts">
<!ENTITY UpdateInterval "Minimum number of days between update checks">
<!ENTITY AutoInstallUpdates "Automatically install updates when found">
<!ENTITY RequireSecureUpdates "Require secure updates">
<!ENTITY greasemonkey.noscriptshere "No installed scripts run on this page.">
<!ENTITY greasemonkey.youhavenoscripts "You don't have any user scripts installed">
Expand Down
8 changes: 7 additions & 1 deletion modules/addons4.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var EXPORTED_SYMBOLS = [
Components.utils.import('resource://gre/modules/AddonManager.jsm');
Components.utils.import('resource://gre/modules/Services.jsm');
Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
Components.utils.import('resource://greasemonkey/prefmanager.js');
Components.utils.import('resource://greasemonkey/util.js');

var Cc = Components.classes;
Expand Down Expand Up @@ -109,7 +110,6 @@ ScriptAddon.prototype.scope = AddonManager.SCOPE_PROFILE;
ScriptAddon.prototype.name = null;
ScriptAddon.prototype.creator = null;
ScriptAddon.prototype.pendingOperations = 0;
ScriptAddon.prototype.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT;
ScriptAddon.prototype.operationsRequiringRestart = AddonManager.OP_NEEDS_RESTART_NONE;

// Optional attributes
Expand All @@ -118,6 +118,12 @@ ScriptAddon.prototype.description = null;
// Private and custom attributes.
ScriptAddon.prototype._script = null;

ScriptAddon.prototype.__defineGetter__('applyBackgroundUpdates',
function ScriptAddon_getApplyBackgroundUpdates() {
return GM_prefRoot.getValue('autoInstallUpdates')
? AddonManager.AUTOUPDATE_ENABLE : AddonManager.AUTOUPDATE_DISABLE;
});

ScriptAddon.prototype.__defineGetter__('executionIndex',
function ScriptAddon_getExecutionIndex() {
return GM_util.getService().config._scripts.indexOf(this._script);
Expand Down

0 comments on commit 2109ae7

Please sign in to comment.