Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix 'QObject::startTimer: Timers cannot be started from another thread' #799

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions feeluown/gui/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
from feeluown.player import State
from feeluown.gui.helpers import elided_text, get_qapp


TOGGLE_APP_TEXT = ('激活主窗口', '隐藏主窗口')
TOGGLE_PLAYER_TEXT = ('播放', '暂停')

IS_MACOS = sys.platform == 'darwin'


logger = logging.getLogger(__name__)


class Tray(QSystemTrayIcon):

def __init__(self, app):
"""
type app: feeluown.app.App
Expand All @@ -31,21 +30,21 @@ def __init__(self, app):
# setup context menu
self._menu = QMenu()
self._status_action = QAction('...')
self._toggle_player_action = QAction(QIcon.fromTheme('media-play'),
TOGGLE_PLAYER_TEXT[0])
self._toggle_player_action = QAction(
QIcon.fromTheme('media-play'), TOGGLE_PLAYER_TEXT[0]
)
self._next_action = QAction(QIcon.fromTheme('media-skip-forward'), '下一首')
self._prev_action = QAction(QIcon.fromTheme('media-skip-backward'), '上一首')
self._quit_action = QAction(QIcon.fromTheme('exit'), '退出')
# add toggle_app action for macOS, on other platforms, user
# can click the tray icon to toggle_app
if IS_MACOS:
self._toggle_app_action: Optional[QAction] = QAction(
QIcon.fromTheme('window'),
TOGGLE_APP_TEXT[1]
QIcon.fromTheme('window'), TOGGLE_APP_TEXT[1]
)
else:
self._toggle_app_action = None
self.activated.connect(self._on_activated) # noqa
self.activated.connect(self._on_activated) # noqa

# bind signals
self._quit_action.triggered.connect(self._app.exit)
Expand All @@ -54,7 +53,9 @@ def __init__(self, app):
self._next_action.triggered.connect(self._app.playlist.next)
if self._toggle_app_action is not None:
self._toggle_app_action.triggered.connect(self._toggle_app_state)
self._app.player.state_changed.connect(self.on_player_state_changed)
self._app.player.state_changed.connect(
self.on_player_state_changed, aioqueue=True
)
self._app.playlist.song_changed.connect(self.on_player_song_changed)
self._app.theme_mgr.theme_changed.connect(self.on_theme_changed)
get_qapp().applicationStateChanged.connect(self.on_app_state_changed)
Expand Down Expand Up @@ -103,8 +104,9 @@ def _toggle_app_state(self):

def _set_icon(self):
# respect system icon
icon = QIcon.fromTheme('feeluown-tray',
QIcon(self._app.theme_mgr.get_icon('tray')))
icon = QIcon.fromTheme(
'feeluown-tray', QIcon(self._app.theme_mgr.get_icon('tray'))
)
self.setIcon(icon)

def on_theme_changed(self, _):
Expand All @@ -115,9 +117,11 @@ def on_player_song_changed(self, song):
status = f'{song.title_display} - {song.artists_name_display}'
if self._app.config.NOTIFY_ON_TRACK_CHANGED:
# TODO: show song cover if possible
self.showMessage(song.title_display,
song.artists_name_display,
msecs=self._app.config.NOTIFY_DURATION)
self.showMessage(
song.title_display,
song.artists_name_display,
msecs=self._app.config.NOTIFY_DURATION
)
self._status_action.setText(elided_text(status, 120))
self._status_action.setToolTip(status)
self.setToolTip(status)
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/uimain/player_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, *args, **kwargs):
self.on_video_format_changed, aioqueue=True)
player = self._app.player
player.metadata_changed.connect(self.on_metadata_changed, aioqueue=True)
player.volume_changed.connect(self.volume_btn.on_volume_changed)
player.volume_changed.connect(self.volume_btn.on_volume_changed, aioqueue=True)
self.cover_label.clicked.connect(self.show_nowplaying_overlay)

self._setup_ui()
Expand Down
Loading