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 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<unknown> & Widget;
@ -127,6 +128,20 @@ WindowProps<Child> & {
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<unknown & Widget, { ap: Var<APType> }>;
export type DeviceBox = AgsBox<unknown & Widget, { dev: BTDev }>;
// Generic widgets
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';
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';
export type WindowGeneric = AgsWindow<unknown & Widget, unknown>;

View file

@ -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;

View file

@ -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<Var<any>>;
const ButtonStates = [] as Array<Var<boolean>>;
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<AgsBox>)
.get_children() as Array<BoxGeneric>)
.find((ch) => ch === menu);
if (!isSetup) {

View file

@ -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;

View file

@ -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',