From c7b26075e1cbc57960553d1af974e856b2829be1 Mon Sep 17 00:00:00 2001 From: Aylur Date: Mon, 16 Oct 2023 01:44:05 +0200 Subject: [PATCH] migrate to girs types --- .eslintrc.yml | 4 ++-- .gitmodules | 4 ---- gi-types | 1 - nix/default.nix | 9 --------- src/app.ts | 11 +++++++---- src/client.ts | 12 ++++++------ src/main.ts | 1 - src/service.ts | 9 ++++----- src/service/battery.ts | 5 ++--- src/service/mpris.ts | 18 +++++++++--------- src/service/notifications.ts | 28 ++++++++++++++++++---------- src/service/systemtray.ts | 25 +++++++++++++------------ src/utils.ts | 4 ++-- src/variable.ts | 15 +++++++-------- src/widgets/entry.ts | 4 ++-- src/widgets/icon.ts | 5 ++--- src/widgets/label.ts | 8 ++++---- src/widgets/overrides.ts | 2 +- src/widgets/revealer.ts | 4 ++-- src/widgets/slider.ts | 20 ++++++++++---------- src/widgets/stack.ts | 6 +++--- src/widgets/window.ts | 4 ++-- tsconfig.json | 22 ++++++---------------- types/ambient.d.ts | 15 --------------- 24 files changed, 102 insertions(+), 134 deletions(-) delete mode 160000 gi-types diff --git a/.eslintrc.yml b/.eslintrc.yml index 5f0a132..1812703 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -22,8 +22,8 @@ plugins: rules: '@typescript-eslint/ban-ts-comment': - 'off' - - + '@typescript-eslint/no-non-null-assertion': + - 'off' '@typescript-eslint/no-unused-vars': - error # Vars use a suffix _ instead of a prefix because of file-scope private vars diff --git a/.gitmodules b/.gitmodules index 4cfed1c..e3feba7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "gi-types"] - path = gi-types - url = https://gitlab.gnome.org/BrainBlasted/gi-typescript-definitions - branch = nightly [submodule "subprojects/gvc"] path = subprojects/gvc url = https://gitlab.gnome.org/GNOME/libgnome-volume-control diff --git a/gi-types b/gi-types deleted file mode 160000 index eb2a87a..0000000 --- a/gi-types +++ /dev/null @@ -1 +0,0 @@ -Subproject commit eb2a87a25c5e2fb580b605fbec0bd312fe34c492 diff --git a/nix/default.nix b/nix/default.nix index c706799..b608cb6 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -29,13 +29,6 @@ let rev = "8e7a5a4c3e51007ce6579292642517e3d3eb9c50"; sha256 = "sha256-FosJwgTCp6/EI6WVbJhPisokRBA6oT0eo7d+Ya7fFX8="; }; - gi-types-src = fetchFromGitLab { - domain = "gitlab.gnome.org"; - owner = "BrainBlasted"; - repo = "gi-typescript-definitions"; - rev = "eb2a87a25c5e2fb580b605fbec0bd312fe34c492"; - sha256 = "sha256-MNLrlKeWZI9EDO/8/gaXpAlrWv9B49jSu4keWDh3q9g="; - }; in stdenv.mkDerivation { pname = "ags"; @@ -57,9 +50,7 @@ stdenv.mkDerivation { prePatch = '' mkdir -p ./subprojects/gvc - mkdir -p ./gi-types cp -r ${gvc-src}/* ./subprojects/gvc - cp -r ${gi-types-src}/* ./gi-types ''; postPatch = '' diff --git a/src/app.ts b/src/app.ts index 5cd7645..b12095b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -93,6 +93,7 @@ export class App extends Gtk.Application { this._load(); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any connect(signal = 'window-toggled', callback: (_: this, ...args: any[]) => void): number { return super.connect(signal, callback); } @@ -133,7 +134,7 @@ export class App extends Gtk.Application { } removeWindow(w: Gtk.Window | string) { - const name = typeof w === 'string' ? w : w.name; + const name = typeof w === 'string' ? w : w.name || 'gtk-layer-shell'; const win = this._windows.get(name); if (!win) { @@ -147,11 +148,13 @@ export class App extends Gtk.Application { addWindow(w: Gtk.Window) { if (!(w instanceof Gtk.Window)) { - console.error(Error(`${w} is not an instanceof Gtk.Window, ` + + return console.error(Error(`${w} is not an instanceof Gtk.Window, ` + ` but it is of type ${typeof w}`)); - return; } + if (!w.name) + return console.error(Error(`${w} has no name`)); + w.connect('notify::visible', () => this.emit('window-toggled', w.name, w.visible)); @@ -207,7 +210,7 @@ export class App extends Gtk.Application { Gio.BusNameOwnerFlags.NONE, (connection: Gio.DBusConnection) => { this._dbus = Gio.DBusExportedObject - .wrapJSObject(AgsIFace(this.application_id) as string, this); + .wrapJSObject(AgsIFace(this.application_id!) as string, this); this._dbus.export(connection, this._objectPath); }, diff --git a/src/client.ts b/src/client.ts index f655863..62b9903 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6,10 +6,10 @@ import { loadInterfaceXML } from './utils.js'; import { type AgsProxy } from './dbus/types.js'; const AgsIFace = (bus: string) => - loadInterfaceXML('com.github.Aylur.ags')?.replace('@BUS@', bus); + loadInterfaceXML('com.github.Aylur.ags')!.replace('@BUS@', bus); const ClientIFace = (bus: string) => - loadInterfaceXML('com.github.Aylur.ags.client')?.replace('@BUS@', bus); + loadInterfaceXML('com.github.Aylur.ags.client')!.replace('@BUS@', bus); const TIME = `${GLib.DateTime.new_now_local().to_unix()}`; @@ -44,11 +44,11 @@ class Client extends Gtk.Application { private _register() { Gio.bus_own_name( Gio.BusType.SESSION, - this.applicationId, + this.application_id, Gio.BusNameOwnerFlags.NONE, (connection: Gio.DBusConnection) => { this._dbus = Gio.DBusExportedObject - .wrapJSObject(ClientIFace(this.applicationId) as string, this); + .wrapJSObject(ClientIFace(this.application_id!) as string, this); this._dbus.export(connection, this._objectPath); }, @@ -68,7 +68,7 @@ class Client extends Gtk.Application { this._register(); this._proxy.RunPromiseRemote( this._promiseJs, - this.applicationId, + this.application_id!, this._objectPath, ); } @@ -76,7 +76,7 @@ class Client extends Gtk.Application { export default function(bus: string, path: string, flags: Flags) { const AgsProxy = Gio.DBusProxy.makeProxyWrapper(AgsIFace(bus)); - const proxy = new AgsProxy(Gio.DBus.session, bus, path) as AgsProxy; + const proxy = AgsProxy(Gio.DBus.session, bus, path) as AgsProxy; if (flags.toggleWindow) print(proxy.ToggleWindowSync(flags.toggleWindow)); diff --git a/src/main.ts b/src/main.ts index d5e791b..7068f61 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,7 +30,6 @@ function isRunning(dbusName: string) { '/org/freedesktop/DBus', 'org.freedesktop.DBus', 'NameHasOwner', - // @ts-expect-error GLib.Variant.new_tuple([new GLib.Variant('s', dbusName)]), new GLib.VariantType('(b)'), Gio.DBusCallFlags.NONE, diff --git a/src/service.ts b/src/service.ts index 9edc3fd..2ce3b9b 100644 --- a/src/service.ts +++ b/src/service.ts @@ -1,5 +1,4 @@ import GObject from 'gi://GObject'; -import { type Ctor } from 'gi-types/gobject2.js'; type PspecType = 'jsobject' | 'string' | 'int' | 'float' | 'double' | 'boolean' | 'gobject'; type PspecFlag = 'rw' | 'r' | 'w'; @@ -42,16 +41,15 @@ export default class Service extends GObject.Object { name, name, name, flags, false); case 'gobject': return GObject.ParamSpec.object( - name, name, name, flags, GObject.Object); + name, name, name, flags, GObject.Object.$gtype); - // @ts-expect-error default: return GObject.ParamSpec.jsobject( - name, name, name, flags, null); + name, name, name, flags); } } static register( - service: Ctor, + service: new (...args: any[]) => GObject.Object, signals?: { [signal: string]: string[] }, properties?: { [prop: string]: [type?: PspecType, handle?: PspecFlag] }, ) { @@ -80,6 +78,7 @@ export default class Service extends GObject.Object { GObject.registerClass({ Signals, Properties }, service); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any connect(signal = 'changed', callback: (_: this, ...args: any[]) => void): number { return super.connect(signal, callback); } diff --git a/src/service/battery.ts b/src/service/battery.ts index c23be6c..68145eb 100644 --- a/src/service/battery.ts +++ b/src/service/battery.ts @@ -4,9 +4,8 @@ import { timeout } from '../utils.js'; import { loadInterfaceXML } from '../utils.js'; import { type BatteryProxy } from '../dbus/types.js'; -const BatteryIFace = loadInterfaceXML('org.freedesktop.UPower.Device'); -const PowerManagerProxy = - Gio.DBusProxy.makeProxyWrapper(BatteryIFace) as BatteryProxy; +const BatteryIFace = loadInterfaceXML('org.freedesktop.UPower.Device')!; +const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(BatteryIFace) as unknown as BatteryProxy; const DeviceState = { CHARGING: 1, diff --git a/src/service/mpris.ts b/src/service/mpris.ts index 0bb57cf..0cf3b7a 100644 --- a/src/service/mpris.ts +++ b/src/service/mpris.ts @@ -6,12 +6,12 @@ import { CACHE_DIR } from '../utils.js'; import { loadInterfaceXML } from '../utils.js'; import { DBusProxy, PlayerProxy, MprisProxy } from '../dbus/types.js'; -const DBusIFace = loadInterfaceXML('org.freedesktop.DBus'); -const PlayerIFace = loadInterfaceXML('org.mpris.MediaPlayer2.Player'); -const MprisIFace = loadInterfaceXML('org.mpris.MediaPlayer2'); -const DBusProxy = Gio.DBusProxy.makeProxyWrapper(DBusIFace) as DBusProxy; -const PlayerProxy = Gio.DBusProxy.makeProxyWrapper(PlayerIFace) as PlayerProxy; -const MprisProxy = Gio.DBusProxy.makeProxyWrapper(MprisIFace) as MprisProxy; +const DBusIFace = loadInterfaceXML('org.freedesktop.DBus')!; +const PlayerIFace = loadInterfaceXML('org.mpris.MediaPlayer2.Player')!; +const MprisIFace = loadInterfaceXML('org.mpris.MediaPlayer2')!; +const DBusProxy = Gio.DBusProxy.makeProxyWrapper(DBusIFace) as unknown as DBusProxy; +const PlayerProxy = Gio.DBusProxy.makeProxyWrapper(PlayerIFace) as unknown as PlayerProxy; +const MprisProxy = Gio.DBusProxy.makeProxyWrapper(MprisIFace) as unknown as MprisProxy; const MEDIA_CACHE_PATH = `${CACHE_DIR}/media`; @@ -144,7 +144,7 @@ class MprisPlayer extends Service { private _updateState() { const metadata = {} as MprisMetadata; for (const prop in this._playerProxy.Metadata) - metadata[prop] = this._playerProxy.Metadata[prop].deep_unpack(); + metadata[prop] = this._playerProxy.Metadata[prop].deepUnpack(); let trackArtists = metadata['xesam:artist']; if (!Array.isArray(trackArtists) || @@ -199,7 +199,7 @@ class MprisPlayer extends Service { Gio.FileCopyFlags.OVERWRITE, GLib.PRIORITY_DEFAULT, // @ts-expect-error - null, null, (source, result) => { + null, null, (source: Gio.File, result: Gio.AsyncResult) => { try { source.copy_finish(result); this.changed('cover-path'); @@ -335,7 +335,7 @@ class Mpris extends Service { } private _onNameOwnerChanged( - _proxy: string, + _proxy: Gio.DBusProxy, _sender: string, [name, oldOwner, newOwner]: string[], ) { diff --git a/src/service/notifications.ts b/src/service/notifications.ts index 37529fe..90e1cee 100644 --- a/src/service/notifications.ts +++ b/src/service/notifications.ts @@ -19,9 +19,9 @@ interface Action { } interface Hints { - 'image-data'?: GLib.Variant<'(iiibiiay)'> - 'desktop-entry'?: GLib.Variant<'s'> - 'urgency'?: GLib.Variant<'y'> + 'image-data'?: InstanceType + 'desktop-entry'?: InstanceType + 'urgency'?: InstanceType } interface NotifcationJson { @@ -37,7 +37,13 @@ interface NotifcationJson { image: string | null } -const _URGENCY = ['low', 'normal', 'critical']; +const _URGENCY = (urgency?: number) => { + switch (urgency) { + case 0: return 'low'; + case 2: return 'critical'; + default: return 'normal'; + } +}; class Notification extends Service { static { @@ -103,10 +109,10 @@ class Notification extends Service { }); } - this._urgency = _URGENCY[hints['urgency']?.unpack() || 1]; + this._urgency = _URGENCY(hints['urgency']?.unpack()); this._id = id; this._appName = appName; - this._appEntry = hints['desktop-entry']?.unpack() || null; + this._appEntry = hints['desktop-entry']?.unpack() || null; this._appIcon = appIcon; this._summary = summary; this._body = body; @@ -162,13 +168,15 @@ class Notification extends Service { return GLib.file_test(this._appIcon, GLib.FileTest.EXISTS) ? this._appIcon : null; } - private _parseImageData(imageData?: GLib.Variant<'(iiibiiay)'>) { + private _parseImageData(imageData?: InstanceType) { if (!imageData) return null; ensureDirectory(NOTIFICATIONS_CACHE_PATH); const fileName = NOTIFICATIONS_CACHE_PATH + `/${this._id}`; - const [w, h, rs, alpha, bps, _, data] = imageData.recursiveUnpack(); + const [w, h, rs, alpha, bps, _, data] = imageData // iiibiiay + .recursiveUnpack<[number, number, number, boolean, number, number, GLib.Bytes]>(); + const pixbuf = GdkPixbuf.Pixbuf.new_from_bytes( data, GdkPixbuf.Colorspace.RGB, alpha, bps, w, h, rs); @@ -298,7 +306,7 @@ class Notifications extends Service { private _onClosed(n: Notification) { this._dbus.emit_signal('NotificationClosed', - GLib.Variant.new('(uu)', [n.id, 3])); + new GLib.Variant('(uu)', [n.id, 3])); this._notifications.delete(n.id); this.notify('notifications'); @@ -310,7 +318,7 @@ class Notifications extends Service { private _onInvoked(n: Notification, id: string) { this._dbus.emit_signal('ActionInvoked', - GLib.Variant.new('(us)', [n.id, id])); + new GLib.Variant('(us)', [n.id, id])); } private _register() { diff --git a/src/service/systemtray.ts b/src/service/systemtray.ts index 01394f1..b00cab2 100644 --- a/src/service/systemtray.ts +++ b/src/service/systemtray.ts @@ -9,10 +9,10 @@ import { StatusNotifierItemProxy } from '../dbus/types.js'; import { bulkConnect, loadInterfaceXML } from '../utils.js'; import Widget from '../widget.js'; -const StatusNotifierWatcherIFace = loadInterfaceXML('org.kde.StatusNotifierWatcher'); -const StatusNotifierItemIFace = loadInterfaceXML('org.kde.StatusNotifierItem'); +const StatusNotifierWatcherIFace = loadInterfaceXML('org.kde.StatusNotifierWatcher')!; +const StatusNotifierItemIFace = loadInterfaceXML('org.kde.StatusNotifierItem')!; const StatusNotifierItemProxy = - Gio.DBusProxy.makeProxyWrapper(StatusNotifierItemIFace) as StatusNotifierItemProxy; + Gio.DBusProxy.makeProxyWrapper(StatusNotifierItemIFace) as unknown as StatusNotifierItemProxy; export class TrayItem extends Service { static { @@ -71,8 +71,8 @@ export class TrayItem extends Service { } openMenu(event: Gdk.Event) { - this.menu // DbusmenuGtk3 imports the gdk type from @girs - ? (this.menu as unknown as Gtk.Menu).popup_at_pointer(event) + this.menu + ? this.menu.popup_at_pointer(event) : this._proxy.ContextMenuAsync(event.get_root_coords()[1], event.get_root_coords()[2]); } @@ -117,8 +117,9 @@ export class TrayItem extends Service { private _itemProxyAcquired(proxy: StatusNotifierItemProxy) { if (proxy.Menu) { const menu = Widget({ - // @ts-expect-error type: DbusmenuGtk3.Menu, + // FIXME + // @ts-expect-error dbus_name: proxy.g_name_owner, dbus_object: proxy.Menu, }); @@ -161,15 +162,15 @@ export class TrayItem extends Service { this._proxy.g_object_path, 'org.freedesktop.DBus.Properties', 'GetAll', - GLib.Variant.new('(s)', [this._proxy.g_interface_name]), - GLib.VariantType.new('(a{sv})'), + new GLib.Variant('(s)', [this._proxy.g_interface_name]), + new GLib.VariantType('(a{sv})'), Gio.DBusCallFlags.NONE, -1, null, (proxy, result) => { - const variant = proxy?.call_finish(result) as GLib.Variant<'(a{sv})'>; + const variant = proxy?.call_finish(result) as GLib.Variant; if (!variant) return; - const [properties] = variant.deep_unpack(); + const [properties] = variant.deepUnpack[]>(); Object.entries(properties).map(([propertyName, value]) => { this._proxy.set_cached_property(propertyName, value); }); @@ -195,7 +196,7 @@ export class TrayItem extends Service { array[i + 3] = alpha; } return GdkPixbuf.Pixbuf.new_from_bytes( - array, + new GLib.Bytes(array), GdkPixbuf.Colorspace.RGB, true, 8, @@ -255,7 +256,7 @@ class SystemTray extends Service { const [service] = serviceName; if (service.startsWith('/')) { objectPath = service; - busName = invocation.get_sender(); + busName = invocation.get_sender()!; } else { busName = service; objectPath = '/StatusNotifierItem'; diff --git a/src/utils.ts b/src/utils.ts index e340592..6bedf38 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -195,8 +195,8 @@ export function execAsync(cmd: string | string[]): Promise { const [, stdout, stderr] = proc.communicate_utf8_finish(res); proc.get_successful() - ? resolve(stdout.trim()) - : reject(stderr.trim()); + ? resolve(stdout!.trim()) + : reject(stderr!.trim()); } catch (e) { reject(e); } diff --git a/src/variable.ts b/src/variable.ts index f30a332..98cb98e 100644 --- a/src/variable.ts +++ b/src/variable.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import GObject from 'gi://GObject'; import Gio from 'gi://Gio'; import GLib from 'gi://GLib'; @@ -18,22 +17,21 @@ export class Variable extends GObject.Object { GTypeName: 'AgsVariable', Signals: { 'changed': {} }, Properties: { - // @ts-expect-error 'value': GObject.ParamSpec.jsobject( 'value', 'value', 'value', - GObject.ParamFlags.READWRITE, null, + GObject.ParamFlags.READWRITE, ), }, }, this); } - private _value: any; + private _value: unknown; private _poll?: Poll; private _listen?: Listen; private _interval?: number; private _subprocess?: Gio.Subprocess | null; - constructor(value: any, { poll, listen }: Options = {}) { + constructor(value: unknown, { poll, listen }: Options = {}) { super(); this.value = value; @@ -48,6 +46,7 @@ export class Variable extends GObject.Object { } } + // eslint-disable-next-line @typescript-eslint/no-explicit-any connect(signal = 'notify::value', callback: (_: this, ...args: any[]) => void): number { return super.connect(signal, callback); } @@ -131,14 +130,14 @@ export class Variable extends GObject.Object { } getValue() { return this._value; } - setValue(value: any) { + setValue(value: unknown) { this._value = value; this.notify('value'); this.emit('changed'); } get value() { return this._value; } - set value(value: any) { this.setValue(value); } + set value(value: unknown) { this.setValue(value); } } -export default (value: any, options: Options) => new Variable(value, options); +export default (value: unknown, options: Options) => new Variable(value, options); diff --git a/src/widgets/entry.ts b/src/widgets/entry.ts index 59752eb..d55b2a6 100644 --- a/src/widgets/entry.ts +++ b/src/widgets/entry.ts @@ -24,13 +24,13 @@ export default class AgsEntry extends Gtk.Entry { this.connect('activate', () => { typeof this.onAccept === 'function' ? this.onAccept(this) - : runCmd(this.onAccept.replace(/\{\}/g, this.text)); + : runCmd(this.onAccept.replace(/\{\}/g, this.text || '')); }); this.connect('notify::text', ({ text }, event) => { typeof this.onChange === 'function' ? this.onChange(this, event) - : runCmd(this.onChange.replace(/\{\}/g, text)); + : runCmd(this.onChange.replace(/\{\}/g, text || '')); }); } } diff --git a/src/widgets/icon.ts b/src/widgets/icon.ts index df5447b..3a4290b 100644 --- a/src/widgets/icon.ts +++ b/src/widgets/icon.ts @@ -3,8 +3,8 @@ import Gtk from 'gi://Gtk?version=3.0'; import GLib from 'gi://GLib'; import GdkPixbuf from 'gi://GdkPixbuf'; import Gdk from 'gi://Gdk?version=3.0'; -import { Context } from 'gi-types/cairo1'; import Service from '../service.js'; +import cairo from '@girs/cairo-1.0'; export default class AgsIcon extends Gtk.Image { static { @@ -84,8 +84,7 @@ export default class AgsIcon extends Gtk.Image { } } - - vfunc_draw(cr: Context): boolean { + vfunc_draw(cr: cairo.Context): boolean { if (this._size > 1) return super.vfunc_draw(cr); diff --git a/src/widgets/label.ts b/src/widgets/label.ts index fe3f173..0e7870f 100644 --- a/src/widgets/label.ts +++ b/src/widgets/label.ts @@ -22,15 +22,15 @@ export default class AgsLabel extends Gtk.Label { super(typeof params === 'string' ? { label: params } : params); } - get label() { return super.label; } + get label() { return super.label || ''; } set label(label: string) { - if (this.useMarkup) { + if (this.use_markup) { try { - // @ts-expect-error Pango.parse_markup(label, label.length, '0'); } catch (e) { + // @ts-expect-error if (e instanceof GLib.MarkupError) - label = GLib.markup_escape_text(label, -1); + label = GLib.markup_escape_text(label, -1) || ''; else console.error(e as Error); } diff --git a/src/widgets/overrides.ts b/src/widgets/overrides.ts index 5419d4e..1de4ae1 100644 --- a/src/widgets/overrides.ts +++ b/src/widgets/overrides.ts @@ -44,7 +44,7 @@ function setCss(widget: Gtk.Widget, css: string) { const provider = new Gtk.CssProvider(); widgetProviders.set(widget, provider); - provider.load_from_data(css); + provider.load_from_data(new TextEncoder().encode(css)); widget.get_style_context() .add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_USER); } diff --git a/src/widgets/revealer.ts b/src/widgets/revealer.ts index 09a5045..964b56a 100644 --- a/src/widgets/revealer.ts +++ b/src/widgets/revealer.ts @@ -18,7 +18,7 @@ export default class AgsRevealer extends Gtk.Revealer { }, this); } - get transition() { return transitions[this.transitionType]; } + get transition() { return transitions[this.transition_type]; } set transition(transition: string) { if (!transition || this.transition === transition) return; @@ -28,6 +28,6 @@ export default class AgsRevealer extends Gtk.Revealer { return; } - this.transitionType = transitions.findIndex(t => t === transition); + this.transition_type = transitions.findIndex(t => t === transition); } } diff --git a/src/widgets/slider.ts b/src/widgets/slider.ts index 635117a..8a91dc7 100644 --- a/src/widgets/slider.ts +++ b/src/widgets/slider.ts @@ -1,7 +1,7 @@ import GObject from 'gi://GObject'; import Gtk from 'gi://Gtk?version=3.0'; +import Gdk from 'gi://Gdk?version=3.0'; import { runCmd } from '../utils.js'; -import { EventButton, EventScroll, EventKey } from 'gi-types/gdk3'; import { Command } from './constructor.js'; import Service from '../service.js'; @@ -43,7 +43,7 @@ export default class AgsSlider extends Gtk.Scale { adjustment: new Gtk.Adjustment({ lower: min, upper: max, - stepIncrement: step, + step_increment: step, }), }); @@ -55,7 +55,7 @@ export default class AgsSlider extends Gtk.Scale { typeof this.onChange === 'function' ? this.onChange(this, event, value) - : runCmd((onChange as string).replace(/\{\}/g, value)); + : runCmd((onChange as string).replace(/\{\}/g, `${value}`)); }); if (value) @@ -89,12 +89,12 @@ export default class AgsSlider extends Gtk.Scale { this.notify('max'); } - get step() { return this.adjustment.stepIncrement; } + get step() { return this.adjustment.step_increment; } set step(step: number) { if (this.step === step) return; - this.adjustment.stepIncrement = step; + this.adjustment.step_increment = step; this.notify('step'); } @@ -120,27 +120,27 @@ export default class AgsSlider extends Gtk.Scale { this.notify('vertical'); } - vfunc_button_release_event(event: EventButton): boolean { + vfunc_button_release_event(event: Gdk.EventButton): boolean { this.dragging = false; return super.vfunc_button_release_event(event); } - vfunc_button_press_event(event: EventButton): boolean { + vfunc_button_press_event(event: Gdk.EventButton): boolean { this.dragging = true; return super.vfunc_button_press_event(event); } - vfunc_key_press_event(event: EventKey): boolean { + vfunc_key_press_event(event: Gdk.EventKey): boolean { this.dragging = true; return super.vfunc_key_press_event(event); } - vfunc_key_release_event(event: EventKey): boolean { + vfunc_key_release_event(event: Gdk.EventKey): boolean { this.dragging = false; return super.vfunc_key_release_event(event); } - vfunc_scroll_event(event: EventScroll): boolean { + vfunc_scroll_event(event: Gdk.EventScroll): boolean { this.dragging = true; event.delta_y > 0 ? this.adjustment.value -= this.step diff --git a/src/widgets/stack.ts b/src/widgets/stack.ts index 677735b..556db56 100644 --- a/src/widgets/stack.ts +++ b/src/widgets/stack.ts @@ -60,7 +60,7 @@ export default class AgsStack extends Gtk.Stack { this.show_all(); } - get transition() { return transitions[this.transitionType]; } + get transition() { return transitions[this.transition_type]; } set transition(transition: string) { if (this.transition === transition) return; @@ -70,12 +70,12 @@ export default class AgsStack extends Gtk.Stack { return; } - this.transitionType = transitions.findIndex(t => t === transition); + this.transition_type = transitions.findIndex(t => t === transition); this.notify('transition'); } get shown() { return this.visible_child_name; } - set shown(name: string) { + set shown(name: string | null) { if (!this.get_child_by_name(name)) { this.visible = false; return; diff --git a/src/widgets/window.ts b/src/widgets/window.ts index 6b10421..46def54 100644 --- a/src/widgets/window.ts +++ b/src/widgets/window.ts @@ -180,8 +180,8 @@ export default class AgsWindow extends Gtk.Window { if (popup) { this.connect('key-press-event', (_, event) => { if (event.get_keyval()[1] === Gdk.KEY_Escape) { - App.getWindow(this.name) - ? App.closeWindow(this.name) + App.getWindow(this.name!) + ? App.closeWindow(this.name!) : this.hide(); } }); diff --git a/tsconfig.json b/tsconfig.json index d12215a..a4e5ed6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,33 +1,23 @@ { "compilerOptions": { - "target": "es2022", - "module": "ES2020", - "lib": [ - "ES2017" - ], + "target": "ES2022", + "module": "ES2022", + "lib": ["ES2017"], "allowJs": true, "checkJs": false, "outDir": "_build/tsc-out", "strict": true, "moduleResolution": "node", "baseUrl": ".", - "paths": { - "*": [ - "*", - "types/*", - "gi-types/*" - ] - }, "typeRoots": [ - "gi-types" + "./node_modules/@girs" ], "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, "include": [ - "gi-types/gi.d.ts", + "@girs", "types/*", - "src/*", - "src/*/*" + "src" ] } diff --git a/types/ambient.d.ts b/types/ambient.d.ts index 9842c2d..95a65e6 100644 --- a/types/ambient.d.ts +++ b/types/ambient.d.ts @@ -39,18 +39,3 @@ declare class TextEncoder { constructor(); encode(input?: string): Uint8Array; } - -declare module 'gi://Gvc' { - import Gvc10 from '@girs/gvc-1.0'; - export default Gvc10; -} - -declare module 'gi://NM' { - import NM10 from '@girs/nm-1.0'; - export default NM10; -} - -declare module 'gi://DbusmenuGtk3' { - import Dbusmenu from '@girs/dbusmenugtk3-0.4'; - export default Dbusmenu; -}