Skip to content

Commit 652878a

Browse files
authored
Merge pull request #16 from leofilip:13-bug-isolate-the-media-controls
bug: Isolate the thumbbar media buttons
2 parents 0a707cb + c38f7b3 commit 652878a

File tree

7 files changed

+82
-135
lines changed

7 files changed

+82
-135
lines changed

.last-build-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.2.7

build-menu.ps1

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ function Set-Version {
8989

9090
# compute suggested next patch
9191
$suggest = "$($cv.Major).$($cv.Minor).$($cv.Build + 1)"
92-
$newver = Read-Host "Enter new version (e.g. $suggest)"
93-
if ([string]::IsNullOrWhiteSpace($newver)) { Write-Host 'No version entered. Returning to menu.'; Pause; return }
92+
$newver = Read-Host "Enter new version [$suggest]"
93+
if ([string]::IsNullOrWhiteSpace($newver)) { $newver = $suggest }
9494

9595
try {
9696
$nv = [Version]$newver
@@ -189,15 +189,57 @@ function Set-Version {
189189
Pause
190190
}
191191

192+
function Test-VersionChanged {
193+
$versionFile = Join-Path -Path $PSScriptRoot -ChildPath '.last-build-version'
194+
$currentVersion = Get-CurrentVersion
195+
196+
if (Test-Path $versionFile) {
197+
$lastVersion = Get-Content $versionFile -Raw
198+
$lastVersion = $lastVersion.Trim()
199+
200+
if ($lastVersion -eq $currentVersion) {
201+
Write-Host "Current version ($currentVersion) has not been incremented since last build." -ForegroundColor Yellow
202+
$response = Read-Host "Do you want to set a new version now? (Y/N)"
203+
if ($response -match '^[Yy]') {
204+
Set-Version
205+
return $true
206+
}
207+
else {
208+
$continue = Read-Host "Continue with current version? (Y/N)"
209+
if ($continue -notmatch '^[Yy]') {
210+
Write-Host "Operation cancelled." -ForegroundColor Yellow
211+
Pause
212+
return $false
213+
}
214+
}
215+
}
216+
}
217+
218+
return $true
219+
}
220+
221+
function Save-BuildVersion {
222+
$versionFile = Join-Path -Path $PSScriptRoot -ChildPath '.last-build-version'
223+
$currentVersion = Get-CurrentVersion
224+
Set-Content -Path $versionFile -Value $currentVersion
225+
}
226+
192227
function Start-DevMode {
228+
if (-not (Test-VersionChanged)) { return }
229+
193230
Write-Host 'Running: cargo tauri dev' -ForegroundColor Cyan
194231
& cmd /c "cargo tauri dev"
232+
Save-BuildVersion
195233
Pause
196234
}
197235

198236
function Build-Release {
237+
if (-not (Test-VersionChanged)) { return }
238+
199239
Write-Host 'Building: cargo tauri build' -ForegroundColor Cyan
200240
& cmd /c "cargo tauri build"
241+
Save-BuildVersion
242+
201243
$msiFolder = Join-Path -Path $PSScriptRoot -ChildPath 'src-tauri\target\release\bundle\msi'
202244
if (Test-Path $msiFolder) {
203245
Write-Host "Opening installer folder: $msiFolder"

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "qobuz-player"
3-
version = "0.2.4"
3+
version = "0.2.7"
44
description = "Web Container for Qobuz Web Player"
55
authors = ["Leonardo Calé"]
66
edition = "2024"

src-tauri/src/main.rs

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,39 @@ use tauri::{
66
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
77
};
88
use raw_window_handle::HasWindowHandle;
9-
// no direct Emitter usage here; native thumbar sends media keys directly
109

1110
mod thumbar;
1211

13-
// Note: we removed the `native_set_playing` command — the native thumbar
14-
// uses static icons now and the renderer/plugin is authoritative for
15-
// playback state. Renderer should listen for `thumbar-*` events and act.
16-
1712
#[tauri::command]
1813
fn native_add_thumb_buttons() {
19-
// Call into the native module to (re)create the thumbbar buttons.
2014
thumbar::add_thumb_buttons();
2115
}
2216

2317
#[tauri::command]
2418
fn native_remove_thumb_buttons() {
25-
// Remove the subclass and cleanup native icons.
2619
thumbar::remove_thumb_buttons();
2720
}
2821

2922
fn main() {
3023
tauri::Builder::default()
3124
.invoke_handler(tauri::generate_handler![native_add_thumb_buttons, native_remove_thumb_buttons])
32-
.on_page_load(|_window, _payload| {
33-
// When the page finishes loading, create the native thumbbar
34-
// buttons for the main window so they appear automatically.
35-
// The HWND is stored during `setup` so the native loader will
36-
// be able to call ThumbBarAddButtons.
25+
.on_page_load(|_window, _payload| {
3726
let _ = thumbar::add_thumb_buttons();
3827
})
3928
.plugin(tauri_plugin_media::init())
40-
.plugin(tauri_plugin_single_instance::init(|_app, _args, _cwd| {}))
29+
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
30+
if let Some(window) = app.get_webview_window("main") {
31+
let _ = window.unminimize();
32+
let _ = window.show();
33+
let _ = window.set_focus();
34+
}
35+
}))
4136
.setup(|app| {
42-
// On Windows, set an explicit AppUserModelID so Explorer
43-
// associates this process with the application identity and
44-
// (when possible) updates the taskbar/pinned icon. This helps
45-
// when icons change during development.
4637
#[cfg(target_os = "windows")]
4738
{
4839
use windows::core::PCWSTR;
4940
use windows::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID;
5041

51-
// Use different AppUserModelID for dev vs release builds so Windows
52-
// doesn't try to use the icon from the installed app location when
53-
// running dev builds. This prevents the "icon not found" issue where
54-
// Explorer looks for C:\Program Files\qobuz-player\qobuz-player.exe
55-
// which doesn't exist during development.
5642
#[cfg(debug_assertions)]
5743
let app_id = "com.leo.qobuz-player.dev";
5844
#[cfg(not(debug_assertions))]
@@ -62,14 +48,11 @@ fn main() {
6248
let pcw = PCWSTR(id.as_ptr());
6349
let _ = unsafe { SetCurrentProcessExplicitAppUserModelID(pcw) };
6450
}
65-
// Build menu items (only production items). The dev helper was
66-
// intentionally removed so development helpers don't clutter the
67-
// codebase — continue developing the thumbar feature instead.
51+
6852
let show = MenuItem::with_id(app, "show", "Show", true, None::<&str>)?;
6953
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
7054
let menu = Menu::with_items(app, &[&show, &quit])?;
7155

72-
// Create tray icon
7356
TrayIconBuilder::new()
7457
.icon(app.default_window_icon().unwrap().clone())
7558
.menu(&menu)
@@ -95,7 +78,6 @@ fn main() {
9578
} => {
9679
let app = tray.app_handle();
9780
if let Some(window) = app.get_webview_window("main") {
98-
// Toggle: if visible -> hide to tray; otherwise show/restore.
9981
match window.is_visible() {
10082
Ok(true) => {
10183
let _ = window.hide();
@@ -104,8 +86,7 @@ fn main() {
10486
let _ = window.unminimize();
10587
let _ = window.show();
10688
let _ = window.set_focus();
107-
// Reinitialize thumbar for this window in case the
108-
// HWND changed during hide/minimize.
89+
10990
#[cfg(target_os = "windows")]
11091
if let Ok(wh) = window.window_handle() {
11192
match wh.into() {
@@ -123,13 +104,9 @@ fn main() {
123104
_ => {}
124105
})
125106
.build(app)?;
126-
// Initialize the thumbar scaffolding (Windows-only integration point)
127-
// Pass the `App` reference so the thumbar module can locate the
128-
// main window and emit events via the app handle.
107+
129108
thumbar::init_thumbar(app, "main");
130-
// Attempt to store the main webview HWND now so native code can
131-
// call ThumbBarAddButtons. This mirrors the logic used when the
132-
// tray toggles the window and ensures a stored HWND early.
109+
133110
if let Some(window) = app.get_webview_window("main") {
134111
if let Ok(wh) = window.window_handle() {
135112
match wh.into() {
@@ -140,18 +117,7 @@ fn main() {
140117
}
141118
}
142119
}
143-
// Thumbbar clicks are handled by the native module which now
144-
// converts them into system media key events. Media state and
145-
// SMTC integration are handled by `tauri-plugin-media`.
146-
// We'll add the thumbbar buttons once the page loads so buttons
147-
// appear automatically. Frontend can still call the commands
148-
// `native_set_playing`, `native_add_thumb_buttons` and
149-
// `native_remove_thumb_buttons` as needed to update state.
150-
// Use `on_page_load` to trigger native creation when the main
151-
// webview finishes loading.
152-
// Note: we register the on_page_load handler on the Builder below.
153-
// Thumbar scaffolding initialized; frontend can be wired to events
154-
// once native thumbar implementation is present.
120+
155121
Ok(())
156122
})
157123
.on_window_event(|app, event| {

0 commit comments

Comments
 (0)