From a1b31ca72b78980c967ea1706b78748437518cf1 Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Mon, 2 Dec 2024 17:58:31 -0500 Subject: [PATCH] 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. --- 11-qubes.js | 68 ++++++++++++++++---------------- plasmoidsetupscripts/template.js | 12 +++--- qubes-systray.js | 56 +++++++++++++------------- 3 files changed, 71 insertions(+), 65 deletions(-) diff --git a/11-qubes.js b/11-qubes.js index 8c15447..844f385 100644 --- a/11-qubes.js +++ b/11-qubes.js @@ -1,37 +1,39 @@ /* replace the default kickoff with Qubes menu */ -for (var i in panelIds) { - var panel = panelById(panelIds[i]) - var widgetIds = panel.widgetIds - var menuLauncherId = -1 - for (id in widgetIds) { - var widget = panel.widgetById(widgetIds[id]) - if (widget.type == 'org.kde.plasma.kickoff') { - var qubesMenu = panel.addWidget('org.kde.plasma.quicklaunch') - qubesMenu.index = widget.index - qubesMenu.currentConfigGroup = ['General'] - qubesMenu.writeConfig('launcherUrls', ['file:///usr/share/applications/open-qubes-app-menu.desktop']) - menuLauncherId = qubesMenu.id - widget.remove() - } else if (widget.type == 'org.kde.plasma.quicklaunch') { - // move existing one too, to fix after earlier broken version - menuLauncherId = widget.id +(function () { + for (var i in panelIds) { + var panel = panelById(panelIds[i]) + var widgetIds = panel.widgetIds + var menuLauncherId = -1 + for (id in widgetIds) { + var widget = panel.widgetById(widgetIds[id]) + if (widget.type == 'org.kde.plasma.kickoff') { + var qubesMenu = panel.addWidget('org.kde.plasma.quicklaunch') + qubesMenu.index = widget.index + qubesMenu.currentConfigGroup = ['General'] + qubesMenu.writeConfig('launcherUrls', ['file:///usr/share/applications/open-qubes-app-menu.desktop']) + menuLauncherId = qubesMenu.id + widget.remove() + } else if (widget.type == 'org.kde.plasma.quicklaunch') { + // move existing one too, to fix after earlier broken version + menuLauncherId = widget.id + } + } + // move the menu launcher as the first applet + if (menuLauncherId != -1) { + panel.currentConfigGroup = ['General'] + var order = panel.readConfig("AppletOrder").split(";") + if (!order) + order = panel.widgetIds + // remove from the list (likely its end) and add it at the beginning + order = order.filter(function(x) { return x != menuLauncherId }) + order.unshift(menuLauncherId) + panel.writeConfig("AppletOrder", order.join(";")) } } - // move the menu launcher as the first applet - if (menuLauncherId != -1) { - panel.currentConfigGroup = ['General'] - var order = panel.readConfig("AppletOrder").split(";") - if (!order) - order = panel.widgetIds - // remove from the list (likely its end) and add it at the beginning - order = order.filter(function(x) { return x != menuLauncherId }) - order.unshift(menuLauncherId) - panel.writeConfig("AppletOrder", order.join(";")) - } -} -/* wallpaper */ -var desktop = desktops()[0]; -desktop.wallpaperPlugin = "org.kde.image" -desktop.currentConfigGroup = Array('Wallpaper', 'org.kde.image', "General"); -desktop.writeConfig('Image', 'file:///usr/share/wallpapers/Qubes_Steel'); + /* wallpaper */ + var desktop = desktops()[0]; + desktop.wallpaperPlugin = "org.kde.image" + desktop.currentConfigGroup = Array('Wallpaper', 'org.kde.image', "General"); + desktop.writeConfig('Image', 'file:///usr/share/wallpapers/Qubes_Steel'); +})(); diff --git a/plasmoidsetupscripts/template.js b/plasmoidsetupscripts/template.js index 57f4491..2f5fc15 100644 --- a/plasmoidsetupscripts/template.js +++ b/plasmoidsetupscripts/template.js @@ -1,5 +1,7 @@ -if (applet.readConfig("icon", "start-here-kde") == "start-here-kde" || - applet.readConfig("icon", "start-here-kde") == "start-here") { - applet.currentConfigGroup = ["General"] - applet.writeConfig("icon", "qubes-logo-icon"); -} \ No newline at end of file +(function() { + if (applet.readConfig("icon", "start-here-kde") == "start-here-kde" || + applet.readConfig("icon", "start-here-kde") == "start-here") { + applet.currentConfigGroup = ["General"]; + applet.writeConfig("icon", "qubes-logo-icon"); + } +})(); diff --git a/qubes-systray.js b/qubes-systray.js index e195d45..7c0f4ea 100644 --- a/qubes-systray.js +++ b/qubes-systray.js @@ -1,36 +1,38 @@ -var biggestId = 0; -var tmpBiggestId = 0; +(function () { + var biggestId = 0; + var tmpBiggestId = 0; -for (var i in activityIds) { - var activity = activityById(activityIds[i]); - if (activity.widgetIds.length > 0) { - tmpBiggestId = Math.max.apply(null, activity.widgetIds); - if (tmpBiggestId > biggestId) { - biggestId = tmpBiggestId; + for (var i in activityIds) { + var activity = activityById(activityIds[i]); + if (activity.widgetIds.length > 0) { + tmpBiggestId = Math.max.apply(null, activity.widgetIds); + if (tmpBiggestId > biggestId) { + biggestId = tmpBiggestId; + } } } -} -for (var i in panelIds) { - var panel = panelById(panelIds[i]); - if (panel.widgetIds.length > 0) { - tmpBiggestId = Math.max.apply(null, panel.widgetIds); - if (tmpBiggestId > biggestId) { - biggestId = tmpBiggestId; + for (var i in panelIds) { + var panel = panelById(panelIds[i]); + if (panel.widgetIds.length > 0) { + tmpBiggestId = Math.max.apply(null, panel.widgetIds); + if (tmpBiggestId > biggestId) { + biggestId = tmpBiggestId; + } } } -} -for (var i in panelIds) { - var panel = panelById(panelIds[i]); - for (var j in panel.widgetIds) { - var widget = panel.widgetById(panel.widgetIds[j]); - if (widget.type == "systemtray") { - widget.writeConfig('DefaultAppletsAdded', 'true') - widget.currentConfigGroup = new Array('Applets', biggestId+1); - widget.writeConfig('plugin', 'battery'); - widget.reloadConfig(); + for (var i in panelIds) { + var panel = panelById(panelIds[i]); + for (var j in panel.widgetIds) { + var widget = panel.widgetById(panel.widgetIds[j]); + if (widget.type == "systemtray") { + widget.writeConfig('DefaultAppletsAdded', 'true') + widget.currentConfigGroup = new Array('Applets', biggestId+1); + widget.writeConfig('plugin', 'battery'); + widget.reloadConfig(); + } } } -} -panels()[0].addWidget("org.kde.notifications") + panels()[0].addWidget("org.kde.notifications") +})();