chore(ags): do more types
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-02-21 19:08:55 -05:00
parent 497d85ca71
commit ba653b728f
5 changed files with 48 additions and 38 deletions

View file

@ -1,6 +1,7 @@
import { Widget } from 'types/@girs/gtk-3.0/gtk-3.0.cjs'; import { Widget } from 'types/@girs/gtk-3.0/gtk-3.0.cjs';
import GObject from 'types/@girs/gobject-2.0/gobject-2.0'; 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'; import { Widget as agsWidget } from 'types/widgets/widget';
export type AgsWidget = agsWidget<unknown> & Widget; export type AgsWidget = agsWidget<unknown> & Widget;
@ -127,6 +128,20 @@ WindowProps<Child> & {
import { PopupWindow } from 'ts/misc/popup'; import { PopupWindow } from 'ts/misc/popup';
export type PopupWindow = PopupWindow; 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<unknown & Widget, { ap: Var<APType> }>;
export type DeviceBox = AgsBox<unknown & Widget, { dev: BTDev }>;
// Generic widgets // Generic widgets
import AgsBox from 'types/widgets/box.ts'; import AgsBox from 'types/widgets/box.ts';
@ -162,5 +177,8 @@ export type RevealerGeneric = AgsRevealer<unknown & Widget, unknown>;
import AgsStack, { StackProps } from 'types/widgets/stack'; import AgsStack, { StackProps } from 'types/widgets/stack';
export type StackGeneric = AgsStack<{ [name: string]: Widget; }, unknown>; export type StackGeneric = AgsStack<{ [name: string]: Widget; }, unknown>;
import AgsScrollable from 'types/widgets/scrollable';
export type ScrollableGeneric = AgsScrollable<unkown & Widget, unknown>;
import AgsWindow from 'types/widgets/window'; import AgsWindow from 'types/widgets/window';
export type WindowGeneric = AgsWindow<unknown & Widget, unknown>; export type WindowGeneric = AgsWindow<unknown & Widget, unknown>;

View file

@ -8,10 +8,9 @@ const SCROLL_THRESH_H = 200;
const SCROLL_THRESH_N = 7; const SCROLL_THRESH_N = 7;
// Types // 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 { ListBoxRow } from 'types/@girs/gtk-3.0/gtk-3.0.cjs';
import { BluetoothDevice as BTDev } from 'types/service/bluetooth.ts'; import { BluetoothDevice as BTDev } from 'types/service/bluetooth.ts';
import { DeviceBox, ScrollableGeneric } from 'global-types';
const BluetoothDevice = (dev: BTDev) => Box({ const BluetoothDevice = (dev: BTDev) => Box({
@ -122,10 +121,10 @@ export const BluetoothMenu = () => {
child: ListBox({ child: ListBox({
setup: (self) => { setup: (self) => {
self.set_sort_func((a, b) => { 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; .attribute.dev.paired;
const aState = (a.get_children()[0] as AgsBox) const aState = (a.get_children()[0] as DeviceBox)
.attribute.dev.paired; .attribute.dev.paired;
return bState - aState; return bState - aState;
@ -176,7 +175,7 @@ export const BluetoothMenu = () => {
); );
const scroll = (self.get_parent() as ListBoxRow) const scroll = (self.get_parent() as ListBoxRow)
?.get_parent() as AgsScrollable; ?.get_parent() as ScrollableGeneric;
if (scroll) { if (scroll) {
const n_child = self.get_children().length; const n_child = self.get_children().length;

View file

@ -13,32 +13,35 @@ import { BluetoothMenu } from './bluetooth.ts';
// Types // Types
import GObject from 'types/@girs/gobject-2.0/gobject-2.0'; 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 { Variable as Var } from 'types/variable.ts';
import {
BoxGeneric,
IconGeneric,
LabelGeneric,
RevealerGeneric,
} from 'global-types';
type IconTuple = [ type IconTuple = [
GObject.Object, GObject.Object,
(self: AgsIcon) => void, (self: IconGeneric) => void,
signal?: string, signal?: string,
]; ];
type IndicatorTuple = [ type IndicatorTuple = [
GObject.Object, GObject.Object,
(self: AgsLabel) => void, (self: LabelGeneric) => void,
signal?: string, signal?: string,
]; ];
type GridButtonType = { type GridButtonType = {
command?(): void command?(): void
secondary_command?(): void secondary_command?(): void
on_open?(menu: AgsRevealer): void on_open?(menu: RevealerGeneric): void
icon: string | IconTuple icon: string | IconTuple
indicator?: IndicatorTuple indicator?: IndicatorTuple
menu?: any // @ts-expect-error me is lazy
menu?: Widget
}; };
const SPACING = 28; const SPACING = 28;
const ButtonStates = [] as Array<Var<any>>; const ButtonStates = [] as Array<Var<boolean>>;
const GridButton = ({ const GridButton = ({
@ -141,14 +144,14 @@ const GridButton = ({
on_hover: (self) => { on_hover: (self) => {
if (menu) { if (menu) {
const rowMenu = const rowMenu =
((((self.get_parent() as AgsBox) ((((self.get_parent() as BoxGeneric)
?.get_parent() as AgsBox) ?.get_parent() as BoxGeneric)
?.get_parent() as AgsBox) ?.get_parent() as BoxGeneric)
?.get_parent() as AgsBox) ?.get_parent() as BoxGeneric)
?.children[1] as AgsBox; ?.children[1] as BoxGeneric;
const isSetup = (rowMenu const isSetup = (rowMenu
.get_children() as Array<AgsBox>) .get_children() as Array<BoxGeneric>)
.find((ch) => ch === menu); .find((ch) => ch === menu);
if (!isSetup) { if (!isSetup) {

View file

@ -9,18 +9,8 @@ const SCROLL_THRESH_H = 200;
const SCROLL_THRESH_N = 7; const SCROLL_THRESH_N = 7;
// Types // Types
import AgsBox from 'types/widgets/box.ts'; import { APType, APBox, ScrollableGeneric } from 'global-types';
import AgsScrollable from 'types/widgets/scrollable.ts';
import { ListBoxRow } from 'types/@girs/gtk-3.0/gtk-3.0.cjs'; 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) => { const AccessPoint = (ap: APType) => {
@ -148,10 +138,10 @@ export const NetworkMenu = () => {
child: ListBox({ child: ListBox({
setup: (self) => { setup: (self) => {
self.set_sort_func((a, b) => { 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; .attribute.ap.value.strength;
const aState = (a.get_children()[0] as AgsBox) const aState = (a.get_children()[0] as APBox)
.attribute.ap.value.strength; .attribute.ap.value.strength;
return bState - aState; return bState - aState;
@ -212,7 +202,7 @@ export const NetworkMenu = () => {
); );
const scroll = (self.get_parent() as ListBoxRow) const scroll = (self.get_parent() as ListBoxRow)
?.get_parent() as AgsScrollable; ?.get_parent() as ScrollableGeneric;
if (scroll) { if (scroll) {
const n_child = self.get_children().length; const n_child = self.get_children().length;

View file

@ -2,14 +2,14 @@ const Mpris = await Service.import('mpris');
const { CenterBox, Icon, ToggleButton } = Widget; const { CenterBox, Icon, ToggleButton } = Widget;
// Types
import AgsRevealer from 'types/widgets/revealer';
const { Gdk } = imports.gi; const { Gdk } = imports.gi;
const display = Gdk.Display.get_default(); const display = Gdk.Display.get_default();
// Types
import { RevealerGeneric } from 'global-types';
export default (rev: AgsRevealer) => {
export default (rev: RevealerGeneric) => {
const child = Icon({ const child = Icon({
icon: `${App.configDir}/icons/down-large.svg`, icon: `${App.configDir}/icons/down-large.svg`,
class_name: 'arrow', class_name: 'arrow',