From 71e744e8c3548287fcec7c00d1dbf3b8cb2cda2f Mon Sep 17 00:00:00 2001 From: RedBearAK <64876997+RedBearAK@users.noreply.github.com> Date: Sun, 22 Oct 2023 16:12:06 -0800 Subject: [PATCH] Add error prevention validations --- contents/code/main.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/contents/code/main.js b/contents/code/main.js index 5245f68..42e9b1c 100644 --- a/contents/code/main.js +++ b/contents/code/main.js @@ -33,7 +33,7 @@ const ignoredApps = ["plasmashell", "org.kde.plasmashell", // desktop shell // "dolphin" function getApp(current) { - if (!current) return ""; + if (!current || typeof current.resourceClass !== 'string') return ""; return String(current.resourceClass); } @@ -78,17 +78,31 @@ function updateAppGroups(current) { appGroups[app] = appGroups[app].filter(window => window && window != current); appGroups[app].push(current); - debug("updating app group", appGroups[app].map(window => window.caption)); + debug("updating app group", appGroups[app].map(window => + window && window.caption ? window.caption : "undefined window" + )); } // return other visible windows of same application as given window function getAppGroup(current) { if (!current) return; - let appGroup = appGroups[getApp(current)].filter(window => window && - !window.minimized && - (window.x11DesktopIds.includes(workspace.currentDesktop) || window.x11DesktopIds.length == 0) && - (window.activities.includes(workspace.currentActivity) || window.activities.length == 0)); - debug("getting app group", appGroup.map(window => window.caption)); + + let appGroup = appGroups[getApp(current)].filter(window => + window && + !window.minimized && + ( + (window.x11DesktopIds && window.x11DesktopIds.includes(workspace.currentDesktop)) || + (window.x11DesktopIds && window.x11DesktopIds.length === 0) + ) && + ( + (window.activities && window.activities.includes(workspace.currentActivity)) || + (window.activities && window.activities.length === 0) + ) + ); + + debug("getting app group", appGroup.map(window => + window && window.caption ? window.caption : "undefined window" + )); return appGroup; } @@ -117,8 +131,10 @@ workspace.clientActivated.connect(active => { setPrevActiveApp(active); // auto-raise other windows of same application for (let window of getAppGroup(active)) { - debug("auto-raising", window.caption); - workspace.activeClient = window; + if (window) { + debug("auto-raising", window.caption); + workspace.activeClient = window; + } } } });