Mulberry/mulberry/__main__.py
Mulberry 615b21d64a
Mulberry 1.1.0: Material You music player for Linux and Windows
- KDE/Windows accent-driven Material 3 theme, live updating
- Library, tabbed playlists, smart/saved lists, queue, ratings
- mpv and Qt Multimedia engines, EQ, ReplayGain, gapless
- Synced lyrics (LRCLIB, NetEase, local .lrc), covers, MusicBrainz tags
- Last.fm/ListenBrainz scrobbling, MPRIS, Windows media keys
- Audio CD playback and ripping
- PyInstaller, Inno Setup and AppImage builds via GitHub Actions

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01J7imThHV9BMkG24GaxPDeq
2026-10-09 23:00:48 -05:00

98 lines
3.1 KiB
Python

"""Entry point: python -m mulberry [files/urls…]"""
from __future__ import annotations
import json
import os
import sys
def main():
from PyQt6.QtCore import Qt
from PyQt6.QtNetwork import QLocalServer, QLocalSocket
from PyQt6.QtWidgets import QApplication
from .config import APP_ID, APP_NAME, IS_LINUX, IS_WIN
if IS_LINUX:
# pip-installed Qt has no KDE platform theme; use the XDG portal so
# file dialogs are the native KDE ones.
from PyQt6.QtCore import QLibraryInfo
themes = os.path.join(QLibraryInfo.path(QLibraryInfo.LibraryPath.PluginsPath), "platformthemes")
have_kde = os.path.isdir(themes) and any("kde" in f.lower() for f in os.listdir(themes))
if not have_kde and os.environ.get("QT_QPA_PLATFORMTHEME", "kde").lower() in ("kde", ""):
os.environ["QT_QPA_PLATFORMTHEME"] = "xdgdesktopportal"
if IS_WIN:
# own taskbar identity (correct icon + grouping instead of python.exe)
try:
import ctypes
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("Mulberry.MusicPlayer")
except Exception: # noqa: BLE001
pass
QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
app = QApplication(sys.argv)
app.setApplicationName(APP_NAME)
app.setApplicationDisplayName(APP_NAME)
app.setOrganizationName(APP_ID)
app.setDesktopFileName(APP_ID)
app.setStyle("Fusion")
app.setQuitOnLastWindowClosed(False)
import locale
locale.setlocale(locale.LC_NUMERIC, "C")
args = [a for a in sys.argv[1:] if not a.startswith("-")]
import getpass
try:
who = getpass.getuser()
except Exception: # noqa: BLE001
who = "user"
server_name = f"{APP_ID}-{who}"
sock = QLocalSocket()
sock.connectToServer(server_name)
if sock.waitForConnected(300):
sock.write(json.dumps([os.path.abspath(a) if os.path.exists(a) else a for a in args] or ["--raise"]).encode())
sock.flush()
sock.waitForBytesWritten(500)
sock.disconnectFromServer()
return 0
from .theme import init_theme
init_theme()
from .library import init_library
init_library()
from .mainwindow import MainWindow
win = MainWindow()
win.show()
server = QLocalServer()
QLocalServer.removeServer(server_name)
server.listen(server_name)
def incoming():
c = server.nextPendingConnection()
if c is None:
return
def read():
try:
items = json.loads(bytes(c.readAll()).decode() or "[]")
except ValueError:
items = []
items = [i for i in items if i != "--raise"]
win.handle_args(items)
win.show()
win.raise_()
win.activateWindow()
c.readyRead.connect(read)
server.newConnection.connect(incoming)
if args:
win.handle_args([os.path.abspath(a) if os.path.exists(a) else a for a in args])
rc = app.exec()
server.close()
return rc
if __name__ == "__main__":
sys.exit(main())