mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
feat(wallpaper): discover Omarchy backgrounds automatically (#157)
Read Omarchy's current/background link (XDG_STATE_HOME, falling back to XDG_CONFIG_HOME) on Hyprland; explicit UU_WALLPAPER keeps precedence.
This commit is contained in:
1 parent
73c503a244
commit
fcfd2b6717
4 files changed
+53
-3
No files matched your search
+1
-1
@@ -26,7 +26,7 @@
|
||||
## Appearance / 外观
|
||||
|
||||
Signed-in graphical hosts report the system wallpaper for disconnected device cards in official clients
|
||||
(no desktop-window screenshot). GNOME/Cinnamon, KDE and Xfce are supported; checks run every 60 seconds
|
||||
(no desktop-window screenshot). GNOME/Cinnamon, KDE, Xfce and Omarchy on Hyprland are supported (following the current wallpaper); checks run every 60 seconds
|
||||
and unchanged content is not uploaded again. Other desktops can set `UU_WALLPAPER=/absolute/path/image.png`
|
||||
(PNG/JPEG/WebP). Set `UU_WALLPAPER_UPLOAD=0` to disable; guest and headless hosts skip reporting.
|
||||
See [protocol evidence and limitations](docs/wallpaper-protocol.md).
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
## 外观 / Appearance
|
||||
|
||||
已登录的图形主机会上报系统壁纸,供官方客户端的设备卡片在未连接时显示背景图(不是桌面窗口截图)。支持 GNOME/Cinnamon、KDE、Xfce;每 60 秒检查一次,内容不变则不重复上传。其他桌面可用 `UU_WALLPAPER=/绝对路径/图片.png` 指定 PNG/JPEG/WebP;`UU_WALLPAPER_UPLOAD=0` 关闭。访客和无桌面模式跳过上报。协议依据与限制见 [设备壁纸上报](docs/wallpaper-protocol.md)。
|
||||
已登录的图形主机会上报系统壁纸,供官方客户端的设备卡片在未连接时显示背景图(不是桌面窗口截图)。支持 GNOME/Cinnamon、KDE、Xfce 和 Hyprland 下的 Omarchy(自动跟随当前壁纸);每 60 秒检查一次,内容不变则不重复上传。其他桌面可用 `UU_WALLPAPER=/绝对路径/图片.png` 指定 PNG/JPEG/WebP;`UU_WALLPAPER_UPLOAD=0` 关闭。访客和无桌面模式跳过上报。协议依据与限制见 [设备壁纸上报](docs/wallpaper-protocol.md)。
|
||||
|
||||
在控制端的 **设置 → 常规 → 外观**,或主机 / 工具窗口的齿轮设置按钮中选择 **跟随系统 / 浅色 / 深色**(默认跟随系统)。
|
||||
选择保存在 `$XDG_CONFIG_HOME/uuremote/theme`(默认 `~/.config/uuremote/theme`)。
|
||||
|
||||
@@ -36,7 +36,11 @@ advertised limit. HTTPS is required and upload redirects are disabled.
|
||||
GNOME/Unity/Cinnamon use GSettings (GNOME dark preference included); KDE reads the first image
|
||||
wallpaper containment, including image packages, or the installed look-and-feel's default wallpaper
|
||||
when no explicit wallpaper is configured; Xfce reads the first `last-image`. Multi-monitor selection, slideshow/XML
|
||||
wallpapers, compositor-specific wallpaper daemons, and unsupported formats are not inferred.
|
||||
wallpapers and unsupported formats are not inferred.
|
||||
On Hyprland, Omarchy's `omarchy/current/background` link is read from `XDG_STATE_HOME`
|
||||
(default `~/.local/state`), falling back to the older `XDG_CONFIG_HOME` location
|
||||
(default `~/.config`). Wallpaper/theme changes are followed on the next check.
|
||||
Other compositor-specific wallpaper daemons are not inferred.
|
||||
`UU_WALLPAPER=/absolute/path/image.png` selects a file explicitly; `UU_WALLPAPER_UPLOAD=0` disables
|
||||
reporting. PNG, JPEG, and WebP are supported. No desktop screenshot fallback is used.
|
||||
|
||||
|
||||
@@ -50,6 +50,13 @@ async fn source() -> Option<PathBuf> {
|
||||
let path = PathBuf::from(path); return path.is_absolute().then_some(path);
|
||||
}
|
||||
let desktop = std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default().to_lowercase();
|
||||
if desktop.split(':').any(|name| name == "hyprland") {
|
||||
let home = std::env::var_os("HOME").map(PathBuf::from);
|
||||
let xdg = |name, fallback| std::env::var_os(name).map(PathBuf::from)
|
||||
.filter(|p| p.is_absolute()).or_else(|| home.as_ref().map(|p| p.join(fallback)));
|
||||
return omarchy_background(xdg("XDG_STATE_HOME", ".local/state").as_deref(),
|
||||
xdg("XDG_CONFIG_HOME", ".config").as_deref()).await;
|
||||
}
|
||||
if desktop.contains("gnome") || desktop.contains("unity") || desktop.contains("cinnamon") {
|
||||
let schema = if desktop.contains("cinnamon") { "org.cinnamon.desktop.background" } else { "org.gnome.desktop.background" };
|
||||
if schema == "org.gnome.desktop.background" && command("gsettings", &["get", "org.gnome.desktop.interface", "color-scheme"])
|
||||
@@ -87,6 +94,16 @@ async fn source() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
// Omarchy maintains this link when changing wallpaper/theme. Prefer its current
|
||||
// XDG state location, while supporting older installations using XDG config.
|
||||
async fn omarchy_background(state: Option<&std::path::Path>, config: Option<&std::path::Path>) -> Option<PathBuf> {
|
||||
for root in [state, config].into_iter().flatten() {
|
||||
let path = root.join("omarchy/current/background");
|
||||
if tokio::fs::metadata(&path).await.is_ok_and(|meta| meta.is_file()) { return Some(path); }
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
async fn package_image(path: PathBuf) -> Option<PathBuf> {
|
||||
if tokio::fs::metadata(&path).await.ok()?.is_file() { return Some(path); }
|
||||
let mut entries = tokio::fs::read_dir(path.join("contents/images")).await.ok()?;
|
||||
@@ -271,6 +288,35 @@ mod tests {
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn omarchy_follows_current_wallpaper_links_and_supports_legacy_location() {
|
||||
use std::os::unix::fs::symlink;
|
||||
let root = std::env::temp_dir().join(format!("uu-omarchy-{}-{}", std::process::id(), rand::random::<u64>()));
|
||||
let state = root.join("custom-state");
|
||||
let config = root.join("custom-config");
|
||||
for dir in [&state, &config] { std::fs::create_dir_all(dir.join("omarchy/current")).unwrap(); }
|
||||
let current = state.join("omarchy/current/background");
|
||||
let legacy = config.join("omarchy/current/background");
|
||||
let first = root.join("first.png");
|
||||
let second = root.join("second.jpg");
|
||||
std::fs::write(&first, b"\x89PNG\r\n\x1a\n").unwrap();
|
||||
std::fs::write(&second, b"\xff\xd8\xff").unwrap();
|
||||
symlink(&second, &legacy).unwrap();
|
||||
let detect = || omarchy_background(Some(&state), Some(&config));
|
||||
assert_eq!(detect().await, Some(legacy.clone()));
|
||||
symlink(&first, ¤t).unwrap();
|
||||
assert_eq!(detect().await, Some(current.clone()));
|
||||
assert_eq!(read_image(&detect().await.unwrap()).await.unwrap(), std::fs::read(&first).unwrap());
|
||||
std::fs::remove_file(¤t).unwrap(); symlink(&second, ¤t).unwrap();
|
||||
assert_eq!(read_image(&detect().await.unwrap()).await.unwrap(), std::fs::read(&second).unwrap());
|
||||
std::fs::remove_file(¤t).unwrap(); symlink(root.join("missing"), ¤t).unwrap();
|
||||
assert_eq!(detect().await, Some(legacy.clone()));
|
||||
std::fs::remove_file(¤t).unwrap(); symlink(&root, ¤t).unwrap();
|
||||
assert_eq!(detect().await, Some(legacy.clone()));
|
||||
std::fs::remove_file(&legacy).unwrap();
|
||||
assert_eq!(detect().await, None);
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn kde_packages_select_landscape_and_image_reads_are_bounded() {
|
||||
let root = std::env::temp_dir().join(format!("uu-wallpaper-test-{}-{}", std::process::id(), rand::random::<u64>()));
|
||||
let images = root.join("contents/images");
|
||||
|
||||
Reference in new issue
Block a user