Compare commits

..

3 Commits

Author SHA1 Message Date
June
114e1335d1
refactor: remove unneces. check for empty array in #getResolvedBoxOrder
Remove unnecessary check for empty array in #getResolvedBoxOrder as
nothing happens when the array is empty anyway.
2025-06-12 01:30:43 +02:00
June
1e87992081
refactor: directly create set of indicator cont. in getValidBoxOrder
Skip the unecessary intermediate variable and directly create a set.
Also remove the "ToDo: simplify" comment as I don't see how this logic
can be simplified more really.
2025-06-12 01:26:44 +02:00
June
5a09b1a2c8
refactor: switch to TypeScript
Aside from introducing a bunch of type annotations and other code
adjustments, also add explicit type checking where necessary.

Inline #associateItem into the constructor in PrefsBoxOrderItemRow as
the method sets this.item and:
> Note that the field needs to be initialized in the constructor itself.
> TypeScript does not analyze methods you invoke from the constructor to
> detect initializations, because a derived class might override those
> methods and fail to initialize the members.
https://www.typescriptlang.org/docs/handbook/2/classes.html

Explicitly ensure we actually have a Gdk.Drag in #setupDNDScroll in
PrefsPage and explicitly only scroll when a DND operation is properly
set up. Even tho previously not having a Gdk.Drag in #setupDNDScroll
would probably just error out the callback and probably be just fine
then, handling this explicitly is at least nicer.

Also see the guide on using TypeScript for GNOME Shell Extensions, which
was followed for this work to some degree:
https://gjs.guide/extensions/development/typescript.html
2025-06-12 00:56:10 +02:00
2 changed files with 8 additions and 18 deletions

View File

@ -215,13 +215,8 @@ export default class BoxOrderManager extends GObject.Object {
roles = this.#taskUpUltraLiteItemRoles; roles = this.#taskUpUltraLiteItemRoles;
} }
// If there are no roles associated, continue. // Create a new resolved box order item for each role and add it to
if (roles.length === 0) { // the resolved box order.
continue;
}
// Otherwise create a new resolved box order item for each role and
// add it to the resolved box order.
for (const role of roles) { for (const role of roles) {
const newResolvedBoxOrderItem = JSON.parse(JSON.stringify(resolvedBoxOrderItem)); const newResolvedBoxOrderItem = JSON.parse(JSON.stringify(resolvedBoxOrderItem));
newResolvedBoxOrderItem.role = role; newResolvedBoxOrderItem.role = role;
@ -259,20 +254,15 @@ export default class BoxOrderManager extends GObject.Object {
// Get a resolved box order. // Get a resolved box order.
let resolvedBoxOrder = this.#getResolvedBoxOrder(box); let resolvedBoxOrder = this.#getResolvedBoxOrder(box);
// ToDo: simplify.
// Get the indicator containers (of the items) currently present in the // Get the indicator containers (of the items) currently present in the
// GNOME Shell top bar. // GNOME Shell top bar.
// They should be St.Bins (see link), so ensure that using a filter. // They should be St.Bins (see link), so ensure that using a filter.
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/48.2/js/ui/panelMenu.js?ref_type=tags#L21 // https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/48.2/js/ui/panelMenu.js?ref_type=tags#L21
const indicatorContainers = [ const indicatorContainers = new Set([
(Main.panel as CustomPanel)._leftBox.get_children(), (Main.panel as CustomPanel)._leftBox.get_children(),
(Main.panel as CustomPanel)._centerBox.get_children(), (Main.panel as CustomPanel)._centerBox.get_children(),
(Main.panel as CustomPanel)._rightBox.get_children(), (Main.panel as CustomPanel)._rightBox.get_children(),
].flat().filter(ic => ic instanceof St.Bin); ].flat().filter(ic => ic instanceof St.Bin));
// Create an indicator containers set from the indicator containers for
// fast easy access.
const indicatorContainerSet = new Set(indicatorContainers);
// Go through the resolved box order and only add items to the valid box // Go through the resolved box order and only add items to the valid box
// order, where their indicator is currently present in the GNOME Shell // order, where their indicator is currently present in the GNOME Shell
@ -285,7 +275,7 @@ export default class BoxOrderManager extends GObject.Object {
continue; continue;
} }
if (indicatorContainerSet.has(associatedIndicatorContainer)) { if (indicatorContainers.has(associatedIndicatorContainer)) {
validBoxOrder.push(item); validBoxOrder.push(item);
} }
} }

View File

@ -28,9 +28,9 @@ export default class PrefsPage extends Adw.PreferencesPage {
} }
_dndEnded?: boolean; _dndEnded?: boolean;
_left_box_order_list_box!: PrefsBoxOrderListBox; declare _left_box_order_list_box: PrefsBoxOrderListBox;
_center_box_order_list_box!: PrefsBoxOrderListBox; declare _center_box_order_list_box: PrefsBoxOrderListBox;
_right_box_order_list_box!: PrefsBoxOrderListBox; declare _right_box_order_list_box: PrefsBoxOrderListBox;
constructor(params = {}) { constructor(params = {}) {
super(params); super(params);