Added import guard around Notify import

This commit is contained in:
Sumner Evans
2020-03-28 21:21:06 -06:00
parent 07213fc77a
commit aa286fdb6d
2 changed files with 16 additions and 4 deletions

View File

@@ -8,6 +8,16 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
import gi
gi.require_version('Gtk', '3.0')
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 .config import ReplayGainType
@@ -23,7 +33,8 @@ from .ui.settings import SettingsDialog
class SublimeMusicApp(Gtk.Application):
def __init__(self, config_file: str):
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.state = ApplicationState()
@@ -767,7 +778,8 @@ class SublimeMusicApp(Gtk.Application):
return False
def on_app_shutdown(self, app: 'SublimeMusicApp'):
# Notify.uninit()
if notification_daemon_exists:
Notify.uninit()
if self.state.config.server is None:
return
@@ -882,7 +894,8 @@ class SublimeMusicApp(Gtk.Application):
self.should_scrobble_song = True
# 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:
notification_lines = []
if song.album:

View File

@@ -52,7 +52,6 @@ class ServerConfiguration:
self.local_network_ssid = local_network_ssid
self.username = username
self.sync_enabled = sync_enabled
self._password = password
self.disable_cert_verify = disable_cert_verify
# Try to save the password in the keyring, but if we can't, then save