Skip to content

Commit a1b31ca

Browse files
committed
Wrap all JavaScript in an Immediately-Invoked Function Expression
This ensures that variables declared in the script do not alter the enclosing scope. Yes, JavaScript is a bad language.
1 parent 0c446fb commit a1b31ca

File tree

3 files changed

+71
-65
lines changed

3 files changed

+71
-65
lines changed

11-qubes.js

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
/* replace the default kickoff with Qubes menu */
2-
for (var i in panelIds) {
3-
var panel = panelById(panelIds[i])
4-
var widgetIds = panel.widgetIds
5-
var menuLauncherId = -1
6-
for (id in widgetIds) {
7-
var widget = panel.widgetById(widgetIds[id])
8-
if (widget.type == 'org.kde.plasma.kickoff') {
9-
var qubesMenu = panel.addWidget('org.kde.plasma.quicklaunch')
10-
qubesMenu.index = widget.index
11-
qubesMenu.currentConfigGroup = ['General']
12-
qubesMenu.writeConfig('launcherUrls', ['file:///usr/share/applications/open-qubes-app-menu.desktop'])
13-
menuLauncherId = qubesMenu.id
14-
widget.remove()
15-
} else if (widget.type == 'org.kde.plasma.quicklaunch') {
16-
// move existing one too, to fix after earlier broken version
17-
menuLauncherId = widget.id
2+
(function () {
3+
for (var i in panelIds) {
4+
var panel = panelById(panelIds[i])
5+
var widgetIds = panel.widgetIds
6+
var menuLauncherId = -1
7+
for (id in widgetIds) {
8+
var widget = panel.widgetById(widgetIds[id])
9+
if (widget.type == 'org.kde.plasma.kickoff') {
10+
var qubesMenu = panel.addWidget('org.kde.plasma.quicklaunch')
11+
qubesMenu.index = widget.index
12+
qubesMenu.currentConfigGroup = ['General']
13+
qubesMenu.writeConfig('launcherUrls', ['file:///usr/share/applications/open-qubes-app-menu.desktop'])
14+
menuLauncherId = qubesMenu.id
15+
widget.remove()
16+
} else if (widget.type == 'org.kde.plasma.quicklaunch') {
17+
// move existing one too, to fix after earlier broken version
18+
menuLauncherId = widget.id
19+
}
20+
}
21+
// move the menu launcher as the first applet
22+
if (menuLauncherId != -1) {
23+
panel.currentConfigGroup = ['General']
24+
var order = panel.readConfig("AppletOrder").split(";")
25+
if (!order)
26+
order = panel.widgetIds
27+
// remove from the list (likely its end) and add it at the beginning
28+
order = order.filter(function(x) { return x != menuLauncherId })
29+
order.unshift(menuLauncherId)
30+
panel.writeConfig("AppletOrder", order.join(";"))
1831
}
1932
}
20-
// move the menu launcher as the first applet
21-
if (menuLauncherId != -1) {
22-
panel.currentConfigGroup = ['General']
23-
var order = panel.readConfig("AppletOrder").split(";")
24-
if (!order)
25-
order = panel.widgetIds
26-
// remove from the list (likely its end) and add it at the beginning
27-
order = order.filter(function(x) { return x != menuLauncherId })
28-
order.unshift(menuLauncherId)
29-
panel.writeConfig("AppletOrder", order.join(";"))
30-
}
31-
}
3233

33-
/* wallpaper */
34-
var desktop = desktops()[0];
35-
desktop.wallpaperPlugin = "org.kde.image"
36-
desktop.currentConfigGroup = Array('Wallpaper', 'org.kde.image', "General");
37-
desktop.writeConfig('Image', 'file:///usr/share/wallpapers/Qubes_Steel');
34+
/* wallpaper */
35+
var desktop = desktops()[0];
36+
desktop.wallpaperPlugin = "org.kde.image"
37+
desktop.currentConfigGroup = Array('Wallpaper', 'org.kde.image', "General");
38+
desktop.writeConfig('Image', 'file:///usr/share/wallpapers/Qubes_Steel');
39+
})();

plasmoidsetupscripts/template.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
if (applet.readConfig("icon", "start-here-kde") == "start-here-kde" ||
2-
applet.readConfig("icon", "start-here-kde") == "start-here") {
3-
applet.currentConfigGroup = ["General"]
4-
applet.writeConfig("icon", "qubes-logo-icon");
5-
}
1+
(function() {
2+
if (applet.readConfig("icon", "start-here-kde") == "start-here-kde" ||
3+
applet.readConfig("icon", "start-here-kde") == "start-here") {
4+
applet.currentConfigGroup = ["General"];
5+
applet.writeConfig("icon", "qubes-logo-icon");
6+
}
7+
})();

qubes-systray.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
var biggestId = 0;
2-
var tmpBiggestId = 0;
1+
(function () {
2+
var biggestId = 0;
3+
var tmpBiggestId = 0;
34

4-
for (var i in activityIds) {
5-
var activity = activityById(activityIds[i]);
6-
if (activity.widgetIds.length > 0) {
7-
tmpBiggestId = Math.max.apply(null, activity.widgetIds);
8-
if (tmpBiggestId > biggestId) {
9-
biggestId = tmpBiggestId;
5+
for (var i in activityIds) {
6+
var activity = activityById(activityIds[i]);
7+
if (activity.widgetIds.length > 0) {
8+
tmpBiggestId = Math.max.apply(null, activity.widgetIds);
9+
if (tmpBiggestId > biggestId) {
10+
biggestId = tmpBiggestId;
11+
}
1012
}
1113
}
12-
}
1314

14-
for (var i in panelIds) {
15-
var panel = panelById(panelIds[i]);
16-
if (panel.widgetIds.length > 0) {
17-
tmpBiggestId = Math.max.apply(null, panel.widgetIds);
18-
if (tmpBiggestId > biggestId) {
19-
biggestId = tmpBiggestId;
15+
for (var i in panelIds) {
16+
var panel = panelById(panelIds[i]);
17+
if (panel.widgetIds.length > 0) {
18+
tmpBiggestId = Math.max.apply(null, panel.widgetIds);
19+
if (tmpBiggestId > biggestId) {
20+
biggestId = tmpBiggestId;
21+
}
2022
}
2123
}
22-
}
2324

24-
for (var i in panelIds) {
25-
var panel = panelById(panelIds[i]);
26-
for (var j in panel.widgetIds) {
27-
var widget = panel.widgetById(panel.widgetIds[j]);
28-
if (widget.type == "systemtray") {
29-
widget.writeConfig('DefaultAppletsAdded', 'true')
30-
widget.currentConfigGroup = new Array('Applets', biggestId+1);
31-
widget.writeConfig('plugin', 'battery');
32-
widget.reloadConfig();
25+
for (var i in panelIds) {
26+
var panel = panelById(panelIds[i]);
27+
for (var j in panel.widgetIds) {
28+
var widget = panel.widgetById(panel.widgetIds[j]);
29+
if (widget.type == "systemtray") {
30+
widget.writeConfig('DefaultAppletsAdded', 'true')
31+
widget.currentConfigGroup = new Array('Applets', biggestId+1);
32+
widget.writeConfig('plugin', 'battery');
33+
widget.reloadConfig();
34+
}
3335
}
3436
}
35-
}
36-
panels()[0].addWidget("org.kde.notifications")
37+
panels()[0].addWidget("org.kde.notifications")
38+
})();

0 commit comments

Comments
 (0)