Fixed the auto-hide functionality for the media bar module. (#588)

This commit is contained in:
Jas Singh
2024-12-21 21:12:12 -08:00
committed by GitHub
parent 440d7ae9db
commit 48faf52e59
9 changed files with 73 additions and 125 deletions

View File

@@ -14,15 +14,15 @@ import { activePlayer, mediaAlbum, mediaArtist, mediaTitle } from 'src/globals/m
const { truncation, truncation_size, show_label, show_active_only, rightClick, middleClick, format } = const { truncation, truncation_size, show_label, show_active_only, rightClick, middleClick, format } =
options.bar.media; options.bar.media;
const isVis = Variable(!show_active_only.get());
Variable.derive([bind(show_active_only), bind(mprisService, 'players')], (showActive, players) => {
isVis.set(!showActive || players?.length > 0);
});
const Media = (): BarBoxChild => { const Media = (): BarBoxChild => {
activePlayer.set(mprisService.get_players()[0]); activePlayer.set(mprisService.get_players()[0]);
const isVis = Variable(!show_active_only.get());
show_active_only.subscribe(() => {
isVis.set(!show_active_only.get() || mprisService.get_players().length > 0);
});
const songIcon = Variable(''); const songIcon = Variable('');
const mediaLabel = Variable.derive( const mediaLabel = Variable.derive(
@@ -55,7 +55,6 @@ const Media = (): BarBoxChild => {
<box <box
className={componentClassName()} className={componentClassName()}
onDestroy={() => { onDestroy={() => {
isVis.drop();
songIcon.drop(); songIcon.drop();
mediaLabel.drop(); mediaLabel.drop();
componentClassName.drop(); componentClassName.drop();

View File

@@ -5,8 +5,8 @@ import { networkService } from 'src/lib/constants/services';
export const wiredIcon: Variable<string> = Variable(''); export const wiredIcon: Variable<string> = Variable('');
export const wirelessIcon: Variable<string> = Variable(''); export const wirelessIcon: Variable<string> = Variable('');
let wiredIconBinding: Variable<void>; let wiredIconBinding: Variable<void> | undefined;
let wirelessIconBinding: Variable<void>; let wirelessIconBinding: Variable<void> | undefined;
/** /**
* Handles the wired network icon binding. * Handles the wired network icon binding.
@@ -15,10 +15,8 @@ let wirelessIconBinding: Variable<void>;
* then checks if the wired network service is available. If available, it binds the icon name to the `wiredIcon` variable. * then checks if the wired network service is available. If available, it binds the icon name to the `wiredIcon` variable.
*/ */
const handleWiredIcon = (): void => { const handleWiredIcon = (): void => {
if (wiredIconBinding) { wiredIconBinding?.drop();
wiredIconBinding(); wiredIconBinding = undefined;
wiredIconBinding.drop();
}
if (!networkService.wired) { if (!networkService.wired) {
return; return;
@@ -36,10 +34,8 @@ const handleWiredIcon = (): void => {
* then checks if the wireless network service is available. If available, it binds the icon name to the `wirelessIcon` variable. * then checks if the wireless network service is available. If available, it binds the icon name to the `wirelessIcon` variable.
*/ */
const handleWirelessIcon = (): void => { const handleWirelessIcon = (): void => {
if (wirelessIconBinding) { wirelessIconBinding?.drop();
wirelessIconBinding(); wirelessIconBinding = undefined;
wirelessIconBinding.drop();
}
if (!networkService.wifi) { if (!networkService.wifi) {
return; return;

View File

@@ -2,13 +2,11 @@ import { bind, Variable } from 'astal';
import { bluetoothService } from 'src/lib/constants/services'; import { bluetoothService } from 'src/lib/constants/services';
export const isDiscovering: Variable<boolean> = Variable(false); export const isDiscovering: Variable<boolean> = Variable(false);
let discoveringBinding: Variable<void>; let discoveringBinding: Variable<void> | undefined;
Variable.derive([bind(bluetoothService, 'adapter')], () => { Variable.derive([bind(bluetoothService, 'adapter')], () => {
if (discoveringBinding) { discoveringBinding?.drop();
discoveringBinding(); discoveringBinding = undefined;
discoveringBinding.drop();
}
if (!bluetoothService.adapter) { if (!bluetoothService.adapter) {
return; return;

View File

@@ -2,13 +2,11 @@ import { bind, Variable } from 'astal';
import { networkService } from 'src/lib/constants/services'; import { networkService } from 'src/lib/constants/services';
export const isWifiEnabled: Variable<boolean> = Variable(false); export const isWifiEnabled: Variable<boolean> = Variable(false);
let wifiEnabledBinding: Variable<void>; let wifiEnabledBinding: Variable<void> | undefined;
Variable.derive([bind(networkService, 'wifi')], () => { Variable.derive([bind(networkService, 'wifi')], () => {
if (wifiEnabledBinding) { wifiEnabledBinding?.drop();
wifiEnabledBinding(); wifiEnabledBinding = undefined;
wifiEnabledBinding.drop();
}
if (!networkService.wifi) { if (!networkService.wifi) {
return; return;

View File

@@ -13,10 +13,10 @@ export const wiredSpeed: Variable<number> = Variable(0);
/******************************************* /*******************************************
* Bindings * * Bindings *
*******************************************/ *******************************************/
let wiredStateBinding: Variable<void>; let wiredStateBinding: Variable<void> | undefined;
let wiredInternetBinding: Variable<void>; let wiredInternetBinding: Variable<void> | undefined;
let wiredIconBinding: Variable<void>; let wiredIconBinding: Variable<void> | undefined;
let wiredSpeedBinding: Variable<void>; let wiredSpeedBinding: Variable<void> | undefined;
/** /**
* Retrieves the current state of the wired network. * Retrieves the current state of the wired network.
@@ -25,10 +25,8 @@ let wiredSpeedBinding: Variable<void>;
* If the wired network service is available, it updates the `wiredState` variable with the current state. * If the wired network service is available, it updates the `wiredState` variable with the current state.
*/ */
const getWiredState = (): void => { const getWiredState = (): void => {
if (wiredStateBinding) { wiredStateBinding?.drop();
wiredStateBinding(); wiredStateBinding = undefined;
wiredStateBinding.drop();
}
if (!networkService.wired) { if (!networkService.wired) {
wiredState.set(AstalNetwork.DeviceState.UNAVAILABLE); wiredState.set(AstalNetwork.DeviceState.UNAVAILABLE);
@@ -47,10 +45,8 @@ const getWiredState = (): void => {
* If the wired network service is available, it updates the `wiredInternet` variable with the current internet status. * If the wired network service is available, it updates the `wiredInternet` variable with the current internet status.
*/ */
const getWiredInternet = (): void => { const getWiredInternet = (): void => {
if (wiredInternetBinding) { wiredInternetBinding?.drop();
wiredInternetBinding(); wiredInternetBinding = undefined;
wiredInternetBinding.drop();
}
if (!networkService.wired) { if (!networkService.wired) {
return; return;
@@ -68,10 +64,8 @@ const getWiredInternet = (): void => {
* If the wired network service is available, it updates the `wiredIcon` variable with the current icon name. * If the wired network service is available, it updates the `wiredIcon` variable with the current icon name.
*/ */
const getWiredIcon = (): void => { const getWiredIcon = (): void => {
if (wiredIconBinding) { wiredIconBinding?.drop();
wiredIconBinding(); wiredIconBinding = undefined;
wiredIconBinding.drop();
}
if (!networkService.wired) { if (!networkService.wired) {
wiredIcon.set('network-wired-symbolic'); wiredIcon.set('network-wired-symbolic');
@@ -90,10 +84,8 @@ const getWiredIcon = (): void => {
* If the wired network service is available, it updates the `wiredSpeed` variable with the current speed. * If the wired network service is available, it updates the `wiredSpeed` variable with the current speed.
*/ */
const getWiredSpeed = (): void => { const getWiredSpeed = (): void => {
if (wiredSpeedBinding) { wiredSpeedBinding?.drop();
wiredSpeedBinding(); wiredSpeedBinding = undefined;
wiredSpeedBinding.drop();
}
if (!networkService.wired) { if (!networkService.wired) {
return; return;
@@ -110,10 +102,3 @@ Variable.derive([bind(networkService, 'wired')], () => {
getWiredIcon(); getWiredIcon();
getWiredSpeed(); getWiredSpeed();
}); });
Variable.derive([bind(networkService, 'wired')], () => {
getWiredState();
getWiredInternet();
getWiredIcon();
getWiredSpeed();
});

View File

@@ -2,13 +2,11 @@ import { bind, Variable } from 'astal';
import { networkService } from 'src/lib/constants/services'; import { networkService } from 'src/lib/constants/services';
export const isScanning: Variable<boolean> = Variable(false); export const isScanning: Variable<boolean> = Variable(false);
let scanningBinding: Variable<void>; let scanningBinding: Variable<void> | undefined;
Variable.derive([bind(networkService, 'wifi')], () => { Variable.derive([bind(networkService, 'wifi')], () => {
if (scanningBinding) { scanningBinding?.drop();
scanningBinding(); scanningBinding = undefined;
scanningBinding.drop();
}
if (!networkService.wifi) { if (!networkService.wifi) {
return; return;

View File

@@ -8,8 +8,8 @@ import { isPrimaryClick, Notify } from 'src/lib/utils';
export const isWifiEnabled: Variable<boolean> = Variable(false); export const isWifiEnabled: Variable<boolean> = Variable(false);
export const wifiAccessPoints: Variable<AstalNetwork.AccessPoint[]> = Variable([]); export const wifiAccessPoints: Variable<AstalNetwork.AccessPoint[]> = Variable([]);
let wifiEnabledBinding: Variable<void>; let wifiEnabledBinding: Variable<void> | undefined;
let accessPointBinding: Variable<void>; let accessPointBinding: Variable<void> | undefined;
export const staging = Variable<AstalNetwork.AccessPoint | undefined>(undefined); export const staging = Variable<AstalNetwork.AccessPoint | undefined>(undefined);
export const connecting = Variable<string>(''); export const connecting = Variable<string>('');
@@ -21,10 +21,8 @@ export const connecting = Variable<string>('');
* If the WiFi service is available, it updates the `isWifiEnabled` variable based on the enabled state. * If the WiFi service is available, it updates the `isWifiEnabled` variable based on the enabled state.
*/ */
const wifiEnabled = (): void => { const wifiEnabled = (): void => {
if (wifiEnabledBinding) { wifiEnabledBinding?.drop();
wifiEnabledBinding(); wifiEnabledBinding = undefined;
wifiEnabledBinding.drop();
}
if (!networkService.wifi) { if (!networkService.wifi) {
return; return;
@@ -42,10 +40,8 @@ const wifiEnabled = (): void => {
* If the WiFi service is available, it updates the `wifiAccessPoints` variable with the list of access points. * If the WiFi service is available, it updates the `wifiAccessPoints` variable with the list of access points.
*/ */
const accessPoints = (): void => { const accessPoints = (): void => {
if (accessPointBinding) { accessPointBinding?.drop();
accessPointBinding(); accessPointBinding = undefined;
accessPointBinding.drop();
}
if (!networkService.wifi) { if (!networkService.wifi) {
return; return;

View File

@@ -44,27 +44,25 @@ export const mediaAlbum = Variable('-----');
export const mediaArtist = Variable('-----'); export const mediaArtist = Variable('-----');
export const mediaArtUrl = Variable(''); export const mediaArtUrl = Variable('');
let positionUnsub: Variable<void>; let positionUnsub: Variable<void> | undefined;
let loopUnsub: Variable<void>; let loopUnsub: Variable<void> | undefined;
let shuffleUnsub: Variable<void>; let shuffleUnsub: Variable<void> | undefined;
let canPlayUnsub: Variable<void>; let canPlayUnsub: Variable<void> | undefined;
let playbackStatusUnsub: Variable<void>; let playbackStatusUnsub: Variable<void> | undefined;
let canGoNextUnsub: Variable<void>; let canGoNextUnsub: Variable<void> | undefined;
let canGoPreviousUnsub: Variable<void>; let canGoPreviousUnsub: Variable<void> | undefined;
let titleUnsub: Variable<void>; let titleUnsub: Variable<void> | undefined;
let albumUnsub: Variable<void>; let albumUnsub: Variable<void> | undefined;
let artistUnsub: Variable<void>; let artistUnsub: Variable<void> | undefined;
let artUrlUnsub: Variable<void>; let artUrlUnsub: Variable<void> | undefined;
const updatePosition = (player: AstalMpris.Player | undefined): void => { const updatePosition = (player: AstalMpris.Player | undefined): void => {
if (positionUnsub) { positionUnsub?.drop();
positionUnsub(); positionUnsub = undefined;
positionUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
timeStamp.set('00:00'); timeStamp.set('00:00');
@@ -91,10 +89,8 @@ const updatePosition = (player: AstalMpris.Player | undefined): void => {
}; };
const updateLoop = (player: AstalMpris.Player | undefined): void => { const updateLoop = (player: AstalMpris.Player | undefined): void => {
if (loopUnsub) { loopUnsub?.drop();
loopUnsub(); loopUnsub = undefined;
loopUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
loopStatus.set(AstalMpris.Loop.NONE); loopStatus.set(AstalMpris.Loop.NONE);
@@ -117,10 +113,8 @@ const updateLoop = (player: AstalMpris.Player | undefined): void => {
}; };
const updateShuffle = (player: AstalMpris.Player | undefined): void => { const updateShuffle = (player: AstalMpris.Player | undefined): void => {
if (shuffleUnsub) { shuffleUnsub?.drop();
shuffleUnsub(); shuffleUnsub = undefined;
shuffleUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
shuffleStatus.set(AstalMpris.Shuffle.OFF); shuffleStatus.set(AstalMpris.Shuffle.OFF);
@@ -138,10 +132,8 @@ const updateShuffle = (player: AstalMpris.Player | undefined): void => {
}; };
const updateCanPlay = (player: AstalMpris.Player | undefined): void => { const updateCanPlay = (player: AstalMpris.Player | undefined): void => {
if (canPlayUnsub) { canPlayUnsub?.drop();
canPlayUnsub(); canPlayUnsub = undefined;
canPlayUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
canPlay.set(false); canPlay.set(false);
@@ -159,10 +151,8 @@ const updateCanPlay = (player: AstalMpris.Player | undefined): void => {
}; };
const updatePlaybackStatus = (player: AstalMpris.Player | undefined): void => { const updatePlaybackStatus = (player: AstalMpris.Player | undefined): void => {
if (playbackStatusUnsub) { playbackStatusUnsub?.drop();
playbackStatusUnsub(); playbackStatusUnsub = undefined;
playbackStatusUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
playbackStatus.set(AstalMpris.PlaybackStatus.STOPPED); playbackStatus.set(AstalMpris.PlaybackStatus.STOPPED);
@@ -181,10 +171,8 @@ const updatePlaybackStatus = (player: AstalMpris.Player | undefined): void => {
}; };
const updateCanGoNext = (player: AstalMpris.Player | undefined): void => { const updateCanGoNext = (player: AstalMpris.Player | undefined): void => {
if (canGoNextUnsub) { canGoNextUnsub?.drop();
canGoNextUnsub(); canGoNextUnsub = undefined;
canGoNextUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
canGoNext.set(false); canGoNext.set(false);
@@ -202,10 +190,8 @@ const updateCanGoNext = (player: AstalMpris.Player | undefined): void => {
}; };
const updateCanGoPrevious = (player: AstalMpris.Player | undefined): void => { const updateCanGoPrevious = (player: AstalMpris.Player | undefined): void => {
if (canGoPreviousUnsub) { canGoPreviousUnsub?.drop();
canGoPreviousUnsub(); canGoPreviousUnsub = undefined;
canGoPreviousUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
canGoPrevious.set(false); canGoPrevious.set(false);
@@ -223,10 +209,8 @@ const updateCanGoPrevious = (player: AstalMpris.Player | undefined): void => {
}; };
const updateTitle = (player: AstalMpris.Player | undefined): void => { const updateTitle = (player: AstalMpris.Player | undefined): void => {
if (titleUnsub) { titleUnsub?.drop();
titleUnsub(); titleUnsub = undefined;
titleUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
mediaTitle.set(noMediaText.get()); mediaTitle.set(noMediaText.get());
@@ -248,10 +232,8 @@ const updateTitle = (player: AstalMpris.Player | undefined): void => {
}; };
const updateAlbum = (player: AstalMpris.Player | undefined): void => { const updateAlbum = (player: AstalMpris.Player | undefined): void => {
if (albumUnsub) { albumUnsub?.drop();
albumUnsub(); albumUnsub = undefined;
albumUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
mediaAlbum.set('-----'); mediaAlbum.set('-----');
@@ -267,10 +249,8 @@ const updateAlbum = (player: AstalMpris.Player | undefined): void => {
}; };
const updateArtist = (player: AstalMpris.Player | undefined): void => { const updateArtist = (player: AstalMpris.Player | undefined): void => {
if (artistUnsub) { artistUnsub?.drop();
artistUnsub(); artistUnsub = undefined;
artistUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
mediaArtist.set('-----'); mediaArtist.set('-----');
@@ -288,10 +268,8 @@ const updateArtist = (player: AstalMpris.Player | undefined): void => {
}; };
const updateArtUrl = (player: AstalMpris.Player | undefined): void => { const updateArtUrl = (player: AstalMpris.Player | undefined): void => {
if (artUrlUnsub) { artUrlUnsub?.drop();
artUrlUnsub(); artUrlUnsub = undefined;
artUrlUnsub.drop();
}
if (player === undefined) { if (player === undefined) {
mediaArtUrl.set(''); mediaArtUrl.set('');

View File

@@ -31,7 +31,7 @@ export async function generateMatugenColors(): Promise<MatugenColors | undefined
const normalizedContrast = contrast.get() > 1 ? 1 : contrast.get() < -1 ? -1 : contrast.get(); const normalizedContrast = contrast.get() > 1 ? 1 : contrast.get() < -1 ? -1 : contrast.get();
const contents = await bash( const contents = await bash(
`matugen image -q ${wallpaperPath} -t scheme-${scheme_type.get()} --contrast ${normalizedContrast} --json hex`, `matugen image --dry-run -q ${wallpaperPath} -t scheme-${scheme_type.get()} --contrast ${normalizedContrast} --json hex`,
); );
return JSON.parse(contents).colors[options.theme.matugen_settings.mode.get()]; return JSON.parse(contents).colors[options.theme.matugen_settings.mode.get()];