Media keys work on macOS!!!!!!!!

This commit is contained in:
Sumner Evans
2020-03-28 22:07:38 -06:00
parent 7efeae063d
commit 53389dd2e3
2 changed files with 18 additions and 1 deletions

View File

@@ -60,6 +60,7 @@ setup(
'Deprecated',
'fuzzywuzzy',
'keyring',
'osxmmkeys ; sys_platform=="darwin"',
'pychromecast',
'PyGObject',
'python-dateutil',

View File

@@ -5,6 +5,12 @@ import random
from concurrent.futures import Future
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
try:
import osxmmkeys
tap_imported = True
except Exception:
tap_imported = False
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gdk, GdkPixbuf, Gio, GLib, Gtk
@@ -39,7 +45,7 @@ class SublimeMusicApp(Gtk.Application):
self.window: Optional[Gtk.Window] = None
self.state = ApplicationState()
self.state.config_file = config_file
self.dbus_manager = None
self.dbus_manager: Optional[DBusManager] = None
self.connect('shutdown', self.on_app_shutdown)
@@ -80,6 +86,13 @@ class SublimeMusicApp(Gtk.Application):
lambda a, p: self.update_play_state_from_server(),
)
if tap_imported:
self.tap = osxmmkeys.Tap()
self.tap.on('play_pause', self.on_play_pause)
self.tap.on('next_track', self.on_next_track)
self.tap.on('prev_track', self.on_prev_track)
self.tap.start()
def do_activate(self):
# We only allow a single window and raise any existing ones
if self.window:
@@ -781,6 +794,9 @@ class SublimeMusicApp(Gtk.Application):
if notification_daemon_exists:
Notify.uninit()
if self.tap:
self.tap.stop()
if self.state.config.server is None:
return