From 633e41c7f3dc37e5a86ec2f21ceb5ce7120c06a3 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Fri, 29 Dec 2023 01:18:43 +0200 Subject: [PATCH] ags: only load widgets when their services are ready --- home/services/ags/config.js | 19 ++++++--------- .../ags/windows/bar/modules/workspaces.js | 21 ++++++++++------- home/services/ags/windows/system-menu/main.js | 23 ++++++++++--------- .../ags/windows/system-menu/sliders.js | 15 ++++++++---- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/home/services/ags/config.js b/home/services/ags/config.js index 4b00559e..eeccd218 100644 --- a/home/services/ags/config.js +++ b/home/services/ags/config.js @@ -31,16 +31,11 @@ function addWindows(windows) { windows.forEach((win) => App.addWindow(win)); } -//timeout to wait for Hyprland service to be fully -//initialized. Maybe connect to Hyprland signal like -//notify::worksapces for more consistant results? -Utils.timeout(100, () => - addWindows( - [ - Bar(), - Music(), - Osd(), - SystemMenu(), - ], - ) +addWindows( + [ + Bar(), + Music(), + Osd(), + SystemMenu(), + ], ); diff --git a/home/services/ags/windows/bar/modules/workspaces.js b/home/services/ags/windows/bar/modules/workspaces.js index 917c1967..6ddf3b0c 100644 --- a/home/services/ags/windows/bar/modules/workspaces.js +++ b/home/services/ags/windows/bar/modules/workspaces.js @@ -37,15 +37,20 @@ export default () => child: Widget.Box({ className: "workspaces module", - children: makeWorkspaces(), - + // The Hyprland service is ready later than ags is done parsing the config, + // so only build the widget when we receive a signal from it. setup: (self) => { - self.lastFocused = Hyprland.active.workspace.id; - self.biggestId = getLastWorkspaceId(); - self - .hook(Hyprland.active.workspace, focusedSwitch) - .hook(Hyprland, added, "workspace-added") - .hook(Hyprland, removed, "workspace-removed"); + const connID = Hyprland.connect("notify::workspaces", () => { + Hyprland.disconnect(connID); + + self.children = makeWorkspaces(); + self.lastFocused = Hyprland.active.workspace.id; + self.biggestId = getLastWorkspaceId(); + self + .hook(Hyprland.active.workspace, focusedSwitch) + .hook(Hyprland, added, "workspace-added") + .hook(Hyprland, removed, "workspace-removed"); + }); }, }), }); diff --git a/home/services/ags/windows/system-menu/main.js b/home/services/ags/windows/system-menu/main.js index 51cda93e..3dce37d7 100644 --- a/home/services/ags/windows/system-menu/main.js +++ b/home/services/ags/windows/system-menu/main.js @@ -3,20 +3,21 @@ import PopupWindow from "../../utils/popup_window.js"; import Toggles from "./toggles.js"; import PowerProfiles from "./powerprofiles.js"; -// import Sliders from "./sliders.js"; +import Sliders from "./sliders.js"; import BatteryInfo from "./battery_info.js"; -const SystemMenuBox = () => Widget.Box({ - className: "system-menu", - vertical: true, +const SystemMenuBox = () => + Widget.Box({ + className: "system-menu", + vertical: true, - children: [ - Toggles(), - PowerProfiles(), - // Sliders(), - BatteryInfo(), - ], -}); + children: [ + Toggles(), + PowerProfiles(), + Sliders(), + BatteryInfo(), + ], + }); export default () => PopupWindow({ diff --git a/home/services/ags/windows/system-menu/sliders.js b/home/services/ags/windows/system-menu/sliders.js index 345211d6..175eaf87 100644 --- a/home/services/ags/windows/system-menu/sliders.js +++ b/home/services/ags/windows/system-menu/sliders.js @@ -63,8 +63,15 @@ export default () => className: "sliders", vertical: true, - children: [ - Slider(vol()), - Slider(brightness()), - ], + // The Audio service is ready later than ags is done parsing the config, + // so only build the widget when we receive a signal from it. + setup: (self) => { + const connID = Audio.connect("notify::speaker", () => { + Audio.disconnect(connID); + self.children = [ + Slider(vol()), + Slider(brightness()), + ]; + }); + }, });