Revision: 15522 http://sourceforge.net/p/skim-app/code/15522 Author: hofman Date: 2025-06-22 14:31:56 +0000 (Sun, 22 Jun 2025) Log Message: ----------- Separate method to register for current document notifications and timer. Pass nil for app will terminate notification, as it will not be equal to the notification name. Delaye registration to allow for reopening files.
Modified Paths: -------------- trunk/SKApplicationController.m Modified: trunk/SKApplicationController.m =================================================================== --- trunk/SKApplicationController.m 2025-06-22 08:47:47 UTC (rev 15521) +++ trunk/SKApplicationController.m 2025-06-22 14:31:56 UTC (rev 15522) @@ -167,10 +167,20 @@ - (void)registerCurrentDocuments:(id)timerOrNotification { [[NSUserDefaults standardUserDefaults] setObject:[[NSApp orderedDocuments] valueForKey:CURRENTDOCUMENTSETUP_KEY] forKey:SKLastOpenFileNamesKey]; - BOOL forced = [timerOrNotification isEqual:SKApplicationStartsTerminatingNotification]; + BOOL forced = timerOrNotification == nil; [[[NSDocumentController sharedDocumentController] documents] makeObjectsPerformSelector:forced ? @selector(saveRecentDocumentInfo) : @selector(saveRecentDocumentInfoIfNeeded)]; } +- (void)registerForCurrentDocumentsNotifications { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc addObserver:self selector:@selector(registerCurrentDocuments:) + name:SKDocumentDidShowNotification object:nil]; + [nc addObserver:self selector:@selector(registerCurrentDocuments:) + name:SKDocumentControllerDidRemoveDocumentNotification object:nil]; + + currentDocumentsTimer = [NSTimer scheduledTimerWithTimeInterval:CURRENTDOCUMENTSETUP_INTERVAL target:self selector:@selector(registerCurrentDocuments:) userInfo:nil repeats:YES]; +} + - (void)reopenLastOpenFiles { didReopen = YES; @@ -231,14 +241,8 @@ [sud setObject:versionString forKey:SKLastVersionLaunchedKey]; } - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc addObserver:self selector:@selector(registerCurrentDocuments:) - name:SKDocumentDidShowNotification object:nil]; - [nc addObserver:self selector:@selector(registerCurrentDocuments:) - name:SKDocumentControllerDidRemoveDocumentNotification object:nil]; + [self performSelector:@selector(registerForCurrentDocumentsNotifications) withObject:nil afterDelay:1.0]; - currentDocumentsTimer = [NSTimer scheduledTimerWithTimeInterval:CURRENTDOCUMENTSETUP_INTERVAL target:self selector:@selector(registerCurrentDocuments:) userInfo:nil repeats:YES]; - // kHIDRemoteModeExclusiveAuto lets the HIDRemote handle activation when the app gets or loses focus if ([sud boolForKey:SKEnableAppleRemoteKey]) { [[HIDRemote sharedHIDRemote] startRemoteControl:kHIDRemoteModeExclusiveAuto]; @@ -315,19 +319,12 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc removeObserver:self name:SKDocumentDidShowNotification object:nil]; [nc removeObserver:self name:SKDocumentControllerDidRemoveDocumentNotification object:nil]; - [self registerCurrentDocuments:aNotification]; + [self registerCurrentDocuments:nil]; } - (void)applicationDocumentControllerCanceledTerminate:(NSApplication *)application { - if (currentDocumentsTimer == nil) { - currentDocumentsTimer = [NSTimer scheduledTimerWithTimeInterval:CURRENTDOCUMENTSETUP_INTERVAL target:self selector:@selector(registerCurrentDocuments:) userInfo:nil repeats:YES]; - - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc addObserver:self selector:@selector(registerCurrentDocuments:) - name:SKDocumentDidShowNotification object:nil]; - [nc addObserver:self selector:@selector(registerCurrentDocuments:) - name:SKDocumentControllerDidRemoveDocumentNotification object:nil]; - } + if (currentDocumentsTimer == nil) + [self registerForCurrentDocumentsNotifications]; } #pragma mark Updater This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit