Added import guard around Notify import
This commit is contained in:
@@ -8,6 +8,16 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
|
|||||||
import gi
|
import gi
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gdk, GdkPixbuf, Gio, GLib, Gtk
|
from gi.repository import Gdk, GdkPixbuf, Gio, GLib, Gtk
|
||||||
|
try:
|
||||||
|
gi.require_version('Notify', '0.7')
|
||||||
|
from gi.repository import Notify
|
||||||
|
notification_daemon_exists = True
|
||||||
|
except Exception:
|
||||||
|
# I really don't care what kind of exception it is, all that matters is the
|
||||||
|
# import failed for some reason.
|
||||||
|
logging.warning(
|
||||||
|
'Unable to import Notify from GLib. Notifications will be disabled.')
|
||||||
|
notification_daemon_exists = False
|
||||||
|
|
||||||
from .cache_manager import CacheManager
|
from .cache_manager import CacheManager
|
||||||
from .config import ReplayGainType
|
from .config import ReplayGainType
|
||||||
@@ -23,7 +33,8 @@ from .ui.settings import SettingsDialog
|
|||||||
class SublimeMusicApp(Gtk.Application):
|
class SublimeMusicApp(Gtk.Application):
|
||||||
def __init__(self, config_file: str):
|
def __init__(self, config_file: str):
|
||||||
super().__init__(application_id="com.sumnerevans.sublimemusic")
|
super().__init__(application_id="com.sumnerevans.sublimemusic")
|
||||||
# Notify.init('Sublime Music')
|
if notification_daemon_exists:
|
||||||
|
Notify.init('Sublime Music')
|
||||||
|
|
||||||
self.window: Optional[Gtk.Window] = None
|
self.window: Optional[Gtk.Window] = None
|
||||||
self.state = ApplicationState()
|
self.state = ApplicationState()
|
||||||
@@ -767,7 +778,8 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def on_app_shutdown(self, app: 'SublimeMusicApp'):
|
def on_app_shutdown(self, app: 'SublimeMusicApp'):
|
||||||
# Notify.uninit()
|
if notification_daemon_exists:
|
||||||
|
Notify.uninit()
|
||||||
|
|
||||||
if self.state.config.server is None:
|
if self.state.config.server is None:
|
||||||
return
|
return
|
||||||
@@ -882,7 +894,8 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
self.should_scrobble_song = True
|
self.should_scrobble_song = True
|
||||||
|
|
||||||
# Show a song play notification.
|
# Show a song play notification.
|
||||||
if self.state.config.song_play_notification and False:
|
if (self.state.config.song_play_notification
|
||||||
|
and notification_daemon_exists):
|
||||||
try:
|
try:
|
||||||
notification_lines = []
|
notification_lines = []
|
||||||
if song.album:
|
if song.album:
|
||||||
|
@@ -52,7 +52,6 @@ class ServerConfiguration:
|
|||||||
self.local_network_ssid = local_network_ssid
|
self.local_network_ssid = local_network_ssid
|
||||||
self.username = username
|
self.username = username
|
||||||
self.sync_enabled = sync_enabled
|
self.sync_enabled = sync_enabled
|
||||||
self._password = password
|
|
||||||
self.disable_cert_verify = disable_cert_verify
|
self.disable_cert_verify = disable_cert_verify
|
||||||
|
|
||||||
# Try to save the password in the keyring, but if we can't, then save
|
# Try to save the password in the keyring, but if we can't, then save
|
||||||
|
Reference in New Issue
Block a user