[AGS] Possibly fixed
This commit is contained in:
		| @@ -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 { Gtk } from "astal/gtk4"; | ||||||
| import AstalBluetooth from "gi://AstalBluetooth"; | import AstalBluetooth from "gi://AstalBluetooth"; | ||||||
| import BTDevice from "./Device"; | import BTDevice from "./Device"; | ||||||
| const ALIGN = Gtk.Align; | const ALIGN = Gtk.Align; | ||||||
|  | const MAX_RETRY = 20; | ||||||
|  |  | ||||||
| const bt = AstalBluetooth.get_default(); | 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 = () => { | const BluetoothModule = () => { | ||||||
|     return ( |     return ( | ||||||
|         <box> |         <box> | ||||||
|             <button |             <button | ||||||
|                 cssClasses={bind(bt.adapter, "powered").as(powered => |                 cssClasses={bind(bt, "isPowered").as(powered => | ||||||
|                     powered |                     powered | ||||||
|                         ? ["toggle-button", "toggle-on"] |                         ? ["toggle-button", "toggle-on"] | ||||||
|                         : ["toggle-button"], |                         : ["toggle-button"], | ||||||
|                 )} |                 )} | ||||||
|                 onClicked={() => |                 onClicked={() => { | ||||||
|  |                     try { | ||||||
|                         bt.adapter.set_powered(!bt.adapter.get_powered()) |                         bt.adapter.set_powered(!bt.adapter.get_powered()) | ||||||
|                 } |                     } catch (_) { } | ||||||
|  |                 }} | ||||||
|                 child={ |                 child={ | ||||||
|                     <box vertical> |                     <box vertical> | ||||||
|                         <label |                         <label | ||||||
| @@ -28,13 +68,13 @@ const BluetoothModule = () => { | |||||||
|                         ></label> |                         ></label> | ||||||
|                         <box halign={ALIGN.CENTER} valign={ALIGN.CENTER}> |                         <box halign={ALIGN.CENTER} valign={ALIGN.CENTER}> | ||||||
|                             <label |                             <label | ||||||
|                                 visible={bind(bt.adapter, "powered").as( |                                 visible={bind(bt, "isPowered").as( | ||||||
|                                     p => !p, |                                     p => !p, | ||||||
|                                 )} |                                 )} | ||||||
|                                 label="Disabled" |                                 label="Disabled" | ||||||
|                             ></label> |                             ></label> | ||||||
|                             <label |                             <label | ||||||
|                                 visible={bind(bt.adapter, "powered")} |                                 visible={bind(bt, "isPowered")} | ||||||
|                                 label={bind(bt, "devices").as(devices => { |                                 label={bind(bt, "devices").as(devices => { | ||||||
|                                     let count = 0; |                                     let count = 0; | ||||||
|                                     devices.forEach(device => { |                                     devices.forEach(device => { | ||||||
| @@ -52,7 +92,7 @@ const BluetoothModule = () => { | |||||||
|             ></button> |             ></button> | ||||||
|             <button |             <button | ||||||
|                 cssClasses={["actions-button"]} |                 cssClasses={["actions-button"]} | ||||||
|                 visible={bind(bt.adapter, "powered")} |                 visible={bind(bt, "isPowered")} | ||||||
|                 child={ |                 child={ | ||||||
|                     <box> |                     <box> | ||||||
|                         <image iconName={"arrow-right-symbolic"}></image> |                         <image iconName={"arrow-right-symbolic"}></image> | ||||||
| @@ -75,28 +115,16 @@ const openBTPicker = () => { | |||||||
|  |  | ||||||
| const BluetoothPickerList = () => { | const BluetoothPickerList = () => { | ||||||
|     let btEnableState = readFile("./btconf") === "true" ? true : false; |     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); |         bt.adapter.set_powered(btEnableState); | ||||||
|     } else { |     } else { | ||||||
|         timeout( 1000, () => { |         timeout(5000, () => { | ||||||
|             if (bt.adapter) { |             if (bt.get_adapter()) { | ||||||
|  |                 print( 'Setting BT state to ' + btEnableState ); | ||||||
|                 bt.adapter.set_powered(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 = () => { |     const updateState = () => { | ||||||
| @@ -107,7 +135,11 @@ const BluetoothPickerList = () => { | |||||||
|     return ( |     return ( | ||||||
|         <box |         <box | ||||||
|             vertical |             vertical | ||||||
|             onDestroy={() => bt.adapter.stop_discovery()} |             onDestroy={() => { | ||||||
|  |                 try { | ||||||
|  |                     bt.adapter.stop_discovery() | ||||||
|  |                 } catch (_) { } | ||||||
|  |             }} | ||||||
|             cssClasses={["popover-box"]} |             cssClasses={["popover-box"]} | ||||||
|         > |         > | ||||||
|             <label cssClasses={["title"]} label={"Bluetooth"}></label> |             <label cssClasses={["title"]} label={"Bluetooth"}></label> | ||||||
|   | |||||||
| @@ -77,7 +77,7 @@ const NetworkWidget = () => { | |||||||
|  |  | ||||||
| const BluetoothWidget = () => { | const BluetoothWidget = () => { | ||||||
|     const bluetooth = AstalBluetooth.get_default(); |     const bluetooth = AstalBluetooth.get_default(); | ||||||
|     const enabled = bind(bluetooth.adapter, "powered"); |     const enabled = bind(bluetooth, "isPowered"); | ||||||
|     const connected = bind(bluetooth, "isConnected"); |     const connected = bind(bluetooth, "isConnected"); | ||||||
|  |  | ||||||
|     // For each connected BT device, render status |     // For each connected BT device, render status | ||||||
|   | |||||||
| @@ -13,8 +13,8 @@ exec-once = /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 | |||||||
| exec-once = hypridle | exec-once = hypridle | ||||||
| exec-once = nm-applet | exec-once = nm-applet | ||||||
| exec-once = nextcloud --background | exec-once = nextcloud --background | ||||||
| exec = ags run ~/projects/active/dotfiles/config/astal/ --gtk4 | exec-once = sleep 2 && bash -c "ags run -d ~/projects/active/dotfiles/config/astal/ --gtk4 >> ~/log 2>&1" | ||||||
| exec = ags run ~/projects/active/dotfiles/config/ags/notifications/ | exec-once = bash -c "ags run -d ~/projects/active/dotfiles/config/ags/notifications/ >> ~/logn 2>&1" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ general { | |||||||
| # └                                                ┘ | # └                                                ┘ | ||||||
| background { | background { | ||||||
|     monitor =  |     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 |     blur_passes = 1 | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								setup
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								setup
									
									
									
									
									
								
							| @@ -72,12 +72,6 @@ echo " | |||||||
|     => Bundling Astal projects |     => Bundling Astal projects | ||||||
| " | " | ||||||
|  |  | ||||||
| cd ./config/astal |  | ||||||
| ags bundle app.ts runner |  | ||||||
|  |  | ||||||
| cd ../ags/notifications |  | ||||||
| ags bundle app.ts notifier |  | ||||||
|  |  | ||||||
| echo " | echo " | ||||||
|     => Installing yazi plugins |     => Installing yazi plugins | ||||||
| " | " | ||||||
| @@ -94,6 +88,7 @@ echo " | |||||||
|     => Installing System Configs |     => Installing System Configs | ||||||
| " | " | ||||||
| sudo cp ./system/environment /etc/environment | sudo cp ./system/environment /etc/environment | ||||||
|  | hyprctl reload | ||||||
|  |  | ||||||
| echo " | echo " | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user