Remove global service declarations and change to declarations upon usage. (#761)

* Remove global service declarations and change to declarations upon usage.

* Only load cava service if cava is enabled.
This commit is contained in:
Jas Singh
2025-02-06 02:15:20 -08:00
committed by GitHub
parent 537a9653ed
commit 6b846b9709
68 changed files with 206 additions and 118 deletions

View File

@@ -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<boolean>): void {
Variable.derive([bind(showActiveOnly), bind(mprisService, 'players')], (showActive, players) => {
export function initVisibilityTracker(isVis: Variable<boolean>): Variable<void> {
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<boolean>): 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<void> | undefined {
const cava = AstalCava.get_default();
if (!cava) {
return;
}
Variable.derive(
return Variable.derive(
[
bind(bars),
bind(channels),