Windows port, AppImage and Windows installer packaging
- Gate MPRIS, tray (zbus/ksni) and the unix-socket single instance to unix; Windows gets stub modules and a loopback-TCP single instance - Use %APPDATA%/%LOCALAPPDATA% on Windows, hide the console window - build.rs embeds the icon and version resource on Windows targets - packaging/appimage.sh builds the AppImage with the libmpv library closure - packaging/mulberry.iss: per-user Inno Setup installer Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
bf0d53403f
commit
75ee4c16df
11 changed files with 231 additions and 1 deletions
|
|
@ -23,11 +23,16 @@ chrono = { version = "0.4", default-features = false, features = ["clock", "std"
|
|||
urlencoding = "2"
|
||||
md5 = "0.8"
|
||||
base64 = "0.22"
|
||||
ksni = { version = "0.3", default-features = false, features = ["async-io", "blocking"] }
|
||||
dirs = "6"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
ksni = { version = "0.3", default-features = false, features = ["async-io", "blocking"] }
|
||||
rfd = { version = "0.17", default-features = false, features = ["xdg-portal", "pollster"] }
|
||||
zbus = "5"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
rfd = { version = "0.17", default-features = false }
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
lto = "thin"
|
||||
|
|
|
|||
29
build.rs
Normal file
29
build.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
//! Windows: embed the icon and version resource into mulberry.exe (needs windres on PATH; skipped without it).
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=packaging/mulberry.ico");
|
||||
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
||||
return;
|
||||
}
|
||||
let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
let ver = std::env::var("CARGO_PKG_VERSION").unwrap();
|
||||
let nums: Vec<&str> = ver.split('.').collect();
|
||||
let comma = format!("{},{},{},0", nums[0], nums.get(1).unwrap_or(&"0"), nums.get(2).unwrap_or(&"0"));
|
||||
let ico = std::fs::canonicalize("packaging/mulberry.ico").unwrap().to_string_lossy().replace('\\', "/");
|
||||
let rc = format!(
|
||||
"1 ICON \"{ico}\"\n\
|
||||
1 VERSIONINFO\nFILEVERSION {comma}\nPRODUCTVERSION {comma}\nBEGIN\n BLOCK \"StringFileInfo\"\n BEGIN\n BLOCK \"040904b0\"\n BEGIN\n\
|
||||
\x20 VALUE \"ProductName\", \"Mulberry\"\n VALUE \"FileDescription\", \"Mulberry music player\"\n VALUE \"FileVersion\", \"{ver}\"\n VALUE \"ProductVersion\", \"{ver}\"\n VALUE \"OriginalFilename\", \"mulberry.exe\"\n\
|
||||
\x20 END\n END\n BLOCK \"VarFileInfo\"\n BEGIN\n VALUE \"Translation\", 0x0409, 1200\n END\nEND\n"
|
||||
);
|
||||
let rc_path = out.join("mulberry.rc");
|
||||
std::fs::write(&rc_path, rc).unwrap();
|
||||
let obj = out.join("mulberry_res.o");
|
||||
let ok = std::process::Command::new("x86_64-w64-mingw32-windres").arg(&rc_path).arg(&obj).status().map(|s| s.success()).unwrap_or(false);
|
||||
if ok {
|
||||
println!("cargo:rustc-link-arg-bins={}", obj.display());
|
||||
} else {
|
||||
println!("cargo:warning=windres not available: mulberry.exe has no icon/version resource");
|
||||
}
|
||||
}
|
||||
43
packaging/appimage.sh
Normal file
43
packaging/appimage.sh
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env bash
|
||||
# Pack the release binary and its libmpv library closure into dist/Mulberry-<version>-x86_64.AppImage.
|
||||
# packaging/appimage.sh <version> (run from anywhere after `cargo build --release`)
|
||||
# glibc, graphics/windowing and other libraries every desktop already has are left to the host.
|
||||
set -euo pipefail
|
||||
version=$1
|
||||
root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
dist="$root/dist"
|
||||
app="$dist/AppDir"
|
||||
bin="$root/target/release/mulberry"
|
||||
rm -rf "$app"
|
||||
mkdir -p "$app/usr/bin" "$app/usr/lib" "$app/usr/share/applications" "$app/usr/share/icons/hicolor/scalable/apps"
|
||||
cp "$bin" "$app/usr/bin/mulberry"
|
||||
|
||||
skip='^(linux-vdso|ld-linux|libc|libm|libdl|libpthread|librt|libutil|libresolv|libnsl|libgcc_s|libstdc\+\+|libGL|libGLX|libGLdispatch|libEGL|libOpenGL|libGLESv2|libgbm|libdrm|libvulkan|libX11|libX11-xcb|libxcb.*|libXau|libXdmcp|libXext|libXfixes|libXrandr|libXrender|libXi|libXcursor|libXss|libXv|libXxf86vm|libXinerama|libwayland-.*|libxkbcommon.*|libfontconfig|libfreetype|libharfbuzz|libglib-2.0|libgobject-2.0|libgio-2.0|libgmodule-2.0|libdbus-1|libsystemd|libudev|libasound|libpulse.*|libpipewire-0.3|libjack|libsndio|libcap|libselinux|libpcre2-8|libffi|libz|libexpat|libnss.*)\.so'
|
||||
ldd "$bin" | awk '/=> \//{print $3}' | while read -r lib; do
|
||||
name=$(basename "$lib")
|
||||
[[ $name =~ $skip ]] && continue
|
||||
cp -L "$lib" "$app/usr/lib/$name"
|
||||
done
|
||||
# the mujs script engine shows up in ldd without a soname arrow
|
||||
for lib in $(ldd "$bin" | awk '$1 ~ /^\// {print $1}'); do
|
||||
cp -L "$lib" "$app/usr/lib/$(basename "$lib")"
|
||||
done
|
||||
|
||||
cp "$root/packaging/mulberry.svg" "$app/mulberry.svg"
|
||||
cp "$root/packaging/mulberry.svg" "$app/usr/share/icons/hicolor/scalable/apps/mulberry.svg"
|
||||
{ sed 's/^Exec=mulberry %U/Exec=mulberry %U/' "$root/packaging/mulberry.desktop"; echo "X-AppImage-Version=$version"; } > "$app/mulberry.desktop"
|
||||
cp "$app/mulberry.desktop" "$app/usr/share/applications/"
|
||||
cat > "$app/AppRun" <<'EOF'
|
||||
#!/bin/sh
|
||||
here=$(dirname "$(readlink -f "$0")")
|
||||
export LD_LIBRARY_PATH="$here/usr/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||
exec "$here/usr/bin/mulberry" "$@"
|
||||
EOF
|
||||
chmod +x "$app/AppRun"
|
||||
|
||||
tool="$dist/appimagetool"
|
||||
if [ ! -x "$tool" ]; then
|
||||
cp "$HOME/Projects/Nacre/dist/appimagetool" "$tool"
|
||||
fi
|
||||
ARCH=x86_64 APPIMAGE_EXTRACT_AND_RUN=1 "$tool" --no-appstream "$app" "$dist/Mulberry-$version-x86_64.AppImage"
|
||||
ls -lh "$dist"/*.AppImage
|
||||
BIN
packaging/mulberry.ico
Normal file
BIN
packaging/mulberry.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 264 KiB |
46
packaging/mulberry.iss
Normal file
46
packaging/mulberry.iss
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
; Inno Setup script: per-user install (no admin), Start menu entry, uninstaller.
|
||||
; Built on Linux under wine: iscc /DVersion=2.0.1 /DSrc=<folder with mulberry.exe and libmpv-2.dll> mulberry.iss
|
||||
#ifndef Version
|
||||
#define Version "0.0.0"
|
||||
#endif
|
||||
#ifndef Src
|
||||
#define Src "..\dist\Mulberry"
|
||||
#endif
|
||||
|
||||
[Setup]
|
||||
AppId={{B4F0C1D2-7A63-4E59-8C1B-52D9E0A7F3C6}
|
||||
AppName=Mulberry
|
||||
AppVersion={#Version}
|
||||
AppVerName=Mulberry {#Version}
|
||||
AppPublisher=Mulberry
|
||||
VersionInfoVersion={#Version}
|
||||
VersionInfoProductName=Mulberry
|
||||
VersionInfoDescription=Mulberry Setup
|
||||
DefaultDirName={localappdata}\Programs\Mulberry
|
||||
DisableProgramGroupPage=yes
|
||||
DisableDirPage=auto
|
||||
PrivilegesRequired=lowest
|
||||
ArchitecturesAllowed=x64compatible
|
||||
ArchitecturesInstallIn64BitMode=x64compatible
|
||||
OutputDir=..\dist
|
||||
OutputBaseFilename=Mulberry-{#Version}-Setup
|
||||
SetupIconFile=mulberry.ico
|
||||
UninstallDisplayIcon={app}\mulberry.exe
|
||||
UninstallDisplayName=Mulberry
|
||||
Compression=lzma2/max
|
||||
SolidCompression=yes
|
||||
WizardStyle=modern
|
||||
CloseApplications=yes
|
||||
|
||||
[Tasks]
|
||||
Name: "desktopicon"; Description: "Create a desktop shortcut"; Flags: unchecked
|
||||
|
||||
[Files]
|
||||
Source: "{#Src}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||
|
||||
[Icons]
|
||||
Name: "{userprograms}\Mulberry"; Filename: "{app}\mulberry.exe"
|
||||
Name: "{userdesktop}\Mulberry"; Filename: "{app}\mulberry.exe"; Tasks: desktopicon
|
||||
|
||||
[Run]
|
||||
Filename: "{app}\mulberry.exe"; Description: "Launch Mulberry"; Flags: nowait postinstall skipifsilent
|
||||
|
|
@ -12,6 +12,14 @@ pub const USER_AGENT: &str = concat!("Mulberry/", env!("CARGO_PKG_VERSION"), " (
|
|||
fn xdg(var: &str, default: &str) -> PathBuf {
|
||||
match std::env::var_os(var) {
|
||||
Some(v) if !v.is_empty() => PathBuf::from(v),
|
||||
#[cfg(windows)]
|
||||
_ => match var {
|
||||
"XDG_CONFIG_HOME" => dirs::config_dir(),
|
||||
"XDG_DATA_HOME" => dirs::data_dir(),
|
||||
_ => dirs::cache_dir(),
|
||||
}
|
||||
.unwrap_or_else(|| dirs::home_dir().unwrap_or_default().join(default)),
|
||||
#[cfg(not(windows))]
|
||||
_ => dirs::home_dir().unwrap_or_default().join(default),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
31
src/instance_win.rs
Normal file
31
src/instance_win.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//! Single instance on Windows: a loopback TCP port instead of a unix socket.
|
||||
|
||||
use crate::bus::{Bus, Msg};
|
||||
use std::io::{Read, Write};
|
||||
use std::net::{Shutdown, TcpListener, TcpStream};
|
||||
|
||||
const ADDR: &str = "127.0.0.1:47613";
|
||||
|
||||
/// If another instance is running, pass it our arguments and return true.
|
||||
pub fn forward(args: &[String]) -> bool {
|
||||
let Ok(mut s) = TcpStream::connect(ADDR) else { return false };
|
||||
let msg = if args.is_empty() { "\u{1}raise".to_string() } else { args.join("\n") };
|
||||
let ok = s.write_all(msg.as_bytes()).is_ok();
|
||||
let _ = s.shutdown(Shutdown::Write);
|
||||
ok
|
||||
}
|
||||
|
||||
pub fn serve(bus: Bus) {
|
||||
let Ok(l) = TcpListener::bind(ADDR) else { return };
|
||||
std::thread::spawn(move || {
|
||||
for mut conn in l.incoming().flatten() {
|
||||
let mut buf = String::new();
|
||||
let _ = conn.read_to_string(&mut buf);
|
||||
if buf == "\u{1}raise" {
|
||||
bus.send(Msg::Raise);
|
||||
} else {
|
||||
bus.send(Msg::OpenArgs(buf.lines().map(String::from).filter(|l| !l.is_empty()).collect()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
12
src/lib.rs
12
src/lib.rs
|
|
@ -4,8 +4,16 @@ pub mod bus;
|
|||
pub mod cd;
|
||||
pub mod config;
|
||||
pub mod icondata;
|
||||
#[cfg(unix)]
|
||||
pub mod instance;
|
||||
#[cfg(windows)]
|
||||
#[path = "instance_win.rs"]
|
||||
pub mod instance;
|
||||
pub mod library;
|
||||
#[cfg(unix)]
|
||||
pub mod mpris;
|
||||
#[cfg(windows)]
|
||||
#[path = "mpris_stub.rs"]
|
||||
pub mod mpris;
|
||||
pub mod nowplaying;
|
||||
pub mod online;
|
||||
|
|
@ -17,6 +25,10 @@ pub mod song;
|
|||
pub mod spectrum;
|
||||
pub mod tags;
|
||||
pub mod theme;
|
||||
#[cfg(unix)]
|
||||
pub mod tray;
|
||||
#[cfg(windows)]
|
||||
#[path = "tray_stub.rs"]
|
||||
pub mod tray;
|
||||
pub mod ui;
|
||||
pub mod util;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")]
|
||||
use eframe::egui;
|
||||
use eframe::App as _;
|
||||
use std::cell::RefCell;
|
||||
|
|
|
|||
42
src/mpris_stub.rs
Normal file
42
src/mpris_stub.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//! Windows has no MPRIS: the same API as mpris.rs, doing nothing.
|
||||
|
||||
use crate::bus::Bus;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Snapshot {
|
||||
pub status: String, // Playing | Paused | Stopped
|
||||
pub loop_status: String,
|
||||
pub shuffle: bool,
|
||||
pub volume: f64,
|
||||
pub can_seek: bool,
|
||||
pub has_song: bool,
|
||||
pub track_id: String,
|
||||
pub title: String,
|
||||
pub artists: Vec<String>,
|
||||
pub album: String,
|
||||
pub album_artist: String,
|
||||
pub genre: String,
|
||||
pub track: i64,
|
||||
pub disc: i64,
|
||||
pub length_us: i64,
|
||||
pub url: String,
|
||||
pub art_url: String,
|
||||
pub year: i64,
|
||||
pub use_count: i64,
|
||||
pub rating: f64,
|
||||
}
|
||||
|
||||
pub struct Mpris;
|
||||
|
||||
impl Mpris {
|
||||
pub fn start(_bus: Bus) -> Option<Mpris> {
|
||||
None
|
||||
}
|
||||
pub fn notify_changed(&self) {}
|
||||
pub fn take_dirty(&self) -> bool {
|
||||
false
|
||||
}
|
||||
pub fn publish(&self, _s: Snapshot) {}
|
||||
pub fn set_position(&self, _sec: f64) {}
|
||||
pub fn seeked(&self, _sec: f64) {}
|
||||
}
|
||||
13
src/tray_stub.rs
Normal file
13
src/tray_stub.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
//! No tray icon on Windows yet: the same API as tray.rs, never started.
|
||||
|
||||
use crate::bus::Bus;
|
||||
|
||||
pub struct Tray;
|
||||
|
||||
impl Tray {
|
||||
pub fn start(_bus: Bus) -> Option<Tray> {
|
||||
None
|
||||
}
|
||||
pub fn set_icon(&self, _rgba: Vec<u8>) {}
|
||||
pub fn set_playing(&self, _playing: bool) {}
|
||||
}
|
||||
Loading…
Reference in a new issue