✨ ags: add ask popup, make notifications work(finally :3) and more improvements
This commit is contained in:
+6
-5
@@ -1,15 +1,16 @@
|
||||
import { bind } from "astal";
|
||||
import { Gtk, Widget } from "astal/gtk3";
|
||||
import AstalNotifd from "gi://AstalNotifd";
|
||||
import { Notifications } from "../../scripts/notification-handler";
|
||||
import { Notifications } from "../../scripts/notifications";
|
||||
|
||||
export const NotificationHistory: Gtk.Widget = new Widget.Scrollable({
|
||||
export const NotifHistory: Gtk.Widget = new Widget.Scrollable({
|
||||
hscroll: Gtk.PolicyType.NEVER,
|
||||
vscroll: Gtk.PolicyType.AUTOMATIC,
|
||||
expand: true,
|
||||
child: new Widget.Box({
|
||||
className: "notifications",
|
||||
children: bind(Notifications, "notificationHistory").as((history: Array<AstalNotifd.Notification>) =>
|
||||
history && history.length > 0 && history.map((notification: AstalNotifd.Notification) =>
|
||||
children: bind(Notifications.getDefault(), "history").as((history: Array<AstalNotifd.Notification>) =>
|
||||
history.map((notification: AstalNotifd.Notification) =>
|
||||
new Widget.Box({
|
||||
className: "notification",
|
||||
hexpand: true,
|
||||
@@ -35,7 +36,7 @@ export const NotificationHistory: Gtk.Widget = new Widget.Scrollable({
|
||||
new Widget.Button({
|
||||
className: "remove",
|
||||
label: "",
|
||||
onClick: () => Notifications.removeFromNotificationHistory(notification.id)
|
||||
onClick: () => Notifications.getDefault().removeHistory(notification.id)
|
||||
} as Widget.ButtonProps)
|
||||
]
|
||||
} as Widget.BoxProps),
|
||||
@@ -1,40 +1,45 @@
|
||||
import { timeout, Variable } from "astal";
|
||||
import { Gtk, Widget } from "astal/gtk3";
|
||||
import { Page } from "./pages/Page";
|
||||
|
||||
const empty = new Widget.Box();
|
||||
const page = new Variable<Gtk.Widget>(empty);
|
||||
let connectionId: (number|undefined);
|
||||
const currentPage = new Variable<Page|undefined>(undefined);
|
||||
|
||||
export const PagesWidget: Widget.Revealer = new Widget.Revealer({
|
||||
revealChild: false,
|
||||
className: "pages",
|
||||
transitionType: Gtk.RevealerTransitionType.SLIDE_DOWN,
|
||||
transitionDuration: 250,
|
||||
child: page()
|
||||
transitionDuration: 360,
|
||||
child: currentPage((page: (Page|undefined)) =>
|
||||
!page ? new Widget.Box() : page.getPage())
|
||||
} as Widget.RevealerProps);
|
||||
|
||||
export function showPages(child: Gtk.Widget, onShow?: (self: Widget.Revealer) => void): void {
|
||||
page.set(child);
|
||||
export function showPages(page: Page): void {
|
||||
currentPage.set(page);
|
||||
PagesWidget.set_reveal_child(true);
|
||||
connectionId !== undefined && PagesWidget.disconnect(connectionId);
|
||||
connectionId = PagesWidget.connect("show", (_) =>
|
||||
onShow && onShow(_));
|
||||
page.props.onOpen && page.props.onOpen();
|
||||
}
|
||||
|
||||
export function getPage(): (Gtk.Widget|null) {
|
||||
return page.get();
|
||||
export function getPage(): (Page|undefined) {
|
||||
return currentPage.get();
|
||||
}
|
||||
|
||||
export function togglePage(page: Gtk.Widget): void {
|
||||
PagesWidget.revealChild ?
|
||||
hidePages()
|
||||
: showPages(page);
|
||||
export function togglePage(page: Page): void {
|
||||
if(!PagesWidget.revealChild) {
|
||||
showPages(page);
|
||||
return;
|
||||
}
|
||||
|
||||
hidePages();
|
||||
}
|
||||
|
||||
export function hidePages(onHide?: () => void) {
|
||||
export function hidePages() {
|
||||
PagesWidget.set_reveal_child(false);
|
||||
console.log("heyyyyy");
|
||||
timeout(300, () => {
|
||||
page.set(empty);
|
||||
onHide && onHide();
|
||||
if(!currentPage.get()) return;
|
||||
|
||||
timeout(500, () => {
|
||||
if(currentPage.get() && currentPage.get()?.props.onClose)
|
||||
currentPage.get()!.props.onClose!();
|
||||
|
||||
currentPage.set(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export const Sliders: Gtk.Widget = new Widget.Box({
|
||||
]
|
||||
} as Widget.BoxProps),
|
||||
/*new Widget.Box({
|
||||
className: "brightness screen",
|
||||
className: "brightness",
|
||||
children: [
|
||||
new Widget.Label({
|
||||
className: "icon nf",
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Gtk, Widget } from "astal/gtk3";
|
||||
import { TileInternet } from "./tiles/Internet";
|
||||
import { TileNetwork } from "./tiles/Network";
|
||||
import { TileBluetooth } from "./tiles/Bluetooth";
|
||||
import { TileRecording } from "./tiles/Recording";
|
||||
|
||||
export const tileList: Array<any> = [
|
||||
TileInternet,
|
||||
TileBluetooth
|
||||
TileNetwork,
|
||||
TileBluetooth,
|
||||
TileRecording
|
||||
];
|
||||
|
||||
export function TilesWidget(): Gtk.Widget {
|
||||
|
||||
@@ -1,98 +1,108 @@
|
||||
import { bind, timeout } from "astal";
|
||||
import { Gtk, Widget } from "astal/gtk3";
|
||||
import AstalBluetooth from "gi://AstalBluetooth?version=0.1";
|
||||
import AstalBluetooth from "gi://AstalBluetooth";
|
||||
import { Page } from "./Page";
|
||||
import { Separator, SeparatorProps } from "../../Separator";
|
||||
|
||||
let watchingDevices: boolean = false;
|
||||
|
||||
export function BluetoothPage() {
|
||||
watchNewDevices();
|
||||
|
||||
return new Widget.Box({
|
||||
className: "page bluetooth container",
|
||||
export const BluetoothPage: Page = new Page({
|
||||
title: "Bluetooth Devices",
|
||||
description: "Manage your Bluetooth devices and add new ones.",
|
||||
className: "bluetooth",
|
||||
setup: () => {
|
||||
watchingDevices = true;
|
||||
watchNewDevices();
|
||||
},
|
||||
onClose: stopBluetoothDevicesWatch,
|
||||
pageChild: () => new Widget.Box({
|
||||
className: "connections",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
expand: true,
|
||||
hexpand: true,
|
||||
children: [
|
||||
new Widget.Box({
|
||||
className: "header",
|
||||
children: [
|
||||
new Widget.Label({
|
||||
hexpand: true,
|
||||
className: "title",
|
||||
label: "Bluetooth",
|
||||
halign: Gtk.Align.START
|
||||
} as Widget.LabelProps),
|
||||
]
|
||||
} as Widget.BoxProps),
|
||||
new Widget.Box({
|
||||
className: "connections",
|
||||
className: "paired",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
expand: true,
|
||||
children: bind(AstalBluetooth.get_default(), "devices").as((devices: Array<AstalBluetooth.Device>) =>
|
||||
devices.filter((device: AstalBluetooth.Device) => device.connected
|
||||
).map((dev: AstalBluetooth.Device) =>
|
||||
new Widget.Button({
|
||||
onClick: () => dev.connected ? dev.disconnect_device(null) : dev.connect_device(null),
|
||||
child: new Widget.Box({
|
||||
className: "device",
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
expand: true,
|
||||
children: [
|
||||
new Widget.Label({
|
||||
className: "alias",
|
||||
halign: Gtk.Align.START,
|
||||
label: bind(dev, "alias")
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Label({
|
||||
className: "battery",
|
||||
halign: Gtk.Align.END,
|
||||
label: bind(dev, "batteryPercentage").as(String)
|
||||
} as Widget.LabelProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.ButtonProps)).concat(
|
||||
devices.filter((device: AstalBluetooth.Device) => !device.connected
|
||||
).map((dev: AstalBluetooth.Device) =>
|
||||
new Widget.Button({
|
||||
onClick: () => dev.connect_device(() => {}),
|
||||
child: new Widget.Box({
|
||||
className: "device",
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
expand: true,
|
||||
children: [
|
||||
new Widget.Label({
|
||||
className: "alias",
|
||||
halign: Gtk.Align.START,
|
||||
label: bind(dev, "alias")
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Label({
|
||||
className: "battery",
|
||||
halign: Gtk.Align.END,
|
||||
label: bind(dev, "batteryPercentage").as(String)
|
||||
} as Widget.LabelProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.ButtonProps))
|
||||
devices.filter((device: AstalBluetooth.Device) => device.connected || device.paired)
|
||||
.map((dev: AstalBluetooth.Device) =>
|
||||
DeviceWidget(dev)
|
||||
)
|
||||
)
|
||||
} as Widget.BoxProps),
|
||||
Separator({
|
||||
size: .5,
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
alpha: .7
|
||||
} as SeparatorProps),
|
||||
new Widget.Box({
|
||||
className: "discovered",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: bind(AstalBluetooth.get_default(), "devices").as((devices: Array<AstalBluetooth.Device>) =>
|
||||
devices.filter((device: AstalBluetooth.Device) => !device.connected && !device.paired)
|
||||
.map((dev: AstalBluetooth.Device) =>
|
||||
DeviceWidget(dev)
|
||||
)
|
||||
)
|
||||
} as Widget.BoxProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
})
|
||||
|
||||
function DeviceWidget(dev: AstalBluetooth.Device): Gtk.Widget {
|
||||
return new Widget.Button({
|
||||
onClick: () => dev.connected ? dev.disconnect_device(null) : dev.connect_device(null),
|
||||
className: bind(dev, "connected").as((connected) => connected ? "connected" : ""),
|
||||
child: new Widget.Box({
|
||||
className: "device",
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
expand: true,
|
||||
children: [
|
||||
new Widget.Icon({
|
||||
className: "icon",
|
||||
icon: bind(dev, "icon").as((icon: string) =>
|
||||
icon ? icon : "bluetooth-active-symbolic"),
|
||||
css: "font-size: 20px; margin-right: 6px;"
|
||||
} as Widget.IconProps),
|
||||
new Widget.Label({
|
||||
className: "alias",
|
||||
halign: Gtk.Align.START,
|
||||
hexpand: true,
|
||||
label: bind(dev, "alias")
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Label({
|
||||
className: "battery",
|
||||
halign: Gtk.Align.END,
|
||||
visible: bind(dev, "batteryPercentage").as((bat: number) =>
|
||||
bat <= -1 ? false : true),
|
||||
label: bind(dev, "batteryPercentage").as((bat: number) =>
|
||||
` ${Math.floor(bat * 100)}%`)
|
||||
} as Widget.LabelProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.ButtonProps)
|
||||
}
|
||||
|
||||
function watchNewDevices(): void {
|
||||
if(watchingDevices) {
|
||||
timeout(10000, () => {
|
||||
reloadDevicesList();
|
||||
timeout(8000, () => {
|
||||
reloadBluetoothDevicesList();
|
||||
watchNewDevices();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
stopBluetoothDevicesWatch();
|
||||
}
|
||||
|
||||
function stopDeviceWatch(): void {
|
||||
export function stopBluetoothDevicesWatch(): void {
|
||||
watchingDevices = false;
|
||||
AstalBluetooth.get_default().adapter.discovering &&
|
||||
AstalBluetooth.get_default().adapter.stop_discovery();
|
||||
}
|
||||
|
||||
function reloadDevicesList(): void {
|
||||
export function reloadBluetoothDevicesList(): void {
|
||||
AstalBluetooth.get_default().adapter.start_discovery();
|
||||
timeout(5000, () => AstalBluetooth.get_default().adapter.stop_discovery());
|
||||
timeout(4000, () => AstalBluetooth.get_default().adapter.stop_discovery());
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { bind } from "astal";
|
||||
import { Gtk, Widget } from "astal/gtk3";
|
||||
import AstalBluetooth from "gi://AstalBluetooth";
|
||||
|
||||
export function WifiPage() {
|
||||
return new Widget.Box({
|
||||
className: "page bluetooth container",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
hexpand: true,
|
||||
children: [
|
||||
new Widget.Box({
|
||||
className: "connections",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
expand: true,
|
||||
children: bind(AstalBluetooth.get_default(), "devices").as((devices: Array<AstalBluetooth.Device>) =>
|
||||
devices && devices.filter((device: AstalBluetooth.Device) => device.connected
|
||||
).map((dev: AstalBluetooth.Device) =>
|
||||
new Widget.Box({
|
||||
className: "device",
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
expand: true,
|
||||
children: [
|
||||
new Widget.Label({
|
||||
className: "alias",
|
||||
halign: Gtk.Align.START,
|
||||
label: bind(dev, "alias")
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Label({
|
||||
className: "battery",
|
||||
halign: Gtk.Align.END,
|
||||
} as Widget.LabelProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
))
|
||||
} as Widget.BoxProps)
|
||||
]
|
||||
} as Widget.BoxProps);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Widget } from "astal/gtk3";
|
||||
import { Page } from "./Page";
|
||||
import AstalNetwork from "gi://AstalNetwork";
|
||||
import { bind } from "astal";
|
||||
|
||||
export const PageNetwork = new Page({
|
||||
title: "Network",
|
||||
className: "network",
|
||||
headerButtons: () => [
|
||||
new Widget.Button({
|
||||
className: "reload nf",
|
||||
label: "",
|
||||
visible: bind(AstalNetwork.get_default(), "primary").as(
|
||||
(primary: AstalNetwork.Primary) => primary === AstalNetwork.Primary.WIFI
|
||||
),
|
||||
tooltipText: "Re-scan connections",
|
||||
onClick: () => AstalNetwork.get_default().wifi.scan()
|
||||
} as Widget.ButtonProps)
|
||||
],
|
||||
pageChild: () => new Widget.Box({
|
||||
} as Widget.BoxProps)
|
||||
});
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { Binding, GObject, register } from "astal";
|
||||
import { Gtk, Widget } from "astal/gtk3";
|
||||
|
||||
export type PageProps = {
|
||||
setup?: () => void;
|
||||
onClose?: () => void;
|
||||
onOpen?: () => void;
|
||||
className?: string | Binding<string | undefined>;
|
||||
title: string | Binding<string | undefined>;
|
||||
description?: string | Binding<string | undefined>;
|
||||
headerButtons?: () => Array<Gtk.Widget>;
|
||||
pageChild: () => Gtk.Widget;
|
||||
};
|
||||
|
||||
@register({ GTypeName: "Page" })
|
||||
class Page extends GObject.Object {
|
||||
readonly #props: PageProps;
|
||||
|
||||
get props() { return this.#props; }
|
||||
|
||||
constructor(props: PageProps) {
|
||||
super();
|
||||
this.#props = props;
|
||||
}
|
||||
|
||||
public getHeaderButtons(): (Array<Gtk.Widget>|null) {
|
||||
return this.props.headerButtons ?
|
||||
this.props.headerButtons()
|
||||
: null;
|
||||
}
|
||||
|
||||
public getPage(): Gtk.Widget {
|
||||
return new Widget.Box({
|
||||
className: (this.props.className instanceof Binding) ?
|
||||
this.props.className.as((clsName: (string|undefined)) => `page ${ clsName || "" }`) : `page ${this.#props.className || ""}`,
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
hexpand: true,
|
||||
setup: this.props.setup,
|
||||
children: [
|
||||
new Widget.Box({
|
||||
className: "header",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
hexpand: true,
|
||||
children: [
|
||||
new Widget.Box({
|
||||
className: "title",
|
||||
children: [
|
||||
new Widget.Label({
|
||||
hexpand: true,
|
||||
className: "title",
|
||||
truncate: true,
|
||||
visible: (this.props.title instanceof Binding) ?
|
||||
this.props.title.as(Boolean)
|
||||
: (this.props.title ? true : false),
|
||||
label: this.props.title,
|
||||
halign: Gtk.Align.START
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Box({
|
||||
className: "button-row",
|
||||
visible: Boolean(this.getHeaderButtons()),
|
||||
children: this.getHeaderButtons() || undefined
|
||||
} as Widget.BoxProps)
|
||||
]
|
||||
} as Widget.BoxProps),
|
||||
new Widget.Label({
|
||||
className: "description",
|
||||
hexpand: true,
|
||||
truncate: true,
|
||||
xalign: 0,
|
||||
visible: (this.props.description instanceof Binding) ?
|
||||
this.props.description.as(Boolean)
|
||||
: this.props.description ? true : false,
|
||||
label: this.props.description
|
||||
} as Widget.LabelProps),
|
||||
]
|
||||
} as Widget.BoxProps),
|
||||
new Widget.Box({
|
||||
className: "content",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
expand: true,
|
||||
setup: (_) => _.add(this.props.pageChild())
|
||||
} as Widget.BoxProps)
|
||||
]
|
||||
} as Widget.BoxProps);
|
||||
}
|
||||
}
|
||||
|
||||
export { Page };
|
||||
@@ -1,4 +1,4 @@
|
||||
import { bind } from "astal";
|
||||
import { bind, Variable } from "astal";
|
||||
import { Tile, TileProps } from "./Tile";
|
||||
import AstalBluetooth from "gi://AstalBluetooth";
|
||||
import { togglePage } from "../Pages";
|
||||
@@ -6,16 +6,18 @@ import { BluetoothPage } from "../pages/Bluetooth";
|
||||
|
||||
export const TileBluetooth = Tile({
|
||||
title: "Bluetooth",
|
||||
description: bind(AstalBluetooth.get_default(), "devices").as((devices: Array<AstalBluetooth.Device>) => {
|
||||
const connected: Array<AstalBluetooth.Device> = devices.filter(
|
||||
(dev: AstalBluetooth.Device) => dev.connected);
|
||||
|
||||
return connected[0] ? connected[0].get_alias() : undefined;
|
||||
}),
|
||||
description: bind(AstalBluetooth.get_default(), "devices").as((devices: Array<AstalBluetooth.Device>) =>
|
||||
devices.filter((dev: AstalBluetooth.Device) => dev.connected)[0]?.get_alias()),
|
||||
onToggledOn: () => AstalBluetooth.get_default().adapter.set_powered(true),
|
||||
onToggledOff: () => AstalBluetooth.get_default().adapter.set_powered(false),
|
||||
onClickMore: () => togglePage(BluetoothPage()),
|
||||
icon: "",
|
||||
onClickMore: () => togglePage(BluetoothPage),
|
||||
icon: Variable.derive([
|
||||
bind(AstalBluetooth.get_default().adapter, "powered"),
|
||||
bind(AstalBluetooth.get_default(), "isConnected")
|
||||
],
|
||||
(powered: boolean, isConnected: boolean) =>
|
||||
powered ? ( isConnected ? "" : "" ) : ""
|
||||
)(),
|
||||
iconSize: 16,
|
||||
toggleState: bind(AstalBluetooth.get_default().adapter, "powered")
|
||||
} as TileProps);
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { bind, execAsync } from "astal";
|
||||
import { Tile, TileProps } from "./Tile";
|
||||
import AstalNetwork from "gi://AstalNetwork";
|
||||
import { Widget } from "astal/gtk3";
|
||||
|
||||
export const TileInternet = new Widget.Box({
|
||||
child: bind(AstalNetwork.get_default(), "wired").as((wired: AstalNetwork.Wired) => Tile({
|
||||
title: "Wired",
|
||||
description: bind(wired, "internet").as((internet: AstalNetwork.Internet) => {
|
||||
switch(internet) {
|
||||
case AstalNetwork.Internet.CONNECTED:
|
||||
return "Connected";
|
||||
case AstalNetwork.Internet.DISCONNECTED:
|
||||
return "Disconnected";
|
||||
case AstalNetwork.Internet.CONNECTING:
|
||||
return "Connecting...";
|
||||
}
|
||||
}),
|
||||
onToggledOn: () => execAsync("nmcli n on"),
|
||||
onToggledOff: () => execAsync("nmcli n off"),
|
||||
icon: "",
|
||||
iconSize: 16,
|
||||
toggleState: bind(wired, "internet").as((internet: AstalNetwork.Internet) =>
|
||||
internet === AstalNetwork.Internet.CONNECTING || internet === AstalNetwork.Internet.CONNECTED)
|
||||
} as TileProps))
|
||||
} as Widget.BoxProps);
|
||||
@@ -0,0 +1,86 @@
|
||||
import { bind, execAsync, Variable } from "astal";
|
||||
import { Tile, TileProps } from "./Tile";
|
||||
import AstalNetwork from "gi://AstalNetwork";
|
||||
import { Widget } from "astal/gtk3";
|
||||
import { showPages, togglePage } from "../Pages";
|
||||
import { PageNetwork } from "../pages/Network";
|
||||
|
||||
export const TileNetwork = new Widget.Box({
|
||||
child: Variable.derive([
|
||||
bind(AstalNetwork.get_default(), "primary"),
|
||||
bind(AstalNetwork.get_default(), "wired"),
|
||||
bind(AstalNetwork.get_default(), "wifi")
|
||||
],
|
||||
(primary: AstalNetwork.Primary, wired: AstalNetwork.Wired, wifi: AstalNetwork.Wifi) => {
|
||||
if(primary === AstalNetwork.Primary.WIFI) {
|
||||
return Tile({
|
||||
title: "Wireless",
|
||||
description: Variable.derive(
|
||||
[ bind(wifi, "ssid"), bind(wifi, "internet") ],
|
||||
(ssid: string, internet: AstalNetwork.Internet) =>
|
||||
ssid ? ssid : (() => {
|
||||
switch(internet) {
|
||||
case AstalNetwork.Internet.CONNECTED:
|
||||
return "Connected";
|
||||
case AstalNetwork.Internet.DISCONNECTED:
|
||||
return "Disconnected";
|
||||
case AstalNetwork.Internet.CONNECTING:
|
||||
return "Connecting...";
|
||||
}
|
||||
})()
|
||||
)(),
|
||||
onToggledOn: () => wifi.set_enabled(true),
|
||||
onToggledOff: () => wifi.set_enabled(false),
|
||||
onClickMore: () => togglePage(PageNetwork),
|
||||
icon: "",
|
||||
iconSize: 16,
|
||||
toggleState: bind(wifi, "enabled")
|
||||
} as TileProps);
|
||||
|
||||
} else if(primary === AstalNetwork.Primary.WIRED) {
|
||||
return Tile({
|
||||
title: "Wired",
|
||||
description: bind(wired, "internet").as((internet: AstalNetwork.Internet) => {
|
||||
switch(internet) {
|
||||
case AstalNetwork.Internet.CONNECTED:
|
||||
return "Connected";
|
||||
case AstalNetwork.Internet.DISCONNECTED:
|
||||
return "Disconnected";
|
||||
case AstalNetwork.Internet.CONNECTING:
|
||||
return "Connecting...";
|
||||
}
|
||||
}),
|
||||
onToggledOn: () => execAsync("nmcli n on"),
|
||||
onToggledOff: () => execAsync("nmcli n off"),
|
||||
onClickMore: () => togglePage(PageNetwork),
|
||||
icon: bind(wired, "internet").as((internet: AstalNetwork.Internet) => {
|
||||
switch(internet) {
|
||||
case AstalNetwork.Internet.CONNECTED:
|
||||
return '';
|
||||
case AstalNetwork.Internet.DISCONNECTED:
|
||||
return '';
|
||||
}
|
||||
|
||||
return "";
|
||||
}),
|
||||
iconSize: 16,
|
||||
toggleState: bind(wired, "internet").as((internet: AstalNetwork.Internet) =>
|
||||
internet === AstalNetwork.Internet.CONNECTING
|
||||
|| internet === AstalNetwork.Internet.CONNECTED
|
||||
)
|
||||
} as TileProps);
|
||||
}
|
||||
|
||||
return Tile({
|
||||
title: "Network",
|
||||
description: "Disconnected",
|
||||
onToggledOn: () => execAsync("nmcli n on"),
|
||||
onToggledOff: () => execAsync("nmcli n off"),
|
||||
onClickMore: () => togglePage(PageNetwork),
|
||||
icon: "",
|
||||
iconSize: 16,
|
||||
toggleState: bind(wired, "internet").as((internet: AstalNetwork.Internet) =>
|
||||
internet === AstalNetwork.Internet.CONNECTING || internet === AstalNetwork.Internet.CONNECTED)
|
||||
} as TileProps);
|
||||
})()
|
||||
} as Widget.BoxProps);
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Tile, TileProps } from "./Tile";
|
||||
import { Recording } from "../../../scripts/recording";
|
||||
import { bind } from "astal";
|
||||
|
||||
export const TileRecording = Tile({
|
||||
title: "Screen Recording",
|
||||
description: bind(Recording.getDefault(), "recording").as(
|
||||
(isRecording: boolean) => isRecording ?
|
||||
"Recording {time}"
|
||||
: "Start a Screen Record"
|
||||
),
|
||||
icon: "",
|
||||
onToggledOff: () => Recording.getDefault().stopRecording(),
|
||||
onToggledOn: () => Recording.getDefault().startRecording(),
|
||||
iconSize: 16,
|
||||
toggleState: bind(Recording.getDefault(), "recording"),
|
||||
} as TileProps);
|
||||
@@ -55,23 +55,38 @@ export function Tile(props: TileProps): Widget.EventBox {
|
||||
new Widget.Label({
|
||||
className: "icon nf",
|
||||
label: props.icon || "icon",
|
||||
css: `.icon { font-size: ${props.iconSize || "12px"} }`
|
||||
css: `label { font-size: ${props.iconSize || "12"}px; }`
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Box({
|
||||
className: "text",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
vexpand: true,
|
||||
hexpand: true,
|
||||
valign: Gtk.Align.CENTER,
|
||||
children: [
|
||||
new Widget.Label({
|
||||
className: "title",
|
||||
xalign: 0,
|
||||
halign: Gtk.Align.START,
|
||||
truncate: true,
|
||||
label: props.title
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Label({
|
||||
className: "description",
|
||||
visible: props.description,
|
||||
visible: Boolean(props.description),
|
||||
setup: (label: Widget.Label) => {
|
||||
if(props.description instanceof Binding) {
|
||||
const sub = props.description.subscribe((value) => {
|
||||
label.set_visible(Boolean(value));
|
||||
});
|
||||
|
||||
const destroyId = label.connect("destroy-event", () => {
|
||||
label.disconnect(destroyId);
|
||||
sub();
|
||||
});
|
||||
}
|
||||
},
|
||||
halign: Gtk.Align.START,
|
||||
truncate: true,
|
||||
xalign: 0,
|
||||
label: props.description
|
||||
|
||||
Reference in New Issue
Block a user