mirror of
https://git.srhtnin.garden/sarah/SaraTune.git
synced 2026-10-14 18:18:11 +02:00
Media controls (MPRIS, Windows SMTC); stop old tracks when switching
This commit is contained in:
1 parent
e2d7515e08
commit
d7f5eba1c2
14 files changed
+799
-26
No files matched your search
@@ -14,6 +14,7 @@ import sys
|
||||
import flet as ft
|
||||
|
||||
from AudioMode import AudioMode
|
||||
from MediaControls import Remote
|
||||
from Core import (
|
||||
AppName, ApplyAppearance, AssetsDir, BuildTheme, BundledFontFamily, ChipButtonStyle, DataHome, EffectiveSettings,
|
||||
IsWindows, LoadConfig, Palette,
|
||||
@@ -200,11 +201,20 @@ def Main(Page: ft.Page) -> None:
|
||||
|
||||
Page.on_keyboard_event = OnKey
|
||||
|
||||
async def Quit() -> None:
|
||||
"""The window's close button and the media controls' Quit. Only
|
||||
once: destroying the window sends another close event."""
|
||||
if State.get("Quitting"):
|
||||
return
|
||||
State["Quitting"] = True
|
||||
ModeViews["Music"].SaveSession()
|
||||
Config.Save() # the volume
|
||||
await Controls.Stop()
|
||||
await Page.window.destroy()
|
||||
|
||||
async def OnWindowEvent(e: ft.WindowEvent) -> None:
|
||||
if e.type == ft.WindowEventType.CLOSE:
|
||||
ModeViews["Music"].SaveSession()
|
||||
Config.Save() # the volume
|
||||
await Page.window.destroy()
|
||||
await Quit()
|
||||
|
||||
Page.window.prevent_close = True
|
||||
Page.window.on_event = OnWindowEvent
|
||||
@@ -232,6 +242,13 @@ def Main(Page: ft.Page) -> None:
|
||||
Page.run_task(ModeViews["Audio"].Open, Files)
|
||||
else:
|
||||
SwitchMode(Config.StartMode if Config.StartMode in ModeViews else "Music")
|
||||
|
||||
# The system's media controls follow whichever mode played last.
|
||||
Controls = Remote(Page, Players, ModeViews, State["Mode"], SetVolume, Quit)
|
||||
if Config.MediaControls:
|
||||
TheApp.MediaChanged = Controls.MediaChanged
|
||||
TheApp.MediaModesChanged = Controls.ModesChanged
|
||||
Page.run_task(Controls.Start)
|
||||
Page.run_task(ModeViews["Music"].Started)
|
||||
Page.run_task(Ticker, [Mode.Bar for Mode in ModeViews.values()])
|
||||
|
||||
|
||||
Reference in new issue
Block a user