Compare commits

...
9 Commits
Author SHA1 Message Date
Ansho Rei 9be6f86557 feat: show play and pause icons instead of words on now playing
A PlayState component draws the triangle and the two bars as vectors in
the highlight colour. The mini player uses it too, in place of the ▶
and ❚❚ glyphs, which a font fallback could draw as emoji or at
different weights.
2026-11-04 14:40:50 +01:00
Ansho Rei 341ae614e1 feat: add a cover backdrop slider to the settings
The first range setting: its row draws a slider, and left and right
change it in steps of 10 while confirm still flips the toggles. Saved
as cover_backdrop in settings.toml, defaulting to the old fixed look.

Up to the default the cover fades in under the old overlay. Above it
the overlay thins as well, down to 0.55 on the left where the title and
progress sit, which kept them readable over a bright cover.
2026-11-04 14:31:17 +01:00
Ansho Rei 2e8b2e6a02 feat: flip the now-playing cover when the picture changes
The cover turns edge-on, swaps, and turns back with an overshooting
curve. Slint has no perspective, so the turn squashes the width.

Whether to flip is decided by a hash of the decoded pixels, not by the
cover id: Navidrome gives every track its own id even when the whole
album shares one image. While the new cover loads the old one stays up,
and the next track's cover is fetched ahead so a skip decides at once.
2026-11-04 13:44:38 +01:00
Ansho Rei 578a4f5607 fix: enlarge the app icon's mark so it reads at small sizes
The tile now starts 2 units from the edge instead of 8 and the mark is
100 tall instead of 74, nudged up 1 unit because its base reads heavier
than the R.
2026-11-04 13:06:36 +01:00
Ansho Rei d90191618d fix: centre the logo on the login screen 2026-11-04 13:05:46 +01:00
Ansho Rei 936e28b483 feat: add an Exit button to the login screen
The login screen could only be left with Ctrl+Q, which a gamepad cannot
press. Exit sits below Connect as the last focus stop and goes through
Action::Quit.
2026-11-04 13:05:45 +01:00
Ansho Rei 62169be746 feat: keep the screensaver off while music is playing
Holds org.freedesktop.ScreenSaver.Inhibit, the call Electron apps
such as VacuumTube use to stay awake in Steam's Game Mode, and the
XDG portal's idle inhibit, from play until pause, stop or quit.
zbus 6 cannot connect through Flatpak's D-Bus proxy, so this uses
zbus 5.
2026-11-04 12:57:14 +01:00
Ansho Rei 5a2386e817 build: add make publish to release a version on Gitea with its bundle
Releases on Gitea had nothing to install, so getting remus onto a Steam
machine meant building the bundle and copying it across by hand. After
a bump and a push with tags, make publish builds the Flatpak bundle for
the tagged commit and creates the release, with the changelog entry as
its notes and remus-X.Y.Z.flatpak attached.

Every check runs before the slow build: a clean tree, HEAD tagged with
the Cargo.toml version, a token, the same tag on the remote and no
release for it yet. The token is read from GITEA_TOKEN or
~/.config/gitea/token and passed to curl in a header file, so it is
never on a command line. If the upload fails, the release is deleted
so the next run starts clean.
2026-11-04 11:25:32 +01:00
Ansho Rei e915d00226 feat: restore the queue and position after a restart
Quitting, a crash or SteamOS restarting the app lost the queue and how
far into the track playback was, which hurts most for long items. The
queue is now saved to queue.json in the state directory, one queue per
user and server, on a track change, on pause, when songs are queued,
every 15 seconds while playing and on quit. It holds song metadata,
never a stream URL, since those carry the token or the password.

On start the saved track is loaded paused and seeked to once it has
prerolled. Nothing plays, and the server is not told about the track,
until play is pressed. An unreadable file is logged and ignored.

