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

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

View File

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

View File

@@ -13,10 +13,10 @@ export const wiredSpeed: Variable<number> = Variable(0);
/*******************************************
* Bindings *
*******************************************/
let wiredStateBinding: Variable<void>;
let wiredInternetBinding: Variable<void>;
let wiredIconBinding: Variable<void>;
let wiredSpeedBinding: Variable<void>;
let wiredStateBinding: Variable<void> | undefined;
let wiredInternetBinding: Variable<void> | undefined;
let wiredIconBinding: Variable<void> | undefined;
let wiredSpeedBinding: Variable<void> | undefined;
/**
* 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.
*/
const getWiredState = (): void => {
if (wiredStateBinding) {
wiredStateBinding();
wiredStateBinding.drop();
}
wiredStateBinding?.drop();
wiredStateBinding = undefined;
if (!networkService.wired) {
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.
*/
const getWiredInternet = (): void => {
if (wiredInternetBinding) {
wiredInternetBinding();
wiredInternetBinding.drop();
}
wiredInternetBinding?.drop();
wiredInternetBinding = undefined;
if (!networkService.wired) {
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.
*/
const getWiredIcon = (): void => {
if (wiredIconBinding) {
wiredIconBinding();
wiredIconBinding.drop();
}
wiredIconBinding?.drop();
wiredIconBinding = undefined;
if (!networkService.wired) {
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.
*/
const getWiredSpeed = (): void => {
if (wiredSpeedBinding) {
wiredSpeedBinding();
wiredSpeedBinding.drop();
}
wiredSpeedBinding?.drop();
wiredSpeedBinding = undefined;
if (!networkService.wired) {
return;
@@ -110,10 +102,3 @@ Variable.derive([bind(networkService, 'wired')], () => {
getWiredIcon();
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';
export const isScanning: Variable<boolean> = Variable(false);
let scanningBinding: Variable<void>;
let scanningBinding: Variable<void> | undefined;
Variable.derive([bind(networkService, 'wifi')], () => {
if (scanningBinding) {
scanningBinding();
scanningBinding.drop();
}
scanningBinding?.drop();
scanningBinding = undefined;
if (!networkService.wifi) {
return;

View File

@@ -8,8 +8,8 @@ import { isPrimaryClick, Notify } from 'src/lib/utils';
export const isWifiEnabled: Variable<boolean> = Variable(false);
export const wifiAccessPoints: Variable<AstalNetwork.AccessPoint[]> = Variable([]);
let wifiEnabledBinding: Variable<void>;
let accessPointBinding: Variable<void>;
let wifiEnabledBinding: Variable<void> | undefined;
let accessPointBinding: Variable<void> | undefined;
export const staging = Variable<AstalNetwork.AccessPoint | undefined>(undefined);
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.
*/
const wifiEnabled = (): void => {
if (wifiEnabledBinding) {
wifiEnabledBinding();
wifiEnabledBinding.drop();
}
wifiEnabledBinding?.drop();
wifiEnabledBinding = undefined;
if (!networkService.wifi) {
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.
*/
const accessPoints = (): void => {
if (accessPointBinding) {
accessPointBinding();
accessPointBinding.drop();
}
accessPointBinding?.drop();
accessPointBinding = undefined;
if (!networkService.wifi) {
return;