SOLVED applicationWillTerminate doesn’t work as predicted?
RafaŁ Buchner last edited by gferreira
I was trying to implement auto-opening ufos on start that were active during the previous RF session.
Here is the code that I'm putting to the startup scripts batch:
import os from mojo.UI import getDefault, setDefault from mojo.roboFont import OpenFont, AllFonts from mojo.events import addObserver, removeObserver ''' Startup script that opens recently closed Robofont session ''' def openRecentSession(): paths = getDefault('recentSessionPaths') if paths is None: return for path in paths: if os.path.exists(path): OpenFont(path, True) print('!!!! opened path', path) def saveCurrentSession(): paths = [f.path for f in AllFonts()] print(paths) if len(paths) == 0: paths = None setDefault('recentSessionPaths', paths) class OpenRecentSessionManager(object): def __init__(self): print('openRecentSession =', getDefault('openRecentSession')) if getDefault('openRecentSession') == 1: openRecentSession() addObserver(self, 'robofontClosing', 'applicationWillTerminate') def robofontClosing(self, info): print('robofotn closing, saving current session', AllFonts()) saveCurrentSession() OpenRecentSessionManager()
My issue: I assumed that
applicationWillTerminateobserver triggers callback whenever the RF app is being closed. It looks like it is not true. It is hard to tell when closing the RF app will trigger my
Maybe I assumption was wrong, and
applicationWillTerminateworks completely differently? is there a better way to implement auto-opening the last RF session?
Thanks in advance for your help
and please, inform me if the question is not clear enough :)
RafaŁ Buchner last edited by
This is so cool! Thanks!!!
and maybe also take a look here: https://github.com/typemytype/projectRoboFontExtension
Mmm, I guess in this case all open fonts are already closed, so
AllFonts()will be an empty list...
Dont overcomplicate it to much and try to use macOS callbacks... like:
import AppKit controller = AppKit.NSDocumentController.sharedDocumentController() print(controller.recentDocumentURLs())