Skip to content

Commit 49f81f9

Browse files
committed
Add rule toggling
1 parent e8bed69 commit 49f81f9

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

src/chrome/content/code/FennecUI.jsm

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,37 @@ function popupToggleMenu(aWindow) {
6060
*/
6161

6262
var urlbarOptions = {
63+
6364
title: "HTTPS Everywhere",
65+
6466
icon: "chrome://https-everywhere/skin/https-everywhere-128.png",
67+
6568
clickCallback: function() {
66-
rulesPrompt.setMultiChoiceItems(getRuleItems());
69+
70+
var popupInfo = getPopupInfo();
71+
72+
rulesPrompt.setMultiChoiceItems(popupInfo.ruleItems);
73+
6774
rulesPrompt.show(function(data) {
68-
aWindow.alert(JSON.stringify(data));
75+
if (data.button === -1) { return null; }
76+
for (var i=0; i<data.button.length; i++) {
77+
if (popupInfo.ruleStatus[i] !== data.button[i]) {
78+
popupInfo.rules[i].toggle();
79+
aWindow.console.log("toggling: "+JSON.stringify(popupInfo.rules[i]));
80+
} else {
81+
aWindow.console.log("skipping: "+JSON.stringify(popupInfo.rules[i]));
82+
}
83+
}
84+
reloadTab();
6985
});
7086
}
7187
};
7288

7389
// The prompt that shows up when someone clicks on the icon
7490
var rulesPrompt = new Prompt({
7591
window: aWindow,
76-
title: "Enable/disable rules"
92+
title: "Enable/disable rules",
93+
buttons: ["Apply changes"]
7794
});
7895

7996
function getApplicableList() {
@@ -86,26 +103,26 @@ function getApplicableList() {
86103
}
87104

88105
// Show active/inactive rules in the popup
89-
function getRuleItems() {
106+
function getPopupInfo() {
90107
var ruleItems = [];
108+
var rules = [];
109+
var ruleStatus = [];
91110
var alist = getApplicableList();
92111
for (var activeRule in alist.active) {
93112
if (alist.active.hasOwnProperty(activeRule)) {
94113
ruleItems.push({ label: activeRule, selected: true });
114+
ruleStatus.push(true);
115+
rules.push(alist.active[activeRule]);
95116
}
96117
}
97118
for (var inactiveRule in alist.inactive) {
98119
if (alist.inactive.hasOwnProperty(inactiveRule)) {
99120
ruleItems.push({ label: inactiveRule });
121+
ruleStatus.push(false);
122+
rules.push(alist.inactive[inactiveRule]);
100123
}
101124
}
102-
return ruleItems;
103-
}
104-
105-
function toggleRule(rule_id) {
106-
// toggle the rule state
107-
HTTPSEverywhere.https_rules.rulesetsByID[rule_id].toggle();
108-
reloadTab();
125+
return { ruleItems: ruleItems, rules: rules, ruleStatus: ruleStatus };
109126
}
110127

111128
function reloadTab() { return; }

0 commit comments

Comments
 (0)