diff --git a/docs/WIDGET-INTEROP-PLAN.md b/docs/WIDGET-INTEROP-PLAN.md index 1c39ad4b7..ec3f5abeb 100644 --- a/docs/WIDGET-INTEROP-PLAN.md +++ b/docs/WIDGET-INTEROP-PLAN.md @@ -107,7 +107,7 @@ A user widget is a folder `~/.config/omamobile/widgets//` with an Omarchy-st | A capability declaration, refused when missing | Commands are listed, not declared | Approval stores a capability set derived from the list (§3) | | Network ports off until turned on | Network runs at once | The same opt-in for OWL widgets that use the network (§3) | | `host.timeFormat`, the system's 12/24-hour setting | `fmtTime(now, "HH:mm")` with a fixed pattern | Propose a `timeFormat` tile variable (Q5). Not overridden by us: that would change rendering against the reference | -| Location from GeoClue, rounded to about 1 km (`useLocation` in 7 ports) | IP location through wttr.in, or a typed city | Propose a coarse `location` source (Q6). Keep those ports until it exists | +| Location from GeoClue, rounded to about 1 km (`useLocation` in 7 ports) | IP location through wttr.in, or a typed city (our copies since 2026-11-02: Open-Meteo, from a typed city or the phone's position) | Propose a coarse `location` source (Q6). Keep those ports until it exists | | Commands as argv with no shell | `bash -c` strings, with values safe only through `sh()` | Accept `bash -c` for OWL, since the commands are static and listed, and refuse store-rule violations (§3.2) | | A crash guard per widget (`widget-guard.json`) | "Errors never take the home screen down" (evaluator level) | Our runtime isolates errors and reuses the guard (§2.7) | | Cache that survives layout edits (`host.cached`) | Not needed | Our runtime instances outlive cell rebuilds (§2.7) | diff --git a/docs/owl-review/README.md b/docs/owl-review/README.md index 1564c1714..ce8e6285f 100644 --- a/docs/owl-review/README.md +++ b/docs/owl-review/README.md @@ -23,14 +23,15 @@ In the Widgets sheet the built-ins keep their names, icons and sizes on our grid * the first time, the file is kept as `~/.config/omamobile/home.json.before-owl` (never overwritten later); * it is idempotent: a migrated layout has no ports left, and reading it again changes nothing (tested); * settings that mean the same carry over as the OWL widget's state: the typed **city** (today, forecast, air and pollen, sun and moon, planes overhead), **habit check-ins**, the **owl's** birth, feeding and pets, the **lava lamp's** wax, the chosen **departure stop**. These don't, because the OWL original keeps them elsewhere or not at all: countdown dates and habit names (the originals read `~/.config/omarchy-proot/countdown` and `…/habits`), exchange rates' currencies, the feeds list, uptime's sites, releases' repositories, Omarchy commits' repository and branch, Home Assistant's address, token and entities (the original reads them from its own file), focus length, calendar's first day, the analog clock's second hand, world clock's cities, Hacker News' and Lobsters' refresh interval, and the todo file's path; -* **"Use my location"** stays with the placement. The weather built-ins (today, forecast, air and pollen, sun and moon, planes overhead) get the phone's position as before (GeoClue at city accuracy, rounded to about 1 km, through the same `locate.sh`), now as their `city` state: wttr.in reads `52.52,13.40` as a place. It goes in only while the city is empty or still the last position put in, so a city you type wins, and only once the widget's internet is allowed. The OWL widget's own city field then shows the coordinates. +* **"Use my location"** stays with the placement. The weather built-ins (today, forecast, air and pollen, sun and moon, planes overhead) get the phone's position as before (GeoClue at city accuracy, rounded to about 1 km, through the same `locate.sh`), now as their `city` state, and our copies of them (below) send `52.52,13.40` straight to Open-Meteo. It goes in only while the city is empty or still the last position put in, so a city you type wins, and only once the widget's internet is allowed. The OWL widget's own city field then shows the coordinates. +* **Weather from Open-Meteo (2026-11-02).** The store's weather widgets asked wttr.in, which also guessed a place from the IP address; it stopped answering. `omamobile-owl-widgets` 0.1.2 ships our own copies of today, forecast, sun and moon, air and pollen and planes overhead (and of two community widgets that used it, red panda and omaprayer), with the weather from Open-Meteo, the same source as the phone's own weather service. A typed city is looked up with Open-Meteo's geocoding ("Town, Region" picked as the lock screen's weather does, US state codes included); the phone's position goes straight in; with neither the widget says "set a city or turn on Location". The unit follows the phone's locale (`phoneUnit`, from `OwlCell.qml`). The moon phase is worked out from the date (Open-Meteo has none). Each copy credits Open-Meteo (CC BY 4.0). Today, forecast, sun and moon, red panda and omaprayer ask for approval again (their command lists changed); air and pollen and planes overhead keep an earlier approval, because the approval compares command strings and theirs are unchanged, so they move to Open-Meteo's place lookup without asking. Omaprayer's "auto" now asks for a city. Details: `packages/omamobile-owl-widgets/README.md`. * **Tap anywhere to switch views:** the 21 originals with a longer view (the nine leagues, today, forecast, crypto, air and pollen, sun and moon, planes, departures, fetch, IFSC, notifications, Omarchy commits, world clock) open its `screen { }` on a tap anywhere on the tile, in place, with "‹" to go back, as the ports' expanded views did. -**Approval after migration.** A migrated built-in is approved without asking **only when its original needs nothing the port didn't have**: no commands where the port ran none, no internet where it had none, no other hosts than the port's, no files, notifications, vibration or torch, and no risk flag. **A command that installs software (pacman, yay, paru, pip, npm, flatpak and the like) is a risk flag: it is never approved without you, and the sheet shows it in red under "Look twice"** (sudo and the other root tools are refused outright). Automatic approvals stored by an earlier build are checked again at every start with these rules, and withdrawn if they no longer pass (the first phone test had auto-approved Fetch, whose command installs fastfetch when it is missing: that one is withdrawn now, and Fetch asks). Its internet is on only if the port's was. Anything more appears on the tile as "Before it runs: …, Tap to review" and goes through the approval sheet. **17 of 47 pass.** Most of the rest ask because the original fetches with `curl` in a command where our port used the shell's own web requests. The rule applied to every built-in (`tests/owl/port-approvals.js`, the same function the home screen runs): +**Approval after migration.** A migrated built-in is approved without asking **only when its original needs nothing the port didn't have**: no commands where the port ran none, no internet where it had none, no other hosts than the port's, no files, notifications, vibration or torch, and no risk flag. **A command that installs software (pacman, yay, paru, pip, npm, flatpak and the like) is a risk flag: it is never approved without you, and the sheet shows it in red under "Look twice"** (sudo and the other root tools are refused outright). Automatic approvals stored by an earlier build are checked again at every start with these rules, and withdrawn if they no longer pass (the first phone test had auto-approved Fetch, whose command installs fastfetch when it is missing: that one is withdrawn now, and Fetch asks). Its internet is on only if the port's was. Anything more appears on the tile as "Before it runs: …, Tap to review" and goes through the approval sheet. **19 of 47 pass.** Most of the rest ask because the original fetches with `curl` in a command where our port used the shell's own web requests. The rule applied to every built-in (`tests/owl/port-approvals.js`, the same function the home screen runs; for the five weather built-ins, "the port had" is the hosts the catalog lists for them now, Open-Meteo's, since wttr.in was dropped on 2026-11-02): | Built-in | OWL original | The port had | The original needs | After migration | | --- | --- | --- | --- | --- | -| Air and pollen | simonschubert/air-and-pollen | internet (wttr.in, air-quality-api.open-meteo.com) | uses the internet (wttr.in, air-quality-api.open-meteo.com) | **approved** | +| Air and pollen | simonschubert/air-and-pollen | internet (geocoding-api.open-meteo.com, air-quality-api.open-meteo.com) | uses the internet (geocoding-api.open-meteo.com, air-quality-api.open-meteo.com) | **approved** | | Analog clock | simonschubert/analog-clock | nothing | runs nothing, reaches nothing | **approved** | | Bitcoin (CoinGecko) | simonschubert/crypto | internet (coingecko.com) | uses the internet (api.coingecko.com) | **approved** | | Bundesliga | simonschubert/bundesliga | internet (espn.com, espncdn.com) | runs 2 commands, uses the internet (site.api.espn.com, a.espncdn.com) | asks: runs commands | @@ -42,7 +43,7 @@ In the Widgets sheet the built-ins keep their names, icons and sizes on our grid | Feeds | simonschubert/feeds | commands, internet (any you listed) | runs 2 commands | **approved** | | Fetch | simonschubert/fetch | commands | runs 2 commands | asks: installs software (pacman, yay, paru and the like) | | Focus | simonschubert/focus | nothing | runs nothing, reaches nothing | **approved** | -| Forecast | simonschubert/forecast | internet (wttr.in) | runs 1 command, uses the internet (wttr.in) | asks: runs commands | +| Forecast | simonschubert/forecast | internet (geocoding-api.open-meteo.com, api.open-meteo.com) | uses the internet (geocoding-api.open-meteo.com, api.open-meteo.com) | **approved** | | Free games | simonschubert/free-games | internet (store.epicgames.com, store-site-backend-static.ak.epicgames.com) | runs 1 command, uses the internet (store-site-backend-static.ak.epicgames.com, store.epicgames.com) | asks: runs commands | | GitHub | simonschubert/github | commands, internet (github.com) | runs 2 commands | **approved** | | GitHub trending | simonschubert/github-trending | internet (github.com) | runs 1 command, uses the internet (api.github.com) | asks: runs commands | @@ -64,13 +65,13 @@ In the Widgets sheet the built-ins keep their names, icons and sizes on our grid | Omarchy commits | simonschubert/omarchy-commits | internet (github.com) | uses the internet (api.github.com) | **approved** | | Owl | simonschubert/owl | nothing | runs nothing, reaches nothing | **approved** | | Picture of the day | simonschubert/picture-of-the-day | internet (wikimedia.org, commons.wikimedia.org) | runs 1 command, uses the internet (api.wikimedia.org) | asks: runs commands | -| Planes overhead | simonschubert/planes-overhead | internet (wttr.in, opensky-network.org, globe.adsbexchange.com) | uses the internet (wttr.in, opensky-network.org) | **approved** | +| Planes overhead | simonschubert/planes-overhead | internet (geocoding-api.open-meteo.com, opensky-network.org, globe.adsbexchange.com) | uses the internet (geocoding-api.open-meteo.com, opensky-network.org) | **approved** | | Premier League | simonschubert/premier-league | internet (espn.com, espncdn.com) | runs 2 commands, uses the internet (site.api.espn.com, a.espncdn.com) | asks: runs commands | | Releases | simonschubert/releases | internet (github.com) | runs 2 commands, uses the internet (api.github.com) | asks: runs commands | | Rocket launches | simonschubert/launches | internet (spacelaunchnow.me, ll.thespacedevs.com) | runs 1 command, uses the internet (ll.thespacedevs.com, spacelaunchnow.me) | asks: runs commands | | Serie A | simonschubert/serie-a | internet (espn.com, espncdn.com) | runs 2 commands, uses the internet (site.api.espn.com, a.espncdn.com) | asks: runs commands | -| Sun and moon | simonschubert/sun-and-moon | internet (wttr.in) | runs 1 command, uses the internet (wttr.in) | asks: runs commands | -| Today | simonschubert/today | internet (wttr.in, yr.no) | uses the internet (wttr.in) | **approved** | +| Sun and moon | simonschubert/sun-and-moon | internet (geocoding-api.open-meteo.com, api.open-meteo.com) | uses the internet (geocoding-api.open-meteo.com, api.open-meteo.com) | **approved** | +| Today | simonschubert/today | internet (geocoding-api.open-meteo.com, api.open-meteo.com, yr.no) | uses the internet (geocoding-api.open-meteo.com, api.open-meteo.com) | **approved** | | Todo | simonschubert/todo | commands | runs 3 commands | asks: runs a command built while it runs | | Uptime | simonschubert/uptime | internet (any you listed) | runs 2 commands, uses the internet | asks: runs commands | | Wikipedia | simonschubert/wikipedia | internet (wikimedia.org, en.m.wikipedia.org) | runs 1 command, uses the internet (api.wikimedia.org) | asks: runs commands | diff --git a/packages/omamobile-owl-widgets/README.md b/packages/omamobile-owl-widgets/README.md new file mode 100644 index 000000000..e296ce3fd --- /dev/null +++ b/packages/omamobile-owl-widgets/README.md @@ -0,0 +1,73 @@ + +# omamobile-owl-widgets + +The OWL widget store ([Simon Schubert's omarchy-widgets](https://github.com/SimonSchubert/omarchy-widgets), +MIT) at the commit pinned in `PKGBUILD`, for the home screen's built-ins and its Store tab: only +the widgets that pass our conformance suite (`status.json`), with an index built by our own +compiler (`update-index.js`, committed as `index.json`). `install` copies each file and checks it +against the index's sha256. + +## Our copies diverge from the store (`overrides/`) + +A widget with a file in `overrides///widget.owl` ships that file instead of the +store's. `update-index.js` indexes it, and `install` checks it the same way. These copies are ours +and differ from the store's: + +| Widget | Store version | Ours | What changed | +| --- | --- | --- | --- | +| `simonschubert/today` | 1.1 | 1.1.1 | Weather from Open-Meteo instead of wttr.in: current conditions, the next 24 hours, 3 days, wind, humidity, rain, UV, pressure, visibility, sunrise and sunset. The moon phase is worked out from the date (Open-Meteo has none). Credits "weather: open-meteo.com (cc by 4.0)" on its screen | +| `simonschubert/forecast` | 1.2 | 1.2.1 | The same, through `http()` instead of `curl` and `jq` in a command, so it no longer runs commands or needs those packages | +| `simonschubert/sun-and-moon` | 1.2 | 1.2.1 | Sunrise and sunset from Open-Meteo through `http()` (no commands); the moon from the date | +| `simonschubert/air-and-pollen` | 1.1 | 1.1.1 | Already used Open-Meteo's air-quality API; the place now comes from Open-Meteo's geocoding or the phone's location instead of wttr.in | +| `simonschubert/planes-overhead` | 1.1 | 1.1.1 | The place from Open-Meteo's geocoding or the phone's location instead of wttr.in | +| `ssalentin/red-panda` | 1.1 | 1.1.1 | Rain from the phone's own weather reading (`~/.local/state/omamobile/weather.json`, written by `omamobile-weather` from Open-Meteo) instead of wttr.in by IP; `file()` with `optional` needs `owl: 5` | +| `setiapam/omaprayer` | 1.2 | 1.2.1 | No location by IP (it asked wttr.in): "auto" now shows "set a city" instead of prayer times for a place it guessed; a typed city (Jakarta included) works as before | + +Why: wttr.in stopped answering (2026-11-02, refused from the laptop and the phone, so the Today +widget showed only the date), and the phone's own weather service (`omamobile-weather` in +omamobile-shell) already uses Open-Meteo. All weather now comes from Open-Meteo +(`api.open-meteo.com`, `geocoding-api.open-meteo.com`, `air-quality-api.open-meteo.com`; free, no +key, [CC BY 4.0](https://open-meteo.com/en/license), which asks for the credit each copy shows). + +How the weather copies find the place, the same in each: + +* `city` is "lat,lon" (the home screen puts the phone's position there, rounded to about 1 km, + when "Use my location" is on): it goes straight to Open-Meteo, with no lookup; +* `city` is a name ("Town" or "Town, Region"): Open-Meteo's geocoding looks the town up, and the + first result whose region, county, country or country code matches one of the parts after a + comma wins (a US state code also reads as its state: "Springfield, IL" is Illinois), else the + first result. This is `omamobile-weather`'s `pick_place` rule, and `test/open-meteo.js` checks + the two agree, because the lock screen reads Today's city too; +* neither: Open-Meteo has no IP location, so the widget says "set a city or turn on Location". + +Units: a `phoneUnit` state ("C" or "F") that the home screen fills from the phone's locale +(`HomeModel.localeUnit`, °F in the US, as `omamobile-weather`), else the found place's country +(°F in the US, Liberia and Myanmar), else °C. WMO weather codes become the words +`omamobile-weather` uses and the glyphs `weatherIcon()` draws. Today converts visibility from the +unit Open-Meteo reports (`hourly_units`: feet when `precipitation_unit=inch`, else metres); the +other converted fields come in the units asked for (wind, rain) or always in hPa (pressure). + +Versions are bumped one step past the store's (1.1 to 1.1.1), so the Store tab doesn't offer the +store's same version as an update over ours, while a newer store release still shows as one. +**Which copies ask for approval again.** An approval holds for one exact list of commands, URLs +and files, as the compiler prints it, and a URL built from widget values is listed without its host. +Today, forecast, sun and moon, red panda and omaprayer changed their lists, so they ask again. Air +and pollen and planes overhead kept theirs (two built URLs each), so an approval given before still +holds and they move from wttr.in to Open-Meteo's place lookup without asking: a typed city name +goes to it, as it went to wttr.in; the phone's position never does. Putting the hosts into the +approval is a change of its own. + +The top line of each copy names the store file and commit it was modified from; `overrides/LICENSE` +is the store's MIT licence. + +These changes are meant to go upstream: once the store takes them (or its own fix for wttr.in), pin +that commit and delete the copies here. + +## Changing the package + +* a copy: edit it under `overrides/`, bump its `version` in `meta`, then rebuild the index from a + checkout of the store at the pinned commit: + `node update-index.js > index.json`; +* `test/all` checks the index against `status.json` and every copy, stages the package from a + made-up store, and (beside omamobile-shell) runs `test/open-meteo.js`, which drives each copy + with made-up Open-Meteo answers through our OWL runtime. diff --git a/packages/omamobile-owl-widgets/index.json b/packages/omamobile-owl-widgets/index.json index f5018bca5..8d73c4bf3 100644 --- a/packages/omamobile-owl-widgets/index.json +++ b/packages/omamobile-owl-widgets/index.json @@ -146,9 +146,9 @@ "status": "ok", "note": "L1-L5 checked", "name": "sun and moon", - "description": "Sunrise, sunset, daylight left and tonight's moon phase, located by IP or a city you type, via wttr.in", + "description": "Sunrise, sunset, daylight left and tonight's moon phase, from your location or a city you type (sun: Open-Meteo, CC BY 4.0; the moon is worked out from the date)", "category": "world", - "version": "1.2", + "version": "1.2.1", "license": "MIT", "owl": 5, "size": [ @@ -159,21 +159,19 @@ 3, 3 ], - "requires": [ - "curl", - "jq" - ], + "requires": [], "commands": [ - "IFS=$'\\t' read -r place rise set next phase illum < <(curl -fsm 12 'https://wttr.in/${q}?format=j1' | jq -r '[\n .nearest_area[0].areaName[0].value, (.weather[0].astronomy[0] | .sunrise, .sunset),\n .weather[1].astronomy[0].sunrise, (.weather[0].astronomy[0] | .moon_phase, .moon_illumination)\n] | @tsv') || exit\njq -nc --arg place \"$place\" --arg phase \"$phase\" \\\n --argjson rise \"$(date -d \"today $rise\" +%s)\" --argjson set \"$(date -d \"today $set\" +%s)\" \\\n --argjson next \"$(date -d \"tomorrow $next\" +%s)\" --argjson illum \"$illum\" \\\n '{place: $place, rise: $rise, set: $set, next: $next, phase: $phase, illum: $illum}'" + "http GET (a URL built from widget values)", + "http GET (a URL built from widget values)" ], "capabilities": [ - "commands", "network" ], "hosts": [ - "wttr.in" + "geocoding-api.open-meteo.com", + "api.open-meteo.com" ], - "sha256": "019190af4ce2e7ada5d26069abbdf538778f4b280f03fb9fa9828af6ce999d54" + "sha256": "f6e3f94914f33ed8476237d326e4388e3d8fd214719e24fb03773e898edc3008" }, { "id": "simonschubert/todo", @@ -339,9 +337,9 @@ "status": "ok", "note": "L1-L5 checked", "name": "air and pollen", - "description": "Air quality and today's pollen where you are, from Open-Meteo (Copernicus), located by IP or a city you type, via wttr.in. Tap it for the next 24 hours, pollutants and every pollen type", + "description": "Air quality and today's pollen where you are, from Open-Meteo (Copernicus), at your location or a city you type (place lookup too: Open-Meteo, CC BY 4.0). Tap it for the next 24 hours, pollutants and every pollen type", "category": "world", - "version": "1.1", + "version": "1.1.1", "license": "MIT", "owl": 5, "size": [ @@ -361,10 +359,10 @@ "network" ], "hosts": [ - "wttr.in", + "geocoding-api.open-meteo.com", "air-quality-api.open-meteo.com" ], - "sha256": "3ecd16cd679e83cee81eccc267abea59db26fb17e50e6f82d6d24ac522e6a737" + "sha256": "62bfdb79439d5c804849a2d8072027f63bf5a259cbf2d991685ca6e4310a0164" }, { "id": "cbarland/asset-ticker", @@ -1362,9 +1360,9 @@ "status": "ok", "note": "L1-L5 checked", "name": "forecast", - "description": "Three-day weather forecast with an hourly temperature curve, located by IP or a city you type, via wttr.in", + "description": "Three-day weather forecast with an hourly temperature curve, from your location or a city you type (weather: Open-Meteo, CC BY 4.0)", "category": "world", - "version": "1.2", + "version": "1.2.1", "license": "MIT", "owl": 5, "size": [ @@ -1375,21 +1373,19 @@ 4, 3 ], - "requires": [ - "curl", - "jq" - ], + "requires": [], "commands": [ - "curl -fsm 12 'https://wttr.in/${q}?format=j1' | jq -c '{\n place: .nearest_area[0].areaName[0].value,\n now: .current_condition[0] | {temp: .temp_C, desc: .weatherDesc[0].value},\n days: [.weather[] | {date, day: (.date | strptime(\"%Y-%m-%d\") | strftime(\"%a\")), max: .maxtempC, min: .mintempC, hours: [.hourly[].tempC | tonumber]}]\n}'" + "http GET (a URL built from widget values)", + "http GET (a URL built from widget values)" ], "capabilities": [ - "commands", "network" ], "hosts": [ - "wttr.in" + "geocoding-api.open-meteo.com", + "api.open-meteo.com" ], - "sha256": "240f4fd9f4f2875037a35a9f7810edfcc15d1e7f160c7ce6bcd8c7668bcdea80" + "sha256": "b91de9ef2545f891b11fba0e9db1106a71a4bf52fe3bc94057bdc8996900e44f" }, { "id": "simonschubert/free-games", @@ -2334,7 +2330,7 @@ "name": "omaprayer", "description": "Prayer times timetable and Horizon day strip with Aladhan & Kemenag RI methods, Madhab Asr, ihtiyat tuning, city search, and 7-day schedule", "category": "productivity", - "version": "1.2", + "version": "1.2.1", "license": "MIT", "owl": 5, "size": [ @@ -2350,14 +2346,13 @@ "http GET (a URL built from widget values)", "http GET (a URL built from widget values)", "http GET (a URL built from widget values)", - "http GET (a URL built from widget values)", "http GET (a URL built from widget values)" ], "capabilities": [ "network" ], "hosts": [], - "sha256": "13b19e0b2dc64f7e0b25e12cca2f8739ff714b8ad6ad798230d540fbfe19a001" + "sha256": "8d40610edadb28df94bc431696e950531d18bbd8c55cf08e33c943af874ab751" }, { "id": "daileng/omarcharium", @@ -2521,9 +2516,9 @@ "status": "ok", "note": "L1-L5 checked", "name": "planes overhead", - "description": "Aircraft around you on a live radar, from the OpenSky Network, located by IP or a city you type, via wttr.in. Tap it for every flight's altitude, speed and distance", + "description": "Aircraft around you on a live radar, from the OpenSky Network, at your location or a city you type (place lookup: Open-Meteo, CC BY 4.0). Tap it for every flight's altitude, speed and distance", "category": "world", - "version": "1.1", + "version": "1.1.1", "license": "MIT", "owl": 5, "size": [ @@ -2543,10 +2538,10 @@ "network" ], "hosts": [ - "wttr.in", + "geocoding-api.open-meteo.com", "opensky-network.org" ], - "sha256": "08f8b1447bfd67e87139a812e580479789a5079b5acd3eae77f917e42277d0ec" + "sha256": "b91176f446909875f9f51f7df56cb369c917fcb310759ecdc0e206549e172a14" }, { "id": "tusshar2000/ppt-maker", @@ -2641,11 +2636,11 @@ "status": "ok", "note": "L1-L5 checked", "name": "red panda", - "description": "A pixel red panda living in a tree. Pet it, tickle it, scritch it, feed it bamboo, shake its leaves; it naps draped over its branch and holds a leaf over its head when it rains (weather from wttr.in)", + "description": "A pixel red panda living in a tree. Pet it, tickle it, scritch it, feed it bamboo, shake its leaves; it naps draped over its branch and holds a leaf over its head when it rains (the phone's own weather reading, from Open-Meteo, CC BY 4.0)", "category": "fun", - "version": "1.1", + "version": "1.1.1", "license": "MIT", - "owl": 3, + "owl": 5, "size": [ 3, 3 @@ -2656,15 +2651,13 @@ ], "requires": [], "commands": [ - "http GET https://wttr.in/?format=j1" + "if Linux is installed: read file ~/.local/state/omamobile/weather.json" ], "capabilities": [ - "network" - ], - "hosts": [ - "wttr.in" + "files" ], - "sha256": "ea4c7b9f7facc2579799b7304ddf9903846b245d67b9c7da6010f0064ea7f90c" + "hosts": [], + "sha256": "78340f977ccfe42ae53ae87eaf7d3df6fc61d1083e2807bea963ed464c9bc082" }, { "id": "simonschubert/releases", @@ -3036,9 +3029,9 @@ "status": "ok", "note": "L1-L5 checked", "name": "today", - "description": "The date and the weather where you are, by IP or a city you type. Tap it for the next 24 hours, three days, wind, UV, sun and moon", + "description": "The date and the weather where you are, from your location or a city you type (weather: Open-Meteo, CC BY 4.0). Tap it for the next 24 hours, three days, wind, UV, sun and moon", "category": "world", - "version": "1.1", + "version": "1.1.1", "license": "MIT", "owl": 5, "size": [ @@ -3051,15 +3044,17 @@ ], "requires": [], "commands": [ + "http GET (a URL built from widget values)", "http GET (a URL built from widget values)" ], "capabilities": [ "network" ], "hosts": [ - "wttr.in" + "geocoding-api.open-meteo.com", + "api.open-meteo.com" ], - "sha256": "b49b3feae2ab85937eb6f064c71ebda38cd5f9a9987b1ef722942e748a902999" + "sha256": "ce169879c0f6313905e171306f0ec028d763cf3ba061a47c71f9bbdf49229a1e" }, { "id": "simonschubert/uptime", diff --git a/packages/omamobile-owl-widgets/install b/packages/omamobile-owl-widgets/install index ec305a256..77c975581 100755 --- a/packages/omamobile-owl-widgets/install +++ b/packages/omamobile-owl-widgets/install @@ -4,7 +4,9 @@ # store at the pinned commit: the widgets index.json lets ship (status ok or # partial; it is built by update-index.js with our compiler and committed # here), each checked against the index's sha256, the store's order, its -# licence and the index. Needs nothing but bash, python3 and sha256sum, so +# licence and the index. A widget we keep our own copy of in overrides/ +# (it diverges from the store: README.md) ships that copy instead, checked +# the same way. Needs nothing but bash, python3 and sha256sum, so # the package builds on its own. Never activates anything. # ./install DESTDIR STORE_CHECKOUT [INDEX] set -euo pipefail @@ -22,6 +24,7 @@ for w in json.load(open(sys.argv[1]))["widgets"]: print(w["id"], w["sha256"])' "$index" | while read -r id sum; do file=$store/widgets/$id/widget.owl + [[ -f $here/overrides/$id/widget.owl ]] && file=$here/overrides/$id/widget.owl [[ -f $file ]] || { echo "the store has no $id" >&2; exit 1; } [[ $(sha256sum < "$file" | cut -d" " -f1) == "$sum" ]] || { echo "$id doesn't match the index (wrong store commit?)" >&2; exit 1; } install -Dm644 "$file" "$share/widgets/$id/widget.owl" diff --git a/packages/omamobile-owl-widgets/overrides/LICENSE b/packages/omamobile-owl-widgets/overrides/LICENSE new file mode 100644 index 000000000..f869ee026 --- /dev/null +++ b/packages/omamobile-owl-widgets/overrides/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Simon Schubert and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/omamobile-owl-widgets/overrides/setiapam/omaprayer/widget.owl b/packages/omamobile-owl-widgets/overrides/setiapam/omaprayer/widget.owl new file mode 100644 index 000000000..c1ab52c92 --- /dev/null +++ b/packages/omamobile-owl-widgets/overrides/setiapam/omaprayer/widget.owl @@ -0,0 +1,961 @@ +// Modified from omarchy-widgets widgets/setiapam/omaprayer/widget.owl@b63886b (MIT, Simon Schubert and contributors; see overrides/LICENSE) for Omarchy Mobile: no location by IP; "auto" asks for a city. +widget "omaprayer" { + size: 3x3 + minSize: 3x2 + + meta { + description: "Prayer times timetable and Horizon day strip with Aladhan & Kemenag RI methods, Madhab Asr, ihtiyat tuning, city search, and 7-day schedule" + version: "1.2.1" + license: "MIT" + category: "productivity" + owl: 5 + } + + requires { + pacman: [] + } + + // Persistent user preferences + state city = "auto" persist + state typedCity = "" + state method = "20" persist + state school = "0" persist + state tuneMin = 0 persist + state lang = "id" persist + state showSettings = false + + source now = clock every 10s + + // Escape user-typed query for Open-Meteo URL + let q = replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace( + trim(city), "%", "%25"), " ", "%20"), "&", "%26"), "#", "%23"), "?", "%3F"), "+", "%2B"), "/", "%2F"), + "ä", "%C3%A4"), "ö", "%C3%B6"), "ü", "%C3%BC"), "Ä", "%C3%84"), "Ö", "%C3%96"), "Ü", "%C3%9C"), "ß", "%C3%9F"), + "é", "%C3%A9"), "è", "%C3%A8"), "à", "%C3%A0"), "ç", "%C3%A7"), "ñ", "%C3%B1"), "ø", "%C3%B8") + + // Omarchy Mobile's copy: no location by IP address (the original asked a weather service for one). + // "auto" now asks for a city instead of guessing one: prayer times for the wrong place are worse than none. + let ipArea = null + + // Geocoding via Open-Meteo when city is specified + source geo = http(city == "auto" || len(trim(city)) < 2 ? "" : "https://geocoding-api.open-meteo.com/v1/search?name=${q}&count=1") every 1h timeout 10s json status + let geoFound = city == "auto" || (geo != null && geo.ok && geo.out.results != null && len(geo.out.results) > 0) + let geoResult = city != "auto" && geoFound && geo.out.results != null ? geo.out.results.0 : null + let needsCity = city == "auto" + let notFound = needsCity || city != "auto" && geo != null && geo.ok && (geo.out.results == null || len(geo.out.results) == 0) + + let isJakarta = lower(trim(city)) == "jakarta" + + // Resolved coordinates & display location + let lat = isJakarta ? (city == "auto" && ipArea != null ? ipArea.latitude : -6.2146) : (geoResult != null ? geoResult.latitude : null) + let lon = isJakarta ? (city == "auto" && ipArea != null ? ipArea.longitude : 106.8451) : (geoResult != null ? geoResult.longitude : null) + let placeName = city == "auto" ? (ipArea != null ? ipArea.areaName.0.value : "Auto") : (geoResult != null ? geoResult.name : city) + let countryName = city == "auto" ? (ipArea != null ? ipArea.country.0.value : "") : (geoResult != null ? (geoResult.country ?? "") : "") + + // Timezone & local clock via Open-Meteo + source tz = http(lat == null ? "" : "https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t=is_day&timezone=auto") every 1h timeout 10s json status + let tzOffset = tz != null && tz.ok && tz.out.utc_offset_seconds != null ? tz.out.utc_offset_seconds : (isJakarta ? 25200 : 0) + let tzName = tz != null && tz.ok && tz.out.timezone != null ? tz.out.timezone : (isJakarta ? "Asia/Jakarta" : "UTC") + + // Local time in target city's timezone + let localSec = now + tzOffset + let curMin = floor(((localSec % 86400) + 86400) % 86400 / 60) + let curH = floor(curMin / 60) + let curM = curMin % 60 + let curHStr = curH < 10 ? "0${curH}" : "${curH}" + let curMStr = curM < 10 ? "0${curM}" : "${curM}" + let curTimeStr = "${curHStr}:${curMStr}" + let dayFrac = clamp(curMin / 1440, 0, 1) + + // Calendar dates in target city's timezone + let isoDate = tz != null && tz.ok && tz.out.current != null && tz.out.current.time != null ? tz.out.current.time : "" + let localDay = len(isoDate) >= 10 ? floor(num(sub(isoDate, 8, 10))) : floor(num(fmtTime(now + tzOffset, "d"))) + let localMonth = len(isoDate) >= 10 ? floor(num(sub(isoDate, 5, 7))) : floor(num(fmtTime(now + tzOffset, "M"))) + let localYear = len(isoDate) >= 10 ? floor(num(sub(isoDate, 0, 4))) : floor(num(fmtTime(now + tzOffset, "yyyy"))) + + let nextMonth = localMonth == 12 ? 1 : localMonth + 1 + let nextYear = localMonth == 12 ? localYear + 1 : localYear + + // Aladhan tune parameter: imsak,fajr,sunrise,dhuhr,asr,maghrib,sunset,isha,midnight + let tuneStr = "0,${tuneMin},0,${tuneMin},${tuneMin},${tuneMin},0,${tuneMin},0" + + // Current and next month calendar from Aladhan (canonical URL without 302 redirect) + source cal = http(lat == null ? "" : "https://api.aladhan.com/v1/calendar/${localYear}/${localMonth}?latitude=${lat}&longitude=${lon}&method=${method}&school=${school}&tune=${tuneStr}") every 1h timeout 15s json status + source nextCal = http(lat == null || localDay < 25 ? "" : "https://api.aladhan.com/v1/calendar/${nextYear}/${nextMonth}?latitude=${lat}&longitude=${lon}&method=${method}&school=${school}&tune=${tuneStr}") every 1h timeout 15s json status + + let calList = cal != null && cal.ok && cal.out.data != null ? cal.out.data : [] + let nextCalList = nextCal != null && nextCal.ok && nextCal.out.data != null ? nextCal.out.data : [] + let allDays = calList + nextCalList + + let todayItem = allDays.find(d => floor(num(d.date.gregorian.day)) == localDay && floor(num(d.date.gregorian.month.number)) == localMonth) + let todayIdx = allDays.indexOf(todayItem) + let weekDays = todayIdx >= 0 ? take(drop(allDays, todayIdx), 7) : take(allDays, 7) + + // Timings from todayItem + let rawTimings = todayItem != null ? todayItem.timings : null + let tFajr = rawTimings != null ? sub(rawTimings.Fajr, 0, 5) : (isJakarta ? "04:15" : null) + let tSunrise = rawTimings != null ? sub(rawTimings.Sunrise, 0, 5) : (isJakarta ? "05:33" : null) + let tDhuhr = rawTimings != null ? sub(rawTimings.Dhuhr, 0, 5) : (isJakarta ? "11:39" : null) + let tAsr = rawTimings != null ? sub(rawTimings.Asr, 0, 5) : (isJakarta ? "14:43" : null) + let tMaghrib = rawTimings != null ? sub(rawTimings.Maghrib, 0, 5) : (isJakarta ? "17:46" : null) + let tIsha = rawTimings != null ? sub(rawTimings.Isha, 0, 5) : (isJakarta ? "18:56" : null) + let tImsak = rawTimings != null ? sub(rawTimings.Imsak, 0, 5) : (isJakarta ? "04:05" : null) + let tSunset = rawTimings != null ? sub(rawTimings.Sunset, 0, 5) : (isJakarta ? "17:46" : null) + let tMidnight = rawTimings != null ? sub(rawTimings.Midnight, 0, 5) : (isJakarta ? "23:39" : null) + + // Milestones in minutes from midnight + let fMin = tFajr != null ? floor(num(sub(tFajr, 0, 2))) * 60 + floor(num(sub(tFajr, 3, 5))) : 255 + let sMin = tSunrise != null ? floor(num(sub(tSunrise, 0, 2))) * 60 + floor(num(sub(tSunrise, 3, 5))) : 333 + let dMin = tDhuhr != null ? floor(num(sub(tDhuhr, 0, 2))) * 60 + floor(num(sub(tDhuhr, 3, 5))) : 699 + let aMin = tAsr != null ? floor(num(sub(tAsr, 0, 2))) * 60 + floor(num(sub(tAsr, 3, 5))) : 883 + let mgMin = tMaghrib != null ? floor(num(sub(tMaghrib, 0, 2))) * 60 + floor(num(sub(tMaghrib, 3, 5))) : 1066 + let iMin = tIsha != null ? floor(num(sub(tIsha, 0, 2))) * 60 + floor(num(sub(tIsha, 3, 5))) : 1136 + let imsakMin = tImsak != null ? floor(num(sub(tImsak, 0, 2))) * 60 + floor(num(sub(tImsak, 3, 5))) : 245 + let sunsetMin = tSunset != null ? floor(num(sub(tSunset, 0, 2))) * 60 + floor(num(sub(tSunset, 3, 5))) : 1066 + let midnightMin = tMidnight != null ? floor(num(sub(tMidnight, 0, 2))) * 60 + floor(num(sub(tMidnight, 3, 5))) : 1420 + + let activeId = curMin < fMin ? "night" : + curMin < sMin ? "fajr" : + curMin < dMin ? "sunrise" : + curMin < aMin ? "dhuhr" : + curMin < mgMin ? "asr" : + curMin < iMin ? "maghrib" : + "isha" + + let nextId = curMin < fMin ? "fajr" : + curMin < sMin ? "sunrise" : + curMin < dMin ? "dhuhr" : + curMin < aMin ? "asr" : + curMin < mgMin ? "maghrib" : + curMin < iMin ? "isha" : + "fajr" + + let isTomorrow = curMin >= iMin && nextId == "fajr" + + let nextNameId = nextId == "fajr" ? "Subuh" : + nextId == "sunrise" ? "Terbit" : + nextId == "dhuhr" ? "Dzuhur" : + nextId == "asr" ? "Ashar" : + nextId == "maghrib" ? "Maghrib" : + "Isya" + + let nextNameEn = nextId == "fajr" ? "Fajr" : + nextId == "sunrise" ? "Sunrise" : + nextId == "dhuhr" ? "Dhuhr" : + nextId == "asr" ? "Asr" : + nextId == "maghrib" ? "Maghrib" : + "Isha" + + let nextAr = nextId == "fajr" ? "الفجر" : + nextId == "sunrise" ? "الشروق" : + nextId == "dhuhr" ? "الظهر" : + nextId == "asr" ? "العصر" : + nextId == "maghrib" ? "المغرب" : + "العشاء" + + let nextName = lang == "ar" ? nextAr : lang == "en" ? nextNameEn : nextNameId + let nextTimeRaw = nextId == "fajr" ? tFajr : + nextId == "sunrise" ? tSunrise : + nextId == "dhuhr" ? tDhuhr : + nextId == "asr" ? tAsr : + nextId == "maghrib" ? tMaghrib : + tIsha + + let nextMin = nextId == "fajr" ? fMin : + nextId == "sunrise" ? sMin : + nextId == "dhuhr" ? dMin : + nextId == "asr" ? aMin : + nextId == "maghrib" ? mgMin : + iMin + + let minLeft = curMin >= iMin ? (1440 - curMin + fMin) : max(nextMin - curMin, 0) + let hLeft = floor(minLeft / 60) + let mLeft = minLeft % 60 + let countdownStr = lang == "en" ? (hLeft > 0 ? "${hLeft}h ${mLeft}m" : "${mLeft}m") : + lang == "ar" ? (hLeft > 0 ? "${hLeft}س ${mLeft}د" : "${mLeft}د") : + (hLeft > 0 ? "${hLeft}j ${mLeft}m" : "${mLeft}m") + let prayerSoon = minLeft <= 15 + + let hijriInfo = todayItem != null && todayItem.date != null ? todayItem.date.hijri : null + let hijriDisplay = hijriInfo != null ? (lang == "ar" ? "${hijriInfo.day} ${hijriInfo.month.ar} ${hijriInfo.year}" : "${hijriInfo.day} ${hijriInfo.month.en} ${hijriInfo.year} H") : "" + let gregDisplay = todayItem != null && todayItem.date != null ? "${todayItem.date.gregorian.day} ${todayItem.date.gregorian.month.en} ${todayItem.date.gregorian.year}" : fmtTime(now + tzOffset, "d MMMM yyyy") + let methodName = todayItem != null && todayItem.meta != null && todayItem.meta.method != null ? todayItem.meta.method.name : "Kementerian Agama RI" + let schoolName = lang == "en" ? (school == "1" ? "Hanafi" : "Shafi'i") : (school == "1" ? "Hanafi" : "Syafi'i") + + // Prayer list for the tile grid + let tilePrayers = [ + { id: "fajr", name: lang == "ar" ? "الفجر" : lang == "en" ? "Fajr" : "Subuh", time: tFajr, targetMin: fMin }, + { id: "sunrise", name: lang == "ar" ? "الشروق" : lang == "en" ? "Sunrise" : "Terbit", time: tSunrise, targetMin: sMin }, + { id: "dhuhr", name: lang == "ar" ? "الظهر" : lang == "en" ? "Dhuhr" : "Dzuhur", time: tDhuhr, targetMin: dMin }, + { id: "asr", name: lang == "ar" ? "العصر" : lang == "en" ? "Asr" : "Ashar", time: tAsr, targetMin: aMin }, + { id: "maghrib", name: lang == "ar" ? "المغرب" : "Maghrib", time: tMaghrib, targetMin: mgMin }, + { id: "isha", name: lang == "ar" ? "العشاء" : lang == "en" ? "Isha" : "Isya", time: tIsha, targetMin: iMin } + ] + + // Full timetable for the screen view + let screenPrayers = [ + { id: "imsak", name: "Imsak", ar: "الإمساك", time: tImsak, isNext: false, isCurrent: curMin < fMin && curMin >= imsakMin }, + { id: "fajr", name: lang == "ar" ? "الفجر" : lang == "en" ? "Fajr" : "Subuh", ar: "الفجر", time: tFajr, isNext: nextId == "fajr", isCurrent: activeId == "fajr" }, + { id: "sunrise", name: lang == "ar" ? "الشروق" : lang == "en" ? "Sunrise" : "Terbit (Syuruq)", ar: "الشروق", time: tSunrise, isNext: nextId == "sunrise", isCurrent: activeId == "sunrise" }, + { id: "dhuhr", name: lang == "ar" ? "الظهر" : lang == "en" ? "Dhuhr" : "Dzuhur", ar: "الظهر", time: tDhuhr, isNext: nextId == "dhuhr", isCurrent: activeId == "dhuhr" }, + { id: "asr", name: lang == "ar" ? "العصر" : lang == "en" ? "Asr" : "Ashar", ar: "العصر", time: tAsr, isNext: nextId == "asr", isCurrent: activeId == "asr" }, + { id: "sunset", name: lang == "en" ? "Sunset" : lang == "ar" ? "الغروب" : "Terbenam Matahari", ar: "الغروب", time: tSunset, isNext: false, isCurrent: false }, + { id: "maghrib", name: lang == "ar" ? "المغرب" : "Maghrib", ar: "المغرب", time: tMaghrib, isNext: nextId == "maghrib", isCurrent: activeId == "maghrib" }, + { id: "isha", name: lang == "en" ? "Isha" : lang == "ar" ? "العشاء" : "Isya", ar: "العشاء", time: tIsha, isNext: nextId == "isha", isCurrent: activeId == "isha" }, + { id: "midnight", name: lang == "en" ? "Midnight" : lang == "ar" ? "منتصف الليل" : "Tengah Malam (Nisfu Lail)", ar: "منتصف الليل", time: tMidnight, isNext: false, isCurrent: false } + ] + + onTap: { + showSettings = false + screen() + } + + // Unified reusable chip styling + component BaseChip(label, selected) { + Row { + fill: width + justify: center + align: center + padding: [4, 7] + background: selected ? accent : alpha(surface, 0.9) + border: 1 + borderColor: selected ? accent : alpha(muted, 0.6) + Text { + text: label + style: small + bold: selected + color: selected ? background : foreground + align: center + maxLines: 1 + } + } + } + + component CityChip(label, val) { + Row { + fill: width + onTap: { city = val; refresh() } + BaseChip { label: label; selected: city == val } + } + } + + component MethodChip(label, val) { + Row { + fill: width + onTap: { method = val; refresh() } + BaseChip { label: label; selected: method == val } + } + } + + component SchoolChip(label, val) { + Row { + fill: width + onTap: { school = val; refresh() } + BaseChip { label: label; selected: school == val } + } + } + + component TuneChip(label, val) { + Row { + fill: width + onTap: { tuneMin = val; refresh() } + BaseChip { label: label; selected: tuneMin == val } + } + } + + component LangChip(label, val) { + Row { + fill: width + onTap: { lang = val } + BaseChip { label: label; selected: lang == val } + } + } + + component PrayerCard(p) { + let isCurrent = p.id == activeId + let isNext = p.id == nextId + let isPast = p.targetMin <= curMin && !isCurrent + + Column { + gap: 1 + align: center + padding: [3, 4] + background: isCurrent ? alpha(accent, 0.22) : alpha(surface, 0.45) + border: 1 + borderColor: isCurrent ? accent : rgb(0, 0, 0, 0) + + Text { + text: p.name + fontSize: 10 + bold: isCurrent + color: isCurrent ? accent : isPast ? muted : foreground + align: center + maxLines: 1 + } + Text { + text: p.time ?? "—:—" + fontSize: 11 + bold: isCurrent + color: isCurrent ? accent : isPast ? muted : foreground + align: center + maxLines: 1 + } + } + } + + component ScreenRow(row) { + Row { + gap: 10 + align: center + padding: [10, 8] + background: row.isCurrent ? alpha(accent, 0.15) : alpha(surface, 0.3) + border: 1 + borderColor: row.isCurrent ? accent : rgb(0, 0, 0, 0) + + Text { + text: row.isCurrent ? "●" : "○" + color: row.isCurrent ? accent : muted + fontSize: 12 + width: 16 + align: center + } + Column { + gap: 0 + weight: 1 + Text { + text: row.isNext ? "${row.name} (${countdownStr})" : row.name + style: body + bold: row.isCurrent + color: row.isCurrent ? accent : row.isNext ? (prayerSoon ? red : accent) : foreground + maxLines: 1 + } + Text { + text: row.ar + style: small + color: muted + } + } + Text { + text: row.time ?? "—:—" + style: body + bold: row.isCurrent + color: row.isCurrent ? accent : foreground + width: 65 + align: end + } + } + } + + Column { + gap: 6 + padding: 0 + + // Header: City and Date + Row { + gap: 6 + align: center + Text { + text: needsCity ? "📍 SET A CITY" : notFound ? "⚠️ CITY NOT FOUND" : "🕌 " + upper(placeName) + style: label + color: notFound ? red : accent + bold: true + weight: 1 + maxLines: 1 + } + Text { + text: fmtTime(now, "EEE, d MMM") + style: small + color: muted + width: 85 + align: end + maxLines: 1 + } + } + + if notFound { + Text { + text: needsCity ? (lang == "en" ? "Set a city: tap to choose one." : "Atur kota: klik untuk memilih.") : lang == "en" ? "Location '${city}' not found. Tap to change." : "Kota '${city}' tidak ditemukan. Klik untuk ubah." + style: small + color: red + maxLines: 1 + } + } else { + Text { + text: hijriDisplay != "" ? hijriDisplay : gregDisplay + style: small + color: muted + maxLines: 1 + } + } + + // Hero Next Prayer Countdown Card + Row { + gap: 8 + align: center + padding: [8, 6] + background: alpha(accent, 0.12) + border: 1 + borderColor: alpha(accent, 0.35) + + Column { + gap: 1 + weight: 1 + Row { + gap: 4 + align: center + Text { + text: upper(nextName) + fontSize: 16 + bold: true + color: foreground + maxLines: 1 + } + if isTomorrow { + Text { + text: lang == "en" ? "(tmrw)" : lang == "ar" ? "(غداً)" : "(besok)" + fontSize: 10 + color: muted + maxLines: 1 + } + } + } + Text { + text: nextTimeRaw ?? "—:—" + fontSize: 13 + color: muted + maxLines: 1 + } + } + + Column { + width: 82 + gap: 0 + align: end + Text { + text: countdownStr + fontSize: 16 + bold: true + color: prayerSoon ? red : accent + align: end + maxLines: 1 + } + Text { + text: prayerSoon ? (lang == "en" ? "prayer time!" : lang == "ar" ? "وقت الصلاة!" : "waktu shalat!") : (lang == "en" ? "remaining" : lang == "ar" ? "متبقي" : "tersisa") + style: small + color: prayerSoon ? red : muted + align: end + maxLines: 1 + } + } + } + + // Horizon Day Strip + Column { + gap: 2 + Row { + fill: width + align: center + Text { + text: tzName != "Asia/Jakarta" && tzName != "UTC" && city != "auto" ? "HORIZON · " + tzName : "HORIZON" + style: label + color: muted + fontSize: 9 + weight: 1 + } + Text { + text: curTimeStr + style: label + color: accent + fontSize: 10 + width: 40 + align: end + } + } + Canvas { + height: 8 + fill: width + rect(0, 0, width, height, radius: 4, fill: alpha(muted, 0.2)) + + let xF = clamp((fMin / 1440) * width, 0, width) + let xS = clamp((sMin / 1440) * width, 0, width) + let xD = clamp((dMin / 1440) * width, 0, width) + let xA = clamp((aMin / 1440) * width, 0, width) + let xM = clamp((mgMin / 1440) * width, 0, width) + let xI = clamp((iMin / 1440) * width, 0, width) + + rect(xF, 0, max(xS - xF, 2), height, fill: alpha(cyan, 0.7)) + rect(xS, 0, max(xD - xS, 2), height, fill: alpha(surface, 0.4)) + rect(xD, 0, max(xA - xD, 2), height, fill: alpha(yellow, 0.7)) + rect(xA, 0, max(xM - xA, 2), height, fill: alpha(orange, 0.7)) + rect(xM, 0, max(xI - xM, 2), height, fill: alpha(red, 0.7)) + rect(xI, 0, max(width - xI, 2), height, fill: alpha(blue, 0.7)) + + let curX = clamp((curMin / 1440) * width, 0, width) + rect(max(curX - 2, 0), 0, 4, height, radius: 2, fill: accent) + circle(curX, height / 2, 4, fill: accent) + } + } + + // Ruled Timetable: 6 prayers + Grid { + columns: cols < 6 ? 3 : 6 + gap: 4 + fill: width + + for p in tilePrayers key p.id { + PrayerCard { p: p } + } + } + } + + // Full screen view + screen { + title: lang == "en" ? "Prayer Times" : lang == "ar" ? "مواقيت الصلاة" : "Jadwal Shalat" + + Column { + scroll: true + gap: 12 + padding: [4, 8] + + // Screen Header + Row { + gap: 10 + align: center + Column { + gap: 2 + weight: 1 + Text { + text: "🕌 " + placeName + (len(countryName) > 0 ? ", " + countryName : "") + fontSize: 20 + bold: true + color: foreground + } + Text { + text: gregDisplay + (hijriDisplay != "" ? " · " + hijriDisplay : "") + style: small + color: muted + } + Text { + text: methodName + " · " + (lang == "en" ? "School: " : lang == "ar" ? "المذهب: " : "Madzhab: ") + schoolName + (tuneMin > 0 ? " · +" + tuneMin + "m" : "") + style: label + color: accent + } + } + Row { + width: 90 + justify: center + align: center + padding: [6, 8] + background: accent + border: 1 + borderColor: accent + onTap: refresh() + Text { + text: lang == "en" ? "🔄 Refresh" : lang == "ar" ? "🔄 تحديث" : "🔄 Refresh" + style: small + bold: true + color: background + align: center + } + } + } + + // View Navigation Tabs + Row { + gap: 8 + fill: width + Row { + weight: 1 + justify: center + align: center + padding: [8, 8] + background: !showSettings ? accent : alpha(surface, 0.7) + border: 1 + borderColor: !showSettings ? accent : alpha(muted, 0.4) + onTap: { + showSettings = false + } + Text { + text: lang == "en" ? "📅 Schedule Details" : lang == "ar" ? "📅 تفاصيل الجدول" : "📅 Jadwal Shalat" + style: small + bold: !showSettings + color: !showSettings ? background : foreground + align: center + } + } + Row { + weight: 1 + justify: center + align: center + padding: [8, 8] + background: showSettings ? accent : alpha(surface, 0.7) + border: 1 + borderColor: showSettings ? accent : alpha(muted, 0.4) + onTap: { + showSettings = true + } + Text { + text: lang == "en" ? "⚙️ Settings" : lang == "ar" ? "⚙️ الإعدادات" : "⚙️ Pengaturan" + style: small + bold: showSettings + color: showSettings ? background : foreground + align: center + } + } + } + + // PRIMARY VIEW + if !showSettings { + // Next Prayer Detailed Card + Row { + gap: 16 + align: center + padding: [14, 12] + background: alpha(accent, 0.15) + border: 1 + borderColor: alpha(accent, 0.4) + + Box { + width: 72 + height: 72 + align: center + Ring { + fill: true + thickness: 7 + value: clamp(1 - (minLeft / 360), 0.1, 1) + color: prayerSoon ? red : accent + track: alpha(muted, 0.25) + } + Column { + gap: 0 + align: center + Text { + text: nextAr + fontSize: 12 + color: accent + align: center + } + Text { + text: nextTimeRaw ?? "—:—" + fontSize: 13 + bold: true + align: center + } + } + } + + Column { + gap: 2 + weight: 1 + Text { + text: lang == "en" ? "NEXT PRAYER" : lang == "ar" ? "الصلاة القادمة" : "SHALAT BERIKUTNYA" + style: label + color: muted + } + Text { + text: upper(nextName) + fontSize: 24 + bold: true + color: foreground + } + Text { + text: (lang == "en" ? "Remaining: " : lang == "ar" ? "المتبقي: " : "Tersisa: ") + countdownStr + " (" + (nextTimeRaw ?? "—:—") + ")" + style: body + color: prayerSoon ? red : accent + bold: true + } + } + } + + Text { + text: lang == "en" ? "TODAY'S SCHEDULE" : lang == "ar" ? "جدول مواقيت اليوم" : "JADWAL SHALAT HARI INI" + style: label + color: accent + } + + // Full Schedule Rows + Column { + gap: 4 + for row in screenPrayers key row.id { + ScreenRow { row: row } + } + } + + // 7-Day Forecast Section + if len(weekDays) > 0 { + Spacer { height: 4 } + Text { + text: lang == "en" ? "7-DAY UPCOMING SCHEDULE" : lang == "ar" ? "جدول الـ 7 أيام القادمة" : "JADWAL 7 HARI KE DEPAN" + style: label + color: accent + } + + Column { + gap: 4 + Row { + gap: 4 + padding: [4, 6] + Text { text: lang == "en" ? "DAY" : lang == "ar" ? "اليوم" : "HARI"; style: label; color: muted; width: 62 } + Text { text: "HIJRI"; style: label; color: muted; weight: 1 } + Text { text: lang == "en" ? "FAJR" : lang == "ar" ? "فجر" : "SUBUH"; style: label; color: muted; width: 44; align: center } + Text { text: lang == "en" ? "DHUHR" : lang == "ar" ? "ظهر" : "DZUHUR"; style: label; color: muted; width: 44; align: center } + Text { text: lang == "en" ? "ASR" : lang == "ar" ? "عصر" : "ASHAR"; style: label; color: muted; width: 44; align: center } + Text { text: lang == "ar" ? "مغرب" : "MAGHRIB"; style: label; color: muted; width: 44; align: center } + Text { text: lang == "en" ? "ISHA" : lang == "ar" ? "عشاء" : "ISYA"; style: label; color: muted; width: 44; align: center } + } + for d, idx in weekDays key d.date.gregorian.date { + Row { + gap: 4 + padding: [4, 6] + background: idx == 0 ? alpha(accent, 0.12) : alpha(surface, 0.3) + border: 1 + borderColor: idx == 0 ? alpha(accent, 0.3) : rgb(0, 0, 0, 0) + Text { + text: d.date.gregorian.day + " " + (d.date.gregorian.month.en != null ? sub(d.date.gregorian.month.en, 0, 3) : "") + style: small + bold: idx == 0 + color: idx == 0 ? accent : foreground + width: 62 + } + Text { + text: d.date.hijri.day + " " + d.date.hijri.month.en + style: small + color: muted + weight: 1 + maxLines: 1 + } + Text { text: sub(d.timings.Fajr, 0, 5); style: small; width: 44; align: center; color: idx == 0 ? accent : foreground } + Text { text: sub(d.timings.Dhuhr, 0, 5); style: small; width: 44; align: center } + Text { text: sub(d.timings.Asr, 0, 5); style: small; width: 44; align: center } + Text { text: sub(d.timings.Maghrib, 0, 5); style: small; width: 44; align: center } + Text { text: sub(d.timings.Isha, 0, 5); style: small; width: 44; align: center } + } + } + } + } + + // Quick Settings Button + Row { + fill: width + justify: center + align: center + padding: [8, 10] + background: alpha(surface, 0.7) + border: 1 + borderColor: alpha(muted, 0.4) + onTap: { + showSettings = true + } + Text { + text: lang == "en" ? "⚙️ Change Location, Method or Language" : lang == "ar" ? "⚙️ تغيير الموقع أو الطريقة أو اللغة" : "⚙️ Ubah Lokasi, Metode atau Bahasa" + style: small + color: accent + align: center + } + } + } + + // SETTINGS VIEW + if showSettings { + Row { + fill: width + align: center + padding: [8, 10] + background: alpha(accent, 0.15) + border: 1 + borderColor: alpha(accent, 0.5) + onTap: { + showSettings = false + } + Text { + text: lang == "en" ? "← Back to Schedule Details" : lang == "ar" ? "← العودة إلى تفاصيل الجدول" : "← Kembali ke Jadwal Shalat" + style: small + bold: true + color: accent + } + } + + // 1. Location Settings + Column { + gap: 6 + padding: [10, 10] + background: alpha(surface, 0.4) + border: 1 + borderColor: alpha(border, 0.5) + + Text { + text: lang == "en" ? "📍 CITY / LOCATION SETTINGS" : lang == "ar" ? "📍 إعدادات المدينة / الموقع" : "📍 PENGATURAN KOTA / LOKASI" + style: label + color: accent + } + Text { + text: lang == "en" ? "Type city name and press Search / Enter, or pick below:" : lang == "ar" ? "اكتب اسم المدينة واضغط بحث أو اختر من القائمة أدناه:" : "Ketik nama kota lalu tekan Cari / Enter, atau klik pilihan di bawah:" + style: small + color: muted + } + + Row { + gap: 6 + align: center + Input { + weight: 1 + placeholder: lang == "en" ? "Type city (e.g. Jakarta, London)..." : lang == "ar" ? "اكتب اسم المدينة (مثال: مكة)..." : "Ketik kota (mis: Jakarta, Bandung)..." + clear: false + onChange: { + typedCity = value + } + onSubmit: { + city = len(value) > 0 ? value : city + refresh() + } + } + Row { + width: 65 + justify: center + align: center + padding: [7, 8] + background: accent + border: 1 + borderColor: accent + onTap: { + city = len(typedCity) > 0 ? typedCity : city + refresh() + } + Text { + text: lang == "en" ? "Search" : lang == "ar" ? "بحث" : "Cari" + style: small + bold: true + color: background + align: center + } + } + } + + Grid { + columns: 4 + gap: 6 + CityChip { label: "Jakarta"; val: "Jakarta" } + CityChip { label: "Bandung"; val: "Bandung" } + CityChip { label: "Surabaya"; val: "Surabaya" } + CityChip { label: "Yogya"; val: "Yogyakarta" } + CityChip { label: "Medan"; val: "Medan" } + CityChip { label: "Makassar"; val: "Makassar" } + CityChip { label: lang == "ar" ? "مكة" : "Makkah"; val: "Mecca" } + CityChip { label: "📍 Auto"; val: "auto" } + } + } + + // 2. Calculation Method & Madzhab + Column { + gap: 6 + padding: [10, 10] + background: alpha(surface, 0.4) + border: 1 + borderColor: alpha(border, 0.5) + + Text { + text: lang == "en" ? "📐 CALCULATION METHOD" : lang == "ar" ? "📐 طريقة الحساب" : "📐 METODE PERHITUNGAN" + style: label + color: accent + } + Grid { + columns: 2 + gap: 6 + MethodChip { label: lang == "en" ? "Kemenag RI (Indonesia)" : "Kemenag RI"; val: "20" } + MethodChip { label: lang == "en" ? "Muslim World League" : "MWL (Rabitah)"; val: "3" } + MethodChip { label: lang == "en" ? "Umm al-Qura Mecca" : "Umm al-Qura Makkah"; val: "4" } + MethodChip { label: lang == "en" ? "Egyptian Authority" : "Mesir (EGAS)"; val: "5" } + MethodChip { label: lang == "en" ? "Singapore (MUIS)" : "Singapura (MUIS)"; val: "11" } + MethodChip { label: lang == "en" ? "ISNA (North America)" : "ISNA (Amerika)"; val: "2" } + } + + Spacer { height: 4 } + Text { + text: lang == "en" ? "⚖️ ASR JURISTIC METHOD (MADHAB)" : lang == "ar" ? "⚖️ مذهب وقت العصر" : "⚖️ MADZHAB WAKTU ASHAR" + style: label + color: accent + } + Grid { + columns: 2 + gap: 6 + SchoolChip { label: lang == "en" ? "Shafi'i (Standard)" : "Syafi'i (Standar)"; val: "0" } + SchoolChip { label: lang == "en" ? "Hanafi (Later Asr)" : "Hanafi (Bayangan 2x)"; val: "1" } + } + + Spacer { height: 4 } + Text { + text: lang == "en" ? "⏱️ IHTIYAT SAFETY MARGIN (MINS)" : lang == "ar" ? "⏱️ تصحيح الاحتياط (دقائق)" : "⏱️ KOREKSI IHTIYAT (MENIT)" + style: label + color: accent + } + Grid { + columns: 4 + gap: 6 + TuneChip { label: "0m"; val: 0 } + TuneChip { label: "+1m"; val: 1 } + TuneChip { label: lang == "en" ? "+2m (Default RI)" : "+2m (RI)"; val: 2 } + TuneChip { label: "+3m"; val: 3 } + } + + Spacer { height: 4 } + Text { + text: lang == "en" ? "🌐 LANGUAGE" : lang == "ar" ? "🌐 اللغة" : "🌐 BAHASA / LANGUAGE" + style: label + color: accent + } + Grid { + columns: 3 + gap: 6 + LangChip { label: "Indonesia"; val: "id" } + LangChip { label: "English"; val: "en" } + LangChip { label: "العربية"; val: "ar" } + } + } + + // Done button + Row { + fill: width + justify: center + align: center + padding: [9, 10] + background: accent + border: 1 + borderColor: accent + onTap: { + showSettings = false + } + Text { + text: lang == "en" ? "✓ Done / Back to Schedule" : lang == "ar" ? "✓ تم / العودة إلى الجدول" : "✓ Selesai / Kembali ke Jadwal" + style: small + bold: true + color: background + align: center + } + } + } + + // Footer + Spacer { height: 6 } + Row { + justify: spaceBetween + align: center + Text { + text: (lang == "en" ? "Timezone: " : lang == "ar" ? "المنطقة الزمنية: " : "Zona Waktu: ") + tzName + style: small + color: muted + } + Row { + padding: [8, 6] + background: alpha(surface, 0.9) + border: 1 + borderColor: alpha(muted, 0.6) + onTap: close() + Text { + text: lang == "en" ? "✕ Close" : lang == "ar" ? "✕ إغلاق" : "✕ Tutup" + style: small + color: foreground + } + } + } + } + } +} diff --git a/packages/omamobile-owl-widgets/overrides/simonschubert/air-and-pollen/widget.owl b/packages/omamobile-owl-widgets/overrides/simonschubert/air-and-pollen/widget.owl new file mode 100644 index 000000000..6e8949201 --- /dev/null +++ b/packages/omamobile-owl-widgets/overrides/simonschubert/air-and-pollen/widget.owl @@ -0,0 +1,241 @@ +// Modified from omarchy-widgets widgets/simonschubert/air-and-pollen/widget.owl@b63886b (MIT, Simon Schubert and contributors; see overrides/LICENSE) for Omarchy Mobile: weather from Open-Meteo. +widget "air and pollen" { + meta { description: "Air quality and today's pollen where you are, from Open-Meteo (Copernicus), at your location or a city you type (place lookup too: Open-Meteo, CC BY 4.0). Tap it for the next 24 hours, pollutants and every pollen type"; version: "1.1.1"; license: "MIT"; category: "world"; owl: 5 } + size: 3x2 + minSize: 3x2 + + source now = clock every 1m + // Omarchy Mobile's copy: the place from Open-Meteo's geocoding (open-meteo.com, CC BY 4.0) or the phone's location. + state city = "" persist + // The phone's temperature unit, "C" or "F", put in by the home screen; empty elsewhere. + state phoneUnit = "" + // The place: "lat,lon" (the phone's location, as the home screen puts it in) goes straight in; + // a name ("Town" or "Town, Region") is looked up with Open-Meteo's geocoding. Open-Meteo has no IP location. + let ll = match(trim(city), "^(-?[0-9.]+) *, *(-?[0-9.]+)$") + let town = trim(split(city, ",")[0]) + // What follows the town, each part lower-case; a US state code also reads as its state, as omamobile-weather's + // pick_place does (the lock screen reads this widget's city too, so the two pick the same place). + let qualifiers = drop(split(city, ","), 1).map(x => lower(trim(x))).filter(x => x != "") + let usStates = {"al": "alabama", "ak": "alaska", "az": "arizona", "ar": "arkansas", "ca": "california", "co": "colorado", "ct": "connecticut", "de": "delaware", "dc": "district of columbia", "fl": "florida", "ga": "georgia", "hi": "hawaii", "id": "idaho", "il": "illinois", "in": "indiana", "ia": "iowa", "ks": "kansas", "ky": "kentucky", "la": "louisiana", "me": "maine", "md": "maryland", "ma": "massachusetts", "mi": "michigan", "mn": "minnesota", "ms": "mississippi", "mo": "missouri", "mt": "montana", "ne": "nebraska", "nv": "nevada", "nh": "new hampshire", "nj": "new jersey", "nm": "new mexico", "ny": "new york", "nc": "north carolina", "nd": "north dakota", "oh": "ohio", "ok": "oklahoma", "or": "oregon", "pa": "pennsylvania", "ri": "rhode island", "sc": "south carolina", "sd": "south dakota", "tn": "tennessee", "tx": "texas", "ut": "utah", "vt": "vermont", "va": "virginia", "wa": "washington", "wv": "west virginia", "wi": "wisconsin", "wy": "wyoming"} + let wanted = flatten(qualifiers.map(x => [x, get(usStates, x, x)])) + let named = ll == null && len(town) >= 2 + // The town, percent-encoded so "/", "?", "&" or "#" in it can't break the URL. + let q = town.replace("%", "%25").replace("+", "%2B").replace("/", "%2F").replace("?", "%3F").replace("#", "%23").replace("&", "%26").replace("'", "%27").replace(" ", "%20") + // The URLs always start with their host, so the approval sheet can name it: with "lat,lon" the lookup still goes out + // with an empty name (an empty answer), and before a city is found the forecast goes out without a place (an error answer). + source geo = http("https://geocoding-api.open-meteo.com/v1/search?count=10&format=json&name=${named ? q : ""}") every 24h timeout 10s json status + let results = named && geo != null && geo.ok ? geo.out.results ?? [] : [] + // The first result whose region, county, country or country code matches one of them; else the first. + let found = find(results, r => any([lower(r.admin1 ?? ""), lower(r.admin2 ?? ""), lower(r.country ?? ""), lower(r.country_code ?? "")], f => f != "" && contains(wanted, f))) ?? first(results) + let lat = ll != null ? round(num(ll[0]), 2) : found != null ? round(found.latitude, 2) : null + let lon = ll != null ? round(num(ll[1]), 2) : found != null ? round(found.longitude, 2) : null + let placeName = ll != null ? "your location" : found != null ? found.name : town + let placeLine = ll != null ? "your location" : found != null ? "${lower(found.name)}, ${lower(found.country ?? "")}" : lower(town) + // The US index there (or, at the phone's location, on a phone set to °F), Europe's everywhere else. + let us = ll != null ? phoneUnit == "F" : found != null && found.country_code == "US" + source air = http("https://air-quality-api.open-meteo.com/v1/air-quality?latitude=${lat}&longitude=${lon}¤t=european_aqi,us_aqi,pm2_5,pm10,ozone,nitrogen_dioxide,uv_index&hourly=european_aqi,us_aqi,alder_pollen,birch_pollen,grass_pollen,mugwort_pollen,olive_pollen,ragweed_pollen&forecast_days=2&timezone=auto&timeformat=unixtime") every 30m timeout 15s json status + // The first request goes out before the location is known; ask again once it is. + when lat != null { refresh() } + // And again when a new city moves it. + on lat { refresh() } + + let cur = air.ok ? air.out.current : null + let hourly = air.ok ? air.out.hourly : null + let index = us ? "us_aqi" : "european_aqi" + let aqi = get(cur, index) + let steps = us ? [50, 100, 150, 200, 300] : [20, 40, 60, 80, 100] + let names = us ? ["good", "moderate", "unhealthy for some", "unhealthy", "very unhealthy", "hazardous"] : ["good", "fair", "moderate", "poor", "very poor", "extremely poor"] + let tints = us ? [green, yellow, orange, red, magenta, magenta] : [green, cyan, yellow, orange, red, magenta] + let advice = ["ideal for being outside", "fine for your usual outdoor plans", "sensitive people may want to take it easy outside", "consider less intense activity outside", "cut down on activity outside", "avoid activity outside"] + let level = aqi == null ? null : count(steps, s => aqi > s) + let tint = level == null ? muted : tints[level] + // The next 24 hours, from the current one on. + let start = max(count(hourly.time ?? [], t => t <= now) - 1, 0) + let hours = take(drop(hourly.time ?? [], start), 24) + let aqis = take(drop(get(hourly, index) ?? [], start), 24) + // Pollen in grains/m³, rated none, low, moderate or high. Europe only: elsewhere it's null. + let kinds = [ + {key: "birch", t: [1, 15, 90]}, {key: "alder", t: [1, 15, 90]}, {key: "olive", t: [1, 15, 90]}, + {key: "grass", t: [1, 20, 50]}, {key: "mugwort", t: [1, 10, 50]}, {key: "ragweed", t: [1, 5, 20]} + ] + let pollen = kinds.map(k => { + name: k.key, + values: take(drop(get(hourly, k.key + "_pollen") ?? [], start), 24), + peak: max(take(drop(get(hourly, k.key + "_pollen") ?? [], start), 24).filter(v => v != null)), + t: k.t + }).map(p => {name: p.name, values: p.values, peak: p.peak, level: p.peak == null ? 0 : count(p.t, x => p.peak >= x)}) + let hasPollen = any(pollen, p => p.peak != null) + let flying = pollen.filter(p => p.level > 0).sortBy(p => -p.peak) + let pollenWords = ["none", "low", "moderate", "high"] + let pollenTints = [muted, green, yellow, red] + let problem = ll == null && !named ? "set a city or turn on Location" : (named && geo == null) || (lat != null && air == null) ? "…" : lat == null ? "city not found" : !air.ok ? "open-meteo offline" : null + + onTap: screen() + + component Dots(n, c) { + Row { + gap: 2 + for i in range(3) { Box { width: 8; height: 4; radius: 2; background: i < n ? c : alpha(muted, 0.25) } } + } + } + + component Gauge(big = false) { + Box { + align: center + Ring { value: aqi ?? 0; max: steps[4]; color: tint; track: alpha(muted, 0.2); thickness: big ? 10 : 6; start: 225; sweep: 270; fill: true; animate value: spring() } + Column { + gap: 0 + align: center + Text { text: aqi == null ? "…" : round(aqi); fontSize: big ? 40 : 20; bold: true; color: tint; align: center } + Text { text: us ? "us aqi" : "eu aqi"; style: label; color: muted; align: center } + } + } + } + + component PollenRow(p, size = 11) { + Row { + gap: 6 + align: center + Text { text: p.name; fontSize: size; weight: 1; maxLines: 1 } + Dots { n: p.level; c: pollenTints[p.level] } + Text { text: pollenWords[p.level]; fontSize: size; color: pollenTints[p.level]; width: size * 5.5; align: end; maxLines: 1 } + } + } + + Column { + gap: 4 + Row { + Text { text: "air"; style: muted; weight: 1 } + Text { text: lower(placeName); fontSize: 10; color: muted; maxLines: 1; width: 96; align: end } + } + if problem != null { + Text { text: problem; style: small; color: muted } + } else { + Row { + gap: 10 + align: center + weight: rows >= 3 ? 0 : 1 + Gauge { size: 64 } + Column { + gap: 0 + weight: 1 + Text { text: names[level]; style: body; bold: true; color: tint; maxLines: 2 } + Text { text: "pm2.5 ${round(cur.pm2_5)} µg/m³"; style: small; color: muted; maxLines: 1 } + if rows >= 3 || !hasPollen { + Text { text: "uv ${round(cur.uv_index)}"; style: small; color: muted; maxLines: 1 } + } else { + // Too short for the pollen list: the worst one, or none. + Text { text: len(flying) == 0 ? "no pollen" : "${flying[0].name} pollen ${pollenWords[flying[0].level]}"; style: small; color: len(flying) == 0 ? green : pollenTints[flying[0].level]; maxLines: 1 } + } + } + } + if rows >= 3 { + Spacer { height: 1; fill: width; background: alpha(muted, 0.25) } + Text { text: "pollen · next 24 h"; style: label; color: muted } + Column { + gap: 3 + weight: 1 + if !hasPollen { + Text { text: "no pollen forecast here (europe only)"; style: small; color: muted } + } else if len(flying) == 0 { + Text { text: "none in the air"; style: small; color: green } + } else { + for p in take(flying, rows >= 4 ? 5 : 3) key p.name { PollenRow { p: p } } + } + } + } + } + } + + screen { + title: "air and pollen" + Input { + text: city + placeholder: "city · empty = your location" + onSubmit: { city = trim(value); refresh() } + } + if problem != null { + Text { text: problem; style: body; color: muted } + } else { + Column { + scroll: true + gap: 14 + Row { + gap: 16 + align: center + Gauge { big: true; size: 132 } + Column { + gap: 2 + weight: 1 + Text { text: names[level]; style: title; color: tint } + Text { text: advice[level]; style: small } + Text { text: placeLine; style: small; color: muted; maxLines: 1 } + } + } + + Spacer { height: 1; fill: width; background: alpha(muted, 0.25) } + Text { text: "next 24 hours"; style: label; color: accent } + Canvas { + height: 110 + fill: width + let n = max(len(aqis), 1) + let top = max(max(aqis.filter(v => v != null)) ?? 0, steps[2]) + let w = width / n + // The category lines, faint, so a bar's height reads as good, fair, ... + for s, i in take(steps, 4) { + if s < top { + line(0, 92 - s / top * 84, width, 92 - s / top * 84, stroke: alpha(tints[i + 1], 0.3), width: 1) + } + } + for v, i in aqis { + if v != null { + rect(i * w + 1, 92 - v / top * 84, max(w - 2, 1), max(v / top * 84, 1), radius: 2, fill: tints[count(steps, s => v > s)]) + } + if i % 6 == 0 { + text(i == 0 ? "now" : fmtTime(hours[i], "HH:mm"), i * w + w / 2, 104, size: 10, align: center, color: muted) + } + } + } + + Spacer { height: 1; fill: width; background: alpha(muted, 0.25) } + Text { text: "pollutants now · µg/m³"; style: label; color: accent } + Grid { + columns: 3 + gap: 8 + for p in [["pm2.5", cur.pm2_5, 25], ["pm10", cur.pm10, 50], ["ozone", cur.ozone, 120], ["no₂", cur.nitrogen_dioxide, 40], ["uv index", cur.uv_index, 6]] { + Column { + gap: 0 + padding: [10, 8] + border: 1 + borderColor: alpha(muted, 0.3) + Text { text: p[0]; style: label; color: muted } + Text { text: p[1] == null ? "…" : round(p[1], 1); style: title; color: p[1] > p[2] ? orange : foreground } + } + } + } + + Spacer { height: 1; fill: width; background: alpha(muted, 0.25) } + Text { text: "pollen · next 24 hours"; style: label; color: accent } + if !hasPollen { + Text { text: "open-meteo only forecasts pollen in europe."; style: small; color: muted } + } else { + for p in pollen.sortBy(p => -(p.peak ?? 0)) key p.name { + Column { + gap: 2 + PollenRow { p: p; size: 14 } + if p.level > 0 { + Row { + gap: 6 + align: center + Sparkline { values: p.values.map(v => v ?? 0); min: 0; max: max(p.peak ?? 0, 1); color: pollenTints[p.level]; area: true; height: 24; weight: 1 } + Text { text: p.peak == null ? "" : "peak ${round(p.peak)}"; style: label; color: muted; width: 72; align: end } + } + } + } + } + } + Text { text: "data: copernicus atmosphere monitoring service via open-meteo.com (cc by 4.0)"; style: label; color: muted } + } + } + } +} diff --git a/packages/omamobile-owl-widgets/overrides/simonschubert/forecast/widget.owl b/packages/omamobile-owl-widgets/overrides/simonschubert/forecast/widget.owl new file mode 100644 index 000000000..d19c78cdd --- /dev/null +++ b/packages/omamobile-owl-widgets/overrides/simonschubert/forecast/widget.owl @@ -0,0 +1,105 @@ +// Modified from omarchy-widgets widgets/simonschubert/forecast/widget.owl@b63886b (MIT, Simon Schubert and contributors; see overrides/LICENSE) for Omarchy Mobile: weather from Open-Meteo. +widget "forecast" { + meta { description: "Three-day weather forecast with an hourly temperature curve, from your location or a city you type (weather: Open-Meteo, CC BY 4.0)"; version: "1.2.1"; license: "MIT"; category: "world"; owl: 5 } + size: 6x3 + minSize: 4x3 + + // Omarchy Mobile's copy: the weather from Open-Meteo (open-meteo.com, CC BY 4.0), with no commands. + state city = "" persist + // The phone's temperature unit, "C" or "F", put in by the home screen; empty elsewhere. + state phoneUnit = "" + // The place: "lat,lon" (the phone's location, as the home screen puts it in) goes straight to the forecast; + // a name ("Town" or "Town, Region") is looked up with Open-Meteo's geocoding. Open-Meteo has no IP location. + let ll = match(trim(city), "^(-?[0-9.]+) *, *(-?[0-9.]+)$") + let town = trim(split(city, ",")[0]) + // What follows the town, each part lower-case; a US state code also reads as its state, as omamobile-weather's + // pick_place does (the lock screen reads this widget's city too, so the two pick the same place). + let qualifiers = drop(split(city, ","), 1).map(x => lower(trim(x))).filter(x => x != "") + let usStates = {"al": "alabama", "ak": "alaska", "az": "arizona", "ar": "arkansas", "ca": "california", "co": "colorado", "ct": "connecticut", "de": "delaware", "dc": "district of columbia", "fl": "florida", "ga": "georgia", "hi": "hawaii", "id": "idaho", "il": "illinois", "in": "indiana", "ia": "iowa", "ks": "kansas", "ky": "kentucky", "la": "louisiana", "me": "maine", "md": "maryland", "ma": "massachusetts", "mi": "michigan", "mn": "minnesota", "ms": "mississippi", "mo": "missouri", "mt": "montana", "ne": "nebraska", "nv": "nevada", "nh": "new hampshire", "nj": "new jersey", "nm": "new mexico", "ny": "new york", "nc": "north carolina", "nd": "north dakota", "oh": "ohio", "ok": "oklahoma", "or": "oregon", "pa": "pennsylvania", "ri": "rhode island", "sc": "south carolina", "sd": "south dakota", "tn": "tennessee", "tx": "texas", "ut": "utah", "vt": "vermont", "va": "virginia", "wa": "washington", "wv": "west virginia", "wi": "wisconsin", "wy": "wyoming"} + let wanted = flatten(qualifiers.map(x => [x, get(usStates, x, x)])) + let named = ll == null && len(town) >= 2 + // The town, percent-encoded so "/", "?", "&" or "#" in it can't break the URL. + let q = town.replace("%", "%25").replace("+", "%2B").replace("/", "%2F").replace("?", "%3F").replace("#", "%23").replace("&", "%26").replace("'", "%27").replace(" ", "%20") + // The URLs always start with their host, so the approval sheet can name it: with "lat,lon" the lookup still goes out + // with an empty name (an empty answer), and before a city is found the forecast goes out without a place (an error answer). + source geo = http("https://geocoding-api.open-meteo.com/v1/search?count=10&format=json&name=${named ? q : ""}") every 24h timeout 10s json status + let results = named && geo != null && geo.ok ? geo.out.results ?? [] : [] + // The first result whose region, county, country or country code matches one of them; else the first. + let found = find(results, r => any([lower(r.admin1 ?? ""), lower(r.admin2 ?? ""), lower(r.country ?? ""), lower(r.country_code ?? "")], f => f != "" && contains(wanted, f))) ?? first(results) + let lat = ll != null ? round(num(ll[0]), 2) : found != null ? round(found.latitude, 2) : null + let lon = ll != null ? round(num(ll[1]), 2) : found != null ? round(found.longitude, 2) : null + let place = ll != null ? "your location" : found != null ? found.name : town + let imperial = phoneUnit != "" ? phoneUnit == "F" : found != null && ll == null && contains(["US", "LR", "MM"], found.country_code) + // Three days of hours; only what's drawn is used. + source w = http("https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t=temperature_2m,weather_code&hourly=temperature_2m&daily=temperature_2m_max,temperature_2m_min&forecast_days=3&timezone=auto&timeformat=unixtime&temperature_unit=${imperial ? "fahrenheit" : "celsius"}") every 30m timeout 10s json status + // The first forecast goes out before a typed city is looked up; ask again once it is, and when the place or unit changes. + let ask = lat == null ? "" : "${lat},${lon},${imperial}" + on ask { refresh() } + let problem = ll == null && !named ? "set a city or turn on Location" : named && geo != null && geo.ok && found == null ? "city not found" : null + let om = w != null && w.ok && lat != null ? w.out : null + // Open-Meteo's WMO weather codes in the words the phone's weather service uses. + let wmoText = {"0": "clear", "1": "mostly clear", "2": "partly cloudy", "3": "overcast", "45": "fog", "48": "fog", "51": "drizzle", "53": "drizzle", "55": "drizzle", "56": "drizzle", "57": "drizzle", "61": "rain", "63": "rain", "65": "rain", "66": "rain", "67": "rain", "71": "snow", "73": "snow", "75": "snow", "77": "snow", "80": "rain", "81": "rain", "82": "rain", "85": "snow", "86": "snow", "95": "thunderstorm", "96": "thunderstorm", "99": "thunderstorm"} + let now = om == null ? null : {temp: round(om.current.temperature_2m), desc: get(wmoText, str(om.current.weather_code), "")} + let days = om == null ? [] : range(len(om.daily.time ?? [])).map(i => { + date: om.daily.time[i], + day: fmtTime(om.daily.time[i], "EEE"), + max: round(om.daily.temperature_2m_max[i]), + min: round(om.daily.temperature_2m_min[i]) + }) + // 8 readings a day, every 3 hours from midnight, as before. + let hours = om == null ? [] : range(0, len(om.hourly.temperature_2m ?? []), 3).map(i => om.hourly.temperature_2m[i]) + let lo = min(hours) - 2 + let hi = max(hours) + 2 + + onTap: screen() + + Column { + gap: 4 + if om == null { + Text { text: problem ?? (w == null || (named && geo == null) ? "…" : "weather offline"); style: small; color: muted; maxLines: 2 } + } else { + Row { + align: center + Text { text: "${now.temp}°"; style: title; width: 56 } + Column { + gap: 0 + weight: 1 + Text { text: now.desc; style: small; maxLines: 1 } + Text { text: place; style: small; color: muted; maxLines: 1 } + } + } + Row { + for d, i in days key d.date { + Column { + weight: 1 + gap: 0 + Text { text: i == 0 ? "today" : lower(d.day); fontSize: 10; color: muted } + Text { text: "${d.max}° / ${d.min}°"; fontSize: 12 } + } + } + } + // The dots mark noon. + Canvas { + weight: 1 + fill: width + let pts = hours.map((t, i) => [i / max(len(hours) - 1, 1) * width, height - 4 - (t - lo) / (hi - lo) * (height - 8)]) + path(pts, stroke: accent, width: 2) + for p, i in pts { + if i % 8 == 4 { circle(p[0], p[1], 3, color: accent) } + } + } + } + } + + screen { + title: "forecast" + Input { + text: city + placeholder: "city · empty = your location" + onSubmit: { city = trim(value); refresh() } + } + Text { text: problem ?? (om == null ? "…" : lower(place)); style: small; color: muted } + Text { text: "weather: open-meteo.com (cc by 4.0)"; style: label; color: muted } + Button { text: "open-meteo.com ↗"; color: muted; onTap: url("https://open-meteo.com/") } + } +} diff --git a/packages/omamobile-owl-widgets/overrides/simonschubert/planes-overhead/widget.owl b/packages/omamobile-owl-widgets/overrides/simonschubert/planes-overhead/widget.owl new file mode 100644 index 000000000..8889809d0 --- /dev/null +++ b/packages/omamobile-owl-widgets/overrides/simonschubert/planes-overhead/widget.owl @@ -0,0 +1,191 @@ +// Modified from omarchy-widgets widgets/simonschubert/planes-overhead/widget.owl@b63886b (MIT, Simon Schubert and contributors; see overrides/LICENSE) for Omarchy Mobile: weather from Open-Meteo. +widget "planes overhead" { + meta { description: "Aircraft around you on a live radar, from the OpenSky Network, at your location or a city you type (place lookup: Open-Meteo, CC BY 4.0). Tap it for every flight's altitude, speed and distance"; version: "1.1.1"; license: "MIT"; category: "world"; owl: 5 } + size: 3x3 + minSize: 2x2 + + source now = clock every 1s + // Omarchy Mobile's copy: the place from Open-Meteo's geocoding (open-meteo.com, CC BY 4.0) or the phone's location. + state city = "" persist + // The phone's temperature unit, "C" or "F", put in by the home screen; empty elsewhere. "F" also means miles. + state phoneUnit = "" + // The place: "lat,lon" (the phone's location, as the home screen puts it in) goes straight in; + // a name ("Town" or "Town, Region") is looked up with Open-Meteo's geocoding. Open-Meteo has no IP location. + let ll = match(trim(city), "^(-?[0-9.]+) *, *(-?[0-9.]+)$") + let town = trim(split(city, ",")[0]) + // What follows the town, each part lower-case; a US state code also reads as its state, as omamobile-weather's + // pick_place does (the lock screen reads this widget's city too, so the two pick the same place). + let qualifiers = drop(split(city, ","), 1).map(x => lower(trim(x))).filter(x => x != "") + let usStates = {"al": "alabama", "ak": "alaska", "az": "arizona", "ar": "arkansas", "ca": "california", "co": "colorado", "ct": "connecticut", "de": "delaware", "dc": "district of columbia", "fl": "florida", "ga": "georgia", "hi": "hawaii", "id": "idaho", "il": "illinois", "in": "indiana", "ia": "iowa", "ks": "kansas", "ky": "kentucky", "la": "louisiana", "me": "maine", "md": "maryland", "ma": "massachusetts", "mi": "michigan", "mn": "minnesota", "ms": "mississippi", "mo": "missouri", "mt": "montana", "ne": "nebraska", "nv": "nevada", "nh": "new hampshire", "nj": "new jersey", "nm": "new mexico", "ny": "new york", "nc": "north carolina", "nd": "north dakota", "oh": "ohio", "ok": "oklahoma", "or": "oregon", "pa": "pennsylvania", "ri": "rhode island", "sc": "south carolina", "sd": "south dakota", "tn": "tennessee", "tx": "texas", "ut": "utah", "vt": "vermont", "va": "virginia", "wa": "washington", "wv": "west virginia", "wi": "wisconsin", "wy": "wyoming"} + let wanted = flatten(qualifiers.map(x => [x, get(usStates, x, x)])) + let named = ll == null && len(town) >= 2 + // The town, percent-encoded so "/", "?", "&" or "#" in it can't break the URL. + let q = town.replace("%", "%25").replace("+", "%2B").replace("/", "%2F").replace("?", "%3F").replace("#", "%23").replace("&", "%26").replace("'", "%27").replace(" ", "%20") + // The URLs always start with their host, so the approval sheet can name it: with "lat,lon" the lookup still goes out + // with an empty name (an empty answer), and before a city is found the forecast goes out without a place (an error answer). + source geo = http("https://geocoding-api.open-meteo.com/v1/search?count=10&format=json&name=${named ? q : ""}") every 24h timeout 10s json status + let results = named && geo != null && geo.ok ? geo.out.results ?? [] : [] + // The first result whose region, county, country or country code matches one of them; else the first. + let found = find(results, r => any([lower(r.admin1 ?? ""), lower(r.admin2 ?? ""), lower(r.country ?? ""), lower(r.country_code ?? "")], f => f != "" && contains(wanted, f))) ?? first(results) + let lat = ll != null ? num(ll[0]) : found != null ? found.latitude : null + let lon = ll != null ? num(ll[1]) : found != null ? found.longitude : null + let placeName = ll != null ? "your location" : found != null ? found.name : town + let imperial = phoneUnit != "" ? phoneUnit == "F" : found != null && ll == null && contains(["US", "LR", "MM"], found.country_code) + // 45 km, or 30 miles, in three rings. + let km = imperial ? 48.28 : 45 + let range = imperial ? "30 mi" : "45 km" + // A box a little larger than the radar (0.5° is 55 km); longitude degrees shrink toward the poles. + let dLat = 0.5 + let dLon = 0.5 / max(cos(rad(lat)), 0.2) + // Anonymous OpenSky allows 400 requests a day; this runs only while its page is on screen. + source sky = http("https://opensky-network.org/api/states/all?lamin=${fixed(lat - dLat, 3)}&lomin=${fixed(lon - dLon, 3)}&lamax=${fixed(lat + dLat, 3)}&lomax=${fixed(lon + dLon, 3)}") every 2m timeout 15s json status + // The first request goes out before the location is known; ask again once it is. + when lat != null { refresh() } + // And again when a new city moves it. + on lat { refresh() } + + // OpenSky's state vectors: [icao24, callsign, country, time_position, last_contact, lon, lat, + // baro_altitude, on_ground, velocity, true_track, vertical_rate, sensors, geo_altitude, ...]. + // Positions are carried forward along each plane's track, so the radar moves between requests. + let planes = (sky.ok ? sky.out.states ?? [] : []) + .filter(s => !s[8] && s[5] != null && s[6] != null) + .map(s => { + id: s[0], + call: trim(s[1] ?? "") == "" ? upper(s[0]) : trim(s[1]), + country: s[2], + alt: s[7] ?? s[13] ?? 0, + speed: s[9] ?? 0, + track: s[10] ?? 0, + climb: s[11] ?? 0, + x: (s[5] - lon) * 111.32 * cos(rad(lat)) + sin(rad(s[10] ?? 0)) * (s[9] ?? 0) * clamp(now - s[3], 0, 180) / 1000, + y: (s[6] - lat) * 110.57 + cos(rad(s[10] ?? 0)) * (s[9] ?? 0) * clamp(now - s[3], 0, 180) / 1000 + }) + let flights = planes.filter(p => p.x * p.x + p.y * p.y <= km * km).sortBy(p => p.x * p.x + p.y * p.y) + let nearest = first(flights) + let problem = ll == null && !named ? "set a city or turn on Location" : named && geo == null ? "locating…" : lat == null ? "city not found" : sky == null ? "listening…" : sky.code == 429 ? "opensky's daily limit is used up" : !sky.ok ? "opensky offline" : null + + onTap: screen() + + // Low planes are warm, cruising ones cool. + component Plane(alt, track, s = 6) { + Canvas { + size: s * 2 + 4 + let c = s + 2 + rotate(track, c, c) { + path([[c, c - s], [c + s * 0.7, c + s * 0.7], [c, c + s * 0.3], [c - s * 0.7, c + s * 0.7]], closed: true, fill: alt < 3000 ? orange : alt < 8000 ? yellow : cyan) + } + } + } + + component Radar(list, labels = false) { + Canvas { + let cx = width / 2 + let cy = height / 2 + let r = min(width, height) / 2 - 2 + let s = r / km + let p = max(r / 20, 3.5) + circle(cx, cy, r, fill: alpha(surface, 0.4), stroke: border, width: 1) + circle(cx, cy, r * 2 / 3, stroke: alpha(muted, 0.3), width: 1) + circle(cx, cy, r / 3, stroke: alpha(muted, 0.3), width: 1) + line(cx - r, cy, cx + r, cy, stroke: alpha(muted, 0.2), width: 1) + line(cx, cy - r, cx, cy + r, stroke: alpha(muted, 0.2), width: 1) + // The sweep, once every four seconds. + rotate(time * 90 % 360, cx, cy) { + arc(cx, cy, r, -45, 45, fill: alpha(accent, 0.12)) + line(cx, cy, cx, cy - r, stroke: alpha(accent, 0.7), width: 1.5) + } + if labels { + text(imperial ? "10 mi" : "15 km", cx + 4, cy - r / 3 - 7, size: 10, color: muted) + text(imperial ? "20 mi" : "30 km", cx + 4, cy - r * 2 / 3 - 7, size: 10, color: muted) + text("N", cx, cy - r + 9, size: 10, align: center, color: muted) + } + for f in list { + rotate(f.track, cx + f.x * s, cy - f.y * s) { + let px = cx + f.x * s + let py = cy - f.y * s + path([[px, py - p], [px + p * 0.7, py + p * 0.7], [px, py + p * 0.3], [px - p * 0.7, py + p * 0.7]], closed: true, fill: f.alt < 3000 ? orange : f.alt < 8000 ? yellow : cyan) + } + if labels { + text(f.call, cx + f.x * s + p + 3, cy - f.y * s, size: 10, color: foreground) + } + } + circle(cx, cy, 3, fill: foreground) + } + } + + Column { + gap: 4 + Row { + Text { text: "planes overhead"; style: muted; weight: 1; maxLines: 1 } + Text { text: problem == null ? len(flights) : ""; style: muted; width: 32; align: end } + } + Box { + weight: 1 + fill: width + Radar { list: flights; labels: cols >= 4 && rows >= 4; fill: true } + if problem != null { + Text { text: problem; style: small; color: muted; align: center } + } + } + if rows >= 3 { + Text { + text: problem != null ? "" : nearest == null ? "clear skies within ${range}" : "${nearest.call} · ${imperial ? "${round(sqrt(nearest.x * nearest.x + nearest.y * nearest.y) / 1.609)} mi" : "${round(sqrt(nearest.x * nearest.x + nearest.y * nearest.y))} km"} away" + style: small + maxLines: 1 + } + } + } + + screen { + title: "planes overhead" + Input { + text: city + placeholder: "city · empty = your location" + onSubmit: { city = trim(value); refresh() } + } + Column { + scroll: true + gap: 10 + Radar { list: flights; labels: true; height: min(screenWidth - 32, screenHeight * 0.55); fill: width } + Text { + text: problem ?? "${len(flights)} ${len(flights) == 1 ? "flight" : "flights"} within ${range} of ${lower(placeName)}" + style: small + color: muted + } + Spacer { height: 1; fill: width; background: alpha(muted, 0.25) } + for f in flights key f.id { + Row { + gap: 10 + align: center + onTap: url("https://globe.adsbexchange.com/?icao=${f.id}") + Plane { alt: f.alt; track: f.track; s: 8 } + Column { + gap: 0 + weight: 1 + Text { text: f.call; font: mono; bold: true; maxLines: 1 } + Text { text: lower(f.country); style: small; color: muted; maxLines: 1 } + } + Column { + gap: 0 + width: 96 + Text { text: "${imperial ? "${round(f.alt * 3.281 / 100) * 100} ft" : "${round(f.alt / 10) * 10} m"} ${f.climb > 1 ? "↑" : f.climb < -1 ? "↓" : ""}"; style: small; align: end; maxLines: 1 } + Text { text: imperial ? "${round(f.speed * 2.237)} mph" : "${round(f.speed * 3.6)} km/h"; style: small; color: muted; align: end; maxLines: 1 } + } + Text { + text: imperial ? "${round(sqrt(f.x * f.x + f.y * f.y) / 1.609)} mi" : "${round(sqrt(f.x * f.x + f.y * f.y))} km" + style: small + color: accent + width: 48 + align: end + } + } + } + Row { + gap: 8 + align: center + Text { text: "data: the opensky network · place: open-meteo.com (cc by 4.0)"; style: label; color: muted; weight: 1; maxLines: 2 } + Button { text: "live map ↗"; color: muted; onTap: url("https://globe.adsbexchange.com/?lat=${lat}&lon=${lon}&zoom=9") } + } + } + } +} diff --git a/packages/omamobile-owl-widgets/overrides/simonschubert/sun-and-moon/widget.owl b/packages/omamobile-owl-widgets/overrides/simonschubert/sun-and-moon/widget.owl new file mode 100644 index 000000000..f8bf0167d --- /dev/null +++ b/packages/omamobile-owl-widgets/overrides/simonschubert/sun-and-moon/widget.owl @@ -0,0 +1,114 @@ +// Modified from omarchy-widgets widgets/simonschubert/sun-and-moon/widget.owl@b63886b (MIT, Simon Schubert and contributors; see overrides/LICENSE) for Omarchy Mobile: weather from Open-Meteo. +widget "sun and moon" { + meta { description: "Sunrise, sunset, daylight left and tonight's moon phase, from your location or a city you type (sun: Open-Meteo, CC BY 4.0; the moon is worked out from the date)"; version: "1.2.1"; license: "MIT"; category: "world"; owl: 5 } + size: 3x3 + minSize: 3x3 + + // Omarchy Mobile's copy: sunrise and sunset from Open-Meteo (open-meteo.com, CC BY 4.0), with no commands. + // Open-Meteo has no moon phase, so the widget works it out from the date. + state city = "" persist + // The place: "lat,lon" (the phone's location, as the home screen puts it in) goes straight in; + // a name ("Town" or "Town, Region") is looked up with Open-Meteo's geocoding. Open-Meteo has no IP location. + let ll = match(trim(city), "^(-?[0-9.]+) *, *(-?[0-9.]+)$") + let town = trim(split(city, ",")[0]) + // What follows the town, each part lower-case; a US state code also reads as its state, as omamobile-weather's + // pick_place does (the lock screen reads this widget's city too, so the two pick the same place). + let qualifiers = drop(split(city, ","), 1).map(x => lower(trim(x))).filter(x => x != "") + let usStates = {"al": "alabama", "ak": "alaska", "az": "arizona", "ar": "arkansas", "ca": "california", "co": "colorado", "ct": "connecticut", "de": "delaware", "dc": "district of columbia", "fl": "florida", "ga": "georgia", "hi": "hawaii", "id": "idaho", "il": "illinois", "in": "indiana", "ia": "iowa", "ks": "kansas", "ky": "kentucky", "la": "louisiana", "me": "maine", "md": "maryland", "ma": "massachusetts", "mi": "michigan", "mn": "minnesota", "ms": "mississippi", "mo": "missouri", "mt": "montana", "ne": "nebraska", "nv": "nevada", "nh": "new hampshire", "nj": "new jersey", "nm": "new mexico", "ny": "new york", "nc": "north carolina", "nd": "north dakota", "oh": "ohio", "ok": "oklahoma", "or": "oregon", "pa": "pennsylvania", "ri": "rhode island", "sc": "south carolina", "sd": "south dakota", "tn": "tennessee", "tx": "texas", "ut": "utah", "vt": "vermont", "va": "virginia", "wa": "washington", "wv": "west virginia", "wi": "wisconsin", "wy": "wyoming"} + let wanted = flatten(qualifiers.map(x => [x, get(usStates, x, x)])) + let named = ll == null && len(town) >= 2 + // The town, percent-encoded so "/", "?", "&" or "#" in it can't break the URL. + let q = town.replace("%", "%25").replace("+", "%2B").replace("/", "%2F").replace("?", "%3F").replace("#", "%23").replace("&", "%26").replace("'", "%27").replace(" ", "%20") + // The URLs always start with their host, so the approval sheet can name it: with "lat,lon" the lookup still goes out + // with an empty name (an empty answer), and before a city is found the forecast goes out without a place (an error answer). + source geo = http("https://geocoding-api.open-meteo.com/v1/search?count=10&format=json&name=${named ? q : ""}") every 24h timeout 10s json status + let results = named && geo != null && geo.ok ? geo.out.results ?? [] : [] + // The first result whose region, county, country or country code matches one of them; else the first. + let found = find(results, r => any([lower(r.admin1 ?? ""), lower(r.admin2 ?? ""), lower(r.country ?? ""), lower(r.country_code ?? "")], f => f != "" && contains(wanted, f))) ?? first(results) + let lat = ll != null ? round(num(ll[0]), 2) : found != null ? round(found.latitude, 2) : null + let lon = ll != null ? round(num(ll[1]), 2) : found != null ? round(found.longitude, 2) : null + // Today's and tomorrow's sunrise and sunset, in Unix time. + source sun = http("https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&daily=sunrise,sunset&forecast_days=2&timezone=auto&timeformat=unixtime") every 1h timeout 10s json status + // The first request goes out before a typed city is looked up; ask again once it is, and when the place changes. + let ask = lat == null ? "" : "${lat},${lon}" + on ask { refresh() } + let problem = ll == null && !named ? "set a city or turn on Location" : named && geo != null && geo.ok && found == null ? "city not found" : null + source now = clock every 60s + // The moon: days since a known new moon (2000-01-06 18:14 UTC), in a 29.53-day month. + let moonAge = ((now - 947182440) / 86400 % 29.530589 + 29.530589) % 29.530589 + let phases = ["New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous", "Full Moon", "Waning Gibbous", "Last Quarter", "Waning Crescent"] + let daily = sun != null && sun.ok && lat != null ? sun.out.daily : null + let sky = daily == null ? null : { + place: ll != null ? "your location" : found != null ? found.name : town, + rise: daily.sunrise[0], + set: daily.sunset[0], + next: daily.sunrise[1], + phase: phases[int(floor(moonAge / 29.530589 * 8 + 0.5)) % 8], + illum: round((1 - cos(moonAge / 29.530589 * 6.2831853)) / 2 * 100) + } + let day = now >= sky.rise && now < sky.set + let p = clamp((now - sky.rise) / (sky.set - sky.rise), 0, 1) + let waxing = contains(sky.phase, "Waxing") || contains(sky.phase, "First") + + onTap: screen() + + Column { + gap: 4 + Row { + Text { text: "sun & moon"; style: muted; weight: 1 } + Text { text: sky.place; fontSize: 10; color: muted; maxLines: 1; width: 72; align: end } + } + if sky == null { + Text { text: problem ?? (sun == null || (named && geo == null) ? "…" : "offline"); style: small; color: muted; maxLines: 2 } + Spacer { weight: 1 } + } else { + // The day as an arc from sunrise (left) to sunset (right). + Canvas { + weight: 1 + fill: width + let cx = width / 2 + let cy = height - 4 + let r = min(width / 2 - 8, height - 12) + let a = rad(-90 + 180 * p) + line(4, cy, width - 4, cy, stroke: border, width: 1) + arc(cx, cy, r, -90, 180, stroke: border, width: 2, cap: round) + if day { arc(cx, cy, r, -90, 180 * p, stroke: yellow, width: 3, cap: round) } + circle(cx + r * sin(a), cy - r * cos(a), day ? 7 : 5, fill: day ? yellow : muted) + } + Row { + Text { text: "↑ ${fmtTime(now < sky.set ? sky.rise : sky.next, "HH:mm")}"; fontSize: 12; weight: 1 } + Text { text: "↓ ${fmtTime(sky.set, "HH:mm")}"; fontSize: 12; width: 56; align: end } + } + Text { + text: now < sky.rise ? "sunrise in ${fmtDuration(sky.rise - now)}" : day ? "${fmtDuration(sky.set - now)} of daylight left" : "sunrise in ${fmtDuration(sky.next - now)}" + style: small; color: muted; maxLines: 1 + } + Row { + align: center + // Lit part of the moon: the limb on one side, the terminator (an ellipse) on the other. + Canvas { + size: 22 + let r = 10 + let c = 11 + let s = waxing ? 1 : -1 + let f = num(sky.illum, 0) / 100 + let ys = range(21).map(i => -r + 2 * r * i / 20) + circle(c, c, r, fill: surface, stroke: border, width: 1) + path(ys.map(y => [c + s * sqrt(max(r * r - y * y, 0)), c + y]) + reverse(ys).map(y => [c + s * sqrt(max(r * r - y * y, 0)) * (1 - 2 * f), c + y]), closed: true, fill: foreground) + } + Text { text: "${lower(sky.phase)} · ${sky.illum}%"; fontSize: 11; maxLines: 1; weight: 1 } + } + } + } + + screen { + title: "sun and moon" + Input { + text: city + placeholder: "city · empty = your location" + onSubmit: { city = trim(value); refresh() } + } + Text { text: problem ?? (sky == null ? "…" : lower(sky.place)); style: small; color: muted } + Text { text: "sunrise and sunset: open-meteo.com (cc by 4.0) · the moon from the date"; style: label; color: muted } + } +} diff --git a/packages/omamobile-owl-widgets/overrides/simonschubert/today/widget.owl b/packages/omamobile-owl-widgets/overrides/simonschubert/today/widget.owl new file mode 100644 index 000000000..6e0bee61e --- /dev/null +++ b/packages/omamobile-owl-widgets/overrides/simonschubert/today/widget.owl @@ -0,0 +1,323 @@ +// Modified from omarchy-widgets widgets/simonschubert/today/widget.owl@b63886b (MIT, Simon Schubert and contributors; see overrides/LICENSE) for Omarchy Mobile: weather from Open-Meteo. +widget "today" { + page: 1 + order: 1 + size: 3x3 + minSize: 3x2 + meta { description: "The date and the weather where you are, from your location or a city you type (weather: Open-Meteo, CC BY 4.0). Tap it for the next 24 hours, three days, wind, UV, sun and moon"; version: "1.1.1"; license: "MIT"; category: "world"; owl: 5 } + + // Omarchy Mobile's copy: the weather from Open-Meteo (open-meteo.com, CC BY 4.0). + source now = clock every 1m + state city = "" persist + // The phone's temperature unit, "C" or "F", put in by the home screen; empty elsewhere. + state phoneUnit = "" + // The place: "lat,lon" (the phone's location, as the home screen puts it in) goes straight to the forecast; + // a name ("Town" or "Town, Region") is looked up with Open-Meteo's geocoding. Open-Meteo has no IP location. + let ll = match(trim(city), "^(-?[0-9.]+) *, *(-?[0-9.]+)$") + let town = trim(split(city, ",")[0]) + // What follows the town, each part lower-case; a US state code also reads as its state, as omamobile-weather's + // pick_place does (the lock screen reads this widget's city too, so the two pick the same place). + let qualifiers = drop(split(city, ","), 1).map(x => lower(trim(x))).filter(x => x != "") + let usStates = {"al": "alabama", "ak": "alaska", "az": "arizona", "ar": "arkansas", "ca": "california", "co": "colorado", "ct": "connecticut", "de": "delaware", "dc": "district of columbia", "fl": "florida", "ga": "georgia", "hi": "hawaii", "id": "idaho", "il": "illinois", "in": "indiana", "ia": "iowa", "ks": "kansas", "ky": "kentucky", "la": "louisiana", "me": "maine", "md": "maryland", "ma": "massachusetts", "mi": "michigan", "mn": "minnesota", "ms": "mississippi", "mo": "missouri", "mt": "montana", "ne": "nebraska", "nv": "nevada", "nh": "new hampshire", "nj": "new jersey", "nm": "new mexico", "ny": "new york", "nc": "north carolina", "nd": "north dakota", "oh": "ohio", "ok": "oklahoma", "or": "oregon", "pa": "pennsylvania", "ri": "rhode island", "sc": "south carolina", "sd": "south dakota", "tn": "tennessee", "tx": "texas", "ut": "utah", "vt": "vermont", "va": "virginia", "wa": "washington", "wv": "west virginia", "wi": "wisconsin", "wy": "wyoming"} + let wanted = flatten(qualifiers.map(x => [x, get(usStates, x, x)])) + let named = ll == null && len(town) >= 2 + // The town, percent-encoded so "/", "?", "&" or "#" in it can't break the URL. + let q = town.replace("%", "%25").replace("+", "%2B").replace("/", "%2F").replace("?", "%3F").replace("#", "%23").replace("&", "%26").replace("'", "%27").replace(" ", "%20") + // The URLs always start with their host, so the approval sheet can name it: with "lat,lon" the lookup still goes out + // with an empty name (an empty answer), and before a city is found the forecast goes out without a place (an error answer). + source geo = http("https://geocoding-api.open-meteo.com/v1/search?count=10&format=json&name=${named ? q : ""}") every 24h timeout 10s json status + let results = named && geo != null && geo.ok ? geo.out.results ?? [] : [] + // The first result whose region, county, country or country code matches one of them; else the first. + let found = find(results, r => any([lower(r.admin1 ?? ""), lower(r.admin2 ?? ""), lower(r.country ?? ""), lower(r.country_code ?? "")], f => f != "" && contains(wanted, f))) ?? first(results) + let lat = ll != null ? round(num(ll[0]), 2) : found != null ? round(found.latitude, 2) : null + let lon = ll != null ? round(num(ll[1]), 2) : found != null ? round(found.longitude, 2) : null + let placeName = ll != null ? "your location" : found != null ? found.name : town + let countryName = found != null && ll == null ? found.country ?? "" : "" + let imperial = phoneUnit != "" ? phoneUnit == "F" : found != null && ll == null && contains(["US", "LR", "MM"], found.country_code) + let unit = imperial ? "F" : "C" + // One forecast request: now, 3 days of hours (for the next 24) and 3 days. + source wx = http("https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t=temperature_2m,apparent_temperature,relative_humidity_2m,is_day,weather_code,precipitation,pressure_msl,wind_speed_10m,wind_direction_10m&hourly=temperature_2m,precipitation_probability,weather_code,is_day,uv_index,visibility&daily=weather_code,temperature_2m_max,temperature_2m_min,sunrise,sunset,precipitation_probability_max,precipitation_sum&forecast_days=3&timezone=auto&timeformat=unixtime&temperature_unit=${imperial ? "fahrenheit" : "celsius"}&wind_speed_unit=${imperial ? "mph" : "kmh"}&precipitation_unit=${imperial ? "inch" : "mm"}") every 30m timeout 10s json status + // The first forecast goes out before a typed city is looked up; ask again once it is, and when the place or unit changes. + let ask = lat == null ? "" : "${lat},${lon},${unit}" + on ask { refresh() } + let problem = ll == null && !named ? "set a city or turn on Location" : named && geo != null && geo.ok && found == null ? "city not found" : null + let om = wx != null && wx.ok && lat != null ? wx.out : null + let now0 = om.current + let hourly = om.hourly + let daily = om.daily + let at = max(count(hourly.time ?? [], t => t <= now) - 1, 0) + // Open-Meteo's WMO weather codes as the older codes weatherIcon() takes, and in the words the phone's weather service uses. + let wmoIcon = {"0": 113, "1": 116, "2": 116, "3": 122, "45": 248, "48": 248, "51": 266, "53": 266, "55": 266, "56": 281, "57": 281, "61": 296, "63": 302, "65": 308, "66": 311, "67": 314, "71": 329, "73": 332, "75": 338, "77": 338, "80": 353, "81": 356, "82": 359, "85": 368, "86": 371, "95": 389, "96": 389, "99": 389} + let wmoText = {"0": "clear", "1": "mostly clear", "2": "partly cloudy", "3": "overcast", "45": "fog", "48": "fog", "51": "drizzle", "53": "drizzle", "55": "drizzle", "56": "drizzle", "57": "drizzle", "61": "rain", "63": "rain", "65": "rain", "66": "rain", "67": "rain", "71": "snow", "73": "snow", "75": "snow", "77": "snow", "80": "rain", "81": "rain", "82": "rain", "85": "snow", "86": "snow", "95": "thunderstorm", "96": "thunderstorm", "99": "thunderstorm"} + // Visibility in metres, from whatever unit Open-Meteo answers in: with precipitation_unit=inch it gives feet (hourly_units). + let visMetres = num(hourly.visibility[at], 0) * (om.hourly_units.visibility == "ft" ? 0.3048 : 1) + let compass = ["n", "nne", "ne", "ene", "e", "ese", "se", "sse", "s", "ssw", "sw", "wsw", "w", "wnw", "nw", "nnw"] + // The current reading, in the shape the tile and screen below draw. + let cur = now0 == null ? null : { + temp: round(now0.temperature_2m), + feels: round(now0.apparent_temperature), + code: get(wmoIcon, str(now0.weather_code), 119), + desc: get(wmoText, str(now0.weather_code), ""), + humidity: round(now0.relative_humidity_2m), + wind: "${round(now0.wind_speed_10m)} ${imperial ? "mph" : "km/h"}", + windDir: compass[int(round(num(now0.wind_direction_10m, 0) / 22.5)) % 16], + precip: "${round(num(now0.precipitation, 0), imperial ? 2 : 1)} ${imperial ? "in" : "mm"}", + pressure: imperial ? "${round(num(now0.pressure_msl, 0) * 0.02953, 2)} inHg" : "${round(now0.pressure_msl)} hPa", + visibility: imperial ? "${round(visMetres / 1609.34)} mi" : "${round(visMetres / 1000)} km", + uv: round(num(hourly.uv_index[at], 0)) + } + let night = now0 != null && now0.is_day == 0 + // The three days: date, icon, low and high, rain chance. + let days = range(len(daily.time ?? [])).map(i => { + date: daily.time[i], + code: get(wmoIcon, str(daily.weather_code[i]), 119), + lo: round(daily.temperature_2m_min[i]), + hi: round(daily.temperature_2m_max[i]), + rain: round(num(daily.precipitation_probability_max[i], 0)) + }) + let day = first(days) + // Clear or partly cloudy gets a warm sun or a cool moon; everything else stays neutral. + let sky = cur != null && contains([113, 116], cur.code) ? (night ? blue : yellow) : foreground + // Sunrise and sunset, Unix time from Open-Meteo, shown in the phone's clock. + let sun = om == null ? ["", ""] : [fmtTime(daily.sunrise[0], "HH:mm"), fmtTime(daily.sunset[0], "HH:mm")] + let sunHours = sun.map(s => num(sub(s, 0, 2))) + let hourNow = num(fmtTime(now, "H")) + // The next 24 hours in 3-hour steps, from the current hour on. + let steps = range(8).map(k => at + k * 3).filter(i => i < len(hourly.time ?? [])).map(i => { + hr: hourNow + (hourly.time[i] - hourly.time[at]) / 3600, + t: round(hourly.temperature_2m[i]), + rain: round(num(hourly.precipitation_probability[i], 0)), + code: get(wmoIcon, str(hourly.weather_code[i]), 119), + night: hourly.is_day[i] == 0 + }) + // The three days' range, so their bars share one scale. + let lowest = min(days.map(d => d.lo)) + let highest = max(days.map(d => d.hi)) + // The moon from the date: Open-Meteo has no moon phase. Days since a known new moon (2000-01-06 18:14 UTC), in a 29.53-day month. + let moonAge = ((now - 947182440) / 86400 % 29.530589 + 29.530589) % 29.530589 + let moonLit = round((1 - cos(moonAge / 29.530589 * 6.2831853)) / 2 * 100) + let moonPhase = ["New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous", "Full Moon", "Waning Gibbous", "Last Quarter", "Waning Crescent"][int(floor(moonAge / 29.530589 * 8 + 0.5)) % 8] + let moonIcons = { + "New Moon": "", "Waxing Crescent": "", "First Quarter": "", "Waxing Gibbous": "", + "Full Moon": "", "Waning Gibbous": "", "Last Quarter": "", "Waning Crescent": "" + } + let uv = cur.uv + + onTap: screen() + + component Rule() { + Spacer { height: 1; fill: width; background: alpha(muted, 0.25) } + } + + component Stat(glyph, label, value, tint = foreground) { + Row { + gap: 10 + align: center + padding: [10, 8] + border: 1 + borderColor: alpha(muted, 0.3) + Text { text: glyph; font: icon; fontSize: 22; color: tint; width: 28; align: center } + Column { + gap: 0 + weight: 1 + Text { text: label; style: label; color: muted; maxLines: 1 } + Text { text: value; style: body; maxLines: 1 } + } + } + } + + Column { + gap: 0 + Row { + gap: 10 + align: center + Text { text: fmtTime(now, "d"); style: huge; width: 60 } + Column { + gap: 0 + weight: 1 + Text { text: lower(fmtTime(now, "EEEE")); style: label; color: accent; maxLines: 1 } + Text { text: lower(fmtTime(now, "MMMM yyyy")); style: small; color: muted; maxLines: 1 } + } + } + Spacer { weight: 1 } + Spacer { height: 1; fill: width; background: alpha(muted, 0.25) } + Spacer { height: 8 } + if cur != null { + Row { + gap: 6 + align: bottom + Text { text: weatherIcon(cur.code, night); font: icon; fontSize: 32; color: sky; width: 26; padding: [0, 0, 0, 3] } + Text { text: "${cur.temp}°"; fontSize: 28; color: cyan; width: 68; maxLines: 1 } + Column { + gap: 0 + weight: 1 + Text { text: cur.desc; style: small; align: end; maxLines: 1 } + Text { text: "↑${day.hi}° ↓${day.lo}°"; style: small; color: muted; align: end; maxLines: 1; padding: [0, 0, 0, 5] } + } + } + Text { text: "feels ${cur.feels}° · ${lower(placeName)}"; style: small; color: muted; maxLines: 1 } + Spacer { weight: 1 } + Spacer { height: 1; fill: width; background: alpha(muted, 0.25) } + Spacer { height: 8 } + // The next two days (icon from the noon reading), then sunrise and sunset. + Row { + gap: 4 + align: center + for d, i in drop(days, 1) key d.date { + Column { + gap: 0 + weight: 1 + align: center + Text { text: lower(fmtTime(now + 86400 * (i + 1), "EEE")); style: label; color: muted; align: center } + Text { text: weatherIcon(d.code, false); font: icon; fontSize: 18; align: center } + Text { text: "${d.hi}° ${d.lo}°"; style: small; align: center; maxLines: 1 } + } + } + Column { + gap: 4 + weight: 1.2 + Row { + gap: 4 + align: center + Text { text: ""; font: icon; fontSize: 14; color: yellow; width: 20 } + Text { text: sun[0]; style: small; maxLines: 1; weight: 1 } + } + Row { + gap: 4 + align: center + Text { text: ""; font: icon; fontSize: 14; color: orange; width: 20 } + Text { text: sun[1]; style: small; maxLines: 1; weight: 1 } + } + } + } + } else { + Text { text: problem ?? (wx == null || (named && geo == null) ? "weather…" : "weather offline"); style: small; color: muted; maxLines: 2 } + } + } + + screen { + title: "weather" + Input { + text: city + placeholder: "city · empty = your location" + onSubmit: { city = trim(value); refresh() } + } + if cur == null { + Text { text: problem ?? (wx == null || (named && geo == null) ? "weather…" : "weather offline"); style: body; color: muted } + } else { + Column { + scroll: true + gap: 14 + // Now. + Row { + gap: 16 + align: center + Text { text: weatherIcon(cur.code, night); font: icon; fontSize: 64; color: sky; width: 80; align: center } + Column { + gap: 0 + weight: 1 + Text { text: "${cur.temp}°${unit}"; fontSize: 44; color: cyan; maxLines: 1 } + Text { text: cur.desc; style: body; maxLines: 2 } + } + } + Text { + text: "feels ${cur.feels}° · ↑${day.hi}° ↓${day.lo}° · ${lower(placeName)}${countryName != "" ? ", " + lower(countryName) : ""}" + style: small + color: muted + } + Rule { } + Grid { + columns: 2 + gap: 8 + Stat { glyph: ""; label: "wind ${cur.windDir}"; value: cur.wind; tint: cyan } + Stat { glyph: ""; label: "humidity"; value: "${cur.humidity}%"; tint: blue } + Stat { glyph: ""; label: "rain today"; value: "${day.rain}% · ${cur.precip}"; tint: blue } + Stat { glyph: ""; label: "uv index"; value: "${uv} ${uv >= 8 ? "very high" : uv >= 6 ? "high" : uv >= 3 ? "moderate" : "low"}"; tint: uv >= 6 ? red : uv >= 3 ? yellow : green } + Stat { glyph: ""; label: "pressure"; value: cur.pressure } + Stat { glyph: ""; label: "visibility"; value: cur.visibility } + } + Rule { } + // The next 24 hours: time, icon and rain chance per step, with the temperature curve under them. + Text { text: "next 24 hours"; style: label; color: accent } + Column { + gap: 4 + Row { + gap: 0 + for s in steps key s.hr { + Column { + gap: 2 + weight: 1 + align: center + Text { text: s.hr == hourNow ? "now" : pad(s.hr % 24, 2, "0"); style: label; color: muted; align: center } + Text { text: weatherIcon(s.code, s.night); font: icon; fontSize: 20; align: center } + } + } + } + Canvas { + height: 84 + fill: width + let n = max(len(steps), 1) + let temps = steps.map(s => s.t) + let lo = min(temps) + let hi = max(temps) + let ys = temps.map(t => 22 + (hi - t) / max(hi - lo, 1) * 26) + let xs = range(n).map(i => (i + 0.5) * width / n) + path(range(n).map(i => [xs[i], ys[i]]), stroke: accent, width: 2) + for s, i in steps { + circle(xs[i], ys[i], 3, fill: accent) + text("${s.t}°", xs[i], ys[i] - 13, size: 12, align: center, color: foreground) + rect(xs[i] - 10, height - 12, 20, 4, radius: 2, fill: alpha(muted, 0.2)) + rect(xs[i] - 10, height - 12, 20 * s.rain / 100, 4, radius: 2, fill: blue) + text("${s.rain}%", xs[i], height - 24, size: 10, align: center, color: s.rain >= 30 ? blue : muted) + } + } + } + Rule { } + // Three days: icon, rain chance and the day's low to high on a shared scale. + Text { text: "3 days"; style: label; color: accent } + for d, i in days key d.date { + let lo = d.lo + let hi = d.hi + Row { + gap: 8 + align: center + Text { text: i == 0 ? "today" : lower(fmtTime(now + 86400 * i, "EEE")); style: body; width: 52; maxLines: 1 } + Text { text: weatherIcon(d.code, false); font: icon; fontSize: 20; width: 26; align: center } + Text { text: "${d.rain}%"; style: small; color: blue; width: 40; align: end; maxLines: 1 } + Text { text: "${lo}°"; style: small; color: muted; width: 36; align: end; maxLines: 1 } + Canvas { + height: 6 + weight: 1 + let span = max(highest - lowest, 1) + let x0 = (lo - lowest) / span * width + let x1 = (hi - lowest) / span * width + rect(0, 0, width, height, radius: 3, fill: alpha(muted, 0.2)) + rect(x0, 0, max(x1 - x0, 6), height, radius: 3, fill: linear(0, 0, width, 0, [cyan, orange])) + } + Text { text: "${hi}°"; style: small; width: 36; maxLines: 1 } + } + } + Rule { } + // Sun and moon. + Row { + gap: 8 + Stat { glyph: ""; label: "sunrise"; value: sun[0]; tint: yellow; weight: 1 } + Stat { glyph: ""; label: "sunset"; value: sun[1]; tint: orange; weight: 1 } + } + Stat { + glyph: get(moonIcons, moonPhase, "") + label: "moon" + value: "${lower(moonPhase)} · ${moonLit}% lit" + tint: foreground + } + // The source, as Open-Meteo's terms ask, and yr.no (Norwegian Meteorological Institute): ad-free and worldwide, opened at the same coordinates. + Row { + justify: end + align: center + Text { text: "weather: open-meteo.com (cc by 4.0) · moon from the date"; style: label; color: muted; weight: 1; maxLines: 2 } + Button { text: "open yr.no ↗"; color: muted; onTap: url("https://www.yr.no/en/forecast/daily-table/${lat},${lon}") } + } + } + } + } +} diff --git a/packages/omamobile-owl-widgets/overrides/ssalentin/red-panda/widget.owl b/packages/omamobile-owl-widgets/overrides/ssalentin/red-panda/widget.owl new file mode 100644 index 000000000..6829dafcb --- /dev/null +++ b/packages/omamobile-owl-widgets/overrides/ssalentin/red-panda/widget.owl @@ -0,0 +1,422 @@ +// Modified from omarchy-widgets widgets/ssalentin/red-panda/widget.owl@b63886b (MIT, Simon Schubert and contributors; see overrides/LICENSE) for Omarchy Mobile: rain from the phone's own Open-Meteo reading. +widget "red panda" { + meta { owl: 5; description: "A pixel red panda living in a tree. Pet it, tickle it, scritch it, feed it bamboo, shake its leaves; it naps draped over its branch and holds a leaf over its head when it rains (the phone's own weather reading, from Open-Meteo, CC BY 4.0)"; version: "1.1.1"; license: "MIT"; category: "fun" } + size: 3x3 + minSize: 2x2 + padding: 0 + + // A red panda in theme colors, drawn from `time` and a little state. It + // needs no shell: the clock says when it's night, and taps and drags do the + // rest. It dozes on its branch at night (22 to 7) and after five minutes + // without company; a tap then only makes it peek, a second tap wakes it. + // Awake, a tap on it is a pet, another tap right after a tickle, a drag a scritch + // behind the ears, a tap on the bamboo a meal, a tap in the leaves a shake, + // and a tap anywhere else makes it look there. When it rains where you are + // (the phone's weather reading says) it shelters under a leaf; a tap on the trunk makes it rain anyway, or never. + // + // Cheap when idle: the breath, blink, tail, stars and z's step on the 1 s clock + // (`now`), so the tile redraws once a second. The frame clock (`time`) is only + // read for a few seconds after a tap or drag, and while it rains, so the + // launcher only animates every frame then. + source now = clock every 1s + // Real rain, where the phone is: Omarchy Mobile's copy reads the phone's own weather reading + // (omamobile-weather: Open-Meteo, open-meteo.com, CC BY 4.0, at the phone's location or set city) + // instead of asking a web service by IP. No reading, or one over 3 hours old, just means no rain. + source wx = file("~/.local/state/omamobile/weather.json") json optional + + state born = 0 persist // Unix seconds of the first tap + state fed = 0 persist // Unix seconds + state pets = 0 persist + state lastTap = 0 persist // last time someone played with it + state wakeUntil = 0 persist // woken by a double tap until then + state rainMode = "auto" persist // auto (with the weather), on or off; tap the trunk to cycle + // The last tap: in Canvas `time`, in Unix seconds, where, and what it did. + state tapAt = -100 + state tapNow = 0 + state tapX = 0 + state tapY = 0 + state tapKind = "" + // Scritching: a drag, with how far it has gone sideways. + state dragAt = -100 + state dragNow = 0 + state dragX = 0 + + let hour = num(fmtTime(now, "H")) + let night = hour != null && (hour >= 22 || hour < 7) // not night while the clock is still loading + let idle = now - lastTap > 5 * 60 + let asleep = (night || idle) && now >= wakeUntil + let hungry = fed > 0 && now - fed > 6 * 3600 + let day = born > 0 ? floor((now - born) / 86400) + 1 : 1 + let sky = wx != null && now - num(wx.at, 0) / 1000 < 3 * 3600 ? lower(wx.text ?? "") : "" + let realRain = contains(sky, "rain") || contains(sky, "drizzle") || contains(sky, "shower") || contains(sky, "sleet") + let raining = rainMode == "on" || rainMode == "auto" && realRain + + // Geometry from the tile's size, so the tap handler knows what was tapped. + // One art pixel, in dp: the tree, the panda and its tail, and the bamboo. + let W = tileWidth ?? 300 + let H = tileHeight ?? 300 + let p = clamp(floor(min(W / 30, H / 27)), 2, 9) + let s = p + 0.5 + let textH = 16 + // The branch stays near the canopy in a tall tile; the trunk just goes on below it. + let branchY = floor(min(H - textH - 6 * p, 27 * p) / p) * p + let bx = floor((W / 2 - 9 * p) / p) * p // the panda's left edge + let by = branchY - 16 * p // its top, feet on the branch + let bambooX = W - 6 * p + + // Sprites: one letter per art pixel, "." is empty, colored by a palette. + // Sitting up and looking at you. Eyes are drawn on, so they can move. + let pandaArt = [ + ".rrr........rrr.", + "rwwrr......rrwwr", + "rwwwrrrrrrrrwwwr", + ".rrrrrrrrrrrrrr.", + ".rrwwwrrrrwwwrr.", + ".rwwwwwrrwwwwwr.", + ".rwwwwwwrwwwwwwr", + ".rwrwwwrrrwwwrwr", + ".rwwwwwrkkrwwwwr", + "..rwwwwwwwwwwwr.", + "...rwwwwwwwwwr..", + "....ddddddddd...", + "...ddddddddddd..", + "..ddddddddddddd.", + "..ddddddddddddd.", + "..ff.ff...ff.ff." + ] + // The tail, ringed, curling up beside the body. + let tailArt = [ + ".rrr.", + "rrrrr", + "rtttr", + "rrrrr", + "tttrr", + "rrrr.", + "rttr.", + "rrr.." + ] + // Asleep: draped over the branch, head on its paws. The part above the branch... + let dozeArt = [ + ".rr.............", + "rwrrrrrrrrrr....", + "rrrrrrrrrrrrrr..", + "rwwrrrrrrrrrrrr.", + "rwwwwrrrrrrrrrrr", + "rwwwwrrrrrrrrrrr", + ".rrwrrrrrrrrrrr." + ] + // ...and the legs and tail hanging down in front of it. + let dangleArt = [ + "..dd..dd....dd.rr", + "..dd..dd....dd.tt", + "...............rr", + "...............tt", + "...............rr", + "...............tt", + "................r" + ] + let heartArt = [".h.h.", "hhhhh", "hhhhh", ".hhh.", "..h.."] + let bambooArt = ["gg", "gg", "GG", "gg", "gg", "GG", "gg", "gg"] + let leafArt = ["lll", "lLl", "lll"] + // A big leaf, held up as an umbrella. + let brollyArt = [ + "...llllll...", + ".llLLLLLLll.", + "lLLLLLLLLLLl", + "......s....." + ] + + // The fur keeps its own colors, whatever the theme: a grey red panda is just a raccoon. + let rust = #c75a1e + let cream = #f6ead6 + let dark = #3a2316 + let ink = #1a1008 + let leaf = mix(green, background, 0.2) + let leafLight = mix(green, foreground, 0.25) + let leafDark = mix(green, background, 0.45) + let bark = mix(orange, background, 0.6) + let barkDark = mix(orange, background, 0.75) + let pal = { + r: rust, w: cream, d: dark, f: dark, k: ink, t: #e8b57c, + h: #e8506a, g: leaf, G: leafDark, l: leafLight, L: leaf, s: leafDark + } + let bodyPal = {r: rust, w: cream, d: dark, k: ink, t: pal.t} + let feetPal = {f: dark} + + Canvas { + onTap: { + // What this tap does, decided before any state changes. + tapKind = x < 4 * p ? "rain" + : asleep ? (now - tapNow <= 3 && tapKind == "peek" ? "wake" : "peek") + : x >= bx - p && x < bx + 20 * p && y >= by - 2 * p && y <= branchY + p ? (now - tapNow <= 2 && (tapKind == "pet" || tapKind == "tickle") ? "tickle" : "pet") + : x >= bambooX - 2 * p && y >= branchY - 12 * p ? "feed" + : y < by + 4 * p ? "shake" : "look" + pets = tapKind == "pet" || tapKind == "tickle" ? pets + 1 : pets + fed = tapKind == "feed" ? now : fed + wakeUntil = tapKind == "wake" ? now + 120 : wakeUntil + rainMode = tapKind != "rain" ? rainMode : rainMode == "auto" ? "on" : rainMode == "on" ? "off" : "auto" + lastTap = tapKind == "peek" || tapKind == "rain" ? lastTap : now + born = born > 0 ? born : now + tapAt = time + tapNow = now + tapX = x + tapY = y + } + onDrag: { + dragX = clamp((time - dragAt < 0.5 ? dragX : 0) + dx, -60, 60) + dragAt = time + dragNow = now + lastTap = asleep ? lastTap : now + } + + // Seconds since the last tap. The wall clock is checked first, so `time` is + // only read while a tap is fresh; and since `time` restarts with the frame + // clock (say, after the page was off screen), an old tap could look recent + // again, so the wall clock has the final say. + let since = now - tapNow < 6 && time >= tapAt ? time - tapAt : 1000 + let scritch = !asleep && now - dragNow < 3 && time >= dragAt && time - dragAt < 0.7 ? 1 - max(time - dragAt - 0.3, 0) / 0.4 : 0 + + // Night sky: a crescent moon and a few twinkling stars. + if night { + for c in range(25) { + let i = c % 5 - 2 + let j = floor(c / 5) - 2 + if i * i + j * j <= 5 && (i + 1) * (i + 1) + (j + 1) * (j + 1) > 4 { + rect(W - 8 * p + i * p, 9 * p + j * p, s, s, fill: yellow) + } + } + for k in range(5) { + let sx = floor(W * (0.2 + 0.15 * k) / p) * p + let sy = (7 + (k * 7) % 5) * p + rect(sx, sy, p, p, fill: alpha(foreground, 0.3 + 0.5 * abs(sin(now * 0.8 + k * 1.9)))) + } + } + + // The tree: a trunk up the left edge, a branch across, leaves along the top. + rect(0, 0, 4 * p, H - textH, fill: bark) + rect(p, 0, p, H - textH, fill: barkDark) + rect(3 * p, 0, p, H - textH, fill: mix(bark, foreground, 0.1)) + rect(0, branchY, W - 4 * p, 2 * p, fill: bark) + rect(0, branchY + p, W - 4 * p, p, fill: barkDark) + rect(W - 4 * p, branchY, 2 * p, p, fill: bark) + // Leaf clusters, placed by a little arithmetic so they look scattered. + for k in range(14) { + let lx = floor((W * ((k * 37) % 23) / 23) / p) * p + let ly = ((k * 5) % 4) * p - p + let big = k % 3 == 0 + rect(lx, ly, (big ? 4 : 3) * p, (big ? 3 : 2) * p, radius: p, fill: k % 2 == 0 ? leaf : leafDark) + rect(lx + p, ly, p, p, fill: leafLight) + } + // A few leaves hanging from the branch. + for k in range(4) { + let lx = floor((W * (0.15 + 0.2 * k)) / p) * p + rect(lx, branchY + 2 * p, 2 * p, p, fill: k % 2 == 0 ? leaf : leafDark) + } + + // Bamboo growing in the bottom-right corner, swaying a little. + let sway = round(sin(now * 0.9)) * p + sprite(bambooArt, bambooX + 2 * p, H - textH - 8 * p, p, palette: pal) + rect(bambooX + sway, H - textH - 9 * p, 3 * p, p, radius: p, fill: leafLight) + rect(bambooX + 4 * p - sway, H - textH - 7 * p, 3 * p, p, radius: p, fill: leaf) + rect(bambooX + 4 * p + sway, H - textH - 5 * p, 2 * p, p, radius: p, fill: leafLight) + + // Falling leaves after a shake. + if tapKind == "shake" && since < 2.4 { + for k in range(7) { + let t = since - k * 0.12 + if t > 0 && t < 2 { + let lx = floor((W * (0.12 + 0.13 * k) + sin(t * 5 + k) * 2 * p) / p) * p + let ly = floor((2 * p + t * t * 16 * p + t * 10 * p) / p) * p + layer(1 - t / 2) { sprite(leafArt, lx, min(ly, H - textH - 3 * p), p, palette: k % 2 == 0 ? {l: leaf, L: leafLight} : {l: leafDark, L: leaf}) } + } + } + } + + // Rain: streaks falling in their own columns, and splashes on the branch. + if raining { + let wet = alpha(mix(blue, foreground, 0.3), 0.55) + for k in range(26) { + let t = (time * (1.1 + (k % 3) * 0.25) + k * 0.37) % 1 + let rx = floor(W * ((k * 53) % 29) / 29 / p) * p + rect(rx, floor(t * (H - textH) / p) * p, s, 3 * p, fill: wet) + } + for k in range(7) { + let rx = floor(W * ((k * 31) % 17) / 17 / p) * p + if (time * 2.5 + k * 0.6) % 1 < 0.3 { rect(rx, branchY - p, p, p, fill: alpha(foreground, 0.5)) } + } + } + + if asleep { + // Draped over the branch. The body breathes; the legs swing gently. + let breath = (floor(now / 2) % 2) * p + let swing = (floor(now / 3) % 2) * p + let dx = floor((W / 2 - 8 * p) / p) * p + let peek = tapKind == "peek" && since < 2.5 + sprite(dozeArt, dx, branchY - 7 * p + breath, p, palette: bodyPal) + sprite(dangleArt, dx + swing, branchY, p, palette: bodyPal) + if raining { sprite(brollyArt.take(3), dx + 4 * p, branchY - 9 * p + breath, p, palette: pal) } + // The ear, drawn on top so the breath doesn't leave it behind. + if peek { + // One eye opens a crack, then it dozes off again. + let open = since < 1.8 ? 2 : 1 + rect(dx + 2 * p, branchY - 3 * p + breath, s, open * p, fill: ink) + } else { + rect(dx + 2 * p, branchY - 3 * p + breath, 2 * p, s, fill: ink) + } + if !peek { + for k in range(3) { + let t = ((now + k * 2) % 6) / 6 + text("z", dx + 6 * p + t * 4 * p, branchY - 9 * p - t * 8 * p, size: (2 + t * 2) * p, bold: true, color: alpha(foreground, 1 - t)) + } + } + } else { + let petting = since < 2.5 && tapKind == "pet" + let tickling = since < 2.2 && tapKind == "tickle" + let eating = since < 2.6 && tapKind == "feed" + let startled = since < 1.6 && tapKind == "shake" + let looking = since < 2.5 && tapKind == "look" + let waking = since < 2.2 && tapKind == "wake" + let chomping = eating && since > 0.7 + let happy = petting || scritch > 0 || chomping + // A hop when petted; otherwise a one-pixel breath. Feet stay on the branch. + let hop = petting ? round(abs(sin(since * 7)) * 2 * max(1.4 - since, 0)) * p : 0 + let breath = (now % 2) * p + // Tickled, it wriggles side to side; scritched, it leans into the hand. Whole pixels, so no seams. + let shimmy = tickling ? [0, 1, 0, -1][floor(since * 12) % 4] * p : scritch > 0 ? sign(dragX) * p : 0 + let bodyX = bx + shimmy + let bodyY = by - hop + + // The tail tip flicks, faster when it's pleased. + let flick = (petting || scritch > 0 ? [0, 1, 1, 0, -1, -1][floor(since * 10) % 6] : [0, 1, 1, 0, -1, -1][now % 6]) * p + sprite(tailArt.take(4), bodyX + 14 * p + flick, bodyY + 8 * p + breath, p, palette: pal) + sprite(tailArt.drop(4), bodyX + 14 * p, bodyY + 12 * p + breath, p, palette: pal) + if raining { + sprite(brollyArt, bodyX + 2 * p, bodyY - 4 * p + breath, p, palette: pal) + rect(bodyX + 8 * p, bodyY + breath, p, 11 * p, fill: leafDark) + } + sprite(pandaArt, bodyX, bodyY + breath, p, palette: bodyPal) + sprite(pandaArt, bodyX, bodyY, p, palette: feetPal) + // An ear twitches now and then. + if now % 7 == 0 { rect(bodyX + 12 * p, bodyY + breath - p, 3 * p, p, fill: rust) } + + // Eyes, in the white patches: columns 3-5 and 10-12, rows 5-6. + let ey = bodyY + breath + let blink = now % 7 == 3 + if waking { + // A yawn: eyes squeezed shut, mouth wide open. + for e in [3, 10] { rect(bodyX + e * p, ey + 6 * p, 3 * p, s, fill: ink) } + rect(bodyX + 7 * p, ey + 9 * p, 2 * p, 2 * p, radius: p, fill: ink) + } else if tickling { + // Squeezed shut (x x) and giggling. + for e in [3, 10] { + rect(bodyX + e * p, ey + 5 * p, s, s, fill: ink) + rect(bodyX + (e + 2) * p, ey + 5 * p, s, s, fill: ink) + rect(bodyX + (e + 1) * p, ey + 6 * p, s, s, fill: ink) + rect(bodyX + e * p, ey + 7 * p, s, s, fill: ink) + rect(bodyX + (e + 2) * p, ey + 7 * p, s, s, fill: ink) + } + if floor(since * 8) % 2 == 0 { rect(bodyX + 7 * p, ey + 9 * p, 2 * p, s, fill: ink) } + } else if happy { + // Content: eyes closed in two little arcs, cheeks blushing. + for e in [3, 10] { + rect(bodyX + e * p, ey + 6 * p, s, s, fill: ink) + rect(bodyX + (e + 1) * p, ey + 5 * p, s, s, fill: ink) + rect(bodyX + (e + 2) * p, ey + 6 * p, s, s, fill: ink) + } + rect(bodyX + 2 * p, ey + 8 * p, 2 * p, p, fill: alpha(#ff7a88, 0.5)) + rect(bodyX + 12 * p, ey + 8 * p, 2 * p, p, fill: alpha(#ff7a88, 0.5)) + } else if startled { + // Wide eyes and a start. + for e in [3, 10] { + rect(bodyX + e * p, ey + 4 * p, 3 * p, 3 * p, fill: ink) + rect(bodyX + (e + 1) * p, ey + 5 * p, s, s, fill: cream) + } + text("!", bodyX + 8 * p, bodyY - 3 * p, size: 4 * p, bold: true, color: #ffd45a, align: center) + } else if blink { + for e in [3, 10] { rect(bodyX + e * p, ey + 6 * p, 3 * p, s, fill: ink) } + } else { + // Looking around, or at the last tap, or up at a bamboo thought. + let lx = looking ? sign(tapX - (bodyX + 8 * p)) : hungry ? 1 : [0, 1, 0, -1][floor(now / 3) % 4] + let ly = looking ? (tapY < ey + 5 * p ? -1 : tapY > ey + 12 * p ? 1 : 0) : hungry ? -1 : 0 + for e in [3, 10] { + rect(bodyX + (e + (lx + 1) / 2) * p, ey + (5 + (ly + 1) / 2) * p, 2 * p, 2 * p, fill: ink) + rect(bodyX + (e + (lx + 1) / 2 + 1) * p, ey + (5 + (ly + 1) / 2) * p, s, s, fill: alpha(cream, 0.7)) + } + } + + // Munching bamboo: the mouth opens and shuts, bits fall. + if chomping { + if floor(since * 6) % 2 == 0 { rect(bodyX + 7 * p, ey + 9 * p, 2 * p, s, fill: ink) } + rect(bodyX + 6 * p, ey + 9 * p, p, 4 * p, fill: leaf) + rect(bodyX + 5 * p, ey + 12 * p, 3 * p, p, fill: dark) + for k in range(3) { + let f = since - 0.7 + rect(bodyX + (6 + k * 2) * p + (k - 1) * f * 6 * p, ey + 10 * p + f * f * 20 * p, p, p, fill: leafLight) + } + } + + // A stalk flies over from the bamboo and lands in its paws. + if eating && since <= 0.7 { + let t = since / 0.7 + let fx = lerp(bambooX + 2 * p, bx + 4 * p, t) + let fy = lerp(H - textH - 8 * p, by + 8 * p, t) - sin(rad(t * 180)) * 6 * p + rect(fx, fy, p, 4 * p, fill: leaf) + } + + // Hearts float up when petted. + if petting { + for k in range(3) { + let t = since - k * 0.35 + if t > 0 && t < 1.8 { + layer(1 - t / 1.8) { + sprite(heartArt, floor((bx + [-2, 6, 13][k] * p + sin(t * 5 + k) * p) / p) * p, floor((by - t * 6 * p) / p) * p, p, palette: pal) + } + } + } + } + // Giggles when tickled. + if tickling { + for k in range(2) { + let t = (since * 0.7 + k / 2) % 1 + text("hihi", bx + (k == 0 ? -2 : 15) * p, by + 4 * p - t * 6 * p, size: 2 * p, bold: true, color: alpha(foreground, 1 - t)) + } + } + // Sparkles while it's scritched. + if scritch > 0 { + for k in range(4) { + let t = (time * 1.5 + k / 4) % 1 + let ang = k * 90 + time * 60 + rect(floor((bx + 8 * p + cos(rad(ang)) * 10 * p) / p) * p, floor((by + 5 * p + sin(rad(ang)) * 7 * p) / p) * p, p, p, fill: alpha(#ffd45a, (1 - t) * scritch)) + } + } + // Wondering what that was. + if looking { + text("?", bx + 8 * p, by - 3 * p, size: 3 * p, bold: true, color: alpha(foreground, 1 - since / 2.5), align: center) + } + // Hungry: a thought bubble with bamboo. + if hungry && !eating { + let cloud = mix(background, foreground, 0.22) + let tx = bx + 16 * p + let ty = by + rect(tx - p, ty + 6 * p, p, p, fill: cloud) + rect(tx, ty + 5 * p, p, p, fill: cloud) + rect(tx + p, ty - 3 * p, 5 * p, 7 * p, radius: p, fill: cloud) + sprite(bambooArt.take(5), tx + 3 * p, ty - 2 * p, p, palette: {g: leafLight, G: leaf}) + } + } + + // What it's up to, along the bottom. + let status = since < 2.5 && tapKind == "rain" ? "rain ${rainMode == "auto" ? "with the weather" : rainMode}" + : asleep ? (night ? "zzz · asleep in the tree" : "napping · tap twice to wake") + : since < 2.5 && tapKind == "pet" ? "happy · ♥︎${pets}" + : since < 2.5 && tapKind == "tickle" ? "hihihi" + : since < 2.5 && tapKind == "feed" ? "nom nom bamboo" + : since < 2.5 && tapKind == "shake" ? "who shook the tree?!" + : since < 2.5 && tapKind == "wake" ? "yawn… good morning" + : scritch > 0 ? "scritches · bliss" + : hungry ? "hungry · tap the bamboo" + : raining ? "day ${day} · ♥︎${pets} · rain" + : "day ${day} · ♥︎${pets}" + text(status, W / 2, H - textH / 2, size: 11, align: center, color: muted) + } +} diff --git a/packages/omamobile-owl-widgets/test/all b/packages/omamobile-owl-widgets/test/all index 6a9066105..5f39ce6f2 100755 --- a/packages/omamobile-owl-widgets/test/all +++ b/packages/omamobile-owl-widgets/test/all @@ -45,6 +45,29 @@ echo "// changed" >> "$tmp/changed/widgets/alice/hello/widget.owl" if ./install "$tmp/root2" "$tmp/changed" test/fake-store/index.json 2>/dev/null; then fail "a file that doesn't match the index is refused"; fi pass "a file that doesn't match the index is refused" +# Our own copies (overrides/): each one is in the index with its own sha256, +# and install ships it in place of the store's file. +python3 - <<'PY' || fail "every override is indexed as our copy" +import hashlib, json, os +idx = {w["id"]: w for w in json.load(open("index.json"))["widgets"]} +for author in sorted(a for a in os.listdir("overrides") if os.path.isdir(os.path.join("overrides", a))): + for name in sorted(os.listdir(os.path.join("overrides", author))): + wid, f = author + "/" + name, os.path.join("overrides", author, name, "widget.owl") + assert wid in idx and idx[wid]["status"] in ("ok", "partial"), wid + assert idx[wid]["sha256"] == hashlib.sha256(open(f, "rb").read()).hexdigest(), wid + " (node update-index.js > index.json)" + assert not any("wttr" in c for c in idx[wid]["commands"]) and "wttr.in" not in idx[wid]["hosts"], wid +PY +mkdir -p "$tmp/ostore/widgets/simonschubert/today" +echo 'widget "the store'"'"'s" { Text { text: "x" } }' > "$tmp/ostore/widgets/simonschubert/today/widget.owl" +cp test/fake-store/LICENSE "$tmp/ostore/" +python3 -c ' +import json, sys +w = [x for x in json.load(open("index.json"))["widgets"] if x["id"] == "simonschubert/today"] +json.dump({"version": 1, "widgets": w}, open(sys.argv[1], "w"))' "$tmp/oindex.json" +./install "$tmp/oroot" "$tmp/ostore" "$tmp/oindex.json" || fail "install ships an override" +cmp -s overrides/simonschubert/today/widget.owl "$tmp/oroot/usr/share/omamobile/owl-widgets/widgets/simonschubert/today/widget.owl" || fail "install ships our copy, not the store's" +pass "our copies are indexed and ship in place of the store's" + # Beside omamobile-shell (the repository): the committed indexes are what # its compiler builds now, and every built-in of the home screen ships. shell=../omamobile-shell/plugins/omamobile.home @@ -56,6 +79,8 @@ const H = require(process.argv[1]); const st = require(process.argv[2]).widgets const missing = H.OWL_ORDER.map(H.owlStoreId).filter((id) => !st[id] || !["ok", "partial"].includes(st[id].status)) if (missing.length) { console.error(missing.join(" ")); process.exit(1) }' "$(realpath "$shell/HomeModel.js")" "$(realpath status.json)" || fail "every built-in ships" pass "the fake store's index is current, and every OWL built-in of the home screen ships" + node test/open-meteo.js ../omamobile-shell/test >/dev/null || { node test/open-meteo.js ../omamobile-shell/test | grep -v '^ok'; fail "our weather copies against made-up Open-Meteo answers"; } + pass "our weather copies parse, use Open-Meteo and map its answers" else pass "beside omamobile-shell # SKIP built on its own" fi diff --git a/packages/omamobile-owl-widgets/test/open-meteo.js b/packages/omamobile-owl-widgets/test/open-meteo.js new file mode 100644 index 000000000..5cf3184fc --- /dev/null +++ b/packages/omamobile-owl-widgets/test/open-meteo.js @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: MIT +// Our copies of the store's weather widgets (overrides/) against made-up +// Open-Meteo answers, with omamobile-shell's OWL runtime: each compiles, +// talks only to Open-Meteo's hosts (and its own extra services), builds the +// URLs we expect from a typed city or the phone's "lat,lon", maps the JSON +// to what it draws (WMO codes to words, units, the place), and says +// "set a city or turn on Location" with neither. Nothing reaches the network. +// +// node test/open-meteo.js +"use strict" +const fs = require("fs"), path = require("path") +const { load } = require(path.resolve(process.argv[2], "owl-load.js")) +const V = load("values.js"), C = load("compiler.js"), R = load("runtime.js"), P = load("phone.js"), B = load("builtins.js") +const here = path.resolve(__dirname, "..") + +let failures = 0 +function check(ok, what) { + if (ok) console.log("ok - " + what) + else { console.log("not ok - " + what); failures++ } +} + +const T = 1793620800 // 2026-11-02 12:00 UTC, made up +process.env.TZ = "UTC" + +// A widget with state and source values set as the phone would: the texts +// it shows (tile and screen) and the URLs its sources would fetch now. +function run(id, state, sources) { + B.setFirstDayOfWeek(0) + const program = C.compile(fs.readFileSync(path.join(here, "overrides", id, "widget.owl"), "utf8")) + const host = { theme: () => 0xff808080, tile: (n) => ({ cols: 4, rows: 4, tileWidth: 300, tileHeight: 300, screenWidth: 480, screenHeight: 1000 })[n] ?? null, + act() {}, runInto() {}, report() {}, changed() {} } + const inst = new R.Instance(program, host, {}) + inst.time = 0 + program.globals.forEach((g, slot) => { + if (g.type === "source" && g.kind === "clock") inst.values[slot] = T + if (g.type === "state" && state && g.name in state) inst.values[slot] = V.fromPlain(state[g.name]) + if (g.type === "source" && sources && g.name in sources) inst.values[slot] = V.fromPlain(sources[g.name]) + }) + inst.invalidate() + const texts = [] + const walk = (items, env) => items.forEach((n) => { + if (n.t === "lets") return walk(n.children, env.withLets(n.values)) + if (n.t === "if") { let c = false; try { c = V.truthy(C.evaluate(n.cond, env)) } catch (e) {} return walk(c ? n.then : n.otherwise, env) } + if (n.t === "for") { let l = []; try { l = V.listOf(C.evaluate(n.list, env)) } catch (e) {} return l.forEach((it, i) => walk(n.body, env.inner([it, i]))) } + if (n.t === "use") { + const args = n.args.map((a) => { try { return C.evaluate(a, env) } catch (e) { return null } }) + return walk(n.body, new C.Env(env.ctx, new C.Env(env.ctx, null, []), args)) + } + if (n.t === "el") { + if (n.kind === "Text" && n.props.text) { try { texts.push(V.display(C.evaluate(n.props.text, env))) } catch (e) { texts.push("ERROR " + C.messageOf(e)) } } + if (n.kind !== "Canvas") walk(n.children || [], env) + } + }) + walk(program.root, inst.env) + if (program.screen) walk(program.screen, inst.env) + const urls = {} + inst.sources().forEach((s) => { if (s.kind === "http") urls[s.name] = s.arg() }) + const value = (name) => V.toPlain(inst.read(program.globals.findIndex((g) => g && g.name === name))) + return { texts, all: texts.join(" | "), urls, caps: P.capabilities(program), program, value } +} + +const ok = (out) => ({ ok: true, code: 200, out, err: "" }) + +// Made-up answers, in Open-Meteo's shapes. +const geocode = { results: [ + { name: "Sample Town", latitude: 40.123456, longitude: -77.654321, country: "United States", country_code: "US", admin1: "Pennsylvania" }, + { name: "Sample Town", latitude: 51.5, longitude: -0.12, country: "United Kingdom", country_code: "GB", admin1: "England" }] } +const hours = Array.from({ length: 72 }, (_, i) => T - 12 * 3600 + i * 3600) +const forecast = { + current: { time: T, temperature_2m: 14.4, apparent_temperature: 12.2, relative_humidity_2m: 70, is_day: 1, weather_code: 2, + precipitation: 0.2, pressure_msl: 1016.3, wind_speed_10m: 11.2, wind_direction_10m: 270 }, + hourly: { time: hours, temperature_2m: hours.map((t, i) => 9 + (i % 24) / 3), precipitation_probability: hours.map(() => 10), + weather_code: hours.map((t, i) => i % 2 ? 61 : 0), is_day: hours.map((t, i) => (i % 24) >= 7 && (i % 24) < 18 ? 1 : 0), + uv_index: hours.map(() => 3.4), visibility: hours.map(() => 24140) }, + daily: { time: [T - 12 * 3600, T + 12 * 3600, T + 36 * 3600], weather_code: [2, 61, 71], temperature_2m_max: [16.2, 15, 14], temperature_2m_min: [8.6, 8, 7], + sunrise: [T - 5 * 3600, T + 19 * 3600, T + 43 * 3600], sunset: [T + 5 * 3600, T + 29 * 3600, T + 53 * 3600], + precipitation_probability_max: [20, 80, 60], precipitation_sum: [0.2, 6, 3] } +} +const air = { current: { european_aqi: 32, us_aqi: 41, pm2_5: 6.1, pm10: 11, ozone: 60, nitrogen_dioxide: 9, uv_index: 2 }, + hourly: { time: hours, european_aqi: hours.map(() => 30), us_aqi: hours.map(() => 40), birch_pollen: hours.map(() => 0), + alder_pollen: hours.map(() => 0), grass_pollen: hours.map(() => 25), mugwort_pollen: hours.map(() => 0), + olive_pollen: hours.map(() => 0), ragweed_pollen: hours.map(() => 0) } } + +// The hosts each copy may name: Open-Meteo's, and the services the widget is about. +const OM_HOSTS = ["geocoding-api.open-meteo.com", "api.open-meteo.com", "air-quality-api.open-meteo.com", "opensky-network.org"] +const widgets = fs.readdirSync(path.join(here, "overrides")).filter((a) => fs.statSync(path.join(here, "overrides", a)).isDirectory()) + .flatMap((a) => fs.readdirSync(path.join(here, "overrides", a)).map((n) => a + "/" + n)) +for (const id of widgets) + check(fs.readFileSync(path.join(here, "overrides", id, "widget.owl"), "utf8").startsWith("// Modified from omarchy-widgets widgets/" + id + "/widget.owl@"), id + " says what it was modified from") +check(/Simon Schubert and contributors/.test(fs.readFileSync(path.join(here, "overrides", "LICENSE"), "utf8")), "overrides/ carries the store's licence") +for (const id of widgets) { + const r = run(id, {}, {}) + const text = fs.readFileSync(path.join(here, "overrides", id, "widget.owl"), "utf8") + check(!/wttr\.in/.test(text) && r.caps.hosts.every((h) => OM_HOSTS.includes(h)), id + " doesn't use wttr.in: " + r.caps.hosts.join(", ")) +} + +// today: a typed city, the US result picked by its region, °F. +{ + const id = "simonschubert/today" + let r = run(id, { city: "Sample Town, Pennsylvania" }, {}) + check(/geocoding-api\.open-meteo\.com\/v1\/search\?count=10&format=json&name=Sample%20Town$/.test(r.urls.geo), "today looks the town up: " + r.urls.geo) + check(!/latitude=-?[0-9]/.test(r.urls.wx), "today's forecast waits for the place: " + r.urls.wx.slice(0, 80)) + r = run(id, { city: "Sample Town, Pennsylvania" }, { geo: ok(geocode), wx: ok(forecast) }) + check(/^https:\/\/api\.open-meteo\.com\/v1\/forecast\?latitude=40\.12&longitude=-77\.65&/.test(r.urls.wx) && /temperature_unit=fahrenheit/.test(r.urls.wx) + && /wind_speed_unit=mph/.test(r.urls.wx), "today asks for the found place, rounded, in °F: " + r.urls.wx) + check(r.texts.includes("14°") && r.texts.includes("partly cloudy") && r.all.includes("sample town, united states"), "today shows the reading, the words and the place") + check(r.all.includes("wind w") && r.all.includes("70%") && r.all.includes("1016 hPa") === false && r.all.includes("30.01 inHg"), "today maps wind, humidity and pressure in imperial units") + // Metric answer read with imperial units would be wrong; Open-Meteo answers visibility in feet with precipitation_unit=inch. + const feet = JSON.parse(JSON.stringify(forecast)); feet.hourly_units = { visibility: "ft" }; feet.hourly.visibility = feet.hourly.visibility.map(() => 132000) + r = run(id, { city: "Sample Town, Pennsylvania" }, { geo: ok(geocode), wx: ok(feet) }) + check(r.all.includes("25 mi"), "today reads visibility in feet as miles: " + r.texts.filter((t) => / mi$/.test(t)).join()) + const metres = JSON.parse(JSON.stringify(forecast)); metres.hourly_units = { visibility: "m" } + r = run(id, { city: "Sample Town, England" }, { geo: ok(geocode), wx: ok(metres) }) + check(r.all.includes("24 km"), "today reads visibility in metres as kilometres") + check(r.all.includes("80%") && r.all.includes("60%"), "today's days get their rain chances") + check(r.all.includes("open-meteo.com (cc by 4.0)"), "today credits Open-Meteo") + check(/% lit/.test(r.all) && !/ERROR/.test(r.all), "today works out the moon from the date, without errors") + // The same city in Britain, and the phone's own unit winning. + r = run(id, { city: "Sample Town, England" }, { geo: ok(geocode), wx: ok(forecast) }) + check(/latitude=51\.5&longitude=-0\.12/.test(r.urls.wx) && /temperature_unit=celsius/.test(r.urls.wx), "today picks the result by region, in °C") + r = run(id, { city: "Sample Town, England", phoneUnit: "F" }, { geo: ok(geocode), wx: ok(forecast) }) + check(/temperature_unit=fahrenheit/.test(r.urls.wx), "today follows the phone's unit") + // The phone's location: straight in, no lookup. + r = run(id, { city: "40.79,-77.86", phoneUnit: "C" }, { wx: ok(forecast) }) + check(/name=$/.test(r.urls.geo) && /latitude=40\.79&longitude=-77\.86&/.test(r.urls.wx), "today takes the phone's lat,lon straight in") + check(r.all.includes("your location"), "today names the phone's location") + // Nothing to go on. + r = run(id, { city: "" }, {}) + check(r.all.includes("set a city or turn on Location"), "today asks for a city or Location without either") + r = run(id, { city: "Nowhere" }, { geo: ok({}) }) + check(r.all.includes("city not found"), "today says a city wasn't found") +} + +// "Town, Region" picks as omamobile-weather's pick_place does (the lock screen reads Today's city): +// each part after a comma, a US state code read as its state, else the first result. +{ + const springfield = { results: [ + { name: "Springfield", latitude: 37.215, longitude: -93.298, country: "United States", country_code: "US", admin1: "Missouri", admin2: "Greene" }, + { name: "Springfield", latitude: 39.802, longitude: -89.644, country: "United States", country_code: "US", admin1: "Illinois", admin2: "Sangamon" }, + { name: "Springfield", latitude: 44.046, longitude: -123.022, country: "United States", country_code: "US", admin1: "Oregon", admin2: "Lane" }] } + const picks = [["Springfield, IL", "39.8"], ["Springfield, Illinois", "39.8"], ["Springfield, OR, US", "37.22"], ["Springfield, Lane", "44.05"], + ["Springfield, US", "37.22"], ["Springfield", "37.22"], ["Springfield, Nowhere", "37.22"]] + const urlOf = { "simonschubert/today": "wx", "simonschubert/forecast": "w", "simonschubert/sun-and-moon": "sun", + "simonschubert/air-and-pollen": "air", "simonschubert/planes-overhead": null } + for (const id of Object.keys(urlOf)) { + const wrong = picks.filter(([city, lat]) => { + const r = run(id, { city, phoneUnit: "C" }, { geo: ok(springfield) }) + return urlOf[id] ? !new RegExp("latitude=" + lat.replace(".", "\\.") + "&").test(r.urls[urlOf[id]]) : Math.abs(r.value("lat") - Number(lat)) > 0.01 + }) + check(!wrong.length, id + " picks the place as the lock screen does" + (wrong.length ? ": wrong for " + wrong.map((w) => w[0]).join("; ") : "")) + } + // The same answers from omamobile-weather's own pick_place, when python3 and the shell are beside this package. + const weather = path.resolve(here, "../omamobile-shell/bin/omamobile-weather") + if (fs.existsSync(weather)) { + const py = "import importlib.machinery, importlib.util, json, sys\n" + + "l = importlib.machinery.SourceFileLoader('w', sys.argv[1]); s = importlib.util.spec_from_loader('w', l); w = importlib.util.module_from_spec(s); l.exec_module(w)\n" + + "print(json.dumps([round(w.pick_place(c, json.loads(sys.argv[2]))['latitude'], 2) for c in json.loads(sys.argv[3])]))" + const out = require("child_process").execFileSync("python3", ["-B", "-c", py, weather, JSON.stringify(springfield), JSON.stringify(picks.map((p) => p[0]))], { encoding: "utf8" }) + const theirs = JSON.parse(out) + check(picks.every((p, i) => Math.abs(theirs[i] - Number(p[1])) < 0.01), "omamobile-weather's pick_place agrees: " + theirs.join(", ")) + } + const r = run("simonschubert/today", { city: "Springfield, IL" }, {}) + check(/name=Springfield$/.test(r.urls.geo), "only the town goes to the lookup") +} + +// forecast: the curve and the days, from the same answers. +{ + const id = "simonschubert/forecast" + let r = run(id, { city: "Sample Town" }, { geo: ok(geocode), w: ok(forecast) }) + check(/latitude=40\.12&longitude=-77\.65&/.test(r.urls.w), "forecast asks for the first result: " + r.urls.w) + check(r.texts.includes("14°") && r.all.includes("partly cloudy") && r.all.includes("Sample Town"), "forecast shows now and the place") + check(r.all.includes("16° / 9°") || r.all.includes("16° / 8°"), "forecast shows the days' highs and lows: " + r.all) + check(r.all.includes("open-meteo.com (cc by 4.0)") && !/ERROR/.test(r.all), "forecast credits Open-Meteo, without errors") + r = run(id, { city: "" }, {}) + check(r.all.includes("set a city or turn on Location"), "forecast asks for a city or Location without either") +} + +// sun and moon: Open-Meteo's sunrise and sunset, the moon from the date. +{ + const id = "simonschubert/sun-and-moon" + let r = run(id, { city: "40.79,-77.86" }, { sun: ok(forecast) }) + check(/^https:\/\/api\.open-meteo\.com\/v1\/forecast\?latitude=40\.79&longitude=-77\.86&daily=sunrise,sunset/.test(r.urls.sun), "sun and moon asks for sunrise and sunset: " + r.urls.sun) + check(r.all.includes("↑ 07:00") && r.all.includes("↓ 17:00") && r.all.includes("of daylight left"), "sun and moon shows the day: " + r.all) + check(/\d+%/.test(r.all) && /(moon|crescent|quarter|gibbous)/.test(r.all) && !/ERROR/.test(r.all), "sun and moon shows the moon's phase") + r = run(id, { city: "" }, {}) + check(r.all.includes("set a city or turn on Location"), "sun and moon asks for a city or Location without either") +} + +// planes overhead: the place only, then OpenSky. +{ + const id = "simonschubert/planes-overhead" + let r = run(id, { city: "Sample Town" }, { geo: ok(geocode), sky: ok({ states: [] }) }) + check(/opensky-network\.org\/api\/states\/all\?lamin=39\.623&/.test(r.urls.sky), "planes overhead centres OpenSky on the place: " + r.urls.sky) + check(r.all.includes("0 flights within 30 mi of sample town"), "planes overhead counts in miles in the US: " + r.all) + r = run(id, { city: "" }, {}) + check(r.all.includes("set a city or turn on Location"), "planes overhead asks for a city or Location without either") +} + +// air and pollen: the place, then the air-quality API. +{ + const id = "simonschubert/air-and-pollen" + let r = run(id, { city: "52.52,13.40", phoneUnit: "C" }, { air: ok(air) }) + check(/^https:\/\/air-quality-api\.open-meteo\.com\/v1\/air-quality\?latitude=52\.52&longitude=13\.4&/.test(r.urls.air), "air and pollen asks at the phone's location: " + r.urls.air) + check(r.all.includes("32") && r.all.includes("your location") && !/ERROR/.test(r.all), "air and pollen shows Europe's index there") + r = run(id, { city: "" }, {}) + check(r.all.includes("set a city or turn on Location"), "air and pollen asks for a city or Location without either") +} + +// red panda: no internet now; it reads the phone's own weather reading (omamobile-weather). +{ + const id = "ssalentin/red-panda" + let r = run(id, {}, {}) + check(r.caps.hosts.length === 0 && !r.caps.network && r.caps.files.join() === "~/.local/state/omamobile/weather.json", "red panda reads the phone's weather reading, not the internet") + r = run(id, { lastTap: T }, { wx: { at: T * 1000, temperature: 9, unit: "°C", text: "Rain", source: "location" } }) + check(r.value("raining") === true, "red panda shelters when the reading says rain") + r = run(id, { lastTap: T }, { wx: { at: (T - 4 * 3600) * 1000, temperature: 9, unit: "°C", text: "Rain", source: "location" } }) + check(r.value("raining") === false, "red panda ignores a reading over 3 hours old") +} + +// omaprayer: no IP location; "auto" uses its own default city. +{ + const r = run("setiapam/omaprayer", { city: "auto" }, {}) + check(r.all.includes("SET A CITY") && !r.all.includes("JAKARTA") && !/ERROR/.test(r.all), "omaprayer's auto asks for a city: " + r.texts.slice(0, 3).join(" | ")) + check(/latitude=-6\.2146/.test(run("setiapam/omaprayer", { city: "Jakarta" }, {}).urls.tz), "omaprayer still knows Jakarta when it is typed") +} + +if (failures) { console.log(failures + " failed"); process.exit(1) } diff --git a/packages/omamobile-owl-widgets/update-index.js b/packages/omamobile-owl-widgets/update-index.js index 2941f95c6..1041f846d 100644 --- a/packages/omamobile-owl-widgets/update-index.js +++ b/packages/omamobile-owl-widgets/update-index.js @@ -6,14 +6,18 @@ // derived capabilities, and the sha256 of its file. Nothing is run. // The index is committed with the package, so building the package needs // no compiler: install only copies the files and checks their sha256. -// Run it from the repository when the pinned commit or status.json changes: +// A widget we keep our own copy of in overrides///widget.owl +// (it diverges from the store: README.md) is indexed from that copy. +// Run it from the repository when the pinned commit, status.json or an +// override changes: // -// node update-index.js [owl runtime dir] [status.json] > index.json +// node update-index.js [owl runtime dir] [status.json] [overrides dir] > index.json "use strict" const fs = require("fs"), path = require("path"), crypto = require("crypto"), Module = require("module") const store = process.argv[2] const owlDir = process.argv[3] || path.join(__dirname, "../omamobile-shell/plugins/omamobile.home/owl") const statusFile = process.argv[4] || path.join(__dirname, "status.json") +const overrides = process.argv[5] || path.join(__dirname, "overrides") const cache = {} function load(name) { @@ -51,7 +55,8 @@ const order = fs.existsSync(path.join(store, "order.txt")) ? fs.readFileSync(pat const widgets = [] for (const id of ordered(ids, order)) { const st = status.widgets[id] || { status: "unsupported", note: "not checked yet" } - const text = fs.readFileSync(path.join(store, "widgets", id, "widget.owl"), "utf8") + const ours = path.join(overrides, id, "widget.owl") + const text = fs.readFileSync(fs.existsSync(ours) ? ours : path.join(store, "widgets", id, "widget.owl"), "utf8") const entry = { id, author: id.split("/")[0], status: st.status, note: st.note || "" } try { const p = C.compile(text) diff --git a/packages/omamobile-owl-widgets/version b/packages/omamobile-owl-widgets/version index 17e51c385..d917d3e26 100644 --- a/packages/omamobile-owl-widgets/version +++ b/packages/omamobile-owl-widgets/version @@ -1 +1 @@ -0.1.1 +0.1.2 diff --git a/packages/omamobile-shell/PKGBUILD b/packages/omamobile-shell/PKGBUILD index 399c75680..ed1f88a61 100644 --- a/packages/omamobile-shell/PKGBUILD +++ b/packages/omamobile-shell/PKGBUILD @@ -7,7 +7,7 @@ pkgdesc="Omarchy Mobile's phone profile for the Omarchy shell: status bar, quick arch=(any) url="https://github.com/derekross/omarchy-mobile" license=(MIT GPL-3.0-or-later) # GPL: the squeekboard layout -depends=(omarchy omamobile-apps 'omamobile-omarchy>=0.1.11' omamobile-owl-widgets bash squeekboard bluez wf-recorder python python-dbus python-gobject +depends=(omarchy omamobile-apps 'omamobile-omarchy>=0.1.11' 'omamobile-owl-widgets>=0.1.2' bash squeekboard bluez wf-recorder python python-dbus python-gobject which # voice input: voxtype finds wtype and wl-copy with which pipewire-audio pipewire-pulse pipewire-alsa wireplumber inotify-tools qt6-declarative diff --git a/packages/omamobile-shell/plugins/omamobile.home/HomeModel.js b/packages/omamobile-shell/plugins/omamobile.home/HomeModel.js index 53c773599..f1cb7566c 100644 --- a/packages/omamobile-shell/plugins/omamobile.home/HomeModel.js +++ b/packages/omamobile-shell/plugins/omamobile.home/HomeModel.js @@ -51,7 +51,7 @@ var WIDGET_ORDER = ["clock", "weather", "battery", "media", "agenda", "notes", " // that ran commands) and which of its settings become the OWL widget's // state. `credit` is the original. var PORTED = { - airAndPollen: {"name": "Air and pollen", "icon": "󰵃", "min": [2, 1], "max": [4, 4], "size": [2, 1], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: wttr.in guesses from your address"}], "source": "wttr.in, air-quality-api.open-meteo.com", "credit": "simonschubert/air-and-pollen"}, + airAndPollen: {"name": "Air and pollen", "icon": "󰵃", "min": [2, 1], "max": [4, 4], "size": [2, 1], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: set a city here or turn on Location"}], "source": "geocoding-api.open-meteo.com, air-quality-api.open-meteo.com", "credit": "simonschubert/air-and-pollen"}, analogClock: {"name": "Analog clock", "icon": "󰅐", "min": [1, 1], "max": [4, 4], "size": [2, 2], "network": false, "config": {"seconds": true}, "schema": [{"key": "seconds", "type": "boolean", "label": "Second hand", "defaultValue": true}], "credit": "simonschubert/analog-clock"}, bundesliga: {"name": "Bundesliga", "icon": "󰒸", "min": [3, 2], "max": [4, 6], "size": [4, 3], "network": true, "config": {"enabled": false}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}], "source": "espn.com, espncdn.com", "credit": "simonschubert/bundesliga"}, calendar: {"name": "Month", "icon": "󰃭", "min": [2, 2], "max": [4, 4], "size": [2, 2], "network": false, "config": {"firstDay": "Monday"}, "schema": [{"key": "firstDay", "type": "enum", "label": "Weeks start on", "options": ["Monday", "Sunday"], "defaultValue": "Monday"}], "credit": "simonschubert/calendar"}, @@ -64,7 +64,7 @@ var PORTED = { feeds: {"name": "Feeds", "icon": "󰑫", "min": [3, 2], "max": [4, 6], "size": [4, 3], "network": true, "config": {"enabled": false, "feeds": "https://archlinux.org/feeds/news/, https://github.com/omacom/omarchy/releases.atom", "interval": 30}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "feeds", "type": "string", "label": "Feeds (URLs, comma-separated)", "defaultValue": "https://archlinux.org/feeds/news/, https://github.com/omacom/omarchy/releases.atom"}, {"key": "interval", "type": "integer", "label": "Refresh every (minutes)", "min": 10, "max": 1440, "defaultValue": 30}], "source": "the feeds you list", "credit": "simonschubert/feeds"}, fetch: {"name": "Fetch", "icon": "󰣇", "min": [2, 2], "max": [4, 4], "size": [3, 2], "network": false, "config": {}, "credit": "simonschubert/fetch"}, focus: {"name": "Focus", "icon": "󰔛", "min": [2, 2], "max": [4, 4], "size": [2, 2], "network": false, "config": {"minutes": 25}, "schema": [{"key": "minutes", "type": "integer", "label": "Session length (minutes)", "min": 5, "max": 60, "defaultValue": 25}], "credit": "simonschubert/focus"}, - forecast: {"name": "Forecast", "icon": "󰖕", "min": [3, 2], "max": [4, 4], "size": [4, 2], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: wttr.in guesses from your address"}], "source": "wttr.in", "credit": "simonschubert/forecast"}, + forecast: {"name": "Forecast", "icon": "󰖕", "min": [3, 2], "max": [4, 4], "size": [4, 2], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: set a city here or turn on Location"}], "source": "geocoding-api.open-meteo.com, api.open-meteo.com", "credit": "simonschubert/forecast"}, freeGames: {"name": "Free games", "icon": "󰊗", "min": [3, 2], "max": [4, 4], "size": [4, 2], "network": true, "config": {"enabled": false}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}], "source": "store.epicgames.com, store-site-backend-static.ak.epicgames.com", "credit": "simonschubert/free-games"}, github: {"name": "GitHub", "icon": "", "min": [3, 2], "max": [4, 6], "size": [4, 3], "network": true, "config": {"enabled": false}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}], "source": "github.com", "credit": "simonschubert/github"}, githubTrending: {"name": "GitHub trending", "icon": "󰊤", "min": [3, 2], "max": [4, 6], "size": [4, 3], "network": true, "config": {"enabled": false}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}], "source": "github.com", "credit": "simonschubert/github-trending"}, @@ -86,12 +86,12 @@ var PORTED = { omarchyCommits: {"name": "Omarchy commits", "icon": "󰜘", "min": [3, 2], "max": [4, 6], "size": [3, 3], "network": true, "config": {"enabled": false, "repo": "omacom/omarchy", "branch": "quattro"}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "repo", "type": "string", "label": "Repository (owner/name)", "defaultValue": "omacom/omarchy"}, {"key": "branch", "type": "string", "label": "Branch", "defaultValue": "quattro"}], "source": "github.com", "credit": "simonschubert/omarchy-commits"}, owl: {"name": "Owl", "icon": "󰈺", "min": [1, 1], "max": [4, 4], "size": [2, 2], "network": false, "config": {"born": 0, "fed": 0, "pets": 0}, "credit": "simonschubert/owl"}, pictureOfTheDay: {"name": "Picture of the day", "icon": "󰋩", "min": [2, 2], "max": [4, 6], "size": [4, 2], "network": true, "config": {"enabled": false}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}], "source": "wikimedia.org, commons.wikimedia.org", "credit": "simonschubert/picture-of-the-day"}, - planesOverhead: {"name": "Planes overhead", "icon": "󰀝", "min": [1, 1], "max": [4, 5], "size": [2, 2], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: wttr.in guesses from your address"}], "source": "wttr.in, opensky-network.org, globe.adsbexchange.com", "credit": "simonschubert/planes-overhead"}, + planesOverhead: {"name": "Planes overhead", "icon": "󰀝", "min": [1, 1], "max": [4, 5], "size": [2, 2], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: set a city here or turn on Location"}], "source": "geocoding-api.open-meteo.com, opensky-network.org, globe.adsbexchange.com", "credit": "simonschubert/planes-overhead"}, premierLeague: {"name": "Premier League", "icon": "󰒸", "min": [3, 2], "max": [4, 6], "size": [4, 3], "network": true, "config": {"enabled": false}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}], "source": "espn.com, espncdn.com", "credit": "simonschubert/premier-league"}, releases: {"name": "Releases", "icon": "󰏗", "min": [3, 2], "max": [4, 6], "size": [4, 2], "network": true, "config": {"enabled": false, "repos": "omacom/omarchy, neovim/neovim, hyprwm/Hyprland, jesseduffield/lazygit, sxyazi/yazi"}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "repos", "type": "string", "label": "Repositories (owner/name, comma-separated)", "defaultValue": "omacom/omarchy, neovim/neovim, hyprwm/Hyprland, jesseduffield/lazygit, sxyazi/yazi"}], "source": "github.com", "credit": "simonschubert/releases"}, serieA: {"name": "Serie A", "icon": "󰒸", "min": [3, 2], "max": [4, 6], "size": [4, 3], "network": true, "config": {"enabled": false}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}], "source": "espn.com, espncdn.com", "credit": "simonschubert/serie-a"}, - sunAndMoon: {"name": "Sun and moon", "icon": "󰖜", "min": [2, 2], "max": [4, 3], "size": [2, 2], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: wttr.in guesses from your address"}], "source": "wttr.in", "credit": "simonschubert/sun-and-moon"}, - today: {"name": "Today", "icon": "󰖐", "min": [2, 1], "max": [4, 4], "size": [2, 2], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: wttr.in guesses from your address"}], "source": "wttr.in, yr.no", "credit": "simonschubert/today"}, + sunAndMoon: {"name": "Sun and moon", "icon": "󰖜", "min": [2, 2], "max": [4, 3], "size": [2, 2], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: set a city here or turn on Location"}], "source": "geocoding-api.open-meteo.com, api.open-meteo.com", "credit": "simonschubert/sun-and-moon"}, + today: {"name": "Today", "icon": "󰖐", "min": [2, 1], "max": [4, 4], "size": [2, 2], "network": true, "config": {"enabled": false, "useLocation": true, "city": ""}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "useLocation", "type": "boolean", "label": "Use my location", "description": "The phone's position (Location), rounded to about 1 km", "defaultValue": true}, {"key": "city", "type": "string", "label": "City when there is no location", "defaultValue": "", "description": "Empty: set a city here or turn on Location"}], "source": "geocoding-api.open-meteo.com, api.open-meteo.com, yr.no", "credit": "simonschubert/today"}, todo: {"name": "Todo", "icon": "󰝖", "min": [2, 2], "max": [4, 6], "size": [2, 3], "network": false, "config": {"path": "~/notes/todo.md"}, "schema": [{"key": "path", "type": "path", "label": "Checklist file", "defaultValue": "~/notes/todo.md"}], "credit": "simonschubert/todo"}, uptime: {"name": "Uptime", "icon": "󰓅", "min": [3, 2], "max": [4, 6], "size": [4, 2], "network": true, "config": {"enabled": false, "sites": "https://archlinux.org, https://github.com", "interval": 5}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}, {"key": "sites", "type": "string", "label": "Sites (URLs, comma-separated)", "defaultValue": "https://archlinux.org, https://github.com"}, {"key": "interval", "type": "integer", "label": "Check every (minutes)", "min": 2, "max": 240, "defaultValue": 5}], "source": "the sites you list", "credit": "simonschubert/uptime"}, wikipedia: {"name": "Wikipedia", "icon": "󰖬", "min": [3, 2], "max": [4, 6], "size": [4, 3], "network": true, "config": {"enabled": false}, "schema": [{"key": "enabled", "type": "boolean", "label": "Use the internet", "description": "Off until you turn it on"}], "source": "wikimedia.org, en.m.wikipedia.org", "credit": "simonschubert/wikipedia"}, @@ -799,6 +799,26 @@ function geocodeUrl(place) { return "https://geocoding-api.open-meteo.com/v1/search?count=1&format=json&name=" + encodeURIComponent(String(place || "").trim()) } +// The phone's temperature unit from its locale, "F" or "C", as +// omamobile-weather's locale_unit (test/weather.py checks the two agree): +// the first of LC_ALL, LC_MEASUREMENT and LANG that is set; °F where the +// territory measures in it. The OWL weather built-ins get it as their +// `phoneUnit` state (OwlCell.qml). +var FAHRENHEIT_TERRITORIES = ["US", "LR", "MM", "BS", "BZ", "KY", "PW", "FM", "MH", "PR", "GU", "VI", "AS", "MP", "UM"] +function localeUnit(env) { + var e = env || {} + var names = ["LC_ALL", "LC_MEASUREMENT", "LANG"] + for (var i = 0; i < names.length; i++) { + var value = String(e[names[i]] || "") + if (!value) continue + var base = value.split(".")[0].split("@")[0] + var cut = base.indexOf("_") + var territory = cut < 0 ? "" : base.slice(cut + 1).toUpperCase() + return FAHRENHEIT_TERRITORIES.indexOf(territory) >= 0 ? "F" : "C" + } + return "C" +} + function forecastUrl(latitude, longitude, units) { var lat = Math.round(Number(latitude) * 100) / 100 var lon = Math.round(Number(longitude) * 100) / 100 @@ -1040,7 +1060,7 @@ if (typeof module !== "undefined") { placeOn: placeOn, addWidget: addWidget, addApp: addApp, removeItem: removeItem, restoreItem: restoreItem, moveItem: moveItem, resizeItem: resizeItem, setConfig: setConfig, addPage: addPage, removePage: removePage, movePage: movePage, setHome: setHome, setGrid: setGrid, transposeLayout: transposeLayout, - weatherText: weatherText, geocodeUrl: geocodeUrl, forecastUrl: forecastUrl, + weatherText: weatherText, localeUnit: localeUnit, geocodeUrl: geocodeUrl, forecastUrl: forecastUrl, parseGeocode: parseGeocode, parseForecast: parseForecast, parseAgenda: parseAgenda, AGENDA_ARGV: AGENDA_ARGV, monthGrid: monthGrid, commandText: commandText, opensShellSurface: opensShellSurface, COVERING_LAYERS: COVERING_LAYERS, layersAfter: layersAfter, homeShown: homeShown, pageShown: pageShown, overdue: overdue diff --git a/packages/omamobile-shell/plugins/omamobile.home/OwlCell.qml b/packages/omamobile-shell/plugins/omamobile.home/OwlCell.qml index 3613bf0e9..6ec7e7f97 100644 --- a/packages/omamobile-shell/plugins/omamobile.home/OwlCell.qml +++ b/packages/omamobile-shell/plugins/omamobile.home/OwlCell.qml @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MIT import QtQuick +import Quickshell import qs.Commons import qs.Commons as Commons import "UserWidgets.js" as UserWidgets @@ -113,7 +114,8 @@ Item { // ---------- location, for the weather built-ins // The ports used the phone's position (GeoClue, about 1 km); their OWL - // originals take a place as `city`, and wttr.in reads "lat,lon" as one. + // originals take a place as `city`, and our copies of them (in + // omamobile-owl-widgets) send a "lat,lon" city straight to Open-Meteo. // The coordinates go in while the city is empty or still the last ones put // in, so a city the user types wins. Needs its internet allowed. readonly property bool wantsLocation: owlCell.running && owlCell.shown && owlCell.config.useLocation === true @@ -121,7 +123,18 @@ Item { GeoLocation { id: geo; active: owlCell.wantsLocation } onLocationTextChanged: owlCell.fillLocation() readonly property string locationText: geo.fix ? Number(geo.fix.lat).toFixed(2) + "," + Number(geo.fix.lon).toFixed(2) : "" - Connections { target: owl; function onInstanceChanged() { owlCell.fillLocation() } } + Connections { target: owl; function onInstanceChanged() { owlCell.fillLocation(); owlCell.fillUnit() } } + // The phone's temperature unit from its locale ("F" in the US, as + // omamobile-weather), for a widget with a `phoneUnit` state: our weather + // copies use it before the place's country. Not persisted, so it follows + // a change of locale. + readonly property string phoneUnit: HomeModel.localeUnit({ LC_ALL: Quickshell.env("LC_ALL") || "", + LC_MEASUREMENT: Quickshell.env("LC_MEASUREMENT") || "", LANG: Quickshell.env("LANG") || "" }) + function fillUnit() { + if (!owl.instance) return + const unit = owl.stateValue("phoneUnit") + if (unit !== undefined && unit !== owlCell.phoneUnit) owl.setStateValue("phoneUnit", owlCell.phoneUnit) + } function fillLocation() { if (!owlCell.wantsLocation || !owlCell.locationText || !owl.instance) return const city = owl.stateValue("city") diff --git a/packages/omamobile-shell/plugins/omamobile.home/owl/builtins.js b/packages/omamobile-shell/plugins/omamobile.home/owl/builtins.js index f57f1726d..4a8b7fe15 100644 --- a/packages/omamobile-shell/plugins/omamobile.home/owl/builtins.js +++ b/packages/omamobile-shell/plugins/omamobile.home/owl/builtins.js @@ -154,7 +154,8 @@ function timeField(d, letter, n) { throw new V.RuntimeError("bad time pattern") } -// Omarchy's weather glyphs (Nerd Font) for wttr.in's weatherCode. +// Omarchy's weather glyphs (Nerd Font) for World Weather Online's weatherCode +// (the codes wttr.in served; our Open-Meteo copies map WMO codes onto them). function weatherGlyph(code, night) { var groups = [ [[113], "", ""], diff --git a/packages/omamobile-shell/plugins/omamobile.home/owl/phone.js b/packages/omamobile-shell/plugins/omamobile.home/owl/phone.js index 498241ae5..c002611a1 100644 --- a/packages/omamobile-shell/plugins/omamobile.home/owl/phone.js +++ b/packages/omamobile-shell/plugins/omamobile.home/owl/phone.js @@ -162,7 +162,7 @@ function capabilities(program) { if (text.indexOf("http GET ") === 0) { out.network = true // A URL built while it runs still has a fixed host when its text - // starts with one (https://wttr.in/${q}): the compiler keeps that prefix. + // starts with one (https://api.open-meteo.com/...${q}): the compiler keeps that prefix. var known = text.slice(9).indexOf("(a URL built") === 0 ? (program.httpPrefixes || [])[httpIndex] || "" : text.slice(9) httpIndex++ var h = hostOf(known) diff --git a/packages/omamobile-shell/test/home-render b/packages/omamobile-shell/test/home-render index 6baeb5dad..cde4deb14 100755 --- a/packages/omamobile-shell/test/home-render +++ b/packages/omamobile-shell/test/home-render @@ -53,8 +53,13 @@ sed -i -E \ "$h/home/Home.qml" grep -c '^ Item { anchors.fill: parent$' "$h/home/Home.qml" >/dev/null || { echo "home-render: no PanelWindow to stand in for" >&2; exit 1; } cp "$here/home-render.qml" "$h/" -# The two store widgets, laid out as the omamobile-owl-widgets package ships them. -for w in today fetch; do install -Dm644 "$store/simonschubert/$w/widget.owl" "$h/store/widgets/simonschubert/$w/widget.owl"; done +# The two store widgets, laid out as the omamobile-owl-widgets package ships them +# (today is our own copy, overrides/, weather from Open-Meteo). +for w in today fetch; do + src=$store/simonschubert/$w/widget.owl + [[ -f $here/../../omamobile-owl-widgets/overrides/simonschubert/$w/widget.owl ]] && src=$here/../../omamobile-owl-widgets/overrides/simonschubert/$w/widget.owl + install -Dm644 "$src" "$h/store/widgets/simonschubert/$w/widget.owl" +done # App icons: three plain tiles, drawn here. magick -size 112x112 xc:none -fill '#3584e4' -draw 'roundrectangle 4,4 108,108 26,26' "$h/icon-browser.png" magick -size 112x112 xc:none -fill '#e5a50a' -draw 'roundrectangle 4,4 108,108 26,26' "$h/icon-files.png" @@ -100,16 +105,22 @@ fs.mkdirSync(path.join(home, ".config/omamobile"), { recursive: true }) fs.writeFileSync(path.join(home, ".config/omamobile/home.json"), JSON.stringify(layout, null, 1) + "\n") fs.writeFileSync(path.join(home, ".config/omamobile/features.json"), JSON.stringify({ owlWidgets: true }) + "\n") fs.writeFileSync(path.join(home, ".config/omamobile/widget-approvals.json"), JSON.stringify(approvals, null, 1) + "\n") -// Made-up data, never a real feed: a wttr.in j1 answer and the phone's facts. -const hours = (base) => [0, 300, 600, 900, 1200, 1500, 1800, 2100].map((t, i) => ({ time: String(t), tempC: String(base + [0, -1, -1, 2, 5, 6, 3, 1][i]), tempF: String(Math.round((base + [0, -1, -1, 2, 5, 6, 3, 1][i]) * 1.8 + 32)), weatherCode: "116", chanceofrain: "10", FeelsLikeC: String(base), windspeedKmph: "11", uvIndex: "2" })) -const wttr = { - current_condition: [{ temp_C: "14", temp_F: "57", FeelsLikeC: "12", FeelsLikeF: "54", weatherCode: "116", weatherIconUrl: [{ value: "" }], weatherDesc: [{ value: "Partly cloudy" }], humidity: "70", windspeedKmph: "11", windspeedMiles: "7", winddir16Point: "W", uvIndex: "2", precipMM: "0.0", precipInches: "0.0", pressure: "1016", pressureInches: "30", visibility: "10", visibilityMiles: "6" }], - nearest_area: [{ areaName: [{ value: "Sample Town" }], country: [{ value: "Example" }], latitude: "52.52", longitude: "13.40" }], - weather: ["2026-10-13", "2026-10-14", "2026-10-15"].map((d, i) => ({ date: d, maxtempC: String(16 - i), mintempC: String(9 - i), maxtempF: String(61 - i * 2), mintempF: String(48 - i * 2), avgtempC: "12", - astronomy: [{ sunrise: "07:26 AM", sunset: "06:18 PM", moonrise: "03:02 AM", moonset: "05:10 PM", moon_phase: "Waning Crescent", moon_illumination: "40" }], hourly: hours(9 - i) })) +// Made-up data, never a real feed: Open-Meteo geocoding and forecast answers, and the phone's facts. +const geo = { results: [{ name: "Sample Town", latitude: 52.52, longitude: 13.4, country: "Example", country_code: "EX", admin1: "Region" }] } +const day0 = T - (T % 86400) +const hourTimes = Array.from({ length: 72 }, (_, i) => day0 + i * 3600) +const meteo = { + current: { time: T, temperature_2m: 14.2, apparent_temperature: 12.1, relative_humidity_2m: 70, is_day: 1, weather_code: 2, precipitation: 0, + pressure_msl: 1016, wind_speed_10m: 11, wind_direction_10m: 270 }, + hourly: { time: hourTimes, temperature_2m: hourTimes.map((t, i) => 9 - Math.floor(i / 24) + [0, -1, -1, 2, 5, 6, 3, 1][Math.floor((i % 24) / 3)]), + precipitation_probability: hourTimes.map(() => 10), weather_code: hourTimes.map(() => 2), is_day: hourTimes.map((t, i) => (i % 24) >= 7 && (i % 24) < 18 ? 1 : 0), + uv_index: hourTimes.map(() => 2), visibility: hourTimes.map(() => 10000) }, + daily: { time: [0, 1, 2].map((i) => day0 + i * 86400), weather_code: [2, 3, 61], temperature_2m_max: [16, 15, 14], temperature_2m_min: [9, 8, 7], + sunrise: [0, 1, 2].map((i) => day0 + i * 86400 + 5 * 3600 + 26 * 60), sunset: [0, 1, 2].map((i) => day0 + i * 86400 + 16 * 3600 + 18 * 60), + precipitation_probability_max: [10, 20, 60], precipitation_sum: [0, 0.4, 3] } } const widgets = {} -widgets[today] = { sources: { now: { value: T }, wx: { text: JSON.stringify(wttr) } }, android: {} } +widgets[today] = { sources: { now: { value: T }, geo: { text: JSON.stringify(geo) }, wx: { text: JSON.stringify(meteo) } }, android: {} } widgets[fetch] = { sources: { lxCmd: { text: JSON.stringify({ os: "Arch Linux ARM", pkgs: 1234, explicit: 210, shell: "bash 5.3", upgraded: "2026-10-12" }) } }, android: { diff --git a/packages/omamobile-shell/test/owl-core.js b/packages/omamobile-shell/test/owl-core.js index ab8409a28..c9d672ce2 100644 --- a/packages/omamobile-shell/test/owl-core.js +++ b/packages/omamobile-shell/test/owl-core.js @@ -76,7 +76,7 @@ test("a feature above the declared level is refused, with the fix", () => { }) test("the commands list names every command, URL and file, in order", () => { const p = C.compile('widget "w" {\n meta { owl: 6 }\n state city = "x"\n source a = cmd("date")\n source b = http("https://example.org/a")\n source c = file("~/notes.txt")\n' + - ' source d = cmd("curl wttr.in/${sh(city)}") optional\n Button { text: "go"; onTap: { run("notify-send hi"); terminal("btop"); url("https://example.org") } }\n Button { text: "x"; onTap: city = run("cat ~/city") }\n}') + ' source d = cmd("curl api.open-meteo.com/${sh(city)}") optional\n Button { text: "go"; onTap: { run("notify-send hi"); terminal("btop"); url("https://example.org") } }\n Button { text: "x"; onTap: city = run("cat ~/city") }\n}') eq(p.commands, ["date", "http GET https://example.org/a", "read file ~/notes.txt", "if Linux is installed: cmd(…) built from widget values", "notify-send hi", "btop", "cat ~/city"]) }) @@ -411,14 +411,14 @@ test("a port's OWL original is approved without asking only within what the port const H = require("../plugins/omamobile.home/HomeModel.js") const grid = { columns: 4, rows: 6 } const info = (text) => K.describe("x", text, grid, 151, 1.16) - const web = info('widget "w" {\n meta { owl: 5 }\n state city = "" persist\n source wx = http("https://wttr.in/${city}?format=j1") json\n Text { text: wx }\n}') + const web = info('widget "w" {\n meta { owl: 5 }\n state city = "" persist\n source geo = http("https://geocoding-api.open-meteo.com/v1/search?name=${city}") json\n source wx = http("https://api.open-meteo.com/v1/forecast?latitude=${city}") json\n Text { text: wx }\n}') const today = K.portApproval(H.portCapabilities("today"), web, true) eq([today.extra, today.approve.network, today.approve.auto], [[], true, true]) eq(K.portApproval(H.portCapabilities("today"), web, false).approve.network, false) const curl = info('widget "w" {\n source q = cmd("curl -s https://earthquake.usgs.gov/x")\n Text { text: q }\n}') eq(K.portApproval(H.portCapabilities("earthquakes"), curl, true).extra, ["runs commands"]) eq(K.portApproval(H.portCapabilities("feeds"), curl, true).approve.commands, ["curl -s https://earthquake.usgs.gov/x"]) - eq(K.portApproval(H.portCapabilities("crypto"), web, true).extra, ["talks to wttr.in"]) + eq(K.portApproval(H.portCapabilities("crypto"), web, true).extra, ["talks to geocoding-api.open-meteo.com, api.open-meteo.com"]) eq(K.portApproval(H.portCapabilities("koiPond"), web, true).extra, ["uses the internet"]) }) @@ -433,10 +433,10 @@ test("the owner's layout: migration approvals, and never a package install witho "owl:simonschubert.owl": 'widget "owl" {\n state born = 0 persist\n Text { text: born }\n}', "owl:simonschubert.koi-pond": 'widget "koi" {\n Canvas { circle(time, 1, 1) }\n}', "owl:simonschubert.crypto": 'widget "bitcoin" {\n meta { owl: 5 }\n source m = http("https://api.coingecko.com/api/v3/x") json status\n Text { text: m }\n}', - "owl:simonschubert.today": 'widget "today" {\n meta { owl: 5 }\n state city = "" persist\n source wx = http("https://wttr.in/${city}?format=j1") json\n Text { text: wx }\n}', + "owl:simonschubert.today": 'widget "today" {\n meta { owl: 5 }\n state city = "" persist\n source geo = http("https://geocoding-api.open-meteo.com/v1/search?name=${city}") json\n source wx = http("https://api.open-meteo.com/v1/forecast?latitude=${city}") json\n Text { text: wx }\n}', "owl:simonschubert.earthquakes": 'widget "q" {\n source q = cmd("curl -s https://earthquake.usgs.gov/x")\n Text { text: q }\n}', "owl:simonschubert.habits": 'widget "h" {\n source n = cmd("cat ~/.config/omarchy-proot/habits")\n Text { text: n }\n}', - "owl:simonschubert.forecast": 'widget "f" {\n source w = cmd("curl -s https://wttr.in/x")\n Text { text: w }\n}' + "owl:simonschubert.forecast": 'widget "f" {\n source w = cmd("curl -s https://api.open-meteo.com/x")\n Text { text: w }\n}' } const infoFor = (t) => K.describe(t, texts[t], grid, 151, 1.16) const fetch = infoFor("owl:simonschubert.fetch") diff --git a/packages/omamobile-shell/test/weather.py b/packages/omamobile-shell/test/weather.py index eabd0915a..a873cceb6 100644 --- a/packages/omamobile-shell/test/weather.py +++ b/packages/omamobile-shell/test/weather.py @@ -60,6 +60,15 @@ def reset(): diff = {k: (mine[k], theirs[k]) for k in theirs if mine.get(k) != theirs[k]} ok(not diff, "the words for each code are the home screen widget's %s" % diff) print("ok - weather: the words for every code are the home screen widget's (HomeModel.weatherText)") + # The unit the OWL weather widgets get (HomeModel.localeUnit) is this one. + envs = [{"LANG": "en_US.UTF-8"}, {"LANG": "de_DE.UTF-8"}, {"LANG": "C.UTF-8"}, {}, {"LANG": "en_LR"}, + {"LC_ALL": "de_DE.UTF-8", "LANG": "en_US.UTF-8"}, {"LC_MEASUREMENT": "en_US.UTF-8", "LANG": "de_DE.UTF-8"}, + {"LANG": "en_PR.UTF-8@euro"}, {"LC_ALL": "", "LANG": "es_US"}] + js = "const M = require(process.argv[1]); console.log(JSON.stringify(JSON.parse(process.argv[2]).map(M.localeUnit)))" + theirs = json.loads(subprocess.run(["node", "-e", js, os.path.join(ROOT, "plugins/omamobile.home/HomeModel.js"), json.dumps(envs)], + check=True, capture_output=True, text=True).stdout) + ok(theirs == [W.locale_unit(e) for e in envs], "HomeModel.localeUnit agrees with locale_unit %s" % theirs) + print("ok - weather: the OWL widgets' unit is the one this service uses (HomeModel.localeUnit)") else: print("ok - weather: the words match the home screen widget's # SKIP no node") diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index d30ff0e30..d66d2f865 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.88 +0.2.90 diff --git a/tests/owl/port-approvals.js b/tests/owl/port-approvals.js index 6a707c8f2..59e3c0b6d 100644 --- a/tests/owl/port-approvals.js +++ b/tests/owl/port-approvals.js @@ -3,7 +3,9 @@ // had, and whether a migrated layout approves it without asking (the same // rule the home screen applies, owl/catalog.js portApproval). Prints a // Markdown table for docs/owl-review; exits 1 if the owner's layout's -// widgets don't come out as the review says. +// widgets don't come out as the review says. Our own copies of store widgets +// (packages/omamobile-owl-widgets/overrides/, what the package ships) are +// read in place of the store's. // node port-approvals.js "use strict" const fs = require("fs"), path = require("path") @@ -14,7 +16,8 @@ const dir = process.argv[2] const rows = [], verdicts = {} for (const port of H.PORTED_ORDER) { const store = H.PORTED[port].credit - const info = K.describe(port, fs.readFileSync(path.join(dir, store, "widget.owl"), "utf8"), H.GRID, 908 / 6, 480 / 6 / 69) + const ours = path.resolve(__dirname, "../../packages/omamobile-owl-widgets/overrides", store, "widget.owl") + const info = K.describe(port, fs.readFileSync(fs.existsSync(ours) ? ours : path.join(dir, store, "widget.owl"), "utf8"), H.GRID, 908 / 6, 480 / 6 / 69) const had = H.portCapabilities(port) const v = K.portApproval(had, info, true) verdicts[port] = !!v.approve @@ -25,7 +28,7 @@ for (const port of H.PORTED_ORDER) { console.log("| Built-in | OWL original | The port had | The original needs | After migration |") console.log("| --- | --- | --- | --- | --- |") rows.forEach((r) => console.log(r)) -const expect = { crypto: true, today: true, earthquakes: false, habits: false, forecast: false } +const expect = { crypto: true, today: true, earthquakes: false, habits: false, forecast: true } const wrong = Object.keys(expect).filter((k) => verdicts[k] !== expect[k]) if (wrong.length) { console.error("unexpected verdicts: " + wrong.join(", ")); process.exit(1) } console.error(Object.values(verdicts).filter(Boolean).length + " of 47 approved without asking") diff --git a/tests/owl/render/layout-jobs.js b/tests/owl/render/layout-jobs.js index aceb28f9a..a28f9d642 100644 --- a/tests/owl/render/layout-jobs.js +++ b/tests/owl/render/layout-jobs.js @@ -15,13 +15,19 @@ const owner = require("./owner-layout.json") const cases = require("../cases.json") const T = cases.time -// A wttr.in j1 answer, made up. -const hours = (base) => [0, 300, 600, 900, 1200, 1500, 1800, 2100].map((t, i) => ({ time: String(t), tempC: String(base + [0, -1, -1, 2, 5, 6, 3, 1][i]), weatherCode: "116", chanceofrain: "10", FeelsLikeC: String(base), windspeedKmph: "11", uvIndex: "2" })) -const wttr = { - current_condition: [{ temp_C: "14", FeelsLikeC: "12", weatherCode: "116", weatherDesc: [{ value: "Partly cloudy" }], humidity: "70", windspeedKmph: "11", winddir16Point: "W", uvIndex: "2", precipMM: "0.0", localObsDateTime: "2026-10-13 01:27 PM" }], - nearest_area: [{ areaName: [{ value: "Sample Town" }], country: [{ value: "Example" }], latitude: "52.52", longitude: "13.40" }], - weather: ["2026-10-13", "2026-10-14", "2026-10-15"].map((d, i) => ({ date: d, maxtempC: String(16 - i), mintempC: String(9 - i), avgtempC: "12", - astronomy: [{ sunrise: "07:26 AM", sunset: "06:18 PM", moonrise: "03:02 AM", moonset: "05:10 PM", moon_phase: "Waning Crescent", moon_illumination: "40" }], hourly: hours(9 - i) })) +// Open-Meteo geocoding and forecast answers, made up (our copies of today and forecast use them). +const geo = { results: [{ name: "Sample Town", latitude: 52.52, longitude: 13.4, country: "Example", country_code: "EX" }] } +const day0 = T - (T % 86400) +const hourTimes = Array.from({ length: 72 }, (_, i) => day0 + i * 3600) +const meteo = { + current: { time: T, temperature_2m: 14.2, apparent_temperature: 12.1, relative_humidity_2m: 70, is_day: 1, weather_code: 2, precipitation: 0, + pressure_msl: 1016, wind_speed_10m: 11, wind_direction_10m: 270 }, + hourly: { time: hourTimes, temperature_2m: hourTimes.map((t, i) => 9 - Math.floor(i / 24) + [0, -1, -1, 2, 5, 6, 3, 1][Math.floor((i % 24) / 3)]), + precipitation_probability: hourTimes.map(() => 10), weather_code: hourTimes.map(() => 2), is_day: hourTimes.map((t, i) => (i % 24) >= 7 && (i % 24) < 18 ? 1 : 0), + uv_index: hourTimes.map(() => 2), visibility: hourTimes.map(() => 10000) }, + daily: { time: [0, 1, 2].map((i) => day0 + i * 86400), weather_code: [2, 3, 61], temperature_2m_max: [16, 15, 14], temperature_2m_min: [9, 8, 7], + sunrise: [0, 1, 2].map((i) => day0 + i * 86400 + 5 * 3600 + 26 * 60), sunset: [0, 1, 2].map((i) => day0 + i * 86400 + 16 * 3600 + 18 * 60), + precipitation_probability_max: [10, 20, 60], precipitation_sum: [0, 0.4, 3] } } const prices = Array.from({ length: 42 }, (_, i) => 61000 + i * 80 + Math.round(Math.sin(i / 3) * 400)) const fixtures = { @@ -29,9 +35,8 @@ const fixtures = { price_change_percentage_1h_in_currency: 0.21, price_change_percentage_24h_in_currency: 1.42, price_change_percentage_7d_in_currency: 3.1, market_cap: 1265000000000, total_volume: 31200000000, circulating_supply: 19750000, max_supply: 21000000, ath: 73700, ath_date: "2024-03-14T07:10:36Z", sparkline_in_7d: { price: prices } }]) } }, - "owl:simonschubert.today": { now: { value: T }, wx: { text: JSON.stringify(wttr) } }, - "owl:simonschubert.forecast": { w: { text: JSON.stringify({ place: "Berlin (sample)", now: { temp: "14", desc: "Partly cloudy" }, - days: wttr.weather.map((d) => ({ date: d.date, day: ["Tue", "Wed", "Thu"][wttr.weather.indexOf(d)], max: d.maxtempC, min: d.mintempC, hours: d.hourly.map((h) => Number(h.tempC)) })) }) } }, + "owl:simonschubert.today": { now: { value: T }, geo: { text: JSON.stringify(geo) }, wx: { text: JSON.stringify(meteo) } }, + "owl:simonschubert.forecast": { geo: { text: JSON.stringify(geo) }, w: { text: JSON.stringify(meteo) } }, "owl:simonschubert.earthquakes": cases.widgets.find((c) => c.id === "simonschubert/earthquakes").sources, "owl:simonschubert.habits": cases.widgets.find((c) => c.id === "simonschubert/habits").sources } @@ -40,7 +45,9 @@ const layout = side === "after" ? H.parse(JSON.stringify(owner), {}) : owner const widgets = [], approvals = {} if (side === "after") { for (const p of H.portPlacements(owner)) { - const text = fs.readFileSync(path.join(storeDir, H.owlStoreId(p.to), "widget.owl"), "utf8") + // What omamobile-owl-widgets ships: our own copy (overrides/) where it keeps one. + const ours = path.resolve(__dirname, "../../../packages/omamobile-owl-widgets/overrides", H.owlStoreId(p.to), "widget.owl") + const text = fs.readFileSync(fs.existsSync(ours) ? ours : path.join(storeDir, H.owlStoreId(p.to), "widget.owl"), "utf8") widgets.push({ id: p.to, text, fixture: { sources: fixtures[p.to] || {} } }) const v = K.portApproval(H.portCapabilities(p.from), K.describe(p.to, text, H.GRID, 908 / 6, 480 / 6 / 69), p.internet) if (v.approve) approvals[p.to] = v.approve