feature: add settings UI for control. how to affect an items visibility

Add settings UI for controlling how the extension should affect a top
bar items visibility (whether to try to forcefully hide or show an item
or not affect its visibility at all).
This commit is contained in:
June 2025-07-08 02:55:57 +02:00
commit fdbacdd683
Signed by: june
SSH key fingerprint: SHA256:o9EAq4Y9N9K0pBQeBTqhSDrND5E7oB+60ZNx0U1yPe0
4 changed files with 112 additions and 0 deletions

View file

@ -0,0 +1,58 @@
"use strict";
import GObject from "gi://GObject";
import Adw from "gi://Adw";
import GLib from "gi://GLib";
import type Gio from "gi://Gio";
import type Gtk from "gi://Gtk";
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
export default class PrefsBoxOrderItemOptionsDialog extends Adw.Dialog {
static {
GObject.registerClass({
GTypeName: "PrefsBoxOrderItemOptionsDialog",
Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-box-order-item-options-dialog.ui", GLib.UriFlags.NONE),
InternalChildren: [
"visibility-row",
],
}, this);
}
declare _visibility_row: Adw.ComboRow;
#settings: Gio.Settings;
item: string;
constructor(params = {}, item: string) {
super(params);
// Associate `this` with an item.
this.item = item;
// Load the settings.
this.#settings = ExtensionPreferences.lookupByURL(import.meta.url)!.getSettings();
}
onVisibilityRowSelectionChanged(): void {
const visibility = (this._visibility_row.get_selected_item() as Gtk.StringObject).get_string();
const itemsToHide = new Set(this.#settings.get_strv("hide"));
const itemsToShow = new Set(this.#settings.get_strv("show"));
switch (visibility) {
case "Forcefully Hide":
itemsToHide.add(this.item)
itemsToShow.delete(this.item);
break;
case "Forcefully Show":
itemsToHide.delete(this.item)
itemsToShow.add(this.item);
break;
case "Default":
itemsToHide.delete(this.item)
itemsToShow.delete(this.item);
break;
}
this.#settings.set_strv("hide", Array.from(itemsToHide));
this.#settings.set_strv("show", Array.from(itemsToShow));
}
}