Merge branch 'windows-release'

This commit is contained in:
yuriy.p committed 2026-10-18 01:07:18 +06:00
commit 365a28ce67
8 files changed
+127 -14

No files matched your search

Generated
+41
View File
@@ -3011,6 +3011,7 @@ dependencies = [
"souvlaki",
"sys-locale",
"tokio",
"winresource",
"ym-api",
]
@@ -4700,6 +4701,15 @@ dependencies = [
"syn 3.0.9",
]
[[package]]
name = "serde_spanned"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c"
dependencies = [
"serde_core",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
@@ -5361,6 +5371,21 @@ dependencies = [
"tokio",
]
[[package]]
name = "toml"
version = "1.1.8+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20489e00e4d8741d6be680764cc12e270655e375a20d1011e844a9c3379e678d"
dependencies = [
"indexmap",
"serde_core",
"serde_spanned",
"toml_datetime",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_datetime"
version = "1.1.2+spec-1.1.0"
@@ -5391,6 +5416,12 @@ dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.1.3+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770"
[[package]]
name = "tower"
version = "0.5.3"
@@ -6505,6 +6536,16 @@ dependencies = [
"memchr",
]
[[package]]
name = "winresource"
version = "0.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2bc6d36480b829272a5bdabf08e6dca8004761c1da7e35efef800540c66221b"
dependencies = [
"toml",
"version_check",
]
[[package]]
name = "wit-bindgen"
version = "0.57.1"
+3
View File
@@ -27,6 +27,9 @@ objc2-foundation = "0.3.2"
objc2-app-kit = "0.3.2"
block2 = "0.6.2"
[build-dependencies]
winresource = "0.1.34"
[dev-dependencies]
iced_test = "0.14"
tokio = { version = "1", features = ["macros", "rt"] }
Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

+12
View File
@@ -0,0 +1,12 @@
fn main() {
// Embed the icon and version info into the Windows executable, so Explorer and the taskbar show them.
println!("cargo:rerun-if-changed=assets/icon/musyx.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
let mut res = winresource::WindowsResource::new();
res.set_icon("assets/icon/musyx.ico")
.set("ProductName", "Musyx")
.set("FileDescription", "Musyx")
.set("OriginalFilename", "Musyx.exe");
res.compile().expect("failed to embed Windows resources");
}
}
+11
View File
@@ -138,6 +138,9 @@ pub enum Message {
ClearCoverCache,
CoverCacheCleared(Result<(), String>),
Media(crate::media::Command),
/// A window opened; Windows media controls need its handle.
WindowOpened(iced::window::Id),
MediaWindow(u64),
LoadLikedIds,
LikedIdsLoaded(Result<LikedIds, Error>),
LikeTrack(Track, bool),
@@ -264,6 +267,9 @@ impl App {
let audio = player::engine::subscription().map(|e| Message::Player(player::Msg::Engine(e)));
let keys = crate::media::subscription().map(Message::Media);
let mut subs = vec![appearance, audio, keys];
if cfg!(windows) {
subs.push(iced::window::open_events().map(Message::WindowOpened));
}
if let Session::SignedOut(sign_in) = &self.session {
subs.push(sign_in.subscription().map(Message::SignIn));
}
@@ -521,6 +527,11 @@ impl App {
self.toast(trf("“{}” plays next", &[&track.full_title()]));
return self.update(Message::Player(player::Msg::PlayNext(track)));
}
Message::WindowOpened(id) => return iced::window::raw_id::<Message>(id).map(Message::MediaWindow),
Message::MediaWindow(raw_id) => {
self.media.attach_window(raw_id);
self.media.update(self.player.track(), self.player.status(), self.player.position(), true);
}
Message::Media(command) => {
use crate::media::Command as C;
let status = self.player.status();
+3
View File
@@ -1,3 +1,6 @@
// No console window behind the app in Windows release builds.
#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")]
mod app;
mod covers;
mod i18n;
+22 -14
View File
@@ -71,21 +71,16 @@ impl Media {
{
*inbox = Some(rx);
}
let controls = MediaControls::new(PlatformConfig { display_name: "Musyx", dbus_name: "musyx", hwnd: None })
.and_then(|mut c| {
c.attach(|event| {
if let Some(command) = Command::from_event(event) {
send(command);
}
})?;
Ok(c)
});
match controls {
Ok(c) => Self { controls: Some(c), shown: None },
Err(e) => {
eprintln!("media controls unavailable: {e:?}");
Self { controls: None, shown: None }
// Windows ties the controls to a window, so they wait for `attach_window`.
let controls = if cfg!(windows) { None } else { connect(None) };
Self { controls, shown: None }
}
/// Connects the controls to the main window (Windows needs its HWND, from `window::raw_id`).
pub fn attach_window(&mut self, raw_id: u64) {
if cfg!(windows) && self.controls.is_none() {
self.controls = connect(Some(raw_id as *mut std::ffi::c_void));
self.shown = None;
}
}
@@ -125,6 +120,19 @@ impl Media {
}
}
fn connect(hwnd: Option<*mut std::ffi::c_void>) -> Option<MediaControls> {
let controls = MediaControls::new(PlatformConfig { display_name: "Musyx", dbus_name: "musyx", hwnd })
.and_then(|mut c| {
c.attach(|event| {
if let Some(command) = Command::from_event(event) {
send(command);
}
})?;
Ok(c)
});
controls.map_err(|e| eprintln!("media controls unavailable: {e:?}")).ok()
}
pub fn subscription() -> Subscription<Command> {
Subscription::run(commands)
}
+35
View File
@@ -0,0 +1,35 @@
# Packs the app icon PNG into a multi-size Windows .ico (PNG-compressed entries).
# Usage: powershell -File tool/make_ico.ps1 crates/musyx/assets/icon/musyx.png crates/musyx/assets/icon/musyx.ico
param([string]$Src, [string]$Dst)
Add-Type -AssemblyName System.Drawing
$sizes = 16, 20, 24, 32, 40, 48, 64, 128, 256
$source = [System.Drawing.Image]::FromFile((Resolve-Path $Src))
$images = foreach ($s in $sizes) {
$bmp = New-Object System.Drawing.Bitmap $s, $s, ([System.Drawing.Imaging.PixelFormat]::Format32bppArgb)
$g = [System.Drawing.Graphics]::FromImage($bmp)
$g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
$g.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
$g.DrawImage($source, 0, 0, $s, $s)
$g.Dispose()
$ms = New-Object System.IO.MemoryStream
$bmp.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
$bmp.Dispose()
, $ms.ToArray()
}
$source.Dispose()
$out = New-Object System.IO.MemoryStream
$w = New-Object System.IO.BinaryWriter $out
$w.Write([uint16]0); $w.Write([uint16]1); $w.Write([uint16]$sizes.Count)
$offset = 6 + 16 * $sizes.Count
for ($i = 0; $i -lt $sizes.Count; $i++) {
$dim = if ($sizes[$i] -ge 256) { 0 } else { $sizes[$i] } # 0 means 256
$w.Write([byte]$dim); $w.Write([byte]$dim); $w.Write([byte]0); $w.Write([byte]0)
$w.Write([uint16]1); $w.Write([uint16]32)
$w.Write([uint32]$images[$i].Length); $w.Write([uint32]$offset)
$offset += $images[$i].Length
}
foreach ($img in $images) { $w.Write($img) }
$w.Flush()
[System.IO.File]::WriteAllBytes((Join-Path (Get-Location) $Dst), $out.ToArray())