From 083ffc0948dcd0b21712b82bfd515f0da7184c10 Mon Sep 17 00:00:00 2001 From: Angel Wang Date: Mon, 22 Jun 2026 22:17:39 -0600 Subject: [PATCH] style(treewide): deno fmt --- .github/workflows/build.yml | 4 +- README.md | 59 +++++++++++++++-------- deno.json | 46 +++++++++--------- package-lock.json | 96 ++++++++++++++++++------------------- package.json | 12 ++--- src/apply/application.ts | 17 +++++-- 6 files changed, 131 insertions(+), 103 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea4f163..53df8cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,5 +62,5 @@ jobs: - name: Upload build artifacts uses: actions/upload-artifact@v4 with: - name: Build artifacts - path: build/ + name: Build artifacts + path: build/ diff --git a/README.md b/README.md index 8248792..0c80a7a 100644 --- a/README.md +++ b/README.md @@ -1,72 +1,91 @@ # rainwall + ![screenshot](./.github/assets/screenshot.png) **rainwall is a program to set your wallpaper based on the weather outside.** ## but how? -This application uses ImageMagick to identify the dominant colour of an image using the Kmeans algorithm in the Oklch colourspace. Once a dominant colour is found, a wallpaper is chosen by identifying the current shortwave radiation, cloud cover, and sun angle, which correspond to lightness, chroma, and hue respectively. + +This application uses ImageMagick to identify the dominant colour of an image using the Kmeans algorithm in the Oklch +colourspace. Once a dominant colour is found, a wallpaper is chosen by identifying the current shortwave radiation, +cloud cover, and sun angle, which correspond to lightness, chroma, and hue respectively. ## dependencies + - [ImageMagick](https://imagemagick.org) ## installing -First, install [ImageMagick](https://imagemagick.org) using your method of choice. Then download the binary from [Releases on GitHub](https://github.com/weightedangelcube/rainwall/releases), or get it from [JSR](https://jsr.io/@angelcube/rainwall/). + +First, install [ImageMagick](https://imagemagick.org) using your method of choice. Then download the binary from +[Releases on GitHub](https://github.com/weightedangelcube/rainwall/releases), or get it from +[JSR](https://jsr.io/@angelcube/rainwall/). Alternatively, if you are using Arch Linux, you can use the PKGBUILD in the repository root to do both for you. ## usage -1. Give both `rainwall-analyze` and `rainwall-apply` an initial run to generate the config files, then edit the config files as needed. See below for configuration options. - - Linux: `$XDG_CONFIG_HOME/rainwall` or `~/.config/rainwall` - - Darwin (macOS/OSX): `~/Library/Preferences/rainwall` - - Windows: `%LocalAppData%/rainwall` + +1. Give both `rainwall-analyze` and `rainwall-apply` an initial run to generate the config files, then edit the config + files as needed. See below for configuration options. + - Linux: `$XDG_CONFIG_HOME/rainwall` or `~/.config/rainwall` + - Darwin (macOS/OSX): `~/Library/Preferences/rainwall` + - Windows: `%LocalAppData%/rainwall` 2. Run `rainwall-analyze` to generate the index of image colours. This will take a while, be patient! 3. Run `rainwall-apply` to set your wallpaper! Enjoy! ## configuring + ### `analyze-config.json` + | option | typeof | default | description | -|-----------------------|------------|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| --------------------- | ---------- | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `imageDir` | `string` | `/home//Pictures` | The directory where your image files are stored. | | `preAnalysisCommands` | `string[]` | `[]` | An array of commands to perform before analysis begins. Examples include applying CLUTs, adjusting HSV, etc. All commands will be properly escaped. **Warning: commands are run directly with `eval`! Don't put anything potentially unsafe...** or do, we don't care. | ### `apply-config.json` + | option | typeof | default | description | -|-------------------------|----------------------------------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| ----------------------- | -------------------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `latitude` | `number` | `0` | The latitude used to discover the weather outside. | | `longitude` | `number` | `0` | The longitude used to discover the weather outside. | | `weatherModel` | `string` | `"best_match"` | The weather model to calculate cloud cover and shortwave radiation with. Find the options on the [Open-Meteo](https://open-meteo.com/en/docs) site. | | `lightnessRange` | `{ start: number; end: number }` | `{ start: 0; end: 1 }` | The range of lightness values to map shortwave radiation to. Use this if your images are all exceptionally light or dark, due to post-processing or other reasons. | | `chromaRange` | `{ start: number; end: number }` | `{ start: 0; end: 1 }` | The range of chroma values to map cloud cover to. Use this if your images are all exceptionally saturated or desaturated, due to post-processing or other reasons. | -| `applyWallpaperCommand` | `string` | `hyprctl hyprpaper wallpaper , %s` | The command used to apply the wallpaper. See "applying the wallpaper" section below for more info. | +| `applyWallpaperCommand` | `string` | `hyprctl hyprpaper wallpaper , %s` | The command used to apply the wallpaper. See "applying the wallpaper" section below for more info. | ## applying the wallpaper + Put `%s` where the image path would normally go. + ### Linux + - GNOME (untested): - - Light theme: `gsettings set org.gnome.desktop.background picture-uri file://%s` - - Dark theme: `gsettings set org.gnome.desktop.background picture-uri-dark file://%s` + - Light theme: `gsettings set org.gnome.desktop.background picture-uri file://%s` + - Dark theme: `gsettings set org.gnome.desktop.background picture-uri-dark file://%s` - KDE Plasma (untested): - - `plasma-apply-wallpaperimage %s` + - `plasma-apply-wallpaperimage %s` - awww (untested) - - `awww img %s` + - `awww img %s` - swaybg (untested) - - `swaybg -i %s` + - `swaybg -i %s` - hyprpaper - - `hyprctl hyprpaper wallpaper , %s` + - `hyprctl hyprpaper wallpaper , %s` ### Darwin (macOS/OSX) + (untested, [source](https://discussions.apple.com/thread/254859103)) -Launch Automator. Click New Document → Choose. From the "Files & Folders" library, drag and drop the "Set the Desktop Picture" action to the right onto the larger workflow window. Save it somewhere accessible. Then, put this into the config file: -`automator -i "%s" /path/to/your.workflow` +Launch Automator. Click New Document → Choose. From the "Files & Folders" library, drag and drop the "Set the Desktop +Picture" action to the right onto the larger workflow window. Save it somewhere accessible. Then, put this into the +config file: `automator -i "%s" /path/to/your.workflow` ### Windows + ...who knows? ## compatibility + - Linux ✅ - Darwin (macOS/OSX) ❓ - Windows ❌ - - [ ] How does one set the wallpaper via CLI? - - [ ] `apply/index.ts @ L80, analyze/analysis.ts @ L20`: equivalent of POSIX eval? - + - [ ] How does one set the wallpaper via CLI? + - [ ] `apply/index.ts @ L80, analyze/analysis.ts @ L20`: equivalent of POSIX eval? diff --git a/deno.json b/deno.json index bf25173..4baf34b 100644 --- a/deno.json +++ b/deno.json @@ -1,25 +1,25 @@ { - "name": "@angelcube/rainwall", - "version": "0.1.0-alpha.stardance", - "license": "GPL-3.0-only", - "exports": { - "./analyze": "./analyze/index.ts", - "./apply": "./apply/index.ts" - }, - "tasks": { - "compile-analyze": "deno compile --output build/rainwall-analyze -A ./src/analyze/index.ts", - "compile-apply": "deno compile --output build/rainwall-apply -A ./src/apply/index.ts", - "analyze": "deno -A ./src/analyze/index.ts", - "apply": "deno -A ./src/apply/index.ts" - }, - "imports": { - "@std/assert": "jsr:@std/assert@1", - "@std/path": "jsr:@std/path@^1.1.5" - }, - "fmt": { - "semiColons": false, - "indentWidth": 4, - "useTabs": true, - "lineWidth": 120 - } + "name": "@angelcube/rainwall", + "version": "0.1.0-alpha.stardance", + "license": "GPL-3.0-only", + "exports": { + "./analyze": "./analyze/index.ts", + "./apply": "./apply/index.ts" + }, + "tasks": { + "compile-analyze": "deno compile --output build/rainwall-analyze -A ./src/analyze/index.ts", + "compile-apply": "deno compile --output build/rainwall-apply -A ./src/apply/index.ts", + "analyze": "deno -A ./src/analyze/index.ts", + "apply": "deno -A ./src/apply/index.ts" + }, + "imports": { + "@std/assert": "jsr:@std/assert@1", + "@std/path": "jsr:@std/path@^1.1.5" + }, + "fmt": { + "semiColons": false, + "indentWidth": 4, + "useTabs": true, + "lineWidth": 120 + } } diff --git a/package-lock.json b/package-lock.json index c5490f9..1ab9443 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,50 +1,50 @@ { - "name": "rainwall", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "dependencies": { - "chalk": "^5.6.2", - "color-diff": "^1.4.0", - "suncalc": "^2.0.0", - "zx": "^8.8.5" - } - }, - "node_modules/chalk": { - "version": "5.6.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz", - "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==", - "license": "MIT", - "engines": { - "node": "^12.17.0 || ^14.13 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/color-diff": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/color-diff/-/color-diff-1.4.0.tgz", - "integrity": "sha512-4oDB/o78lNdppbaqrg0HjOp7pHmUc+dfCxWKWFnQg6AB/1dkjtBDop3RZht5386cq9xBUDRvDvSCA7WUlM9Jqw==", - "license": "BSD-3-Clause" - }, - "node_modules/suncalc": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/suncalc/-/suncalc-2.0.0.tgz", - "integrity": "sha512-RcO28GOMXNnB+sr+c7/+zv5UPMa9wxIsUVGE3HddjQykqCVEC2rc4t4IjBB7qaa7K7dx5Cxp8UZwexyXrX8JkA==" - }, - "node_modules/zx": { - "version": "8.8.5", - "resolved": "https://registry.npmjs.org/zx/-/zx-8.8.5.tgz", - "integrity": "sha512-SNgDF5L0gfN7FwVOdEFguY3orU5AkfFZm9B5YSHog/UDHv+lvmd82ZAsOenOkQixigwH2+yyH198AwNdKhj+RA==", - "license": "Apache-2.0", - "bin": { - "zx": "build/cli.js" - }, - "engines": { - "node": ">= 12.17.0" - } - } - } + "name": "rainwall", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "chalk": "^5.6.2", + "color-diff": "^1.4.0", + "suncalc": "^2.0.0", + "zx": "^8.8.5" + } + }, + "node_modules/chalk": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz", + "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==", + "license": "MIT", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/color-diff": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/color-diff/-/color-diff-1.4.0.tgz", + "integrity": "sha512-4oDB/o78lNdppbaqrg0HjOp7pHmUc+dfCxWKWFnQg6AB/1dkjtBDop3RZht5386cq9xBUDRvDvSCA7WUlM9Jqw==", + "license": "BSD-3-Clause" + }, + "node_modules/suncalc": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/suncalc/-/suncalc-2.0.0.tgz", + "integrity": "sha512-RcO28GOMXNnB+sr+c7/+zv5UPMa9wxIsUVGE3HddjQykqCVEC2rc4t4IjBB7qaa7K7dx5Cxp8UZwexyXrX8JkA==" + }, + "node_modules/zx": { + "version": "8.8.5", + "resolved": "https://registry.npmjs.org/zx/-/zx-8.8.5.tgz", + "integrity": "sha512-SNgDF5L0gfN7FwVOdEFguY3orU5AkfFZm9B5YSHog/UDHv+lvmd82ZAsOenOkQixigwH2+yyH198AwNdKhj+RA==", + "license": "Apache-2.0", + "bin": { + "zx": "build/cli.js" + }, + "engines": { + "node": ">= 12.17.0" + } + } + } } diff --git a/package.json b/package.json index bc8d848..1009ca6 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "dependencies": { - "chalk": "^5.6.2", - "color-diff": "^1.4.0", - "suncalc": "^2.0.0", - "zx": "^8.8.5" - } + "dependencies": { + "chalk": "^5.6.2", + "color-diff": "^1.4.0", + "suncalc": "^2.0.0", + "zx": "^8.8.5" + } } diff --git a/src/apply/application.ts b/src/apply/application.ts index bf3fa64..037ca04 100644 --- a/src/apply/application.ts +++ b/src/apply/application.ts @@ -41,7 +41,7 @@ export async function getOpenMeteoData( current: "cloud_cover", minutely_15: "shortwave_radiation_instant", forecast_minutely_15: "1", - past_minutely_15: "1" + past_minutely_15: "1", }), }, ) @@ -89,14 +89,23 @@ export function findMatchingImages( for (const image of imagesData.files) { const targetAValue = image.oklch[1] * Math.cos(image.oklch[2]) const targetBValue = image.oklch[1] * Math.sin(image.oklch[2]) - + // then use the CIEDE2000 algorithm to calculate the difference between the colours - const difference = colourDiff.diff({L: lightnessValue, a: aValue, b: bValue}, {L: image.oklch[0], a: targetAValue, b: targetBValue}) + const difference = colourDiff.diff({ + L: lightnessValue, + a: aValue, + b: bValue, + }, { + L: image.oklch[0], + a: targetAValue, + b: targetBValue, + }) + if (difference <= targetDifference) { matchingImages.push(image) } } targetDifference += 0.01 - } + } return matchingImages } -- 2.51.2