🌈️ apply a wallpaper based on the weather outside
0

Configure Feed

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

feat(apply): execute Windows script through iex

Angel Wang (Jun 23, 2026, 5:06 PM -0600) 7dba1cc5 01272db9

+33 -32
+9 -30
src/utils.ts
··· 35 35 export const applyConfigPath = path.fromFileUrl(`file:///${getConfigPath()}/apply-config.json`) 36 36 export const analyzeConfigPath = path.fromFileUrl(`file:///${getConfigPath()}/analyze-config.json`) 37 37 export const cachePath = path.fromFileUrl(`file:///${getCachePath()}/analysis.json`) 38 - export const windowsApplyScriptPath = path.fromFileUrl(`file:///${getConfigPath()}/setWallpaper.ps1`) 39 - 40 - if (!fs.statSync(windowsApplyScriptPath, { throwIfNoEntry: false })) { 41 - // C# in TypeScript. who would've thought 42 - const command = ` 43 - $imagePath = $args[0] 44 - $setwallpapersrc = @" 45 - using System.Runtime.InteropServices; 46 - public class wallpaper { 47 - public const int SetDesktopWallpaper = 20; 48 - public const int UpdateIniFile = 0x01; 49 - public const int SendWinIniChange = 0x02; 50 - 51 - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 52 - private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni); 53 - 54 - public static void SetWallpaper (string path) { 55 - SystemParametersInfo(SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange); 56 - } 57 - } 58 - "@ 59 - Add-Type -TypeDefinition $setwallpapersrc 60 - 61 - [wallpaper]::SetWallpaper("$imagePath") 62 - ` 63 - await fs.writeFile(windowsApplyScriptPath, command) 64 - console.info(`Wrote Windows wallpaper apply script at ${windowsApplyScriptPath}!`) 65 - } 66 38 67 39 export async function loadConfig(pathToConfig: string, defaultConfig: object) { 68 40 let config: object | undefined ··· 112 84 return 1 - Math.pow(1 - x, 5) 113 85 } 114 86 115 - export function mapEased(number: number, min: number, max: number, newMin: number, newMax: number, func: (n: number) => number) { 87 + export function mapEased( 88 + number: number, 89 + min: number, 90 + max: number, 91 + newMin: number, 92 + newMax: number, 93 + func: (n: number) => number, 94 + ) { 116 95 return func((number - min) / (max - min)) * (newMax - newMin) + newMin 117 - } 96 + }
+24 -2
src/apply/index.ts
··· 98 98 if (Deno.build.os != "windows") { 99 99 await $`eval ${config.applyWallpaperCommand.replace("%s", matchingImage.path)}` 100 100 } else { 101 - const command = new Deno.Command(`pwsh`, { args: [ windowsApplyScriptPath, targetImage.path ], stdout: "piped" } ) 102 - command.spawn() 101 + const command = ` 102 + $setwallpapersrc = @" 103 + using System.Runtime.InteropServices; 104 + public class Wallpaper { 105 + public const int SetDesktopWallpaper = 20; 106 + public const int UpdateIniFile = 0x01; 107 + public const int SendWinIniChange = 0x02; 108 + 109 + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 110 + private static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); 111 + 112 + public static void SetWallpaper (string path) { 113 + SystemParametersInfo(SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange); 114 + } 103 115 } 116 + "@ 117 + Add-Type -TypeDefinition $setwallpapersrc 118 + 119 + [Wallpaper]::SetWallpaper("${matchingImage.path}") 120 + ` 121 + usePowerShell() 122 + // await $`Write-Host ${command}` 123 + await $`${command} | iex` 124 + } 125 + 104 126 console.info(`Success! Enjoy :)`)