June 9a6474b947
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-11 22:12:42 +02:00

33 lines
999 B
TypeScript

"use strict";
import Gtk from "gi://Gtk";
import Gdk from "gi://Gdk";
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
import PrefsPage from "./prefsModules/PrefsPage.js";
export default class TopBarOrganizerPreferences extends ExtensionPreferences {
getPreferencesWidget() {
const provider = new Gtk.CssProvider();
provider.load_from_path(this.metadata.dir.get_path() + "/css/prefs.css");
const defaultGdkDisplay = Gdk.Display.get_default();
Gtk.StyleContext.add_provider_for_display(
(defaultGdkDisplay as Gdk.Display),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
const prefsPage = new PrefsPage();
prefsPage.connect("destroy", () => {
Gtk.StyleContext.remove_provider_for_display(
(defaultGdkDisplay as Gdk.Display),
provider
);
});
return prefsPage;
}
}