Provide a cli command to clear notifications. (#444)

This commit is contained in:
Jas Singh
2024-11-05 21:11:50 -08:00
committed by GitHub
parent 6250c2b3be
commit ec3be1cad8
3 changed files with 14 additions and 3 deletions

2
globals.d.ts vendored
View File

@@ -7,6 +7,8 @@ declare global {
var useTheme: (filePath: string) => void; var useTheme: (filePath: string) => void;
var getSystrayItems: () => string; var getSystrayItems: () => string;
var isWindowVisible: (windowName: string) => boolean; var isWindowVisible: (windowName: string) => boolean;
var clearAllNotifications: () => Promise<void>;
var globalWeatherVar: VariableType<Weather>; var globalWeatherVar: VariableType<Weather>;
var options: Options; var options: Options;
var removingNotifications: VariableType<boolean>; var removingNotifications: VariableType<boolean>;

View File

@@ -1,6 +1,10 @@
const notifs = await Service.import('notifications');
import icons from 'modules/icons/index'; import icons from 'modules/icons/index';
import options from 'options';
import { Notification } from 'types/service/notifications'; import { Notification } from 'types/service/notifications';
const { clearDelay } = options.notifications;
export const removingNotifications = Variable<boolean>(false); export const removingNotifications = Variable<boolean>(false);
export const getNotificationIcon = (app_name: string, app_icon: string, app_entry: string): string => { export const getNotificationIcon = (app_name: string, app_icon: string, app_entry: string): string => {
@@ -25,7 +29,7 @@ export const getNotificationIcon = (app_name: string, app_icon: string, app_entr
return icon; return icon;
}; };
export const closeNotifications = async (notifications: Notification[], delay: number): Promise<void> => { export const clearNotifications = async (notifications: Notification[], delay: number): Promise<void> => {
removingNotifications.value = true; removingNotifications.value = true;
for (const notif of notifications) { for (const notif of notifications) {
notif.close(); notif.close();
@@ -34,4 +38,9 @@ export const closeNotifications = async (notifications: Notification[], delay: n
removingNotifications.value = false; removingNotifications.value = false;
}; };
const clearAllNotifications = async (): Promise<void> => {
clearNotifications(notifs.notifications, clearDelay.value);
};
globalThis['removingNotifications'] = removingNotifications; globalThis['removingNotifications'] = removingNotifications;
globalThis['clearAllNotifications'] = clearAllNotifications;

View File

@@ -1,4 +1,4 @@
import { closeNotifications } from 'globals/notification'; import { clearNotifications } from 'globals/notification';
import { BoxWidget } from 'lib/types/widget'; import { BoxWidget } from 'lib/types/widget';
import { Notifications } from 'types/service/notifications'; import { Notifications } from 'types/service/notifications';
import options from 'options'; import options from 'options';
@@ -53,7 +53,7 @@ const Controls = (notifs: Notifications): BoxWidget => {
return; return;
} }
return closeNotifications(notifs.notifications, delay); return clearNotifications(notifs.notifications, delay);
}; };
}), }),
child: Widget.Label({ child: Widget.Label({