🌈️ apply a wallpaper based on the weather outside
0

Configure Feed

Select the types of activity you want to include in your feed.

fix(apply): write Windows apply wallpaper script to a file

Angel Wang (Jun 23, 2026, 12:09 AM -0600) f2ad6231 33dbc8a1

+39 -31
+2 -25
src/apply/index.ts
··· 1 1 import type { ImageAnalysisData } from "../analyze/analysis.ts" 2 - import { applyConfigPath, cachePath, chalkDebug, loadConfig, map, mapEaseOutExp, mapEaseOutQuint } from "../utils.ts" 2 + import { applyConfigPath, cachePath, chalkDebug, loadConfig, map, mapEaseOutExp, mapEaseOutQuint, windowsApplyScriptPath } from "../utils.ts" 3 3 import { type ApplicationConfig, defaultConfig, findMatchingImages, getOpenMeteoData } from "./application.ts" 4 4 import * as SunCalc from "suncalc" 5 5 import "zx/globals" ··· 83 83 if (Deno.build.os != "windows") { 84 84 await $`eval ${config.applyWallpaperCommand.replace("%s", targetImage.path)}` 85 85 } else { 86 - // C# in TypeScript. who would've thought 87 - // uiAction: SPI_SetDeskWallpaper = 0x0014 = 20 88 - // uiParam: unused = 0 89 - // pvParam: path to the image 90 - // fWinIni: SPIF_SENDCHANGE (update user profile + broadcast setting change) = 0x02 = 2 91 - const command = ` 92 - $code = @' 93 - using System.Runtime.InteropServices; 94 - namespace Win32 { 95 - public class Wallpaper { 96 - [DllImport("user32.dll", CharSet=CharSet.Auto)] 97 - static extern int SystemParametersInfoA(int uiAction, int uiParam, string pvParam, int fWinIni); 98 - 99 - public static void SetWallpaper(string imagePath){ 100 - SystemParametersInfo(20, 0, imagePath, 2); 101 - } 102 - } 103 - } 104 - '@ 105 - 106 - add-type $code 107 - [Win32.Wallpaper]::SetWallpaper(${targetImage.path}) 108 - ` 109 - await $`pwsh ${command}` 86 + await $`pwsh ${windowsApplyScriptPath}` 110 87 } 111 88 console.info(`Success! Enjoy :)`)
+37 -6
src/utils.ts
··· 23 23 } 24 24 } 25 25 26 + // ensure the config and cache directories exist 27 + if (!fs.statSync(path.fromFileUrl(`file:///${getConfigPath()}`), { throwIfNoEntry: false })) { 28 + fs.mkdirSync(path.fromFileUrl(`file:///${getConfigPath()}`), { recursive: true }) 29 + } 30 + 31 + if (!fs.statSync(path.fromFileUrl(`file:///${getCachePath()}`), { throwIfNoEntry: false })) { 32 + fs.mkdirSync(path.fromFileUrl(`file:///${getCachePath()}`), { recursive: true }) 33 + } 34 + 26 35 export const applyConfigPath = path.fromFileUrl(`file:///${getConfigPath()}/apply-config.json`) 27 36 export const analyzeConfigPath = path.fromFileUrl(`file:///${getConfigPath()}/analyze-config.json`) 28 37 export const cachePath = path.fromFileUrl(`file:///${getCachePath()}/analysis.json`) 38 + export const windowsApplyScriptPath = path.fromFileUrl(`file:///${getConfigPath()}/setWallpaper.ps1`) 29 39 30 - // ensure the config and cache directories exist 31 - if (!fs.statSync(path.fromFileUrl(`file:///${getConfigPath()}`))) { 32 - fs.mkdirSync(path.fromFileUrl(`file:///${getConfigPath()}`), { recursive: true }) 33 - } 40 + if (!fs.statSync(windowsApplyScriptPath, { throwIfNoEntry: false })) { 41 + // C# in TypeScript. who would've thought 42 + // uiAction: SPI_SetDeskWallpaper = 0x0014 = 20 43 + // uiParam: unused = 0 44 + // pvParam: path to the image 45 + // fWinIni: SPIF_SENDCHANGE (update user profile + broadcast setting change) = 0x02 = 2 46 + 47 + const command = ` 48 + $imagePath = $args[0] 49 + $code = @' 50 + using System.Runtime.InteropServices; 51 + namespace Win32 { 52 + public class Wallpaper { 53 + [DllImport("user32.dll", CharSet=CharSet.Auto)] 54 + static extern int SystemParametersInfoA(int uiAction, int uiParam, string pvParam, int fWinIni); 55 + 56 + public static void SetWallpaper(string imagePath){ 57 + SystemParametersInfo(20, 0, imagePath, 2); 58 + } 59 + } 60 + } 61 + '@ 34 62 35 - if (!fs.statSync(path.fromFileUrl(`file:///${getCachePath()}`))) { 36 - fs.mkdirSync(path.fromFileUrl(`file:///${getCachePath()}`), { recursive: true }) 63 + add-type $code 64 + [Win32.Wallpaper]::SetWallpaper($imagePath) 65 + ` 66 + await fs.writeFile(windowsApplyScriptPath, command) 67 + console.info(`Wrote Windows wallpaper apply script at ${windowsApplyScriptPath}!`) 37 68 } 38 69 39 70 export async function loadConfig(pathToConfig: string, defaultConfig: object) {