diff --git a/app.ts b/app.ts index 15e5822..4457e61 100644 --- a/app.ts +++ b/app.ts @@ -7,6 +7,9 @@ import './src/globals/dropdown'; import './src/globals/utilities'; import './src/components/bar/utils/sideEffects'; +import AstalHyprland from 'gi://AstalHyprland?version=0.1'; +const hyprland = AstalHyprland.get_default(); + import { Bar } from './src/components/bar'; import { DropdownMenus, StandardWindows } from './src/components/menus/exports'; import Notifications from './src/components/notifications'; @@ -16,7 +19,6 @@ import options from 'src/options'; import OSD from 'src/components/osd/index'; import { App } from 'astal/gtk3'; import { execAsync } from 'astal'; -import { hyprlandService } from 'src/lib/constants/services'; import { handleRealization } from 'src/components/menus/shared/dropdown/helpers'; import { isDropdownMenu } from 'src/lib/constants/options.js'; import { initializeSystemBehaviors } from 'src/lib/behaviors'; @@ -64,7 +66,7 @@ App.start({ }, }); -hyprlandService.connect('monitor-added', () => { +hyprland.connect('monitor-added', () => { const { restartCommand } = options.hyprpanel; if (options.hyprpanel.restartAgs.get()) { diff --git a/src/cli/commander/commands/utility/index.ts b/src/cli/commander/commands/utility/index.ts index 2fb9181..d7ad3ab 100644 --- a/src/cli/commander/commands/utility/index.ts +++ b/src/cli/commander/commands/utility/index.ts @@ -1,8 +1,10 @@ +import AstalWp from 'gi://AstalWp?version=0.1'; import { errorHandler } from 'src/lib/utils'; import { Command } from '../../types'; import { execAsync, Gio, GLib } from 'astal'; import { checkDependencies } from './checkDependencies'; -import { audioService } from 'src/lib/constants/services'; + +const audio = AstalWp.get_default(); export const utilityCommands: Command[] = [ { @@ -49,7 +51,12 @@ export const utilityCommands: Command[] = [ ], handler: (args: Record): number => { try { - const speaker = audioService.defaultSpeaker; + const speaker = audio?.defaultSpeaker; + + if (speaker === undefined) { + throw new Error('A default speaker was not found.'); + } + const volumeInput = Number(args['volume']) / 100; if (options.menus.volume.raiseMaximumVolume.get()) { diff --git a/src/components/bar/modules/battery/index.tsx b/src/components/bar/modules/battery/index.tsx index 6ceabc1..a58d724 100644 --- a/src/components/bar/modules/battery/index.tsx +++ b/src/components/bar/modules/battery/index.tsx @@ -1,4 +1,4 @@ -import { batteryService } from 'src/lib/constants/services.js'; +import AstalBattery from 'gi://AstalBattery?version=0.1'; import { Astal } from 'astal/gtk3'; import { openMenu } from '../../utils/menu'; import options from 'src/options'; @@ -6,10 +6,10 @@ import { BarBoxChild } from 'src/lib/types/bar.js'; import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js'; import Variable from 'astal/variable'; import { bind } from 'astal'; -import AstalBattery from 'gi://AstalBattery?version=0.1'; import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers'; import { getBatteryIcon } from './helpers'; +const batteryService = AstalBattery.get_default(); const { label: show_label, rightClick, middleClick, scrollUp, scrollDown, hideLabelWhenFull } = options.bar.battery; const BatteryLabel = (): BarBoxChild => { diff --git a/src/components/bar/modules/bluetooth/index.tsx b/src/components/bar/modules/bluetooth/index.tsx index a0b13ec..712edb4 100644 --- a/src/components/bar/modules/bluetooth/index.tsx +++ b/src/components/bar/modules/bluetooth/index.tsx @@ -1,4 +1,3 @@ -import { bluetoothService } from 'src/lib/constants/services.js'; import options from 'src/options.js'; import { openMenu } from '../../utils/menu.js'; import { BarBoxChild } from 'src/lib/types/bar.js'; @@ -8,6 +7,8 @@ import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/l import AstalBluetooth from 'gi://AstalBluetooth?version=0.1'; import { Astal } from 'astal/gtk3'; +const bluetoothService = AstalBluetooth.get_default(); + const { rightClick, middleClick, scrollDown, scrollUp } = options.bar.bluetooth; const Bluetooth = (): BarBoxChild => { diff --git a/src/components/bar/modules/cava/helpers.ts b/src/components/bar/modules/cava/helpers.ts index 66c45db..d79607e 100644 --- a/src/components/bar/modules/cava/helpers.ts +++ b/src/components/bar/modules/cava/helpers.ts @@ -1,7 +1,9 @@ import { bind, Variable } from 'astal'; -import { cavaService, mprisService } from 'src/lib/constants/services'; +import AstalCava from 'gi://AstalCava?version=0.1'; +import AstalMpris from 'gi://AstalMpris?version=0.1'; import options from 'src/options'; +const mprisService = AstalMpris.get_default(); const { showActiveOnly, bars, @@ -20,8 +22,10 @@ const { * * @param isVis - A variable that holds the visibility status. */ -export function initVisibilityTracker(isVis: Variable): void { - Variable.derive([bind(showActiveOnly), bind(mprisService, 'players')], (showActive, players) => { +export function initVisibilityTracker(isVis: Variable): Variable { + const cavaService = AstalCava.get_default(); + + return Variable.derive([bind(showActiveOnly), bind(mprisService, 'players')], (showActive, players) => { isVis.set(cavaService !== null && (!showActive || players?.length > 0)); }); } @@ -29,14 +33,14 @@ export function initVisibilityTracker(isVis: Variable): void { /** * Initializes a settings tracker that updates the CAVA service settings based on the provided options. */ -export function initSettingsTracker(): void { - const cava = cavaService; +export function initSettingsTracker(): Variable | undefined { + const cava = AstalCava.get_default(); if (!cava) { return; } - Variable.derive( + return Variable.derive( [ bind(bars), bind(channels), diff --git a/src/components/bar/modules/cava/index.tsx b/src/components/bar/modules/cava/index.tsx index 063127a..7a216d7 100644 --- a/src/components/bar/modules/cava/index.tsx +++ b/src/components/bar/modules/cava/index.tsx @@ -1,11 +1,11 @@ import { Variable, bind } from 'astal'; import { Astal } from 'astal/gtk3'; -import { cavaService } from 'src/lib/constants/services'; import { BarBoxChild } from 'src/lib/types/bar'; import { Module } from '../../shared/Module'; import { inputHandler } from '../../utils/helpers'; import options from 'src/options'; import { initSettingsTracker, initVisibilityTracker } from './helpers'; +import AstalCava from 'gi://AstalCava?version=0.1'; const { icon, @@ -22,12 +22,13 @@ const { const isVis = Variable(!showActiveOnly.get()); -initVisibilityTracker(isVis); -initSettingsTracker(); - export const Cava = (): BarBoxChild => { let labelBinding: Variable = Variable(''); + const visTracker = initVisibilityTracker(isVis); + const settingsTracker = initSettingsTracker(); + const cavaService = AstalCava.get_default(); + if (cavaService) { labelBinding = Variable.derive( [bind(cavaService, 'values'), bind(spaceCharacter), bind(barCharacters)], @@ -71,6 +72,8 @@ export const Cava = (): BarBoxChild => { }, onDestroy: () => { labelBinding.drop(); + visTracker.drop(); + settingsTracker?.drop(); }, }, }); diff --git a/src/components/bar/modules/kblayout/index.tsx b/src/components/bar/modules/kblayout/index.tsx index b9b4ddb..df11a0c 100644 --- a/src/components/bar/modules/kblayout/index.tsx +++ b/src/components/bar/modules/kblayout/index.tsx @@ -1,4 +1,3 @@ -import { hyprlandService } from 'src/lib/constants/services'; import options from 'src/options'; import { Module } from '../../shared/Module'; import { inputHandler } from 'src/components/bar/utils/helpers'; @@ -7,7 +6,9 @@ import { BarBoxChild } from 'src/lib/types/bar'; import { bind } from 'astal'; import { useHook } from 'src/lib/shared/hookHandler'; import { Astal } from 'astal/gtk3'; +import AstalHyprland from 'gi://AstalHyprland?version=0.1'; +const hyprlandService = AstalHyprland.get_default(); const { label, labelType, icon, leftClick, rightClick, middleClick, scrollUp, scrollDown } = options.bar.customModules.kbLayout; diff --git a/src/components/bar/modules/media/index.tsx b/src/components/bar/modules/media/index.tsx index 7744943..c5b999d 100644 --- a/src/components/bar/modules/media/index.tsx +++ b/src/components/bar/modules/media/index.tsx @@ -2,13 +2,14 @@ import { openMenu } from '../../utils/menu.js'; import options from 'src/options.js'; import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js'; import { generateMediaLabel } from './helpers/index.js'; -import { mprisService } from 'src/lib/constants/services.js'; import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers.js'; import { bind, Variable } from 'astal'; import { BarBoxChild } from 'src/lib/types/bar.js'; import { Astal } from 'astal/gtk3'; import { activePlayer, mediaAlbum, mediaArtist, mediaTitle } from 'src/globals/media.js'; +import AstalMpris from 'gi://AstalMpris?version=0.1'; +const mprisService = AstalMpris.get_default(); const { truncation, truncation_size, diff --git a/src/components/bar/modules/netstat/index.tsx b/src/components/bar/modules/netstat/index.tsx index ae0f7f5..2aeff8f 100644 --- a/src/components/bar/modules/netstat/index.tsx +++ b/src/components/bar/modules/netstat/index.tsx @@ -1,4 +1,3 @@ -import { networkService } from 'src/lib/constants/services'; import options from 'src/options'; import { Module } from '../../shared/Module'; import { inputHandler } from 'src/components/bar/utils/helpers'; @@ -12,6 +11,7 @@ import { bind, Variable } from 'astal'; import AstalNetwork from 'gi://AstalNetwork?version=0.1'; import { Astal } from 'astal/gtk3'; +const networkService = AstalNetwork.get_default(); const { label, labelType, diff --git a/src/components/bar/modules/network/helpers.ts b/src/components/bar/modules/network/helpers.ts index 400437e..ff56a22 100644 --- a/src/components/bar/modules/network/helpers.ts +++ b/src/components/bar/modules/network/helpers.ts @@ -1,10 +1,11 @@ import AstalNetwork from 'gi://AstalNetwork?version=0.1'; import { bind, Variable } from 'astal'; -import { networkService } from 'src/lib/constants/services'; export const wiredIcon: Variable = Variable(''); export const wirelessIcon: Variable = Variable(''); +const networkService = AstalNetwork.get_default(); + let wiredIconBinding: Variable | undefined; let wirelessIconBinding: Variable | undefined; diff --git a/src/components/bar/modules/network/index.tsx b/src/components/bar/modules/network/index.tsx index 9537716..269fe57 100644 --- a/src/components/bar/modules/network/index.tsx +++ b/src/components/bar/modules/network/index.tsx @@ -1,4 +1,3 @@ -import { networkService } from 'src/lib/constants/services.js'; import options from 'src/options'; import { openMenu } from '../../utils/menu'; import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js'; @@ -9,6 +8,7 @@ import AstalNetwork from 'gi://AstalNetwork?version=0.1'; import { BarBoxChild } from 'src/lib/types/bar.js'; import { formatWifiInfo, wiredIcon, wirelessIcon } from './helpers'; +const networkService = AstalNetwork.get_default(); const { label, truncation, truncation_size, rightClick, middleClick, scrollDown, scrollUp, showWifiInfo } = options.bar.network; diff --git a/src/components/bar/modules/notifications/index.tsx b/src/components/bar/modules/notifications/index.tsx index bf8d278..6f06ca8 100644 --- a/src/components/bar/modules/notifications/index.tsx +++ b/src/components/bar/modules/notifications/index.tsx @@ -7,8 +7,8 @@ import { BarBoxChild } from 'src/lib/types/bar.js'; import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js'; import { bind, Variable } from 'astal'; import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers'; -import { notifdService } from 'src/lib/constants/services'; +const notifdService = AstalNotifd.get_default(); const { show_total, rightClick, middleClick, scrollUp, scrollDown, hideCountWhenZero } = options.bar.notifications; const { ignore } = options.notifications; diff --git a/src/components/bar/modules/submap/helpers/index.ts b/src/components/bar/modules/submap/helpers/index.ts index 2f3b0ee..6ffdf0e 100644 --- a/src/components/bar/modules/submap/helpers/index.ts +++ b/src/components/bar/modules/submap/helpers/index.ts @@ -1,5 +1,7 @@ import { Variable } from 'astal'; -import { hyprlandService } from 'src/lib/constants/services'; +import AstalHyprland from 'gi://AstalHyprland?version=0.1'; + +const hyprlandService = AstalHyprland.get_default(); /** * Determines if a submap is enabled based on the provided submap name. diff --git a/src/components/bar/modules/submap/index.tsx b/src/components/bar/modules/submap/index.tsx index b442492..6c22341 100644 --- a/src/components/bar/modules/submap/index.tsx +++ b/src/components/bar/modules/submap/index.tsx @@ -1,4 +1,3 @@ -import { hyprlandService } from 'src/lib/constants/services'; import options from 'src/options'; import { Module } from '../../shared/Module'; import { inputHandler } from 'src/components/bar/utils/helpers'; @@ -7,7 +6,9 @@ import { capitalizeFirstLetter } from 'src/lib/utils'; import { getInitialSubmap, isSubmapEnabled } from './helpers'; import { bind, Variable } from 'astal'; import { Astal } from 'astal/gtk3'; +import AstalHyprland from 'gi://AstalHyprland?version=0.1'; +const hyprlandService = AstalHyprland.get_default(); const { label, showSubmapName, diff --git a/src/components/bar/modules/volume/index.tsx b/src/components/bar/modules/volume/index.tsx index a773c64..11789f7 100644 --- a/src/components/bar/modules/volume/index.tsx +++ b/src/components/bar/modules/volume/index.tsx @@ -1,4 +1,3 @@ -import { audioService } from 'src/lib/constants/services.js'; import { openMenu } from '../../utils/menu.js'; import options from 'src/options'; import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js'; @@ -7,6 +6,10 @@ import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/l import { getIcon } from './helpers/index.js'; import { BarBoxChild } from 'src/lib/types/bar.js'; import { Astal } from 'astal/gtk3'; +import AstalWp from 'gi://AstalWp?version=0.1'; + +const wireplumber = AstalWp.get_default() as AstalWp.Wp; +const audioService = wireplumber?.audio; const { rightClick, middleClick, scrollUp, scrollDown } = options.bar.volume; diff --git a/src/components/bar/modules/window_title/helpers/title.ts b/src/components/bar/modules/window_title/helpers/title.ts index c8cb4f7..0f8bc92 100644 --- a/src/components/bar/modules/window_title/helpers/title.ts +++ b/src/components/bar/modules/window_title/helpers/title.ts @@ -1,9 +1,9 @@ import options from 'src/options'; import { capitalizeFirstLetter } from 'src/lib/utils'; import AstalHyprland from 'gi://AstalHyprland?version=0.1'; -import { hyprlandService } from 'src/lib/constants/services'; import { bind, Variable } from 'astal'; +const hyprlandService = AstalHyprland.get_default(); export const clientTitle = Variable(''); let clientBinding: Variable | undefined; diff --git a/src/components/bar/modules/window_title/index.tsx b/src/components/bar/modules/window_title/index.tsx index 348ecaa..62b06f8 100644 --- a/src/components/bar/modules/window_title/index.tsx +++ b/src/components/bar/modules/window_title/index.tsx @@ -1,13 +1,13 @@ import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers'; import { BarBoxChild } from 'src/lib/types/bar'; import options from 'src/options'; -import { hyprlandService } from 'src/lib/constants/services'; import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers'; import { bind, Variable } from 'astal'; import { clientTitle, getTitle, getWindowMatch, truncateTitle } from './helpers/title'; import { Astal } from 'astal/gtk3'; +const hyprlandService = AstalHyprland.get_default(); const { leftClick, rightClick, middleClick, scrollDown, scrollUp } = options.bar.windowtitle; const ClientTitle = (): BarBoxChild => { diff --git a/src/components/bar/modules/workspaces/helpers/index.ts b/src/components/bar/modules/workspaces/helpers/index.ts index 47ab9d5..d9fbf85 100644 --- a/src/components/bar/modules/workspaces/helpers/index.ts +++ b/src/components/bar/modules/workspaces/helpers/index.ts @@ -1,10 +1,10 @@ import { Variable } from 'astal'; import AstalHyprland from 'gi://AstalHyprland?version=0.1'; -import { hyprlandService } from 'src/lib/constants/services'; import { MonitorMap, WorkspaceMonitorMap, WorkspaceRule } from 'src/lib/types/workspace'; import { range } from 'src/lib/utils'; import options from 'src/options'; +const hyprlandService = AstalHyprland.get_default(); const { workspaces, reverse_scroll, ignored } = options.bar.workspaces; /** diff --git a/src/components/bar/modules/workspaces/helpers/utils.ts b/src/components/bar/modules/workspaces/helpers/utils.ts index 5d2c033..866b8c6 100644 --- a/src/components/bar/modules/workspaces/helpers/utils.ts +++ b/src/components/bar/modules/workspaces/helpers/utils.ts @@ -1,9 +1,10 @@ -import { hyprlandService } from 'src/lib/constants/services'; +import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import { defaultApplicationIcons } from 'src/lib/constants/workspaces'; import { AppIconOptions, WorkspaceIconMap } from 'src/lib/types/workspace'; import { isValidGjsColor } from 'src/lib/utils'; import options from 'src/options'; +const hyprlandService = AstalHyprland.get_default(); const { monochrome, background } = options.theme.bar.buttons; const { background: wsBackground, active } = options.theme.bar.buttons.workspaces; diff --git a/src/components/bar/modules/workspaces/workspaces.tsx b/src/components/bar/modules/workspaces/workspaces.tsx index 8a1bca7..3969581 100644 --- a/src/components/bar/modules/workspaces/workspaces.tsx +++ b/src/components/bar/modules/workspaces/workspaces.tsx @@ -1,4 +1,3 @@ -import { hyprlandService } from 'src/lib/constants/services'; import options from 'src/options'; import { forceUpdater, getWorkspacesToRender, initWorkspaceEvents, workspaceRules } from './helpers'; import { getAppIcon, getWsColor, renderClassnames, renderLabel } from './helpers/utils'; @@ -8,6 +7,7 @@ import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import { Gtk } from 'astal/gtk3'; import { isPrimaryClick } from 'src/lib/utils'; +const hyprlandService = AstalHyprland.get_default(); const { workspaces, monitorSpecific, diff --git a/src/components/bar/utils/monitors.ts b/src/components/bar/utils/monitors.ts index eb9d11a..4fbcfa0 100644 --- a/src/components/bar/utils/monitors.ts +++ b/src/components/bar/utils/monitors.ts @@ -1,7 +1,9 @@ -import { hyprlandService } from 'src/lib/constants/services'; import { Gdk } from 'astal/gtk3'; +import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import { BarLayout, BarLayouts } from 'src/lib/types/options'; +const hyprlandService = AstalHyprland.get_default(); + type GdkMonitors = { [key: string]: { key: string; diff --git a/src/components/menus/audio/active/devices/index.tsx b/src/components/menus/audio/active/devices/index.tsx index 8b5f981..5cc1a9d 100644 --- a/src/components/menus/audio/active/devices/index.tsx +++ b/src/components/menus/audio/active/devices/index.tsx @@ -1,6 +1,9 @@ -import { audioService } from 'src/lib/constants/services'; import { SliderItem } from '../sliderItem/SliderItem'; import { ActiveDeviceMenu } from '..'; +import AstalWp from 'gi://AstalWp?version=0.1'; + +const wireplumber = AstalWp.get_default() as AstalWp.Wp; +const audioService = wireplumber.audio; const ActiveDeviceContainer = ({ children }: ActiveDeviceContainerProps): JSX.Element => { return ( diff --git a/src/components/menus/audio/active/playbacks/index.tsx b/src/components/menus/audio/active/playbacks/index.tsx index cffc88f..06624cd 100644 --- a/src/components/menus/audio/active/playbacks/index.tsx +++ b/src/components/menus/audio/active/playbacks/index.tsx @@ -1,7 +1,10 @@ import { bind } from 'astal'; -import { audioService } from 'src/lib/constants/services'; import { SliderItem } from '../sliderItem/SliderItem'; import { ActiveDeviceMenu } from '..'; +import AstalWp from 'gi://AstalWp?version=0.1'; + +const wireplumber = AstalWp.get_default() as AstalWp.Wp; +const audioService = wireplumber.audio; const NoStreams = (): JSX.Element => { return