mirror of
https://gitlab.gnome.org/julianschacher/top-bar-organizer.git
synced 2025-10-27 15:19:09 +00:00
update: properly handle top bar items of Task Up UltraLite extension
Since the Task Up UltraLite extension creates a bunch of top bar items as part of its functionality, the Top Bar Organizer settings would get spammed with items, making them hard to navigate and making it practically impossible to manage the top bar items of the Task Up UltraLite extension itself. Therefore introduce functionality for properly handling the Task Up UltraLite top bar items, by grouping them internally and just exposing a single Top Bar Organizer settings item for all the Task Up UltraLite items, which then allows to manage the Task Up UltraLite top bar items nicely. This fixes #25: https://gitlab.gnome.org/june/top-bar-organizer/-/issues/25 Task Up UltraLite extension: https://extensions.gnome.org/extension/7700/task-up-ultralite/
This commit is contained in:
parent
185a48c857
commit
979e770057
@ -16,8 +16,8 @@ import * as Main from "resource:///org/gnome/shell/ui/main.js";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides an interfaces to the box orders stored in settings.
|
* This class provides an interfaces to the box orders stored in settings.
|
||||||
* It takes care of handling AppIndicator items and resolving from the internal
|
* It takes care of handling AppIndicator and Task Up UltraLite items and
|
||||||
* item settings identifiers to roles.
|
* resolving from the internal item settings identifiers to roles.
|
||||||
* In the end this results in convenient functions, which are directly useful in
|
* In the end this results in convenient functions, which are directly useful in
|
||||||
* other extension code.
|
* other extension code.
|
||||||
*/
|
*/
|
||||||
@ -32,6 +32,7 @@ export default class BoxOrderManager extends GObject.Object {
|
|||||||
|
|
||||||
#appIndicatorReadyHandlerIdMap;
|
#appIndicatorReadyHandlerIdMap;
|
||||||
#appIndicatorItemSettingsIdToRolesMap;
|
#appIndicatorItemSettingsIdToRolesMap;
|
||||||
|
#taskUpUltraLiteItemRoles;
|
||||||
#settings;
|
#settings;
|
||||||
|
|
||||||
constructor(params = {}, settings) {
|
constructor(params = {}, settings) {
|
||||||
@ -39,6 +40,7 @@ export default class BoxOrderManager extends GObject.Object {
|
|||||||
|
|
||||||
this.#appIndicatorReadyHandlerIdMap = new Map();
|
this.#appIndicatorReadyHandlerIdMap = new Map();
|
||||||
this.#appIndicatorItemSettingsIdToRolesMap = new Map();
|
this.#appIndicatorItemSettingsIdToRolesMap = new Map();
|
||||||
|
this.#taskUpUltraLiteItemRoles = [];
|
||||||
|
|
||||||
this.#settings = settings;
|
this.#settings = settings;
|
||||||
}
|
}
|
||||||
@ -134,10 +136,31 @@ export default class BoxOrderManager extends GObject.Object {
|
|||||||
return itemSettingsId;
|
return itemSettingsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a Task Up UltraLite item by storing its role and returning the
|
||||||
|
* Task Up UltraLite settings identifier.
|
||||||
|
* This is needed since the Task Up UltraLite extension creates a bunch of
|
||||||
|
* top bar items as part of its functionality, so we want to group them
|
||||||
|
* under one identifier in the settings.
|
||||||
|
* https://extensions.gnome.org/extension/7700/task-up-ultralite/
|
||||||
|
* @param {string} role - The role of the Task Up UltraLite item.
|
||||||
|
* @returns {string} The settings identifier to use.
|
||||||
|
*/
|
||||||
|
#handleTaskUpUltraLiteItem(role) {
|
||||||
|
const roles = this.#taskUpUltraLiteItemRoles;
|
||||||
|
|
||||||
|
if (!roles.includes(role)) {
|
||||||
|
roles.push(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "item-role-group-task-up-ultralite";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a resolved box order for the given top bar box, where all
|
* Gets a resolved box order for the given top bar box, where all
|
||||||
* AppIndicator items got resolved using their roles, meaning they might be
|
* AppIndicator and Task Up UltraLite items got resolved using their roles,
|
||||||
* present multiple times or not at all depending on the roles stored.
|
* meaning they might be present multiple times or not at all depending on
|
||||||
|
* the roles stored.
|
||||||
* The items of the box order also have additional information stored.
|
* The items of the box order also have additional information stored.
|
||||||
* @param {string} box - The top bar box for which to get the resolved box order.
|
* @param {string} box - The top bar box for which to get the resolved box order.
|
||||||
* Must be one of the following values:
|
* Must be one of the following values:
|
||||||
@ -170,9 +193,11 @@ export default class BoxOrderManager extends GObject.Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the items settings identifier doesn't indicate that the item
|
// If the items settings identifier doesn't indicate that the item
|
||||||
// is an AppIndicator/KStatusNotifierItem item, then its identifier
|
// is an AppIndicator/KStatusNotifierItem item or the Task Up
|
||||||
// is the role and it can just be added to the resolved box order.
|
// UltraLite item role group, then its identifier is the role and it
|
||||||
if (!itemSettingsId.startsWith("appindicator-kstatusnotifieritem-")) {
|
// can just be added to the resolved box order.
|
||||||
|
if (!itemSettingsId.startsWith("appindicator-kstatusnotifieritem-") &&
|
||||||
|
itemSettingsId !== "item-role-group-task-up-ultralite") {
|
||||||
resolvedBoxOrderItem.role = resolvedBoxOrderItem.settingsId;
|
resolvedBoxOrderItem.role = resolvedBoxOrderItem.settingsId;
|
||||||
resolvedBoxOrder.push(resolvedBoxOrderItem);
|
resolvedBoxOrder.push(resolvedBoxOrderItem);
|
||||||
continue;
|
continue;
|
||||||
@ -181,8 +206,13 @@ export default class BoxOrderManager extends GObject.Object {
|
|||||||
// If the items settings identifier indicates otherwise, then handle
|
// If the items settings identifier indicates otherwise, then handle
|
||||||
// the item specially.
|
// the item specially.
|
||||||
|
|
||||||
// Get the roles roles associated with the items settings id.
|
// Get the roles associated with the items settings id.
|
||||||
let roles = this.#appIndicatorItemSettingsIdToRolesMap.get(resolvedBoxOrderItem.settingsId);
|
let roles = [];
|
||||||
|
if (itemSettingsId.startsWith("appindicator-kstatusnotifieritem-")) {
|
||||||
|
roles = this.#appIndicatorItemSettingsIdToRolesMap.get(resolvedBoxOrderItem.settingsId);
|
||||||
|
} else if (itemSettingsId === "item-role-group-task-up-ultralite") {
|
||||||
|
roles = this.#taskUpUltraLiteItemRoles;
|
||||||
|
}
|
||||||
|
|
||||||
// If there are no roles associated, continue.
|
// If there are no roles associated, continue.
|
||||||
if (!roles) {
|
if (!roles) {
|
||||||
@ -217,8 +247,8 @@ export default class BoxOrderManager extends GObject.Object {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a valid box order for the given top bar box, where all AppIndicator
|
* Gets a valid box order for the given top bar box, where all AppIndicator
|
||||||
* items got resolved and where only items are included, which are in some
|
* and Task Up UltraLite items got resolved and where only items are
|
||||||
* GNOME Shell top bar box.
|
* included, which are in some GNOME Shell top bar box.
|
||||||
* The items of the box order also have additional information stored.
|
* The items of the box order also have additional information stored.
|
||||||
* @param {string} box - The top bar box to return the valid box order for.
|
* @param {string} box - The top bar box to return the valid box order for.
|
||||||
* Must be one of the following values:
|
* Must be one of the following values:
|
||||||
@ -308,10 +338,10 @@ export default class BoxOrderManager extends GObject.Object {
|
|||||||
|
|
||||||
// Then get a settings identifier for the item.
|
// Then get a settings identifier for the item.
|
||||||
let itemSettingsId;
|
let itemSettingsId;
|
||||||
|
if (role.startsWith("appindicator-")) {
|
||||||
// If the role indicates that the item is an
|
// If the role indicates that the item is an
|
||||||
// AppIndicator/KStatusNotifierItem item, then handle it
|
// AppIndicator/KStatusNotifierItem item, then handle it
|
||||||
// differently
|
// differently.
|
||||||
if (role.startsWith("appindicator-")) {
|
|
||||||
try {
|
try {
|
||||||
itemSettingsId = this.#handleAppIndicatorItem(indicatorContainer, role);
|
itemSettingsId = this.#handleAppIndicatorItem(indicatorContainer, role);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -320,6 +350,10 @@ export default class BoxOrderManager extends GObject.Object {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else if (role.startsWith("task-button-")) {
|
||||||
|
// If the role indicates that the item is a Task Up
|
||||||
|
// UltraLite item, then handle it differently.
|
||||||
|
itemSettingsId = this.#handleTaskUpUltraLiteItem(role);
|
||||||
} else { // Otherwise just use the role as the settings identifier.
|
} else { // Otherwise just use the role as the settings identifier.
|
||||||
itemSettingsId = role;
|
itemSettingsId = role;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,10 @@ export default class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
|||||||
// Set the title to something nicer, if the associated item is an
|
// Set the title to something nicer, if the associated item is an
|
||||||
// AppIndicator/KStatusNotifierItem item.
|
// AppIndicator/KStatusNotifierItem item.
|
||||||
this.set_title(item.replace("appindicator-kstatusnotifieritem-", ""));
|
this.set_title(item.replace("appindicator-kstatusnotifieritem-", ""));
|
||||||
|
} else if (item === "item-role-group-task-up-ultralite") {
|
||||||
|
// Set the title to something nicer, if the item in question is the
|
||||||
|
// Task Up UltraLite item role group.
|
||||||
|
this.set_title("Task Up UltraLite Items");
|
||||||
} else {
|
} else {
|
||||||
// Otherwise just set it to `item`.
|
// Otherwise just set it to `item`.
|
||||||
this.set_title(item);
|
this.set_title(item);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user