Two player bugs had to go for this. A failing source posts several
errors, and the later ones counted against the next track, so one
missing song skipped two tracks or stopped the queue. Play pressed
while a track was still loading was dropped.
2026-11-04 11:23:31 +01:00
24 changed files with 1474 additions and 79 deletions
+54
View File
@@ -2,6 +2,60 @@
One section per version, newest first.
## v0.6.5 (2026-11-04)
### Features
- The now-playing screen shows a play or pause icon under the progress bar instead of the words Playing and Paused. The mini player uses the same icons, which no longer depend on the font.
## v0.6.4 (2026-11-04)
### Features
- Settings has a Cover backdrop slider for how much of the cover shows behind the now-playing screen, from off to 100 in steps of 10. Left and right change it. The default looks as before, and the strongest setting still keeps the text readable over a bright cover.
## v0.6.3 (2026-11-04)
### Features
- On the now-playing screen the cover flips around when the next track has a different picture, and settles with a small bounce. Tracks that share a picture do not flip, even on servers such as Navidrome that give every track its own cover id.
## v0.6.2 (2026-11-04)
### Bug fixes
- The app icon has thinner margins and a larger mark, so it stays legible at small sizes such as a taskbar or a repository avatar.
## v0.6.1 (2026-11-04)
### Bug fixes
- The logo is centred on the login screen.
## v0.6.0 (2026-11-04)
### Features
- The login screen has an Exit button below Connect, so remus can be closed from a controller before logging in.
## v0.5.0 (2026-11-04)
### Features
- While music plays, remus asks the system to keep the screensaver and sleep away, and lets go when playback is paused or stopped, or remus quits.
## v0.4.0 (2026-11-04)
### Features
- The queue survives a restart, a crash or SteamOS closing the app. It comes back paused on the same track, at most 15 seconds before where it was, and the server hears nothing until play is pressed. Each server keeps its own saved queue.
- Each release on Gitea has the Flatpak bundle attached, so installing on a Steam machine no longer needs a local build.
### Bug fixes
- A track that cannot be played is skipped on its own. Before, it could skip the next track too, or stop the queue.
- Play pressed while a track is still loading is no longer ignored.
## v0.3.0 (2026-11-04)
### Features
Generated
+5 -1
View File
@@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
[[package]]
name = "remus"
version = "0.3.0"
version = "0.6.5"
dependencies = [
"anyhow",
"directories",
@@ -4404,6 +4404,7 @@ dependencies = [
"slint-build",
"tokio",
"toml",
"zbus",
]
[[package]]
@@ -5407,8 +5408,10 @@ dependencies = [
"libc",
"mio",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"tracing",
"windows-sys 0.61.2",
]
@@ -6727,6 +6730,7 @@ dependencies = [
"rustix 1.1.6",
"serde",
"serde_repr",
"tokio",
"tracing",
"uds_windows",
"uuid",
+2 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "remus"
version = "0.3.0"
version = "0.6.5"
edition = "2024"
license = "MIT"
@@ -21,6 +21,7 @@ serde_json = "1.0.154"
slint = "1.18.1"
tokio = { version = "1.54.1", features = ["rt-multi-thread", "sync", "macros", "time"] }
toml = "1.1.8"
zbus = { version = "5.19.0", default-features = false, features = ["tokio"] }
[build-dependencies]
slint-build = "1.18.1"
+15 -2
View File
@@ -60,13 +60,13 @@ test-live: ## Every Subsonic call against a real server (DEMO_URL, DEMO_USER, DE
.PHONY: shots
shots: ## Screenshot the main screens against the demo server into target/shots
@mkdir -p $(SHOTS_DIR) $(SCRATCH)/config/remus $(SCRATCH)/cache
@mkdir -p $(SHOTS_DIR) $(SCRATCH)/config/remus $(SCRATCH)/cache $(SCRATCH)/state
@salt=$$(head -c 8 /dev/urandom | od -An -tx1 | tr -d ' \n'); \
token=$$(printf '%s%s' '$(DEMO_PASS)' "$$salt" | md5sum | cut -d' ' -f1); \
printf 'url = "%s"\nusername = "%s"\nsalt = "%s"\ntoken = "%s"\n' \
'$(DEMO_URL)' '$(DEMO_USER)' "$$salt" "$$token" > $(SCRATCH)/config/remus/config.toml
cargo build
XDG_CONFIG_HOME=$(CURDIR)/$(SCRATCH)/config XDG_CACHE_HOME=$(CURDIR)/$(SCRATCH)/cache \
XDG_CONFIG_HOME=$(CURDIR)/$(SCRATCH)/config XDG_CACHE_HOME=$(CURDIR)/$(SCRATCH)/cache XDG_STATE_HOME=$(CURDIR)/$(SCRATCH)/state \
REMUS_DEV_SCRIPT="wait:4000,shot:$(SHOTS_DIR)/home.png,right,activate,wait:3000,shot:$(SHOTS_DIR)/album.png,down,activate,wait:3000,now-playing,wait:2500,shot:$(SHOTS_DIR)/now-playing.png,play-pause,back,section-next,section-next,section-next,wait:3000,shot:$(SHOTS_DIR)/artists.png,quit" \
./target/debug/remus
@@ -187,6 +187,19 @@ bump:
git tag -a "v$$new" -m "v$$new"; \
echo "$$current -> $$new, tagged v$$new on $$(git rev-parse --short HEAD) ($$(git log -1 --format=%s))"
# Publishing. Builds the bundle for the version tagged on HEAD and attaches it
# to a new Gitea release, with the changelog entry as its notes.
GITEA_URL ?= https://gitea.anshorei.me
GITEA_REPO ?= Fettleshed/Remus
GITEA_REMOTE ?= origin
GITEA_TOKEN_FILE ?= $(HOME)/.config/gitea/token
.PHONY: publish
publish: ## Release the tagged version on Gitea with the Flatpak bundle attached
@VERSION="$(CURRENT)" GITEA_URL="$(GITEA_URL)" GITEA_REPO="$(GITEA_REPO)" \
GITEA_REMOTE="$(GITEA_REMOTE)" GITEA_TOKEN_FILE="$(GITEA_TOKEN_FILE)" \
bash scripts/publish.sh
.PHONY: clean
clean: ## Remove build output, screenshots and scratch config
cargo clean
+18 -3
View File
@@ -27,7 +27,7 @@ Preferences live apart from the login, in `~/.config/remus/settings.toml`, so lo
## Install on SteamOS
Build the bundle on any Linux machine with Flatpak:
A published version has `remus-<version>.flatpak` attached to its release on Gitea (see [Versions](#versions)). Download that, or build the bundle on any Linux machine with Flatpak:
```
make flatpak-bundle # writes target/flatpak/remus.flatpak
@@ -37,13 +37,13 @@ make flatpak-bundle # writes target/flatpak/remus.flatpak
On the Steam machine, in Desktop Mode:
1. Copy `remus.flatpak` over and install it from a terminal: `flatpak install --user remus.flatpak`. Flatpak pulls the freedesktop 26.08 runtime from Flathub.
1. Copy the bundle over and install it from a terminal: `flatpak install --user remus.flatpak`. Flatpak pulls the freedesktop 26.08 runtime from Flathub.
2. In Steam, choose Games → Add a Non-Steam Game to My Library and pick Remus.
3. Back in Game Mode, open its controller settings and pick a Gamepad layout, so Steam passes the buttons through as a controller and not as keyboard and mouse.
The Flatpak keeps its login and cover cache in `~/.var/app/me.anshorei.Fettleshed.Remus/`, not in `~/.config` and `~/.cache`. Flatpak sets `XDG_CONFIG_HOME` itself there, so overriding it with `flatpak run --env` has no effect.
To update, build a new bundle and install it the same way.
A bundle does not update itself. To update, install the next version's bundle the same way.
## Controls
@@ -92,3 +92,18 @@ Every finished ticket bumps the version, so a build on the Deck can be matched t
- Before bumping, add a `## v<new> (<date>)` entry at the top of `CHANGELOG.md`, with `### Features` and `### Bug fixes` subsections (leave out an empty one), and commit it with the change. `make version` prints the current version.
- Bump on local `master` only: fast-forward `master` to the finished work, switch to it, then bump. The targets refuse any other branch.
- The bump writes the new version to `Cargo.toml`, `Cargo.lock` and the Flatpak metainfo, amends that into the last commit and tags it `v<new>`. It refuses a dirty tree, a commit that is already tagged or pushed, and a version the changelog has no entry for.
To release a version once it is bumped:
1. `git push --follow-tags origin master`
2. `make publish`
`make publish` builds the Flatpak bundle for the version tagged on HEAD and creates its Gitea release. The release has the tag as its title and the changelog entry as its notes, and `remus-<version>.flatpak` is attached. It needs a Gitea token with `write:repository`, from `GITEA_TOKEN` or the file `~/.config/gitea/token` (`GITEA_TOKEN_FILE` to put it elsewhere). It checks everything before the build and refuses when:
- the tree is dirty
- HEAD is not tagged with the version in `Cargo.toml`
- there is no token
- the tag is not on the remote, or the remote's tag is a different one
- the version already has a release
If the upload fails, it deletes the release again so the next run starts clean. `GITEA_URL`, `GITEA_REPO` and `GITEA_REMOTE` default to this repository on `gitea.anshorei.me`.
+5 -3
View File
@@ -166,12 +166,14 @@ def variants() -> dict[str, str]:
# Full-bleed square, the composition of the source artwork.
v["remus-square.svg"] = svg(1024, 1024, mark(CREAM, 512, 512, 512), MAROON)
# Desktop / Flatpak app icon: rounded tile with a margin, 128 grid.
# Desktop / Flatpak app icon: rounded tile on a 128 grid. The margins are
# kept thin so the mark stays legible at 16 to 32 px. The mark sits 1 unit
# above centre because its wide base reads heavier than the R.
v["remus-icon.svg"] = svg(
128,
128,
f'<rect x="8" y="8" width="112" height="112" rx="26" fill="{MAROON}"/>'
+ mark(CREAM, 64, 64, 74),
f'<rect x="2" y="2" width="124" height="124" rx="24" fill="{MAROON}"/>'
+ mark(CREAM, 64, 63, 100),
)
# Lockups with the wordmark, transparent background.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

+1 -1
View File
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><rect x="8" y="8" width="112" height="112" rx="26" fill="#5a0712"/><g fill="#faebda" transform="translate(64 64) scale(0.117741) translate(-627.5 -627.25)"><path d="M456.32,605.50C452.96,605.35 452.88,605.29 452.88,603.08C452.88,601.03 453.05,600.88 456.88,599.52C460.01,598.41 460.90,598.05 463.45,596.85C464.45,596.38 465.33,596.00 465.40,596.00C465.81,596.00 472.53,592.55 474.76,591.20C490.25,581.80 496.47,573.90 499.54,559.75L500.11,557.12L500.24,497.38C500.43,412.59 500.22,363.56 499.67,360.75C498.12,352.93 496.40,348.79 492.61,343.77C485.58,334.43 474.65,326.59 459.62,320.12C457.15,319.06 454.76,318.08 454.31,317.95C453.12,317.62 452.67,316.78 452.80,315.14C452.86,314.39 453.06,313.60 453.24,313.39C453.53,313.04 462.72,313.00 547.89,313.00C653.06,313.00 647.36,312.92 660.75,314.64C672.81,316.19 690.05,321.27 698.25,325.70C709.70,331.88 714.98,335.69 721.89,342.78C731.72,352.87 738.85,366.60 740.96,379.50C742.04,386.15 742.34,389.75 742.17,394.18C741.67,407.42 738.27,418.76 731.68,429.15C724.99,439.71 714.77,449.22 702.54,456.28C701.26,457.02 699.91,457.80 699.54,458.02C693.02,461.86 679.82,467.01 670.12,469.50C665.05,470.81 664.39,471.06 664.30,471.71C664.21,472.26 665.78,474.37 671.26,481.12C672.72,482.91 677.78,489.21 682.52,495.13C687.27,501.04 692.08,507.00 693.22,508.38C694.36,509.75 696.22,512.11 697.37,513.62C698.51,515.14 700.73,517.97 702.29,519.91C710.78,530.50 718.71,540.31 721.45,543.62C723.15,545.69 726.41,549.68 728.71,552.50C735.86,561.29 738.22,564.01 742.11,567.89C750.99,576.78 762.35,584.44 773.88,589.31C774.70,589.66 776.22,590.31 777.25,590.75C778.28,591.20 779.69,591.76 780.38,592.00C783.56,593.10 786.30,593.97 788.25,594.49C789.42,594.79 791.11,595.26 792.00,595.52C793.57,595.97 795.02,596.30 799.48,597.23C802.20,597.80 802.25,597.88 802.25,601.41C802.25,604.02 802.21,604.27 801.65,604.92L801.04,605.62L753.96,605.62C715.51,605.62 706.46,605.56 704.62,605.28C692.89,603.51 683.14,597.15 674.69,585.75C673.21,583.76 671.10,580.94 670.00,579.50C667.28,575.93 664.03,571.58 660.00,566.13C658.14,563.62 655.56,560.13 654.25,558.38C652.94,556.62 650.03,552.70 647.77,549.66C641.97,541.85 633.78,530.97 619.02,511.50C617.41,509.37 613.97,504.81 611.37,501.38C608.78,497.94 605.19,493.21 603.39,490.88C601.59,488.54 599.31,485.56 598.33,484.25C596.30,481.54 595.64,480.88 594.74,480.66C594.38,480.58 589.15,480.50 583.11,480.49L572.13,480.47L571.68,481.02C571.25,481.55 571.24,483.35 571.31,519.85C571.38,549.72 571.47,558.48 571.72,559.75C574.89,575.81 583.99,585.82 604.45,595.75C605.86,596.44 607.11,597.00 607.23,597.00C607.35,597.00 608.15,597.35 609.02,597.78C609.88,598.21 611.16,598.76 611.86,599.01C614.40,599.93 615.15,600.22 616.31,600.72L617.50,601.23L617.50,602.84C617.50,604.03 617.38,604.59 617.03,605.02L616.57,605.60L537.85,605.61C494.55,605.62 457.86,605.57 456.32,605.50ZM600.38,463.00C606.75,462.53 613.03,461.37 618.38,459.66C629.72,456.04 637.60,451.38 645.27,443.75C651.89,437.18 657.19,428.71 659.74,420.62C660.05,419.66 660.44,418.48 660.62,418.00C662.11,413.97 663.57,406.53 664.03,400.62C664.33,396.86 664.17,385.71 663.79,383.88C663.64,383.19 663.40,381.84 663.25,380.88C662.92,378.72 661.84,373.77 661.37,372.25C661.18,371.63 660.75,370.23 660.41,369.12C660.07,368.02 659.61,366.79 659.40,366.38C659.18,365.96 659.00,365.51 659.00,365.36C659.00,365.22 658.26,363.65 657.35,361.86C648.63,344.78 632.27,333.74 611.62,331.03C610.52,330.88 608.67,330.63 607.50,330.47C606.12,330.28 599.60,330.14 589.00,330.06L572.62,329.95L571.94,330.50L571.25,331.04L571.31,396.95L571.38,462.86L571.89,463.12C572.56,463.45 595.54,463.36 600.38,463.00Z"/><path fill-rule="evenodd" d="M453,633Q453,632 454,632H801Q802,632 802,633V653A13 12 0 0 1 789,665H466A13 12 0 0 1 453,653ZM493.5,677H761.5V683A16 16 0 0 1 745.5,699H509.5A16 16 0 0 1 493.5,683ZM520,710H735Q726,714 726,724V856Q726.5,870 735,873H520Q528.5,870 529,856V724Q529,714 520,710ZM562.5,855.5V738.5A11.5 11.5 0 0 1 585.5,738.5V855.5ZM616.0,855.5V738.5A11.5 11.5 0 0 1 639.0,738.5V855.5ZM669.5,855.5V738.5A11.5 11.5 0 0 1 692.5,738.5V855.5ZM487,905V900A16 16 0 0 1 503,884H752A16 16 0 0 1 768,900V905ZM460,941.5V930A14 14 0 0 1 474,916H781A14 14 0 0 1 795,930V941.5Z"/><rect x="460.0" y="741" width="30" height="115" rx="6"/><rect x="765.0" y="741" width="30" height="115" rx="6"/><rect x="400.0" y="707" width="30" height="182" rx="6"/><rect x="825.0" y="707" width="30" height="182" rx="6"/><rect x="340.0" y="757" width="30" height="99" rx="6"/><rect x="885.0" y="757" width="30" height="99" rx="6"/></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><rect x="2" y="2" width="124" height="124" rx="24" fill="#5a0712"/><g fill="#faebda" transform="translate(64 63) scale(0.159109) translate(-627.5 -627.25)"><path d="M456.32,605.50C452.96,605.35 452.88,605.29 452.88,603.08C452.88,601.03 453.05,600.88 456.88,599.52C460.01,598.41 460.90,598.05 463.45,596.85C464.45,596.38 465.33,596.00 465.40,596.00C465.81,596.00 472.53,592.55 474.76,591.20C490.25,581.80 496.47,573.90 499.54,559.75L500.11,557.12L500.24,497.38C500.43,412.59 500.22,363.56 499.67,360.75C498.12,352.93 496.40,348.79 492.61,343.77C485.58,334.43 474.65,326.59 459.62,320.12C457.15,319.06 454.76,318.08 454.31,317.95C453.12,317.62 452.67,316.78 452.80,315.14C452.86,314.39 453.06,313.60 453.24,313.39C453.53,313.04 462.72,313.00 547.89,313.00C653.06,313.00 647.36,312.92 660.75,314.64C672.81,316.19 690.05,321.27 698.25,325.70C709.70,331.88 714.98,335.69 721.89,342.78C731.72,352.87 738.85,366.60 740.96,379.50C742.04,386.15 742.34,389.75 742.17,394.18C741.67,407.42 738.27,418.76 731.68,429.15C724.99,439.71 714.77,449.22 702.54,456.28C701.26,457.02 699.91,457.80 699.54,458.02C693.02,461.86 679.82,467.01 670.12,469.50C665.05,470.81 664.39,471.06 664.30,471.71C664.21,472.26 665.78,474.37 671.26,481.12C672.72,482.91 677.78,489.21 682.52,495.13C687.27,501.04 692.08,507.00 693.22,508.38C694.36,509.75 696.22,512.11 697.37,513.62C698.51,515.14 700.73,517.97 702.29,519.91C710.78,530.50 718.71,540.31 721.45,543.62C723.15,545.69 726.41,549.68 728.71,552.50C735.86,561.29 738.22,564.01 742.11,567.89C750.99,576.78 762.35,584.44 773.88,589.31C774.70,589.66 776.22,590.31 777.25,590.75C778.28,591.20 779.69,591.76 780.38,592.00C783.56,593.10 786.30,593.97 788.25,594.49C789.42,594.79 791.11,595.26 792.00,595.52C793.57,595.97 795.02,596.30 799.48,597.23C802.20,597.80 802.25,597.88 802.25,601.41C802.25,604.02 802.21,604.27 801.65,604.92L801.04,605.62L753.96,605.62C715.51,605.62 706.46,605.56 704.62,605.28C692.89,603.51 683.14,597.15 674.69,585.75C673.21,583.76 671.10,580.94 670.00,579.50C667.28,575.93 664.03,571.58 660.00,566.13C658.14,563.62 655.56,560.13 654.25,558.38C652.94,556.62 650.03,552.70 647.77,549.66C641.97,541.85 633.78,530.97 619.02,511.50C617.41,509.37 613.97,504.81 611.37,501.38C608.78,497.94 605.19,493.21 603.39,490.88C601.59,488.54 599.31,485.56 598.33,484.25C596.30,481.54 595.64,480.88 594.74,480.66C594.38,480.58 589.15,480.50 583.11,480.49L572.13,480.47L571.68,481.02C571.25,481.55 571.24,483.35 571.31,519.85C571.38,549.72 571.47,558.48 571.72,559.75C574.89,575.81 583.99,585.82 604.45,595.75C605.86,596.44 607.11,597.00 607.23,597.00C607.35,597.00 608.15,597.35 609.02,597.78C609.88,598.21 611.16,598.76 611.86,599.01C614.40,599.93 615.15,600.22 616.31,600.72L617.50,601.23L617.50,602.84C617.50,604.03 617.38,604.59 617.03,605.02L616.57,605.60L537.85,605.61C494.55,605.62 457.86,605.57 456.32,605.50ZM600.38,463.00C606.75,462.53 613.03,461.37 618.38,459.66C629.72,456.04 637.60,451.38 645.27,443.75C651.89,437.18 657.19,428.71 659.74,420.62C660.05,419.66 660.44,418.48 660.62,418.00C662.11,413.97 663.57,406.53 664.03,400.62C664.33,396.86 664.17,385.71 663.79,383.88C663.64,383.19 663.40,381.84 663.25,380.88C662.92,378.72 661.84,373.77 661.37,372.25C661.18,371.63 660.75,370.23 660.41,369.12C660.07,368.02 659.61,366.79 659.40,366.38C659.18,365.96 659.00,365.51 659.00,365.36C659.00,365.22 658.26,363.65 657.35,361.86C648.63,344.78 632.27,333.74 611.62,331.03C610.52,330.88 608.67,330.63 607.50,330.47C606.12,330.28 599.60,330.14 589.00,330.06L572.62,329.95L571.94,330.50L571.25,331.04L571.31,396.95L571.38,462.86L571.89,463.12C572.56,463.45 595.54,463.36 600.38,463.00Z"/><path fill-rule="evenodd" d="M453,633Q453,632 454,632H801Q802,632 802,633V653A13 12 0 0 1 789,665H466A13 12 0 0 1 453,653ZM493.5,677H761.5V683A16 16 0 0 1 745.5,699H509.5A16 16 0 0 1 493.5,683ZM520,710H735Q726,714 726,724V856Q726.5,870 735,873H520Q528.5,870 529,856V724Q529,714 520,710ZM562.5,855.5V738.5A11.5 11.5 0 0 1 585.5,738.5V855.5ZM616.0,855.5V738.5A11.5 11.5 0 0 1 639.0,738.5V855.5ZM669.5,855.5V738.5A11.5 11.5 0 0 1 692.5,738.5V855.5ZM487,905V900A16 16 0 0 1 503,884H752A16 16 0 0 1 768,900V905ZM460,941.5V930A14 14 0 0 1 474,916H781A14 14 0 0 1 795,930V941.5Z"/><rect x="460.0" y="741" width="30" height="115" rx="6"/><rect x="765.0" y="741" width="30" height="115" rx="6"/><rect x="400.0" y="707" width="30" height="182" rx="6"/><rect x="825.0" y="707" width="30" height="182" rx="6"/><rect x="340.0" y="757" width="30" height="99" rx="6"/><rect x="885.0" y="757" width="30" height="99" rx="6"/></g></svg>

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

@@ -20,6 +20,14 @@
</supports>
<content_rating type="oars-1.1"/>
<releases>
<release version="0.6.5" date="2026-11-04"/>
<release version="0.6.4" date="2026-11-04"/>
<release version="0.6.3" date="2026-11-04"/>
<release version="0.6.2" date="2026-11-04"/>
<release version="0.6.1" date="2026-11-04"/>
<release version="0.6.0" date="2026-11-04"/>
<release version="0.5.0" date="2026-11-04"/>
<release version="0.4.0" date="2026-11-04"/>
<release version="0.3.0" date="2026-11-04"/>
<release version="0.2.1" date="2026-11-04"/>
<release version="0.2.0" date="2026-11-04"/>
+1 -1
View File
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><rect x="8" y="8" width="112" height="112" rx="26" fill="#5a0712"/><g fill="#faebda" transform="translate(64 64) scale(0.117741) translate(-627.5 -627.25)"><path d="M456.32,605.50C452.96,605.35 452.88,605.29 452.88,603.08C452.88,601.03 453.05,600.88 456.88,599.52C460.01,598.41 460.90,598.05 463.45,596.85C464.45,596.38 465.33,596.00 465.40,596.00C465.81,596.00 472.53,592.55 474.76,591.20C490.25,581.80 496.47,573.90 499.54,559.75L500.11,557.12L500.24,497.38C500.43,412.59 500.22,363.56 499.67,360.75C498.12,352.93 496.40,348.79 492.61,343.77C485.58,334.43 474.65,326.59 459.62,320.12C457.15,319.06 454.76,318.08 454.31,317.95C453.12,317.62 452.67,316.78 452.80,315.14C452.86,314.39 453.06,313.60 453.24,313.39C453.53,313.04 462.72,313.00 547.89,313.00C653.06,313.00 647.36,312.92 660.75,314.64C672.81,316.19 690.05,321.27 698.25,325.70C709.70,331.88 714.98,335.69 721.89,342.78C731.72,352.87 738.85,366.60 740.96,379.50C742.04,386.15 742.34,389.75 742.17,394.18C741.67,407.42 738.27,418.76 731.68,429.15C724.99,439.71 714.77,449.22 702.54,456.28C701.26,457.02 699.91,457.80 699.54,458.02C693.02,461.86 679.82,467.01 670.12,469.50C665.05,470.81 664.39,471.06 664.30,471.71C664.21,472.26 665.78,474.37 671.26,481.12C672.72,482.91 677.78,489.21 682.52,495.13C687.27,501.04 692.08,507.00 693.22,508.38C694.36,509.75 696.22,512.11 697.37,513.62C698.51,515.14 700.73,517.97 702.29,519.91C710.78,530.50 718.71,540.31 721.45,543.62C723.15,545.69 726.41,549.68 728.71,552.50C735.86,561.29 738.22,564.01 742.11,567.89C750.99,576.78 762.35,584.44 773.88,589.31C774.70,589.66 776.22,590.31 777.25,590.75C778.28,591.20 779.69,591.76 780.38,592.00C783.56,593.10 786.30,593.97 788.25,594.49C789.42,594.79 791.11,595.26 792.00,595.52C793.57,595.97 795.02,596.30 799.48,597.23C802.20,597.80 802.25,597.88 802.25,601.41C802.25,604.02 802.21,604.27 801.65,604.92L801.04,605.62L753.96,605.62C715.51,605.62 706.46,605.56 704.62,605.28C692.89,603.51 683.14,597.15 674.69,585.75C673.21,583.76 671.10,580.94 670.00,579.50C667.28,575.93 664.03,571.58 660.00,566.13C658.14,563.62 655.56,560.13 654.25,558.38C652.94,556.62 650.03,552.70 647.77,549.66C641.97,541.85 633.78,530.97 619.02,511.50C617.41,509.37 613.97,504.81 611.37,501.38C608.78,497.94 605.19,493.21 603.39,490.88C601.59,488.54 599.31,485.56 598.33,484.25C596.30,481.54 595.64,480.88 594.74,480.66C594.38,480.58 589.15,480.50 583.11,480.49L572.13,480.47L571.68,481.02C571.25,481.55 571.24,483.35 571.31,519.85C571.38,549.72 571.47,558.48 571.72,559.75C574.89,575.81 583.99,585.82 604.45,595.75C605.86,596.44 607.11,597.00 607.23,597.00C607.35,597.00 608.15,597.35 609.02,597.78C609.88,598.21 611.16,598.76 611.86,599.01C614.40,599.93 615.15,600.22 616.31,600.72L617.50,601.23L617.50,602.84C617.50,604.03 617.38,604.59 617.03,605.02L616.57,605.60L537.85,605.61C494.55,605.62 457.86,605.57 456.32,605.50ZM600.38,463.00C606.75,462.53 613.03,461.37 618.38,459.66C629.72,456.04 637.60,451.38 645.27,443.75C651.89,437.18 657.19,428.71 659.74,420.62C660.05,419.66 660.44,418.48 660.62,418.00C662.11,413.97 663.57,406.53 664.03,400.62C664.33,396.86 664.17,385.71 663.79,383.88C663.64,383.19 663.40,381.84 663.25,380.88C662.92,378.72 661.84,373.77 661.37,372.25C661.18,371.63 660.75,370.23 660.41,369.12C660.07,368.02 659.61,366.79 659.40,366.38C659.18,365.96 659.00,365.51 659.00,365.36C659.00,365.22 658.26,363.65 657.35,361.86C648.63,344.78 632.27,333.74 611.62,331.03C610.52,330.88 608.67,330.63 607.50,330.47C606.12,330.28 599.60,330.14 589.00,330.06L572.62,329.95L571.94,330.50L571.25,331.04L571.31,396.95L571.38,462.86L571.89,463.12C572.56,463.45 595.54,463.36 600.38,463.00Z"/><path fill-rule="evenodd" d="M453,633Q453,632 454,632H801Q802,632 802,633V653A13 12 0 0 1 789,665H466A13 12 0 0 1 453,653ZM493.5,677H761.5V683A16 16 0 0 1 745.5,699H509.5A16 16 0 0 1 493.5,683ZM520,710H735Q726,714 726,724V856Q726.5,870 735,873H520Q528.5,870 529,856V724Q529,714 520,710ZM562.5,855.5V738.5A11.5 11.5 0 0 1 585.5,738.5V855.5ZM616.0,855.5V738.5A11.5 11.5 0 0 1 639.0,738.5V855.5ZM669.5,855.5V738.5A11.5 11.5 0 0 1 692.5,738.5V855.5ZM487,905V900A16 16 0 0 1 503,884H752A16 16 0 0 1 768,900V905ZM460,941.5V930A14 14 0 0 1 474,916H781A14 14 0 0 1 795,930V941.5Z"/><rect x="460.0" y="741" width="30" height="115" rx="6"/><rect x="765.0" y="741" width="30" height="115" rx="6"/><rect x="400.0" y="707" width="30" height="182" rx="6"/><rect x="825.0" y="707" width="30" height="182" rx="6"/><rect x="340.0" y="757" width="30" height="99" rx="6"/><rect x="885.0" y="757" width="30" height="99" rx="6"/></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><rect x="2" y="2" width="124" height="124" rx="24" fill="#5a0712"/><g fill="#faebda" transform="translate(64 63) scale(0.159109) translate(-627.5 -627.25)"><path d="M456.32,605.50C452.96,605.35 452.88,605.29 452.88,603.08C452.88,601.03 453.05,600.88 456.88,599.52C460.01,598.41 460.90,598.05 463.45,596.85C464.45,596.38 465.33,596.00 465.40,596.00C465.81,596.00 472.53,592.55 474.76,591.20C490.25,581.80 496.47,573.90 499.54,559.75L500.11,557.12L500.24,497.38C500.43,412.59 500.22,363.56 499.67,360.75C498.12,352.93 496.40,348.79 492.61,343.77C485.58,334.43 474.65,326.59 459.62,320.12C457.15,319.06 454.76,318.08 454.31,317.95C453.12,317.62 452.67,316.78 452.80,315.14C452.86,314.39 453.06,313.60 453.24,313.39C453.53,313.04 462.72,313.00 547.89,313.00C653.06,313.00 647.36,312.92 660.75,314.64C672.81,316.19 690.05,321.27 698.25,325.70C709.70,331.88 714.98,335.69 721.89,342.78C731.72,352.87 738.85,366.60 740.96,379.50C742.04,386.15 742.34,389.75 742.17,394.18C741.67,407.42 738.27,418.76 731.68,429.15C724.99,439.71 714.77,449.22 702.54,456.28C701.26,457.02 699.91,457.80 699.54,458.02C693.02,461.86 679.82,467.01 670.12,469.50C665.05,470.81 664.39,471.06 664.30,471.71C664.21,472.26 665.78,474.37 671.26,481.12C672.72,482.91 677.78,489.21 682.52,495.13C687.27,501.04 692.08,507.00 693.22,508.38C694.36,509.75 696.22,512.11 697.37,513.62C698.51,515.14 700.73,517.97 702.29,519.91C710.78,530.50 718.71,540.31 721.45,543.62C723.15,545.69 726.41,549.68 728.71,552.50C735.86,561.29 738.22,564.01 742.11,567.89C750.99,576.78 762.35,584.44 773.88,589.31C774.70,589.66 776.22,590.31 777.25,590.75C778.28,591.20 779.69,591.76 780.38,592.00C783.56,593.10 786.30,593.97 788.25,594.49C789.42,594.79 791.11,595.26 792.00,595.52C793.57,595.97 795.02,596.30 799.48,597.23C802.20,597.80 802.25,597.88 802.25,601.41C802.25,604.02 802.21,604.27 801.65,604.92L801.04,605.62L753.96,605.62C715.51,605.62 706.46,605.56 704.62,605.28C692.89,603.51 683.14,597.15 674.69,585.75C673.21,583.76 671.10,580.94 670.00,579.50C667.28,575.93 664.03,571.58 660.00,566.13C658.14,563.62 655.56,560.13 654.25,558.38C652.94,556.62 650.03,552.70 647.77,549.66C641.97,541.85 633.78,530.97 619.02,511.50C617.41,509.37 613.97,504.81 611.37,501.38C608.78,497.94 605.19,493.21 603.39,490.88C601.59,488.54 599.31,485.56 598.33,484.25C596.30,481.54 595.64,480.88 594.74,480.66C594.38,480.58 589.15,480.50 583.11,480.49L572.13,480.47L571.68,481.02C571.25,481.55 571.24,483.35 571.31,519.85C571.38,549.72 571.47,558.48 571.72,559.75C574.89,575.81 583.99,585.82 604.45,595.75C605.86,596.44 607.11,597.00 607.23,597.00C607.35,597.00 608.15,597.35 609.02,597.78C609.88,598.21 611.16,598.76 611.86,599.01C614.40,599.93 615.15,600.22 616.31,600.72L617.50,601.23L617.50,602.84C617.50,604.03 617.38,604.59 617.03,605.02L616.57,605.60L537.85,605.61C494.55,605.62 457.86,605.57 456.32,605.50ZM600.38,463.00C606.75,462.53 613.03,461.37 618.38,459.66C629.72,456.04 637.60,451.38 645.27,443.75C651.89,437.18 657.19,428.71 659.74,420.62C660.05,419.66 660.44,418.48 660.62,418.00C662.11,413.97 663.57,406.53 664.03,400.62C664.33,396.86 664.17,385.71 663.79,383.88C663.64,383.19 663.40,381.84 663.25,380.88C662.92,378.72 661.84,373.77 661.37,372.25C661.18,371.63 660.75,370.23 660.41,369.12C660.07,368.02 659.61,366.79 659.40,366.38C659.18,365.96 659.00,365.51 659.00,365.36C659.00,365.22 658.26,363.65 657.35,361.86C648.63,344.78 632.27,333.74 611.62,331.03C610.52,330.88 608.67,330.63 607.50,330.47C606.12,330.28 599.60,330.14 589.00,330.06L572.62,329.95L571.94,330.50L571.25,331.04L571.31,396.95L571.38,462.86L571.89,463.12C572.56,463.45 595.54,463.36 600.38,463.00Z"/><path fill-rule="evenodd" d="M453,633Q453,632 454,632H801Q802,632 802,633V653A13 12 0 0 1 789,665H466A13 12 0 0 1 453,653ZM493.5,677H761.5V683A16 16 0 0 1 745.5,699H509.5A16 16 0 0 1 493.5,683ZM520,710H735Q726,714 726,724V856Q726.5,870 735,873H520Q528.5,870 529,856V724Q529,714 520,710ZM562.5,855.5V738.5A11.5 11.5 0 0 1 585.5,738.5V855.5ZM616.0,855.5V738.5A11.5 11.5 0 0 1 639.0,738.5V855.5ZM669.5,855.5V738.5A11.5 11.5 0 0 1 692.5,738.5V855.5ZM487,905V900A16 16 0 0 1 503,884H752A16 16 0 0 1 768,900V905ZM460,941.5V930A14 14 0 0 1 474,916H781A14 14 0 0 1 795,930V941.5Z"/><rect x="460.0" y="741" width="30" height="115" rx="6"/><rect x="765.0" y="741" width="30" height="115" rx="6"/><rect x="400.0" y="707" width="30" height="182" rx="6"/><rect x="825.0" y="707" width="30" height="182" rx="6"/><rect x="340.0" y="757" width="30" height="99" rx="6"/><rect x="885.0" y="757" width="30" height="99" rx="6"/></g></svg>

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

+3
View File
@@ -15,6 +15,9 @@ finish-args:
# GPU rendering and gamepads (evdev). --device=input would be narrower but
# needs Flatpak 1.15.6, which not every SteamOS release ships.
- --device=all
# Keeps the screensaver off while music plays, the way Chromium and
# Electron apps do. The XDG portal route needs no permission.
- --talk-name=org.freedesktop.ScreenSaver
build-options:
append-path: /usr/lib/sdk/rust-stable/bin
+119
View File
@@ -0,0 +1,119 @@
#!/usr/bin/env bash
# Publishes the tagged version on HEAD as a Gitea release with the Flatpak
# bundle attached. Run by `make publish`, after a bump and a push with tags.
#
# Every check runs before the slow Flatpak build, so a refusal costs seconds.
#
# Environment, set by the Makefile:
# VERSION version in Cargo.toml
# GITEA_URL e.g. https://gitea.anshorei.me
# GITEA_REPO owner/name, e.g. Fettleshed/Remus
# GITEA_REMOTE git remote that holds the tags
# GITEA_TOKEN or GITEA_TOKEN_FILE API token with write:repository
set -euo pipefail
fail() {
echo "error: $*" >&2
exit 1
}
for tool in curl jq git awk; do
command -v "$tool" >/dev/null || fail "$tool is not installed"
done
[ -n "${VERSION:-}" ] || fail "no version found in the [package] table of Cargo.toml"
tag="v$VERSION"
api="${GITEA_URL%/}/api/v1/repos/$GITEA_REPO"
asset="remus-$VERSION.flatpak"
# The bundle is built from the working tree, so it has to be the tagged commit.
if [ -n "$(git status --porcelain)" ]; then
echo "error: working tree is dirty, and the bundle would not be what $tag names:" >&2
git status --short >&2
exit 1
fi
head_tags=$(git tag --points-at HEAD --list 'v*')
if ! grep -qxF "$tag" <<<"$head_tags"; then
if [ -n "$head_tags" ]; then
fail "HEAD is tagged $(paste -sd' ' <<<"$head_tags"), but Cargo.toml says $VERSION"
fi
fail "HEAD is not tagged $tag. Check out the tag, or bump first with make patch, minor or major."
fi
# The token goes to curl in a header file, so it is never on a command line
# or in the output.
if [ -n "${GITEA_TOKEN:-}" ]; then
token=$GITEA_TOKEN
elif [ -n "${GITEA_TOKEN_FILE:-}" ] && [ -r "$GITEA_TOKEN_FILE" ]; then
token=$(tr -d '[:space:]' <"$GITEA_TOKEN_FILE")
else
fail "no Gitea token. Set GITEA_TOKEN, or put one in ${GITEA_TOKEN_FILE:-a file named by GITEA_TOKEN_FILE}. It needs write:repository."
fi
[ -n "$token" ] || fail "the Gitea token is empty"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
(umask 077 && printf 'Authorization: token %s\n' "$token" >"$tmp/auth")
unset token GITEA_TOKEN
# Calls the API. Prints the body and returns the HTTP status in $status.
call() {
local method=$1 url=$2
shift 2
status=$(curl -sS -o "$tmp/body" -w '%{http_code}' -X "$method" -H @"$tmp/auth" "$@" "$url") ||
fail "could not reach $GITEA_URL"
}
# The local tag object has to be the one on the remote, or the release would
# point at a tag that names another commit, or at none.
remote_tag=$(git ls-remote --tags "$GITEA_REMOTE" "refs/tags/$tag" | cut -f1) ||
fail "could not list the tags on $GITEA_REMOTE"
[ -n "$remote_tag" ] || fail "$tag is not on $GITEA_REMOTE yet. Push it first: git push --follow-tags $GITEA_REMOTE"
[ "$remote_tag" = "$(git rev-parse "refs/tags/$tag")" ] ||
fail "$tag on $GITEA_REMOTE is not the local $tag. Find out which one is right before publishing."
notes=$(awk -v h="## $tag " '
index($0, h) == 1 { found = 1; next }
found && /^## / { exit }
found { print }
' CHANGELOG.md | sed -e '/./,$!d')
[ -n "$notes" ] || fail "CHANGELOG.md has no text under '## $tag'"
call GET "$api"
case $status in
200) ;;
401 | 403) fail "Gitea refused the token ($status). It needs write:repository on $GITEA_REPO." ;;
404) fail "no repository $GITEA_REPO on $GITEA_URL, or the token cannot see it" ;;
*) fail "checking $GITEA_REPO returned HTTP $status: $(cat "$tmp/body")" ;;
esac
call GET "$api/releases/tags/$tag"
case $status in
404) ;;
200) fail "$tag is already published: $(jq -r .html_url "$tmp/body"). Delete that release on Gitea to publish it again." ;;
*) fail "checking for an existing release returned HTTP $status: $(cat "$tmp/body")" ;;
esac
echo "Building the Flatpak bundle for $tag"
"${MAKE:-make}" --no-print-directory flatpak-bundle
cp target/flatpak/remus.flatpak "target/flatpak/$asset"
body=$(jq -n --arg tag "$tag" --arg notes "$notes" \
'{tag_name: $tag, name: $tag, body: $notes, draft: false, prerelease: false}')
call POST "$api/releases" -H 'Content-Type: application/json' --data "$body"
[ "$status" = 201 ] || fail "creating the release returned HTTP $status: $(cat "$tmp/body")"
id=$(jq -r .id "$tmp/body")
url=$(jq -r .html_url "$tmp/body")
call POST "$api/releases/$id/assets?name=$asset" -F "attachment=@target/flatpak/$asset"
if [ "$status" != 201 ]; then
echo "error: uploading $asset returned HTTP $status: $(cat "$tmp/body")" >&2
# A release without its bundle would block the next try, so take it back.
call DELETE "$api/releases/$id"
if [ "$status" = 204 ]; then
echo "Removed the release again, so make publish can be rerun." >&2
else
echo "Could not remove the release ($status). Delete $url by hand before rerunning." >&2
fi
exit 1
fi
echo "Published $tag with $asset: $url"
+434 -32
View File
@@ -17,9 +17,11 @@ use tokio::runtime::Handle;
use tokio::sync::Semaphore;
use crate::config::{self, Config, Settings};
use crate::inhibit::Inhibitor;
use crate::palette::{Lab, Palette, Role, Tone};
use crate::player::{Player, PlayerEvent};
use crate::prompts::{self, Control, Family, Prompts};
use crate::saved_queue::{self, SavedQueue, SavedQueues};
use crate::subsonic::{self, Album, Artist, Client, Playlist, SearchResult, Song};
use crate::{Action, AppWindow, Area, Header, Hint, Item, Screen, Theme};
@@ -58,12 +60,22 @@ pub fn install(ui: &AppWindow, rt: Handle) {
with_app(|app| app.start());
}
/// Drops the app, which stops playback.
/// Saves the queue and drops the app, which stops playback.
pub fn shutdown() {
let app = APP.with(|cell| cell.borrow_mut().take());
drop(app);
if let Some(mut app) = app {
app.save_queue();
if let Some(i) = app.inhibitor.take() {
i.shutdown();
}
}
}
/// How often the position is saved while playing, so a crash or power loss
/// costs at most this much. A queue of a few hundred songs is tens of KB, so
/// even hours of play write little compared to what flash storage is rated for.
const SAVE_EVERY: Duration = Duration::from_secs(15);
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum Section {
Recent,
@@ -112,10 +124,14 @@ enum Target {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Setting {
AlbumArtColours,
CoverBackdrop,
}
/// How long the UI takes to change from one palette to the next.
const FADE: Duration = Duration::from_millis(800);
/// How long the now-playing cover takes to turn edge-on, the `in` animation
/// of the `turned` state in NowPlayingView. The turn back is in the .slint.
const FLIP_OUT: Duration = Duration::from_millis(170);
/// The palette on screen and the one it is fading towards.
struct Fade {
@@ -187,6 +203,8 @@ struct Covers {
/// Per cover id, whatever size it was decoded at. None for a cover with
/// too little colour to base a palette on.
tones: LruCache<String, Option<Tone>>,
/// Hash of each decoded cover's pixels, to tell two ids with one picture.
prints: LruCache<CoverKey, u64>,
pending: HashSet<CoverKey>,
failed: HashSet<CoverKey>,
limit: Arc<Semaphore>,
@@ -198,6 +216,8 @@ pub struct App {
rt: Handle,
client: Option<Client>,
player: Option<Player>,
/// Keeps the screensaver off while music plays. Taken at shutdown.
inhibitor: Option<Inhibitor>,
screen: Screen,
area: Area,
section: usize,
@@ -215,6 +235,16 @@ pub struct App {
duration: f64,
paused: bool,
scrobbled: bool,
/// Queue restored paused and not played since: the now-playing update
/// waits for the user to press play.
held: bool,
now_playing_due: bool,
/// Track index and position being restored, until the player reports
/// that track. Saved in its place if the app quits before then.
restoring: Option<(usize, f64)>,
saved: SavedQueues,
saved_path: Option<PathBuf>,
last_save: Instant,
login_focus: i32,
toast_timer: Timer,
/// Keyboard keys or the buttons of the controller used last.
@@ -223,6 +253,20 @@ pub struct App {
icons: RefCell<HashMap<(Prompts, Control), Vec<Image>>>,
settings: Settings,
fade: Fade,
/// The now-playing art on screen, `None` when nothing is playing.
art_shown: Option<ShownArt>,
/// Runs while the cover turns away; the new art goes up when it fires.
flip_timer: Timer,
}
/// What the now-playing art shows, to decide whether a track change flips it.
/// Compared by picture, not by id: Navidrome gives every track its own cover
/// id even when the whole album shares one image.
struct ShownArt {
/// Cover id of the track the art belongs to.
id: Option<String>,
/// Hash of the decoded cover, `None` for the letter placeholder.
print: Option<u64>,
}
impl App {
@@ -231,17 +275,21 @@ impl App {
let queue_items = Rc::new(VecModel::default());
ui.set_items(ModelRc::from(items.clone()));
ui.set_queue_items(ModelRc::from(queue_items.clone()));
let saved_path = saved_queue::path();
let saved = saved_path.as_deref().map(saved_queue::load).unwrap_or_default();
let dir = config::cache_dir().map(|d| d.join("covers"));
if let Some(d) = &dir
&& let Err(e) = std::fs::create_dir_all(d)
{
log::warn!("cover cache disabled, cannot create {}: {e}", d.display());
}
let inhibitor = Inhibitor::spawn(&rt);
App {
ui,
rt,
client: None,
player: None,
inhibitor: Some(inhibitor),
screen: Screen::Login,
area: Area::Content,
section: 0,
@@ -254,6 +302,7 @@ impl App {
covers: Covers {
images: LruCache::new(NonZeroUsize::new(400).unwrap()),
tones: LruCache::new(NonZeroUsize::new(400).unwrap()),
prints: LruCache::new(NonZeroUsize::new(400).unwrap()),
pending: HashSet::new(),
failed: HashSet::new(),
limit: Arc::new(Semaphore::new(6)),
@@ -266,8 +315,16 @@ impl App {
duration: 0.0,
paused: false,
scrobbled: false,
held: false,
now_playing_due: false,
restoring: None,
saved,
saved_path,
last_save: Instant::now(),
login_focus: 0,
toast_timer: Timer::default(),
art_shown: None,
flip_timer: Timer::default(),
prompts: Prompts::Keyboard,
icons: RefCell::default(),
settings: config::load_settings(),
@@ -282,6 +339,7 @@ impl App {
}
fn start(&mut self) {
self.render_backdrop();
let labels: Vec<SharedString> = SECTIONS.iter().map(|s| s.label().into()).collect();
self.ui.set_sections(ModelRc::new(VecModel::from(labels)));
@@ -336,7 +394,7 @@ impl App {
}
fn set_login_focus(&mut self, i: i32) {
self.login_focus = i.clamp(0, 3);
self.login_focus = i.clamp(0, 4);
self.ui.set_login_focus(self.login_focus);
self.ui.invoke_focus_login(self.login_focus);
self.render_hints();
@@ -347,6 +405,7 @@ impl App {
Action::Up | Action::SectionPrev => self.set_login_focus(self.login_focus - 1),
Action::Down | Action::SectionNext => self.set_login_focus(self.login_focus + 1),
Action::Activate if self.login_focus < 2 => self.set_login_focus(self.login_focus + 1),
Action::Activate if self.login_focus == 4 => self.action(Action::Quit),
Action::Activate => self.login_submit(),
_ => {}
}
@@ -408,6 +467,9 @@ impl App {
self.section = usize::MAX;
self.select_section(0);
self.set_area(Area::Content);
if self.queue.is_empty() {
self.restore_queue();
}
}
// ---------------------------------------------------------------- input
@@ -516,6 +578,9 @@ impl App {
_ => {}
},
Area::Content => match a {
Action::Left | Action::Right if let Some(s) = self.selected_range_setting() => {
self.adjust_setting(s, a == Action::Right)
}
Action::Up | Action::Down | Action::Left | Action::Right | Action::PageUp | Action::PageDown => {
self.move_sel(a)
}
@@ -811,12 +876,43 @@ impl App {
}
}
/// The range setting under the selection, which left and right adjust.
fn selected_range_setting(&self) -> Option<Setting> {
let page = self.current_page()?;
match page.entries.get(page.sel)?.target {
Target::Setting(s @ Setting::CoverBackdrop) => Some(s),
_ => None,
}
}
// ---------------------------------------------------------------- settings
fn toggle_setting(&mut self, setting: Setting) {
match setting {
Setting::AlbumArtColours => self.settings.album_art_colours = !self.settings.album_art_colours,
// A range: left and right change it, confirm does nothing.
Setting::CoverBackdrop => return,
}
self.settings_changed();
}
/// Moves a range setting one step up or down.
fn adjust_setting(&mut self, setting: Setting, up: bool) {
match setting {
Setting::CoverBackdrop => {
let v = step_backdrop(self.settings.cover_backdrop, up);
if v == self.settings.cover_backdrop {
return;
}
self.settings.cover_backdrop = v;
}
Setting::AlbumArtColours => return,
}
self.settings_changed();
}
/// Saves the settings and shows what they change.
fn settings_changed(&mut self) {
if let Err(e) = config::save_settings(&self.settings) {
self.toast(format!("Could not save settings: {e:#}"));
}
@@ -828,9 +924,17 @@ impl App {
self.sync_items(true);
}
}
self.render_backdrop();
self.update_theme();
}
fn render_backdrop(&self) {
let (opacity, left, right) = backdrop_look(self.settings.cover_backdrop);
self.ui.set_np_backdrop_opacity(opacity);
self.ui.set_np_backdrop_left(left);
self.ui.set_np_backdrop_right(right);
}
// ---------------------------------------------------------------- theme
/// The palette the UI should show: from the playing track's cover when
@@ -1239,6 +1343,10 @@ impl App {
_ => false,
};
let cover = entry.cover.as_deref().and_then(|id| self.cover(id, px));
let level = match entry.target {
Target::Setting(Setting::CoverBackdrop) => Some(self.settings.cover_backdrop as f32 / 100.0),
_ => None,
};
Some(Item {
index: index as i32,
letter: initial(&entry.title).into(),
@@ -1252,6 +1360,8 @@ impl App {
round: entry.round,
show_art: entry.show_art,
playing,
slider: level.is_some(),
level: level.unwrap_or_default(),
})
}
@@ -1269,7 +1379,12 @@ impl App {
};
match self.screen {
Screen::Login => {
h(Control::Activate, if self.login_focus < 2 { "Next" } else { "Connect" });
let label = match self.login_focus {
0 | 1 => "Next",
4 => "Exit",
_ => "Connect",
};
h(Control::Activate, label);
}
Screen::Browse => match self.area {
Area::Sidebar => {
@@ -1290,6 +1405,7 @@ impl App {
.map(|e| &e.target);
match target {
Some(Target::Song(_)) => h(Control::Activate, "Play"),
Some(Target::Setting(Setting::CoverBackdrop)) => h(Control::Seek, "Adjust"),
Some(Target::Setting(_)) => h(Control::Activate, "Change"),
Some(_) => h(Control::Activate, "Open"),
None if self.current_page().is_some_and(|p| p.error.is_some()) => {
@@ -1406,11 +1522,12 @@ impl App {
None
}
fn cover_loaded(&mut self, key: CoverKey, result: Result<(SharedPixelBuffer<Rgb8Pixel>, Option<Tone>)>) {
fn cover_loaded(&mut self, key: CoverKey, result: Result<(SharedPixelBuffer<Rgb8Pixel>, Option<Tone>, u64)>) {
self.covers.pending.remove(&key);
match result {
Ok((buf, tone)) => {
Ok((buf, tone, print)) => {
self.covers.images.put(key.clone(), Image::from_rgb8(buf));
self.covers.prints.put(key.clone(), print);
// The first size decoded decides: other sizes give a tone that
// differs in the last digits, which would restart the fade.
if !self.covers.tones.contains(&key.0) {
@@ -1420,7 +1537,16 @@ impl App {
}
Err(e) => {
log::debug!("cover {} failed: {e:#}", key.0);
// The playing track's art may be waiting on this to flip.
let playing = self
.current
.and_then(|i| self.queue.get(i))
.and_then(|s| s.cover_art.as_deref())
== Some(key.0.as_str());
self.covers.failed.insert(key);
if playing {
self.render_player();
}
// The playing track's cover failing means the brand palette.
self.update_theme();
return;
@@ -1518,6 +1644,7 @@ impl App {
let n = songs.len();
self.queue.extend(songs);
self.sync_queue(true);
self.save_queue();
self.toast(if n == 1 {
format!("Queued {what}")
} else {
@@ -1565,6 +1692,9 @@ impl App {
self.position = p;
self.render_progress();
self.maybe_scrobble();
if !self.paused && self.last_save.elapsed() >= SAVE_EVERY {
self.save_queue();
}
}
PlayerEvent::Duration(d) => {
self.duration = d;
@@ -1573,6 +1703,14 @@ impl App {
PlayerEvent::Paused(p) => {
self.paused = p;
self.ui.set_np_paused(p);
if p {
self.save_queue();
} else {
self.held = false;
if std::mem::take(&mut self.now_playing_due) {
self.send_now_playing();
}
}
}
PlayerEvent::Track(t) => {
// Reported once per track started, so the same index again is a
@@ -1581,13 +1719,16 @@ impl App {
self.current = t;
self.position = 0.0;
self.scrobbled = false;
if let (Some(song), Some(client)) = (t.and_then(|i| self.queue.get(i)), self.client.clone()) {
let id = song.id.clone();
self.spawn(async move { client.scrobble(&id, false).await }, |_, r| {
if let Err(e) = r {
log::debug!("now-playing update failed: {e:#}");
}
});
if let Some((i, _)) = self.restoring.take()
&& t == Some(i)
{
// Paused, so the player reports no duration until played.
self.duration = self.queue[i].duration.unwrap_or(0) as f64;
}
if self.held {
self.now_playing_due = t.is_some();
} else {
self.send_now_playing();
}
if let Some(i) = t
&& self.screen == Screen::NowPlaying
@@ -1597,8 +1738,84 @@ impl App {
self.render_player();
self.sync_items(true);
self.sync_queue(true);
self.save_queue();
}
}
self.sync_inhibit();
}
/// Inhibits only while sound is coming out: a restored queue is loaded
/// paused and held until play is pressed.
fn sync_inhibit(&self) {
if let Some(i) = &self.inhibitor {
i.set(self.current.is_some() && !self.paused && !self.held);
}
}
fn send_now_playing(&self) {
let (Some(song), Some(client)) = (self.current.and_then(|i| self.queue.get(i)), self.client.clone()) else {
return;
};
let id = song.id.clone();
self.spawn(async move { client.scrobble(&id, false).await }, |_, r| {
if let Err(e) = r {
log::debug!("now-playing update failed: {e:#}");
}
});
}
/// Loads the queue saved for this server, paused at the track and
/// position it was at.
fn restore_queue(&mut self) {
let (Some(client), Some(player)) = (&self.client, &self.player) else {
return;
};
let Some(saved) = self.saved.get(client).cloned() else {
return;
};
if saved.songs.is_empty() {
return;
}
let current = saved.current.filter(|&i| i < saved.songs.len());
log::info!(
"restoring a queue of {} songs at {:?}, {:.0}s",
saved.songs.len(),
current,
saved.position
);
let urls: Vec<String> = saved.songs.iter().map(|s| client.stream_url(&s.id)).collect();
player.load_paused(&urls, current, saved.position);
self.queue = saved.songs;
self.current = None;
self.queue_sel = current.unwrap_or(0);
self.held = current.is_some();
self.restoring = current.map(|i| (i, saved.position));
self.sync_queue(true);
}
/// Writes the queue to disk. Failures are logged rather than shown,
/// since this runs every few seconds while playing.
fn save_queue(&mut self) {
self.last_save = Instant::now();
let (Some(client), Some(path)) = (&self.client, &self.saved_path) else {
return;
};
let (current, position) = match (self.current, self.restoring) {
(None, Some((i, pos))) => (Some(i), pos),
(current, _) => (current, self.position),
};
let queue = SavedQueue {
songs: self.queue.clone(),
current,
position,
};
if self.saved.get(client) == Some(&queue) {
return;
}
self.saved.set(client, queue);
if let Err(e) = saved_queue::save(path, &self.saved) {
log::warn!("could not save the queue: {e:#}");
}
}
/// Submits a play once half the track (or four minutes) has been heard,
@@ -1639,18 +1856,16 @@ impl App {
self.ui.set_np_paused(self.paused);
match song {
Some(s) => {
let px = self.now_playing_px();
let cover = s.cover_art.as_deref().and_then(|id| self.cover(id, px));
self.ui
.set_np_letter(initial(s.album.as_deref().unwrap_or(&s.title)).into());
self.ui.set_np_tint(tint(s.album.as_deref().unwrap_or(&s.title)));
self.ui.set_np_has_cover(cover.is_some());
self.ui.set_np_cover(cover.unwrap_or_default());
self.update_art(&s);
self.prefetch_next_cover();
self.ui.set_np_title(s.title.into());
self.ui.set_np_artist(s.artist.unwrap_or_default().into());
self.ui.set_np_album(s.album.unwrap_or_default().into());
}
None => {
self.flip_timer.stop();
self.ui.set_np_flip_out(false);
self.art_shown = None;
self.ui.set_np_has_cover(false);
self.ui.set_np_cover(Image::default());
self.ui.set_np_letter("".into());
@@ -1663,6 +1878,94 @@ impl App {
self.update_theme();
}
/// Shows the song's art, flipping the cover if it is a different picture
/// from the one on screen. While a changed track's cover loads, the old one
/// stays up: the load ends in a render either way, and decides then.
fn update_art(&mut self, s: &Song) {
if self.flip_timer.running() {
// Mid-turn: the midpoint puts up whatever is current then.
return;
}
let Some(shown) = &self.art_shown else {
// From nothing playing: no flip, the cover fades in when it loads.
self.render_art(s);
return;
};
if shown.id == s.cover_art || self.screen != Screen::NowPlaying {
self.render_art(s);
return;
}
let Some(print) = self.art_print(s) else { return };
if Some(print) == self.art_shown.as_ref().map(|a| a.print) {
log::debug!("same cover picture under a new id, no flip");
self.render_art(s);
} else {
log::debug!("cover picture changed, flipping");
self.ui.set_np_flip_out(true);
self.flip_timer
.start(slint::TimerMode::SingleShot, FLIP_OUT, || with_app(|app| app.flip_in()));
}
}
/// The picture the song's art will show: `Some(None)` for the placeholder,
/// `None` while its cover is still loading.
fn art_print(&mut self, s: &Song) -> Option<Option<u64>> {
let Some(id) = s.cover_art.as_deref() else {
return Some(None);
};
let key: CoverKey = (id.to_string(), self.now_playing_px());
if let Some(p) = self.covers.prints.get(&key) {
return Some(Some(*p));
}
if self.covers.failed.contains(&key) {
return Some(None);
}
// Starts the load if it is not under way.
self.cover(id, key.1);
None
}
/// Loads the next track's cover at the now-playing size, so a skip can
/// tell at once whether the picture changes.
fn prefetch_next_cover(&mut self) {
if self.screen != Screen::NowPlaying {
return;
}
let next = self.current.and_then(|i| self.queue.get(i + 1));
if let Some(id) = next.and_then(|s| s.cover_art.clone()) {
let px = self.now_playing_px();
self.cover(&id, px);
}
}
/// Puts the song's cover, or its letter placeholder, on screen.
fn render_art(&mut self, s: &Song) {
let px = self.now_playing_px();
let cover = s.cover_art.as_deref().and_then(|id| self.cover(id, px));
let print = s
.cover_art
.as_ref()
.and_then(|id| self.covers.prints.get(&(id.clone(), px)).copied())
.filter(|_| cover.is_some());
let name = s.album.as_deref().unwrap_or(&s.title);
self.ui.set_np_letter(initial(name).into());
self.ui.set_np_tint(tint(name));
self.ui.set_np_has_cover(cover.is_some());
self.ui.set_np_cover(cover.unwrap_or_default());
self.art_shown = Some(ShownArt {
id: s.cover_art.clone(),
print,
});
}
/// The cover is edge-on: swap in the current track's art and turn it back.
fn flip_in(&mut self) {
if let Some(s) = self.current.and_then(|i| self.queue.get(i)).cloned() {
self.render_art(&s);
}
self.ui.set_np_flip_out(false);
}
// ---------------------------------------------------------------- now playing
fn open_now_playing(&mut self) {
@@ -1758,6 +2061,8 @@ impl App {
round: false,
show_art: true,
playing: Some(index) == self.current,
slider: false,
level: 0.0,
}
}
}
@@ -1846,20 +2151,70 @@ fn song_entry(s: &Song, index: usize) -> Entry {
fn settings_data(s: &Settings) -> PageData {
let on_off = |on: bool| if on { "On" } else { "Off" }.to_string();
PageData {
entries: vec![Entry {
title: "Colours from album art".to_string(),
subtitle: "Tint the interface with the cover of the playing track".to_string(),
detail: on_off(s.album_art_colours),
number: String::new(),
cover: None,
round: false,
show_art: false,
target: Target::Setting(Setting::AlbumArtColours),
}],
entries: vec![
Entry {
title: "Colours from album art".to_string(),
subtitle: "Tint the interface with the cover of the playing track".to_string(),
detail: on_off(s.album_art_colours),
number: String::new(),
cover: None,
round: false,
show_art: false,
target: Target::Setting(Setting::AlbumArtColours),
},
Entry {
title: "Cover backdrop".to_string(),
subtitle: "How much of the cover shows behind the now-playing screen".to_string(),
detail: if s.cover_backdrop == 0 {
"Off".to_string()
} else {
s.cover_backdrop.to_string()
},
number: String::new(),
cover: None,
round: false,
show_art: false,
target: Target::Setting(Setting::CoverBackdrop),
},
],
..Default::default()
}
}
/// One step of the cover backdrop setting, kept within 0 to 100.
fn step_backdrop(v: u8, up: bool) -> u8 {
let v = v.min(100);
if up { (v + 10).min(100) } else { v.saturating_sub(10) }
}
/// The now-playing backdrop for a strength of 0 to 100: the cover's opacity
/// and the background alpha over it at the left and right edges.
///
/// Up to the default the cover fades in under today's overlay. Above it the
/// overlay thins too, but never below 0.55 on the left, where the title and
/// progress are, so the text stays readable over a bright cover.
fn backdrop_look(v: u8) -> (f32, f32, f32) {
// Today's look, reached at the default.
const OPACITY: f32 = 0.16;
const LEFT: f32 = 0.67;
const RIGHT: f32 = 0.95;
// The strongest, at 100.
const OPACITY_MAX: f32 = 0.40;
const LEFT_MIN: f32 = 0.55;
const RIGHT_MIN: f32 = 0.80;
let v = v.min(100) as f32;
let d = config::COVER_BACKDROP_DEFAULT as f32;
if v <= d {
return (OPACITY * v / d, LEFT, RIGHT);
}
let u = (v - d) / (100.0 - d);
(
OPACITY + u * (OPACITY_MAX - OPACITY),
LEFT + u * (LEFT_MIN - LEFT),
RIGHT + u * (RIGHT_MIN - RIGHT),
)
}
fn search_data(r: SearchResult) -> PageData {
let mut entries: Vec<Entry> = r.artist.into_iter().map(artist_entry).collect();
entries.extend(r.album.into_iter().map(|a| Entry {
@@ -1899,7 +2254,7 @@ fn bucket(px: f32) -> u32 {
}
/// Decodes a cover at `px` and works out its tone for the album art palette.
fn decode_cover(bytes: &[u8], px: u32) -> Result<(SharedPixelBuffer<Rgb8Pixel>, Option<Tone>)> {
fn decode_cover(bytes: &[u8], px: u32) -> Result<(SharedPixelBuffer<Rgb8Pixel>, Option<Tone>, u64)> {
let img = image::load_from_memory(bytes)?;
let img = if img.width() > px || img.height() > px {
img.resize(px, px, image::imageops::FilterType::Triangle)
@@ -1912,8 +2267,11 @@ fn decode_cover(bytes: &[u8], px: u32) -> Result<(SharedPixelBuffer<Rgb8Pixel>,
.to_rgb8();
let tone = crate::palette::tone(small.as_raw());
let rgb = img.to_rgb8();
let mut hasher = std::hash::DefaultHasher::new();
std::hash::Hash::hash(rgb.as_raw(), &mut hasher);
let print = std::hash::Hasher::finish(&hasher);
let buf = SharedPixelBuffer::clone_from_slice(rgb.as_raw(), rgb.width(), rgb.height());
Ok((buf, tone))
Ok((buf, tone, print))
}
fn color(lab: Lab) -> Color {
@@ -2022,6 +2380,50 @@ fn join_dot<I: IntoIterator<Item = Option<String>>>(parts: I) -> String {
mod tests {
use super::*;
fn png(pixel: [u8; 3]) -> Vec<u8> {
let img = image::RgbImage::from_pixel(8, 8, image::Rgb(pixel));
let mut out = std::io::Cursor::new(Vec::new());
img.write_to(&mut out, image::ImageFormat::Png).unwrap();
out.into_inner()
}
#[test]
fn one_picture_under_two_ids_has_one_print() {
let (_, _, a) = decode_cover(&png([120, 20, 30]), 64).unwrap();
let (_, _, b) = decode_cover(&png([120, 20, 30]), 64).unwrap();
let (_, _, c) = decode_cover(&png([20, 120, 30]), 64).unwrap();
assert_eq!(a, b);
assert_ne!(a, c);
}
#[test]
fn default_backdrop_looks_like_before_it_was_a_setting() {
assert_eq!(backdrop_look(config::COVER_BACKDROP_DEFAULT), (0.16, 0.67, 0.95));
}
#[test]
fn backdrop_off_draws_no_cover() {
assert_eq!(backdrop_look(0).0, 0.0);
}
#[test]
fn backdrop_strongest_keeps_an_overlay() {
let (opacity, left, right) = backdrop_look(100);
assert!((opacity - 0.40).abs() < 1e-6);
assert!((left - 0.55).abs() < 1e-6);
assert!((right - 0.80).abs() < 1e-6);
assert_eq!(backdrop_look(250), backdrop_look(100));
}
#[test]
fn backdrop_steps_stay_in_range() {
assert_eq!(step_backdrop(30, true), 40);
assert_eq!(step_backdrop(30, false), 20);
assert_eq!(step_backdrop(100, true), 100);
assert_eq!(step_backdrop(0, false), 0);
assert_eq!(step_backdrop(200, false), 90);
}
#[test]
fn grid_window_is_row_aligned() {
assert_eq!(window(1000, 0, 5, false), (0, 55));
+34 -3
View File
@@ -63,6 +63,12 @@ pub fn cache_dir() -> Option<PathBuf> {
dirs().map(|d| d.cache_dir().to_path_buf())
}
/// For state that is not configuration, such as the saved queue. Not every
/// platform has a state directory, so it falls back to the data directory.
pub fn state_dir() -> Option<PathBuf> {
dirs().map(|d| d.state_dir().unwrap_or(d.data_dir()).to_path_buf())
}
pub fn load() -> Result<Option<Config>> {
let Some(path) = config_path() else { return Ok(None) };
match fs::read_to_string(&path) {
@@ -82,11 +88,25 @@ pub fn save(cfg: &Config) -> Result<()> {
}
/// Preferences. Kept apart from the login, so logging out does not reset them.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct Settings {
/// Tint the UI with the colours of the playing track's cover.
pub album_art_colours: bool,
/// How strongly the cover shows behind the now-playing screen, 0 to 100.
pub cover_backdrop: u8,
}
/// The cover backdrop strength that looks like it did before it was a setting.
pub const COVER_BACKDROP_DEFAULT: u8 = 30;
impl Default for Settings {
fn default() -> Self {
Settings {
album_art_colours: false,
cover_backdrop: COVER_BACKDROP_DEFAULT,
}
}
}
fn settings_path() -> Option<PathBuf> {
@@ -119,11 +139,13 @@ pub fn save_settings(s: &Settings) -> Result<()> {
/// Writes aside, syncs, then renames over the old file, so a power cut
/// mid-save leaves either the old file or the new one, never a torn one.
/// Owner-only, since the login file holds a token.
fn write_atomic(path: &Path, text: &str) -> Result<()> {
pub fn write_atomic(path: &Path, text: &str) -> Result<()> {
if let Some(dir) = path.parent() {
fs::create_dir_all(dir)?;
}
let tmp = path.with_extension("toml.tmp");
let mut tmp = path.as_os_str().to_owned();
tmp.push(".tmp");
let tmp = PathBuf::from(tmp);
let mut f = fs::OpenOptions::new()
.write(true)
.create(true)
@@ -185,12 +207,21 @@ mod tests {
let s: Settings = toml::from_str("").unwrap();
assert_eq!(s, Settings::default());
assert!(!s.album_art_colours);
assert_eq!(s.cover_backdrop, COVER_BACKDROP_DEFAULT);
}
#[test]
fn settings_from_before_the_backdrop_load_its_default() {
let s: Settings = toml::from_str("album_art_colours = true\n").unwrap();
assert!(s.album_art_colours);
assert_eq!(s.cover_backdrop, COVER_BACKDROP_DEFAULT);
}
#[test]
fn settings_round_trip() {
let s = Settings {
album_art_colours: true,
cover_backdrop: 70,
};
let back: Settings = toml::from_str(&toml::to_string(&s).unwrap()).unwrap();
assert_eq!(back, s);
+316
View File
@@ -0,0 +1,316 @@
//! Keeps the screensaver and idle sleep away while music plays.
//!
//! Two routes, each held independently: org.freedesktop.ScreenSaver, the one
//! Chromium and Electron apps use during playback, and the XDG portal's
//! Inhibit, which needs no Flatpak permission and covers desktops where the
//! first is not served. A route that fails is logged once and otherwise
//! ignored. Services normally drop an inhibit when its client leaves the bus,
//! so a crash should not leave one behind.
use std::collections::HashMap;
use std::time::Duration;
use anyhow::Result;
use tokio::runtime::Handle;
use tokio::sync::{oneshot, watch};
use zbus::Connection;
use zbus::zvariant::{OwnedObjectPath, Value};
const APP: &str = "remus";
const REASON: &str = "Playing music";
/// The portal's idle and suspend flags.
const PORTAL_FLAGS: u32 = 4 | 8;
pub struct Inhibitor {
want: watch::Sender<bool>,
done: oneshot::Receiver<()>,
rt: Handle,
}
impl Inhibitor {
pub fn spawn(rt: &Handle) -> Inhibitor {
let (want, rx) = watch::channel(false);
let (done_tx, done) = oneshot::channel();
rt.spawn(async move {
run(DBus::default(), rx).await;
let _ = done_tx.send(());
});
Inhibitor {
want,
done,
rt: rt.clone(),
}
}
/// Hold the inhibit while `on`, release it otherwise.
pub fn set(&self, on: bool) {
self.want.send_if_modified(|v| std::mem::replace(v, on) != on);
}
/// Releases what is held before the runtime goes away. Called from
/// outside the runtime, so it may block briefly.
pub fn shutdown(self) {
let Inhibitor { want, done, rt } = self;
drop(want);
// The timer needs the runtime, so it is made inside block_on.
let _ = rt.block_on(async { tokio::time::timeout(Duration::from_secs(1), done).await });
}
}
/// One way of inhibiting, so the loop can be tested without a bus.
trait Backend {
/// Takes every route that is not held yet.
async fn acquire(&mut self);
/// Gives back every route that is held.
async fn release(&mut self);
}
/// Follows the wanted state until the sender is dropped, then releases.
async fn run(mut backend: impl Backend, mut want: watch::Receiver<bool>) {
while want.changed().await.is_ok() {
// Changes that arrive while a call is in flight coalesce into the latest.
if *want.borrow_and_update() {
backend.acquire().await;
} else {
backend.release().await;
}
}
backend.release().await;
}
#[derive(Default)]
struct DBus {
conn: Option<Connection>,
cookie: Option<u32>,
request: Option<OwnedObjectPath>,
warned_bus: bool,
warned_screensaver: bool,
warned_portal: bool,
}
impl DBus {
async fn connection(&mut self) -> Option<Connection> {
if self.conn.is_none() {
match Connection::session().await {
Ok(c) => self.conn = Some(c),
Err(e) => {
warn_once(
&mut self.warned_bus,
format_args!("no session bus, the screensaver stays on: {e}"),
);
return None;
}
}
}
self.conn.clone()
}
}
impl Backend for DBus {
async fn acquire(&mut self) {
let Some(conn) = self.connection().await else { return };
if self.cookie.is_none() {
match screensaver_inhibit(&conn).await {
Ok(c) => {
log::debug!("screensaver inhibited (cookie {c})");
self.cookie = Some(c);
}
Err(e) => warn_once(
&mut self.warned_screensaver,
format_args!("org.freedesktop.ScreenSaver inhibit failed: {e:#}"),
),
}
}
if self.request.is_none() {
match portal_inhibit(&conn).await {
Ok(r) => {
log::debug!("portal inhibit requested ({})", r.as_str());
self.request = Some(r);
}
Err(e) => warn_once(&mut self.warned_portal, format_args!("portal inhibit failed: {e:#}")),
}
}
}
async fn release(&mut self) {
let Some(conn) = self.conn.clone() else { return };
if let Some(c) = self.cookie.take() {
let r = conn
.call_method(
Some("org.freedesktop.ScreenSaver"),
"/org/freedesktop/ScreenSaver",
Some("org.freedesktop.ScreenSaver"),
"UnInhibit",
&(c,),
)
.await;
match r {
Ok(_) => log::debug!("screensaver released (cookie {c})"),
Err(e) => log::warn!("org.freedesktop.ScreenSaver uninhibit failed: {e}"),
}
}
if let Some(r) = self.request.take()
&& let Err(e) = conn
.call_method(
Some("org.freedesktop.portal.Desktop"),
r.as_str(),
Some("org.freedesktop.portal.Request"),
"Close",
&(),
)
.await
{
if gone(&e) {
// Some portal backends drop the request at once, for example
// when they do not implement Inhibit, so there is nothing to close.
log::debug!("portal inhibit was not held any more: {e}");
} else {
log::warn!("portal inhibit release failed: {e}");
}
}
}
}
async fn screensaver_inhibit(conn: &Connection) -> Result<u32> {
let reply = conn
.call_method(
Some("org.freedesktop.ScreenSaver"),
"/org/freedesktop/ScreenSaver",
Some("org.freedesktop.ScreenSaver"),
"Inhibit",
&(APP, REASON),
)
.await?;
Ok(reply.body().deserialize::<u32>()?)
}
async fn portal_inhibit(conn: &Connection) -> Result<OwnedObjectPath> {
let options: HashMap<&str, Value<'_>> = HashMap::from([("reason", Value::from(REASON))]);
let reply = conn
.call_method(
Some("org.freedesktop.portal.Desktop"),
"/org/freedesktop/portal/desktop",
Some("org.freedesktop.portal.Inhibit"),
"Inhibit",
// No parent window identifier: the inhibit is for the whole app.
&("", PORTAL_FLAGS, options),
)
.await?;
Ok(reply.body().deserialize::<OwnedObjectPath>()?)
}
/// The object being called no longer exists.
fn gone(e: &zbus::Error) -> bool {
const GONE: [&str; 2] = [
"org.freedesktop.DBus.Error.UnknownMethod",
"org.freedesktop.DBus.Error.UnknownObject",
];
match e {
zbus::Error::MethodError(name, ..) => GONE.contains(&name.as_str()),
zbus::Error::FDO(f) => {
matches!(
**f,
zbus::fdo::Error::UnknownMethod(_) | zbus::fdo::Error::UnknownObject(_)
)
}
_ => false,
}
}
fn warn_once(warned: &mut bool, msg: std::fmt::Arguments<'_>) {
if std::mem::replace(warned, true) {
log::debug!("{msg}");
} else {
log::warn!("{msg}");
}
}
#[cfg(test)]
mod tests {
use std::sync::{Arc, Mutex};
use super::*;
#[derive(Clone, Default)]
struct Fake {
calls: Arc<Mutex<Vec<&'static str>>>,
held: Arc<Mutex<bool>>,
}
impl Backend for Fake {
async fn acquire(&mut self) {
self.calls.lock().unwrap().push("acquire");
*self.held.lock().unwrap() = true;
}
async fn release(&mut self) {
self.calls.lock().unwrap().push("release");
*self.held.lock().unwrap() = false;
}
}
/// Sends each state and lets the loop act on it before the next.
async fn drive(states: &[bool]) -> Fake {
let fake = Fake::default();
let (tx, rx) = watch::channel(false);
let task = tokio::spawn(run(fake.clone(), rx));
for &s in states {
tx.send_if_modified(|v| std::mem::replace(v, s) != s);
tokio::task::yield_now().await;
}
drop(tx);
task.await.unwrap();
fake
}
#[tokio::test]
async fn follows_play_and_pause() {
let fake = drive(&[true, false, true]).await;
assert_eq!(
*fake.calls.lock().unwrap(),
["acquire", "release", "acquire", "release"]
);
}
#[tokio::test]
async fn repeated_state_does_not_call_again() {
let fake = drive(&[true, true, true]).await;
assert_eq!(*fake.calls.lock().unwrap(), ["acquire", "release"]);
}
#[tokio::test]
async fn releases_when_dropped_while_held() {
let fake = drive(&[true]).await;
assert!(!*fake.held.lock().unwrap());
}
#[tokio::test]
async fn nothing_held_when_never_played() {
let fake = drive(&[false]).await;
assert_eq!(*fake.calls.lock().unwrap(), ["release"]);
assert!(!*fake.held.lock().unwrap());
}
/// Against the real session bus: `cargo test live_inhibit -- --ignored`.
/// Prints which routes this session serves rather than failing on a
/// missing one, since a desktop may serve only one of them.
#[tokio::test]
#[ignore]
async fn live_inhibit() {
let conn = Connection::session().await.expect("session bus");
let ss = screensaver_inhibit(&conn).await;
let portal = portal_inhibit(&conn).await;
println!("org.freedesktop.ScreenSaver: {ss:?}");
println!("portal: {portal:?}");
assert!(ss.is_ok() || portal.is_ok(), "neither route is served");
let mut bus = DBus {
conn: Some(conn),
cookie: ss.ok(),
request: portal.ok(),
..DBus::default()
};
bus.release().await;
assert!(bus.cookie.is_none() && bus.request.is_none());
}
}
+2
View File
@@ -3,10 +3,12 @@ slint::include_modules!();
mod app;
mod config;
mod devscript;
mod inhibit;
mod input;
mod palette;
mod player;
mod prompts;
mod saved_queue;
mod subsonic;
use std::time::Duration;
+155 -15
View File
@@ -26,6 +26,11 @@ struct Queue {
current: Option<usize>,
/// Handed to playbin, becomes `current` at its stream-start.
pending: Option<usize>,
/// Loaded paused by `load_paused` and not played since: a track that
/// fails is skipped without starting playback.
hold: bool,
/// Seconds to seek to once the paused track has prerolled.
seek_to: Option<f64>,
}
pub struct Player {
@@ -103,11 +108,34 @@ impl Player {
}
}
/// Replaces the queue with `urls` and readies `index` paused at
/// `position` seconds, so nothing plays until `toggle_pause`. With no
/// index the queue is only stored, as after it played to the end.
pub fn load_paused(&self, urls: &[String], index: Option<usize>, position: f64) {
let url = {
let mut q = lock(&self.queue);
q.urls = urls.to_vec();
q.current = None;
q.pending = None;
q.hold = false;
q.seek_to = None;
let Some(i) = index else { return };
let Some(url) = q.urls.get(i).cloned() else { return };
q.pending = Some(i);
q.hold = true;
q.seek_to = (position > 0.0).then_some(position);
url
};
start_paused(&self.playbin, &url);
}
pub fn play_index(&self, index: usize) {
let url = {
let mut q = lock(&self.queue);
let Some(url) = q.urls.get(index).cloned() else { return };
q.pending = Some(index);
q.hold = false;
q.seek_to = None;
url
};
// Not under the lock: a state change waits for the streaming threads,
@@ -116,11 +144,22 @@ impl Player {
}
pub fn toggle_pause(&self) {
let target = match self.playbin.current_state() {
// Toggles where the pipeline is heading, so play pressed while a
// paused track is still loading is not lost.
let (_, current, pending) = self.playbin.state(gst::ClockTime::ZERO);
let heading = if pending == gst::State::VoidPending {
current
} else {
pending
};
let target = match heading {
gst::State::Playing => gst::State::Paused,
gst::State::Paused => gst::State::Playing,
_ => return,
};
if target == gst::State::Playing {
lock(&self.queue).hold = false;
}
let _ = self.playbin.set_state(target);
}
@@ -142,17 +181,7 @@ impl Player {
let Some(pos) = self.playbin.query_position::<gst::ClockTime>() else {
return;
};
let mut target = (pos.seconds_f64() + seconds).max(0.0);
if let Some(dur) = self.playbin.query_duration::<gst::ClockTime>() {
target = target.min((dur.seconds_f64() - 1.0).max(0.0));
}
let flags = gst::SeekFlags::FLUSH | gst::SeekFlags::KEY_UNIT;
if let Err(e) = self
.playbin
.seek_simple(flags, gst::ClockTime::from_seconds_f64(target))
{
log::debug!("seek failed: {e}");
}
seek_to(&self.playbin, pos.seconds_f64() + seconds);
}
}
@@ -178,6 +207,27 @@ fn start(playbin: &gst::Element, url: &str) {
}
}
fn start_paused(playbin: &gst::Element, url: &str) {
let _ = playbin.set_state(gst::State::Ready);
playbin.set_property("uri", url);
if let Err(e) = playbin.set_state(gst::State::Paused) {
log::warn!("could not load the track: {e}");
}
}
/// Seeks to `seconds`, kept a second short of the end so a stale position
/// does not land past a track that has since changed.
fn seek_to(playbin: &gst::Element, seconds: f64) {
let mut target = seconds.max(0.0);
if let Some(dur) = playbin.query_duration::<gst::ClockTime>() {
target = target.min((dur.seconds_f64() - 1.0).max(0.0));
}
let flags = gst::SeekFlags::FLUSH | gst::SeekFlags::KEY_UNIT;
if let Err(e) = playbin.seek_simple(flags, gst::ClockTime::from_seconds_f64(target)) {
log::debug!("seek failed: {e}");
}
}
fn watch_bus(playbin: &gst::Element, queue: &Mutex<Queue>, stop: &AtomicBool, emit: &dyn Fn(PlayerEvent)) {
let Some(bus) = playbin.bus() else { return };
let mut last_tick = Instant::now();
@@ -217,6 +267,16 @@ fn watch_bus(playbin: &gst::Element, queue: &Mutex<Queue>, stop: &AtomicBool, em
gst::State::Paused if s.pending() == gst::State::VoidPending => emit(PlayerEvent::Paused(true)),
_ => {}
},
// Prerolled: the first moment a paused track can seek, and the
// ticks below report no position while paused, so report it here.
MessageView::AsyncDone(_) => {
let target = lock(queue).seek_to.take();
if let Some(s) = target {
seek_to(playbin, s);
} else if let Some(p) = playbin.query_position::<gst::ClockTime>() {
emit(PlayerEvent::Position(p.seconds_f64()));
}
}
MessageView::Eos(_) => {
{
let mut q = lock(queue);
@@ -226,15 +286,23 @@ fn watch_bus(playbin: &gst::Element, queue: &Mutex<Queue>, stop: &AtomicBool, em
let _ = playbin.set_state(gst::State::Ready);
report_track(None, false);
}
// A failing source posts several errors. Once the first has moved
// on to the next track, the source is out of playbin and the rest
// would count as the next track failing too.
MessageView::Error(err) if err.src().is_some_and(|s| !s.has_as_ancestor(playbin)) => {
log::debug!("dropping an error from a track already skipped: {}", err.error());
}
MessageView::Error(err) => {
let detail = err.debug().map(|d| d.to_string()).unwrap_or_default();
log::warn!("playback error: {} ({})", err.error(), strip_queries(&detail));
// Skip the track that failed rather than stopping the queue.
let (next, len) = {
let (next, len, hold) = {
let mut q = lock(queue);
let failed = q.pending.take().or(q.current);
q.current = None;
(failed.map_or(usize::MAX, |i| i + 1), q.urls.len())
// The position belonged to the track that failed.
q.seek_to = None;
(failed.map_or(usize::MAX, |i| i + 1), q.urls.len(), q.hold)
};
if next < len {
let url = {
@@ -242,7 +310,11 @@ fn watch_bus(playbin: &gst::Element, queue: &Mutex<Queue>, stop: &AtomicBool, em
q.pending = Some(next);
q.urls[next].clone()
};
start(playbin, &url);
if hold {
start_paused(playbin, &url);
} else {
start(playbin, &url);
}
} else {
let _ = playbin.set_state(gst::State::Ready);
report_track(None, false);
@@ -395,4 +467,72 @@ mod tests {
drop(player);
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn a_paused_load_seeks_and_waits_for_play() {
// SAFETY: set before any thread reads the environment in this test.
unsafe { std::env::set_var("REMUS_AUDIO_SINK", "fakesink") };
let dir = std::env::temp_dir().join(format!("remus-player-paused-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
// The saved track no longer exists, so the next one is readied instead.
let missing = format!("file://{}", dir.join("gone.wav").display());
let urls = vec![
silent_wav(&dir, "a.wav", 10.0),
missing,
silent_wav(&dir, "c.wav", 10.0),
];
let (tx, rx) = mpsc::channel();
let player = Player::spawn(move |ev| {
let _ = tx.send(ev);
})
.unwrap();
player.load_paused(&urls, Some(1), 5.0);
let mut track = None;
let mut started = false;
let deadline = Instant::now() + Duration::from_secs(2);
while let Some(left) = deadline.checked_duration_since(Instant::now()) {
match rx.recv_timeout(left) {
Ok(PlayerEvent::Track(t)) => track = t,
Ok(PlayerEvent::Paused(false)) => started = true,
Ok(PlayerEvent::Position(p)) if p > 0.0 => started = true,
Ok(_) => {}
Err(_) => break,
}
}
assert_eq!(track, Some(2), "skipped the missing track");
assert!(!started, "nothing plays before play is pressed");
player.toggle_pause();
let mut played = false;
while let Ok(ev) = rx.recv_timeout(Duration::from_secs(3)) {
if let PlayerEvent::Position(p) = ev
&& p > 0.0
{
played = true;
// The seek was dropped with the track it belonged to.
assert!(p < 4.0, "position {p}");
break;
}
}
assert!(played, "plays once play is pressed");
player.load_paused(&urls, Some(0), 5.0);
player.toggle_pause();
let mut pos = None;
while let Ok(ev) = rx.recv_timeout(Duration::from_secs(3)) {
if let PlayerEvent::Position(p) = ev
&& p > 0.0
{
pos = Some(p);
break;
}
}
let p = pos.expect("a position once playing");
assert!((4.5..7.0).contains(&p), "resumed at {p}");
drop(player);
let _ = std::fs::remove_dir_all(&dir);
}
}
+166
View File
@@ -0,0 +1,166 @@
//! The queue saved to disk, so a restart picks up where playback was.
//!
//! One file holds a queue per server, keyed by user and server address. It
//! stores song ids and what is needed to draw the queue, never a stream URL:
//! those carry the token or the password, and are rebuilt from the client.
use std::collections::BTreeMap;
use std::fs;
use std::path::{Path, PathBuf};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use crate::config;
use crate::subsonic::{Client, Song};
const VERSION: u32 = 1;
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SavedQueue {
pub songs: Vec<Song>,
pub current: Option<usize>,
/// Seconds into the current song.
pub position: f64,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SavedQueues {
version: u32,
servers: BTreeMap<String, SavedQueue>,
}
impl Default for SavedQueues {
fn default() -> Self {
SavedQueues {
version: VERSION,
servers: BTreeMap::new(),
}
}
}
impl SavedQueues {
pub fn get(&self, client: &Client) -> Option<&SavedQueue> {
self.servers.get(&key(client))
}
pub fn set(&mut self, client: &Client, queue: SavedQueue) {
self.servers.insert(key(client), queue);
}
}
/// Song ids are only unique within one server, and two users of a server
/// have their own queues.
fn key(client: &Client) -> String {
format!("{}@{}", client.user(), client.base())
}
pub fn path() -> Option<PathBuf> {
config::state_dir().map(|d| d.join("queue.json"))
}
/// The saved queues, or none when there is no file or it cannot be read.
/// A bad file is logged and left for the next save to replace.
pub fn load(path: &Path) -> SavedQueues {
let text = match fs::read_to_string(path) {
Ok(text) => text,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return SavedQueues::default(),
Err(e) => {
log::warn!("reading {}: {e}", path.display());
return SavedQueues::default();
}
};
match serde_json::from_str::<SavedQueues>(&text) {
Ok(q) if q.version == VERSION => q,
Ok(q) => {
log::warn!("ignoring {}: unknown version {}", path.display(), q.version);
SavedQueues::default()
}
Err(e) => {
log::warn!("ignoring {}: {e}", path.display());
SavedQueues::default()
}
}
}
pub fn save(path: &Path, queues: &SavedQueues) -> Result<()> {
config::write_atomic(path, &serde_json::to_string(queues)?)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::subsonic::Auth;
fn song(id: &str) -> Song {
serde_json::from_value(serde_json::json!({
"id": id, "title": format!("Song {id}"), "artist": "A", "album": "B",
"coverArt": "al-1", "duration": 200, "track": 1,
}))
.unwrap()
}
fn temp(name: &str) -> PathBuf {
let dir = std::env::temp_dir().join(format!("remus-queue-{name}-{}", std::process::id()));
let _ = fs::remove_dir_all(&dir);
dir.join("queue.json")
}
#[test]
fn round_trips_a_queue_per_server() {
let path = temp("round-trip");
let home = Client::new("https://home", "u", Auth::Password("secret-pass".into()));
let other = Client::new(
"https://other",
"u",
Auth::Token {
salt: "s".into(),
token: "secret-token".into(),
},
);
let mut queues = SavedQueues::default();
let a = SavedQueue {
songs: vec![song("1"), song("2")],
current: Some(1),
position: 93.5,
};
let b = SavedQueue {
songs: vec![song("9")],
current: None,
position: 0.0,
};
queues.set(&home, a.clone());
queues.set(&other, b.clone());
save(&path, &queues).unwrap();
let back = load(&path);
assert_eq!(back.get(&home), Some(&a));
assert_eq!(back.get(&other), Some(&b));
let text = fs::read_to_string(&path).unwrap();
assert!(!text.contains("secret") && !text.contains("stream"), "{text}");
let _ = fs::remove_dir_all(path.parent().unwrap());
}
#[test]
fn an_unreadable_file_loads_as_empty() {
let path = temp("unreadable");
fs::create_dir_all(path.parent().unwrap()).unwrap();
let client = Client::new("https://h", "u", Auth::Password("p".into()));
for text in ["{ not json", "{\"version\": 99, \"servers\": {}}", ""] {
fs::write(&path, text).unwrap();
assert_eq!(load(&path).get(&client), None, "{text:?}");
}
// A directory in its place cannot be read as a file at all.
fs::remove_file(&path).unwrap();
fs::create_dir(&path).unwrap();
assert_eq!(load(&path).get(&client), None);
let _ = fs::remove_dir_all(path.parent().unwrap());
}
#[test]
fn a_missing_file_loads_as_empty() {
let path = temp("missing");
assert_eq!(load(&path), SavedQueues::default());
}
}
+2 -2
View File
@@ -4,8 +4,8 @@ use std::hash::{BuildHasher, RandomState};
use std::time::{SystemTime, UNIX_EPOCH};
use anyhow::{Context, Result, anyhow, bail};
use serde::Deserialize;
use serde::de::{DeserializeOwned, Deserializer};
use serde::{Deserialize, Serialize};
const API_VERSION: &str = "1.16.1";
const CLIENT_NAME: &str = "remus";
@@ -415,7 +415,7 @@ pub struct AlbumDetail {
pub song: Vec<Song>,
}
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Song {
#[serde(deserialize_with = "de_id")]
+134 -15
View File
@@ -27,6 +27,9 @@ export struct Item {
round: bool,
show-art: bool,
playing: bool,
// A setting with a range: draws `level` (0 to 1) as a slider before `detail`.
slider: bool,
level: float,
}
export struct Header {
@@ -237,10 +240,38 @@ component Row inherits Rectangle {
}
}
if root.item.slider: VerticalLayout {
alignment: center;
Rectangle {
width: 180px * Theme.s;
height: 6px * Theme.s;
border-radius: 3px * Theme.s;
background: Theme.line;
Rectangle {
x: 0;
width: parent.width * root.item.level;
border-radius: 3px * Theme.s;
background: root.selected && root.active ? Theme.highlight : Theme.muted;
animate width { duration: 120ms; easing: ease-out; }
}
Rectangle {
x: parent.width * root.item.level - self.width / 2;
width: 16px * Theme.s;
height: 16px * Theme.s;
border-radius: 8px * Theme.s;
background: root.selected && root.active ? Theme.text : Theme.muted;
animate x { duration: 120ms; easing: ease-out; }
}
}
}
Text {
// Fixed for a slider, so the bar does not shift as the number grows.
min-width: root.item.slider ? 44px * Theme.s : 0;
text: root.item.detail;
font-size: 15px * Theme.s;
color: Theme.muted;
horizontal-alignment: right;
vertical-alignment: center;
}
}
@@ -473,6 +504,39 @@ component SearchBox inherits Rectangle {
}
}
// Play triangle or pause bars, drawn as vectors so no font fallback can turn
// them into emoji or give the two different weights.
component PlayState {
in property <bool> paused;
in property <color> tint: Theme.highlight;
in property <length> size: 14px * Theme.s;
width: root.size;
height: root.size;
if !root.paused: Path {
width: root.size;
height: root.size;
viewbox-width: 12;
viewbox-height: 12;
commands: "M 1.5 0.5 L 11.5 6 L 1.5 11.5 Z";
fill: root.tint;
}
if root.paused: Rectangle {
x: root.size * 0.12;
width: root.size * 0.28;
height: root.size;
border-radius: root.size * 0.06;
background: root.tint;
}
if root.paused: Rectangle {
x: root.size * 0.60;
width: root.size * 0.28;
height: root.size;
border-radius: root.size * 0.06;
background: root.tint;
}
}
component NowBar inherits Rectangle {
in property <bool> has-track;
in property <string> title;
@@ -543,11 +607,12 @@ component NowBar inherits Rectangle {
color: Theme.muted;
vertical-alignment: center;
}
if root.has-track: Text {
text: root.paused ? "❚❚" : "▶";
font-size: 18px * Theme.s;
color: Theme.highlight;
vertical-alignment: center;
if root.has-track: VerticalLayout {
alignment: center;
PlayState {
paused: root.paused;
size: 15px * Theme.s;
}
}
}
}
@@ -641,6 +706,7 @@ component LoginView inherits Rectangle {
in property <string> error;
in property <bool> busy;
callback submit;
callback exit;
callback field-clicked(int);
public function focus-field(i: int) {
if (i == 0) {
@@ -665,7 +731,7 @@ component LoginView inherits Rectangle {
spacing: 20px * Theme.s;
HorizontalLayout {
alignment: start;
alignment: center;
Image {
source: @image-url("../branding/svg/remus-logo.svg");
height: 68px * Theme.s;
@@ -711,6 +777,21 @@ component LoginView inherits Rectangle {
clicked => { root.submit(); }
}
}
// Secondary to Connect: outlined, no fill, and only lit when focused.
Rectangle {
height: 46px * Theme.s;
border-radius: 12px * Theme.s;
border-width: 2px * Theme.s;
border-color: root.focus-index == 4 ? Theme.focus : Theme.line;
Text {
text: "Exit";
font-size: 17px * Theme.s;
color: root.focus-index == 4 ? Theme.text : Theme.muted;
}
TouchArea {
clicked => { root.exit(); }
}
}
if root.error != "": Text {
text: root.error;
font-size: 15px * Theme.s;
@@ -740,6 +821,14 @@ component NowPlayingView inherits Rectangle {
in property <string> duration;
in property <bool> paused;
in property <bool> has-track;
// From the cover backdrop setting: the blown-up cover's opacity and the
// alpha of the background drawn over it, at the left and right edges.
in property <float> backdrop-opacity: 0.16;
in property <float> backdrop-left: 0.67;
in property <float> backdrop-right: 0.95;
// True while the cover turns away; the app swaps the cover at edge-on and
// sets it back to false to turn the new one in.
in property <bool> flip-out;
in property <[Item]> queue;
in property <int> queue-count;
in property <int> queue-selected;
@@ -749,15 +838,15 @@ component NowPlayingView inherits Rectangle {
out property <length> art-size: 440px * Theme.s;
// Blown-up cover as a dim backdrop.
if root.has-cover: Image {
if root.has-cover && root.backdrop-opacity > 0: Image {
width: parent.width;
height: parent.height;
source: root.cover;
image-fit: ImageFit.cover;
opacity: 0.16;
opacity: root.backdrop-opacity;
}
Rectangle {
background: @linear-gradient(90deg, Theme.bg.with-alpha(0.67), Theme.bg.with-alpha(0.95));
background: @linear-gradient(90deg, Theme.bg.with-alpha(root.backdrop-left), Theme.bg.with-alpha(root.backdrop-right));
}
HorizontalLayout {
@@ -770,9 +859,11 @@ component NowPlayingView inherits Rectangle {
spacing: 10px * Theme.s;
width: root.art-size;
Art {
art := Art {
width: root.art-size;
height: root.art-size;
// Set here so the turned state below has a value to return to.
transform-scale-x: 100%;
source: root.cover;
has-image: root.has-cover;
tint: root.tint;
@@ -820,12 +911,17 @@ component NowPlayingView inherits Rectangle {
font-size: 14px * Theme.s;
color: Theme.muted;
}
Text {
// Sized below the time text, so the row keeps the text's height.
HorizontalLayout {
horizontal-stretch: 1;
text: root.has-track ? (root.paused ? "Paused" : "Playing") : "";
font-size: 14px * Theme.s;
color: Theme.highlight;
horizontal-alignment: center;
alignment: center;
if root.has-track: VerticalLayout {
alignment: center;
PlayState {
paused: root.paused;
size: 11px * Theme.s;
}
}
}
Text {
text: root.duration;
@@ -857,6 +953,20 @@ component NowPlayingView inherits Rectangle {
}
}
}
// A flip around the vertical axis, faked by squashing the width: Slint has
// no perspective. The turn back overshoots a little and settles.
states [
turned when root.flip-out: {
art.transform-scale-x: 0%;
in {
animate art.transform-scale-x { duration: 170ms; easing: ease-in; }
}
out {
animate art.transform-scale-x { duration: 380ms; easing: cubic-bezier(0.34, 1.5, 0.64, 1); }
}
}
]
}
export component AppWindow inherits Window {
@@ -920,6 +1030,10 @@ export component AppWindow inherits Window {
in property <string> np-position;
in property <string> np-duration;
in property <bool> np-paused;
in property <bool> np-flip-out;
in property <float> np-backdrop-opacity: 0.16;
in property <float> np-backdrop-left: 0.67;
in property <float> np-backdrop-right: 0.95;
in property <[Item]> queue-items;
in property <int> queue-count;
in property <int> queue-selected;
@@ -999,6 +1113,7 @@ export component AppWindow inherits Window {
error: root.login-error;
busy: root.login-busy;
submit => { root.login-submit(); }
exit => { root.action(Action.quit); }
field-clicked(i) => { root.login-field-clicked(i); }
}
@@ -1080,6 +1195,10 @@ export component AppWindow inherits Window {
duration: root.np-duration;
paused: root.np-paused;
has-track: root.np-has-track;
flip-out: root.np-flip-out;
backdrop-opacity: root.np-backdrop-opacity;
backdrop-left: root.np-backdrop-left;
backdrop-right: root.np-backdrop-right;
queue: root.queue-items;
queue-count: root.queue-count;
queue-selected: root.queue-selected;