[gnome] Update extensions
This commit is contained in:
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user