From 819b838c1b58009e8e68c4d514adc3312c5e5bcf Mon Sep 17 00:00:00 2001 From: Angel Wang Date: Mon, 22 Jun 2026 20:56:59 -0600 Subject: [PATCH] feat: set windows wallpaper? untested!! --- src/apply/index.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/apply/index.ts b/src/apply/index.ts index 3730b54..76bdf4c 100644 --- a/src/apply/index.ts +++ b/src/apply/index.ts @@ -48,7 +48,7 @@ console.info(`Current sun altitude is ${currentSunData.altitude}°!`) const hueValue = Number(currentSunData.altitude) >= -0.833 ? mapEaseOutQuint(Number(currentSunData.altitude), -0.833, zenithSunData.altitude, 0, 264) : mapEaseOutQuint(Number(currentSunData.altitude), nadirSunData.altitude, -0.833, 264, 360) - + const chromaValue = map( 100 - Number(openMeteoData.cloudCover), // gotta invert this one 0, @@ -76,8 +76,36 @@ console.debug(chalkDebug(`Opened cache file ${pathToCache}!`)) const targetImages = findMatchingImages(imagesData, hueValue, chromaValue, lightnessValue) const targetImage = targetImages[Math.floor(Math.random() * targetImages.length)] -console.info(`Found target image ${targetImage.path} with colour oklch(${targetImage.oklch[0]} ${targetImage.oklch[1]} ${targetImage.oklch[2]})!`) +console.info( + `Found target image ${targetImage.path} with colour oklch(${targetImage.oklch[0]} ${targetImage.oklch[1]} ${ + targetImage.oklch[2] + })!`, +) console.info(`Setting wallpaper...`) -await $`eval ${config.applyWallpaperCommand.replace("%s", targetImage.path)}` + +if (Deno.build.os != "windows") { + await $`eval ${config.applyWallpaperCommand.replace("%s", targetImage.path)}` +} else { + // C# in TypeScript. who would've thought + const command = ` + $code = @' + using System.Runtime.InteropServices; + namespace Win32 { + public class Wallpaper { + [DllImport("user32.dll", CharSet=CharSet.Auto)] + static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni); + + public static void SetWallpaper(string imagePath){ + SystemParametersInfo(20, 0, imagePath, 3); + } + } + } + '@ + + add-type $code + [Win32.Wallpaper]::SetWallpaper(${targetImage.path}) + ` + await $`pwsh ${command}` +} console.info(`Success! Enjoy :)`) -- 2.51.2