[AGS] Possibly fixed

This commit is contained in:
Janis Hutz 2025-04-25 21:36:19 +02:00
parent 03d9d89102
commit bf7d61945b
5 changed files with 64 additions and 37 deletions

View File

@ -1,23 +1,63 @@
import { bind, exec, interval, readFile, timeout, writeFile } from "astal";
import { bind, interval, readFile, timeout, writeFile } from "astal";
import { Gtk } from "astal/gtk4";
import AstalBluetooth from "gi://AstalBluetooth";
import BTDevice from "./Device";
const ALIGN = Gtk.Align;
const MAX_RETRY = 20;
const bt = AstalBluetooth.get_default();
// const LaunchBluetoothModule = () => {
// const box = new Gtk.Box();
//
// const placeholder = () => {
// return <button cssClasses={["toggle-button"]} child={
// <box>
// <label
// cssClasses={['title-2']}
// label={"Bluetooth"}></label>
// <label label={"Backend missing"}></label>
// </box>
// }>
// </button>
// }
//
// if (bt.adapter) {
// box.append(BluetoothModule());
// } else {
// const p = placeholder();
// box.append(p);
//
// let count = 0;
// const i = interval(1000, () => {
// if (bt.adapter !== null) {
// box.remove(p);
// box.append(BluetoothModule());
// i.cancel();
// } else if (count >= MAX_RETRY) {
// i.cancel();
// }
// count++;
// });
// }
//
// return box;
// }
const BluetoothModule = () => {
return (
<box>
<button
cssClasses={bind(bt.adapter, "powered").as(powered =>
cssClasses={bind(bt, "isPowered").as(powered =>
powered
? ["toggle-button", "toggle-on"]
: ["toggle-button"],
)}
onClicked={() =>
bt.adapter.set_powered(!bt.adapter.get_powered())
}
onClicked={() => {
try {
bt.adapter.set_powered(!bt.adapter.get_powered())
} catch (_) { }
}}
child={
<box vertical>
<label
@ -28,13 +68,13 @@ const BluetoothModule = () => {
></label>
<box halign={ALIGN.CENTER} valign={ALIGN.CENTER}>
<label
visible={bind(bt.adapter, "powered").as(
visible={bind(bt, "isPowered").as(
p => !p,
)}
label="Disabled"
></label>
<label
visible={bind(bt.adapter, "powered")}
visible={bind(bt, "isPowered")}
label={bind(bt, "devices").as(devices => {
let count = 0;
devices.forEach(device => {
@ -52,7 +92,7 @@ const BluetoothModule = () => {
></button>
<button
cssClasses={["actions-button"]}
visible={bind(bt.adapter, "powered")}
visible={bind(bt, "isPowered")}
child={
<box>
<image iconName={"arrow-right-symbolic"}></image>
@ -75,28 +115,16 @@ const openBTPicker = () => {
const BluetoothPickerList = () => {
let btEnableState = readFile("./btconf") === "true" ? true : false;
if (bt.adapter) {
if (bt.get_adapter()) {
print( 'Setting BT state to ' + btEnableState );
bt.adapter.set_powered(btEnableState);
} else {
timeout( 1000, () => {
if (bt.adapter) {
timeout(5000, () => {
if (bt.get_adapter()) {
print( 'Setting BT state to ' + btEnableState );
bt.adapter.set_powered(btEnableState);
} else {
timeout( 2000, () => {
if ( bt.adapter ) {
bt.adapter.set_powered(btEnableState);
} else {
timeout( 10000, () => {
if ( bt.adapter ) {
bt.adapter.set_powered(btEnableState);
} else {
exec( `/bin/bash -c "notify-send 'Failed to connect to bluetooth adapter'"` );
}
} )
}
} )
}
} );
})
}
const updateState = () => {
@ -107,7 +135,11 @@ const BluetoothPickerList = () => {
return (
<box
vertical
onDestroy={() => bt.adapter.stop_discovery()}
onDestroy={() => {
try {
bt.adapter.stop_discovery()
} catch (_) { }
}}
cssClasses={["popover-box"]}
>
<label cssClasses={["title"]} label={"Bluetooth"}></label>

View File

@ -77,7 +77,7 @@ const NetworkWidget = () => {
const BluetoothWidget = () => {
const bluetooth = AstalBluetooth.get_default();
const enabled = bind(bluetooth.adapter, "powered");
const enabled = bind(bluetooth, "isPowered");
const connected = bind(bluetooth, "isConnected");
// For each connected BT device, render status

View File

@ -13,8 +13,8 @@ exec-once = /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1
exec-once = hypridle
exec-once = nm-applet
exec-once = nextcloud --background
exec = ags run ~/projects/active/dotfiles/config/astal/ --gtk4
exec = ags run ~/projects/active/dotfiles/config/ags/notifications/
exec-once = sleep 2 && bash -c "ags run -d ~/projects/active/dotfiles/config/astal/ --gtk4 >> ~/log 2>&1"
exec-once = bash -c "ags run -d ~/projects/active/dotfiles/config/ags/notifications/ >> ~/logn 2>&1"

View File

@ -18,7 +18,7 @@ general {
# └ ┘
background {
monitor =
path = /home/janis/NextCloud/Wallpapers/arch/arch-simple.jpg # Or screenshot
path = /home/janis/NextCloud/Wallpapers/dark/mountains.jpg # Or screenshot
blur_passes = 1
}

7
setup
View File

@ -72,12 +72,6 @@ echo "
=> Bundling Astal projects
"
cd ./config/astal
ags bundle app.ts runner
cd ../ags/notifications
ags bundle app.ts notifier
echo "
=> Installing yazi plugins
"
@ -94,6 +88,7 @@ echo "
=> Installing System Configs
"
sudo cp ./system/environment /etc/environment
hyprctl reload
echo "