refactor(ags): do more types

This commit is contained in:
matt1432 2024-01-29 20:56:56 -05:00
parent 9c64b00243
commit caac0507a1
13 changed files with 95 additions and 71 deletions
modules/ags/config/ts/osd

View file

@ -3,24 +3,7 @@ import { Box, Icon, ProgressBar } from 'resource:///com/github/Aylur/ags/widget.
const Y_POS = 80;
// Types
import AgsBox from 'types/widgets/box';
import { IconProps } from 'types/widgets/icon';
import GObject from 'types/@girs/gobject-2.0/gobject-2.0';
import AgsStack from 'types/widgets/stack';
import { Widget } from 'types/@girs/gtk-3.0/gtk-3.0.cjs';
import { Connectable } from 'types/widgets/widget';
import AgsProgressBar from 'types/widgets/progressbar';
type ConnectFunc = (self?: AgsProgressBar) => void;
type OSD = {
stack: AgsStack
icon: string | IconProps
info: {
mod: GObject.Object
signal?: string
logic?(self: AgsProgressBar): void
widget?: Widget
}
};
import { ConnectFunc, OSD, ProgressBarGeneric } from 'global-types';
export default ({ stack, icon, info }: OSD) => {
@ -58,7 +41,7 @@ export default ({ stack, icon, info }: OSD) => {
connectFunc = () => stack.attribute.popup(osd);
}
((osd.children[0] as AgsBox).children[1] as Connectable<AgsProgressBar>)
(osd.children[0].children[1] as ProgressBarGeneric)
.hook(info.mod, connectFunc, info.signal);
return osd;

View file

@ -4,11 +4,12 @@ import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import { Stack } from 'resource:///com/github/Aylur/ags/widget.js';
import PopupWindow from '../misc/popup.ts';
import AgsBox from 'types/widgets/box.ts';
import AgsStack from 'types/widgets/stack.ts';
// Types
import { BoxGeneric, StackGeneric } from 'global-types';
// Import all the OSDs as an array
const OSDList = [] as Array<(stack: AgsStack) => AgsBox>;
const OSDList = [] as Array<(stack: StackGeneric) => BoxGeneric>;
import * as Modules from './osds.ts';
for (const osd in Modules) {
@ -24,7 +25,9 @@ const OSDs = () => {
transition: 'over_up_down',
transition_duration,
attribute: { popup: () => {/**/} },
attribute: { popup: (osd: BoxGeneric) => {
console.log(osd);
} },
});
// Send reference of stack to all items
@ -35,7 +38,7 @@ const OSDs = () => {
timeout(1000, () => {
let count = 0;
stack.attribute.popup = (osd: AgsBox) => {
stack.attribute.popup = (osd: BoxGeneric) => {
++count;
stack.set_visible_child(osd);
App.openWindow('osd');

View file

@ -17,10 +17,10 @@ globalThis.showSpeaker = () => {
};
// Types
import AgsStack from 'types/widgets/stack.ts';
import { OSDStack } from 'global-types';
export const SpeakerOSD = (stack: AgsStack) => OSD({
export const SpeakerOSD = (stack: OSDStack) => OSD({
stack,
icon: { icon: SpeakerIcon.bind() },
info: {
@ -35,12 +35,12 @@ export const SpeakerOSD = (stack: AgsStack) => OSD({
Audio.speaker.volume / AUDIO_MAX :
0;
self.sensitive = !Audio.speaker?.stream.is_muted;
self.sensitive = !Audio.speaker.stream?.is_muted;
},
},
});
export const ScreenBrightnessOSD = (stack: AgsStack) => OSD({
export const ScreenBrightnessOSD = (stack: OSDStack) => OSD({
stack,
icon: { icon: Brightness.bind('screenIcon') },
info: {
@ -53,7 +53,7 @@ export const ScreenBrightnessOSD = (stack: AgsStack) => OSD({
},
});
export const KbdBrightnessOSD = (stack: AgsStack) => OSD({
export const KbdBrightnessOSD = (stack: OSDStack) => OSD({
stack,
icon: 'keyboard-brightness-symbolic',
info: {
@ -72,7 +72,7 @@ export const KbdBrightnessOSD = (stack: AgsStack) => OSD({
},
});
export const MicOSD = (stack: AgsStack) => OSD({
export const MicOSD = (stack: OSDStack) => OSD({
stack,
icon: { icon: MicIcon.bind() },
info: {
@ -85,12 +85,12 @@ export const MicOSD = (stack: AgsStack) => OSD({
}
self.value = Audio.microphone ? Audio.microphone.volume : 0;
self.sensitive = !Audio.microphone?.stream.is_muted;
self.sensitive = !Audio.microphone.stream?.is_muted;
},
},
});
export const CapsLockOSD = (stack: AgsStack) => OSD({
export const CapsLockOSD = (stack: OSDStack) => OSD({
stack,
icon: { icon: Brightness.bind('capsIcon') },
info: {