[gnome] Update extensions

This commit is contained in:
2026-04-09 09:51:44 -04:00
parent dadc78f2f4
commit 505c67d292
61 changed files with 1729 additions and 365 deletions

View File

@ -14,6 +14,14 @@ function getObjectLabel(name, values) {
.map(([label, value]) => `${label}: '${value}'`);
return `${name}(${labels.join(", ")})`;
}
function safeRegexTest(pattern, value) {
try {
return new RegExp(pattern).test(value);
}
catch {
return null;
}
}
function getWindowLabel(window) {
return getObjectLabel("Window", {
["Title"]: window.title,
@ -46,7 +54,11 @@ export default class JunkNotificationCleaner extends Extension {
this.log(LogLevel.DEBUG, `${windowLabel}: received ${event}`);
const excludedApps = this.settings.get_strv("excluded-apps");
for (const wmClassPattern of excludedApps) {
if (new RegExp(wmClassPattern).test(window.wmClass)) {
const result = safeRegexTest(wmClassPattern, window.wmClass);
if (result === null) {
this.log(LogLevel.WARN, `${windowLabel}: invalid regex '${wmClassPattern}'`);
}
else if (result) {
this.log(LogLevel.DEBUG, `${windowLabel}: excluded by '${wmClassPattern}'`);
return;
}
@ -78,9 +90,11 @@ export default class JunkNotificationCleaner extends Extension {
disable() {
if (this.focusListenerId !== null) {
global.display.disconnect(this.focusListenerId);
this.focusListenerId = null;
}
if (this.closeListenerId !== null) {
global.window_manager.disconnect(this.closeListenerId);
this.closeListenerId = null;
}
if (this.settings) {
this.settings = null;

View File

@ -11,5 +11,5 @@
],
"url": "https://github.com/murar8/junk-notification-cleaner",
"uuid": "junk-notification-cleaner@murar8.github.com",
"version": 6
"version": 10
}

View File

@ -3,6 +3,15 @@ import Gio from "gi://Gio";
import Gtk from "gi://Gtk";
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
const LOG_LEVELS = ["debug", "info", "warn", "error"];
function isValidRegex(pattern) {
try {
new RegExp(pattern);
return true;
}
catch {
return false;
}
}
export default class JunkNotificationCleanerPreferences extends ExtensionPreferences {
async fillPreferencesWindow(window) {
const settings = this.getSettings();
@ -90,24 +99,43 @@ export default class JunkNotificationCleanerPreferences extends ExtensionPrefere
placeholder_text: "Enter WM Class regex (e.g. .*firefox.*)",
hexpand: true,
});
const errorLabel = new Gtk.Label({
label: "Invalid regular expression",
css_classes: ["error"],
xalign: 0,
visible: false,
});
const addButton = new Gtk.Button({
label: "Add",
css_classes: ["suggested-action"],
});
entry.connect("changed", () => {
entry.remove_css_class("error");
errorLabel.set_visible(false);
});
addButton.connect("clicked", () => {
const text = entry.get_text().trim();
if (!text)
return;
const currentApps = settings.get_strv("excluded-apps");
if (currentApps.includes(text))
return;
settings.set_strv("excluded-apps", [...currentApps, text]);
this.addExcludedAppRow(text, listBox, settings);
entry.set_text("");
if (!isValidRegex(text)) {
entry.add_css_class("error");
errorLabel.set_visible(true);
}
else {
entry.remove_css_class("error");
errorLabel.set_visible(false);
const currentApps = settings.get_strv("excluded-apps");
if (currentApps.includes(text))
return;
settings.set_strv("excluded-apps", [...currentApps, text]);
this.addExcludedAppRow(text, listBox, settings);
entry.set_text("");
}
});
addBox.append(entry);
addBox.append(addButton);
excludedBox.append(addBox);
excludedBox.append(errorLabel);
excludedGroup.add(excludedBox);
}
addExcludedAppRow(app, listBox, settings) {