diff -r 91421eeb4426 -r 9fce700d42de ui.py --- a/ui.py Sun Jan 21 14:56:56 2018 +0000 +++ b/ui.py Sun Jan 21 16:21:53 2018 +0000 @@ -6,11 +6,12 @@ import time import datetime import logging +import borgend from threading import Lock, Timer -from config import settings, appname_stylised +from config import settings import objc -logger=logging.getLogger(__name__) +logger=borgend.logger.getChild(__name__) INACTIVE=0 ACTIVE=1 @@ -33,10 +34,13 @@ # Workaround to rumps brokenness; # see https://github.com/jaredks/rumps/issues/59 def notification_workaround(title, subtitle, message): - NSDictionary = objc.lookUpClass("NSDictionary") - d=NSDictionary() + try: + NSDictionary = objc.lookUpClass("NSDictionary") + d=NSDictionary() - rumps.notification(title, subtitle, message, data=d) + rumps.notification(title, subtitle, message, data=d) + except Exception as err: + logger.debug('Unable to display notificaton:%s:%s',err.__class__.__name__, str(err)) # Based on code snatched from # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778 @@ -104,7 +108,6 @@ return title, state - class BorgendTray(rumps.App): def __init__(self, backups): self.lock=Lock() @@ -130,6 +133,7 @@ menu, state=self.__rebuild_menu() self.refresh_timer=None + self.logwindow=None super().__init__(traynames[state], menu=menu, quit_button=None) @@ -147,6 +151,9 @@ menu.append(item) state=combine_state(state, this_state) + menu_log=rumps.MenuItem("Show log", callback=self.showlog) + menu.append(menu_log) + if not settings['no_quit_menu_entry']: menu_quit=rumps.MenuItem("Quit...", callback=self.my_quit) menu.append(menu_quit) @@ -180,10 +187,11 @@ logger.debug("Opening notification for error %s '%s'", msgid, errorlog['message']) - notification_workaround(appname_stylised, + notification_workaround(borgend.appname_stylised, msgid, errorlog['message']) def my_quit(self, _): + logging.shutdown() rumps.quit_application() def __menu_select_backup(self, sender, b): @@ -194,10 +202,25 @@ except Exception as err: logger.debug("Opening notification for exception %s '%s'", err.__class__.__name__, str(err)) - notification_workaround(appname_stylised, + notification_workaround(borgend.appname_stylised, err.__class__.__name__, str(err)) @rumps.notifications def notification_center(data): pass + def showlog(self, _): + try: + if not self.logwindow: + lines=borgend.fifolog.formatAll() + msg="\n".join(lines[0:]) + self.logwindow=rumps.Window(title=borgend.appname_stylised+' log', + default_text=msg, + ok='Close', + dimensions=(640,320)) + self.logwindow.run() + # Does not return until closed + self.logwindow=None + except Exception as err: + logger.critical('%s:%s', err.__class__.__name__, str(err)) +