From ba653b728f82133fd04817ecd18b0960e3c0cbd6 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Wed, 21 Feb 2024 19:08:55 -0500 Subject: [PATCH] chore(ags): do more types --- modules/ags/config/global-types.d.ts | 18 ++++++++++ .../ags/config/ts/quick-settings/bluetooth.ts | 9 +++-- .../config/ts/quick-settings/button-grid.ts | 33 ++++++++++--------- .../ags/config/ts/quick-settings/network.ts | 18 +++------- .../config/ts/quick-settings/toggle-button.ts | 8 ++--- 5 files changed, 48 insertions(+), 38 deletions(-) diff --git a/modules/ags/config/global-types.d.ts b/modules/ags/config/global-types.d.ts index 5c235d00..77866edb 100644 --- a/modules/ags/config/global-types.d.ts +++ b/modules/ags/config/global-types.d.ts @@ -1,6 +1,7 @@ import { Widget } from 'types/@girs/gtk-3.0/gtk-3.0.cjs'; import GObject from 'types/@girs/gobject-2.0/gobject-2.0'; +import { Variable as Var } from 'types/variable'; import { Widget as agsWidget } from 'types/widgets/widget'; export type AgsWidget = agsWidget & Widget; @@ -127,6 +128,20 @@ WindowProps & { import { PopupWindow } from 'ts/misc/popup'; export type PopupWindow = PopupWindow; +// For ./ts/quick-settings +import { BluetoothDevice as BTDev } from 'types/service/bluetooth.ts'; +export type APType = { + bssid: string + address: string + lastSeen: number + ssid: string + active: boolean + strength: number + iconName: string +}; +export type APBox = AgsBox }>; +export type DeviceBox = AgsBox; + // Generic widgets import AgsBox from 'types/widgets/box.ts'; @@ -162,5 +177,8 @@ export type RevealerGeneric = AgsRevealer; import AgsStack, { StackProps } from 'types/widgets/stack'; export type StackGeneric = AgsStack<{ [name: string]: Widget; }, unknown>; +import AgsScrollable from 'types/widgets/scrollable'; +export type ScrollableGeneric = AgsScrollable; + import AgsWindow from 'types/widgets/window'; export type WindowGeneric = AgsWindow; diff --git a/modules/ags/config/ts/quick-settings/bluetooth.ts b/modules/ags/config/ts/quick-settings/bluetooth.ts index d18b2c44..9abb2159 100644 --- a/modules/ags/config/ts/quick-settings/bluetooth.ts +++ b/modules/ags/config/ts/quick-settings/bluetooth.ts @@ -8,10 +8,9 @@ const SCROLL_THRESH_H = 200; const SCROLL_THRESH_N = 7; // Types -import AgsBox from 'types/widgets/box.ts'; -import AgsScrollable from 'types/widgets/scrollable.ts'; import { ListBoxRow } from 'types/@girs/gtk-3.0/gtk-3.0.cjs'; import { BluetoothDevice as BTDev } from 'types/service/bluetooth.ts'; +import { DeviceBox, ScrollableGeneric } from 'global-types'; const BluetoothDevice = (dev: BTDev) => Box({ @@ -122,10 +121,10 @@ export const BluetoothMenu = () => { child: ListBox({ setup: (self) => { self.set_sort_func((a, b) => { - const bState = (b.get_children()[0] as AgsBox) + const bState = (b.get_children()[0] as DeviceBox) .attribute.dev.paired; - const aState = (a.get_children()[0] as AgsBox) + const aState = (a.get_children()[0] as DeviceBox) .attribute.dev.paired; return bState - aState; @@ -176,7 +175,7 @@ export const BluetoothMenu = () => { ); const scroll = (self.get_parent() as ListBoxRow) - ?.get_parent() as AgsScrollable; + ?.get_parent() as ScrollableGeneric; if (scroll) { const n_child = self.get_children().length; diff --git a/modules/ags/config/ts/quick-settings/button-grid.ts b/modules/ags/config/ts/quick-settings/button-grid.ts index 1112920f..36222a36 100644 --- a/modules/ags/config/ts/quick-settings/button-grid.ts +++ b/modules/ags/config/ts/quick-settings/button-grid.ts @@ -13,32 +13,35 @@ import { BluetoothMenu } from './bluetooth.ts'; // Types import GObject from 'types/@girs/gobject-2.0/gobject-2.0'; -import AgsBox from 'types/widgets/box.ts'; -import AgsIcon from 'types/widgets/icon.ts'; -import AgsLabel from 'types/widgets/label.ts'; -import AgsRevealer from 'types/widgets/revealer.ts'; import { Variable as Var } from 'types/variable.ts'; +import { + BoxGeneric, + IconGeneric, + LabelGeneric, + RevealerGeneric, +} from 'global-types'; type IconTuple = [ GObject.Object, - (self: AgsIcon) => void, + (self: IconGeneric) => void, signal?: string, ]; type IndicatorTuple = [ GObject.Object, - (self: AgsLabel) => void, + (self: LabelGeneric) => void, signal?: string, ]; type GridButtonType = { command?(): void secondary_command?(): void - on_open?(menu: AgsRevealer): void + on_open?(menu: RevealerGeneric): void icon: string | IconTuple indicator?: IndicatorTuple - menu?: any + // @ts-expect-error me is lazy + menu?: Widget }; const SPACING = 28; -const ButtonStates = [] as Array>; +const ButtonStates = [] as Array>; const GridButton = ({ @@ -141,14 +144,14 @@ const GridButton = ({ on_hover: (self) => { if (menu) { const rowMenu = - ((((self.get_parent() as AgsBox) - ?.get_parent() as AgsBox) - ?.get_parent() as AgsBox) - ?.get_parent() as AgsBox) - ?.children[1] as AgsBox; + ((((self.get_parent() as BoxGeneric) + ?.get_parent() as BoxGeneric) + ?.get_parent() as BoxGeneric) + ?.get_parent() as BoxGeneric) + ?.children[1] as BoxGeneric; const isSetup = (rowMenu - .get_children() as Array) + .get_children() as Array) .find((ch) => ch === menu); if (!isSetup) { diff --git a/modules/ags/config/ts/quick-settings/network.ts b/modules/ags/config/ts/quick-settings/network.ts index 68224dba..6d115921 100644 --- a/modules/ags/config/ts/quick-settings/network.ts +++ b/modules/ags/config/ts/quick-settings/network.ts @@ -9,18 +9,8 @@ const SCROLL_THRESH_H = 200; const SCROLL_THRESH_N = 7; // Types -import AgsBox from 'types/widgets/box.ts'; -import AgsScrollable from 'types/widgets/scrollable.ts'; +import { APType, APBox, ScrollableGeneric } from 'global-types'; import { ListBoxRow } from 'types/@girs/gtk-3.0/gtk-3.0.cjs'; -type APType = { - bssid: string - address: string - lastSeen: number - ssid: string - active: boolean - strength: number - iconName: string -}; const AccessPoint = (ap: APType) => { @@ -148,10 +138,10 @@ export const NetworkMenu = () => { child: ListBox({ setup: (self) => { self.set_sort_func((a, b) => { - const bState = (b.get_children()[0] as AgsBox) + const bState = (b.get_children()[0] as APBox) .attribute.ap.value.strength; - const aState = (a.get_children()[0] as AgsBox) + const aState = (a.get_children()[0] as APBox) .attribute.ap.value.strength; return bState - aState; @@ -212,7 +202,7 @@ export const NetworkMenu = () => { ); const scroll = (self.get_parent() as ListBoxRow) - ?.get_parent() as AgsScrollable; + ?.get_parent() as ScrollableGeneric; if (scroll) { const n_child = self.get_children().length; diff --git a/modules/ags/config/ts/quick-settings/toggle-button.ts b/modules/ags/config/ts/quick-settings/toggle-button.ts index f4be7729..838e0809 100644 --- a/modules/ags/config/ts/quick-settings/toggle-button.ts +++ b/modules/ags/config/ts/quick-settings/toggle-button.ts @@ -2,14 +2,14 @@ const Mpris = await Service.import('mpris'); const { CenterBox, Icon, ToggleButton } = Widget; -// Types -import AgsRevealer from 'types/widgets/revealer'; - const { Gdk } = imports.gi; const display = Gdk.Display.get_default(); +// Types +import { RevealerGeneric } from 'global-types'; -export default (rev: AgsRevealer) => { + +export default (rev: RevealerGeneric) => { const child = Icon({ icon: `${App.configDir}/icons/down-large.svg`, class_name: 'arrow',