From 51581b198fd353705d4cfcb5606851962f8a4994 Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Fri, 8 Nov 2024 20:56:47 -0800 Subject: [PATCH] Implemented a callable function that sets the wallpaper. (#463) * Implemented a callable function that sets the wallpaper. * Remove log --- globals.d.ts | 1 + globals/wallpaper.ts | 22 ++++++++++++++++++++++ main.ts | 1 + 3 files changed, 24 insertions(+) create mode 100644 globals/wallpaper.ts diff --git a/globals.d.ts b/globals.d.ts index d33c59c..a1ef76c 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -8,6 +8,7 @@ declare global { var getSystrayItems: () => string; var isWindowVisible: (windowName: string) => boolean; var clearAllNotifications: () => Promise; + var setWallpaper: (filePath: string) => void; var globalWeatherVar: VariableType; var options: Options; diff --git a/globals/wallpaper.ts b/globals/wallpaper.ts new file mode 100644 index 0000000..5ffb85c --- /dev/null +++ b/globals/wallpaper.ts @@ -0,0 +1,22 @@ +import GLib from 'gi://GLib?version=2.0'; +import { Notify } from 'lib/utils'; +import options from 'options'; +import Wallpaper from 'services/Wallpaper'; + +const { EXISTS, IS_REGULAR } = GLib.FileTest; +const { enable: enableWallpaper, image } = options.wallpaper; + +globalThis.setWallpaper = (filePath: string): void => { + if (!(GLib.file_test(filePath, EXISTS) && GLib.file_test(filePath, IS_REGULAR))) { + Notify({ + summary: 'Failed to set Wallpaper', + body: 'The input file is not a valid wallpaper.', + }); + } + + image.value = filePath; + + if (enableWallpaper.value) { + Wallpaper.set(filePath); + } +}; diff --git a/main.ts b/main.ts index c937a30..8a2758a 100644 --- a/main.ts +++ b/main.ts @@ -1,6 +1,7 @@ import 'lib/session'; import 'scss/style'; import 'globals/useTheme'; +import 'globals/wallpaper'; import 'globals/systray'; import 'globals/dropdown.js'; import 'globals/utilities';