diff options
Diffstat (limited to 'platform/macos/app/AppDelegate.m')
-rw-r--r-- | platform/macos/app/AppDelegate.m | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/platform/macos/app/AppDelegate.m b/platform/macos/app/AppDelegate.m index f7b35d0c83..eda989d7f9 100644 --- a/platform/macos/app/AppDelegate.m +++ b/platform/macos/app/AppDelegate.m @@ -135,6 +135,8 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask"; } - (void)applicationWillTerminate:(NSNotification *)notification { + [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:nil]; + if (![[NSUserDefaults standardUserDefaults] boolForKey:@"NSQuitAlwaysKeepsWindows"]) { NSDocument *currentDocument = [NSDocumentController sharedDocumentController].currentDocument; if ([currentDocument isKindOfClass:[MapDocument class]]) { @@ -204,6 +206,7 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask"; - (IBAction)delete:(id)sender { for (MGLOfflinePack *pack in self.offlinePacksArrayController.selectedObjects) { + [self unwatchOfflinePack:pack]; [[MGLOfflineStorage sharedOfflineStorage] removePack:pack withCompletionHandler:^(NSError * _Nullable error) { if (error) { [[NSAlert alertWithError:error] runModal]; @@ -228,11 +231,13 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask"; } case MGLOfflinePackStateInactive: + [self watchOfflinePack:pack]; [pack resume]; break; case MGLOfflinePackStateActive: [pack suspend]; + [self unwatchOfflinePack:pack]; break; default: @@ -241,6 +246,27 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask"; } } +- (void)watchOfflinePack:(MGLOfflinePack *)pack { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(offlinePackDidChangeProgress:) name:MGLOfflinePackProgressChangedNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(offlinePackDidReceiveError:) name:MGLOfflinePackErrorNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(offlinePackDidReceiveError:) name:MGLOfflinePackMaximumMapboxTilesReachedNotification object:nil]; +} + +- (void)unwatchOfflinePack:(MGLOfflinePack *)pack { + [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:pack]; +} + +- (void)offlinePackDidChangeProgress:(NSNotification *)notification { + MGLOfflinePack *pack = notification.object; + if (pack.state == MGLOfflinePackStateComplete) { + [[NSSound soundNamed:@"Glass"] play]; + } +} + +- (void)offlinePackDidReceiveError:(NSNotification *)notification { + [[NSSound soundNamed:@"Basso"] play]; +} + #pragma mark Help methods - (IBAction)showShortcuts:(id)sender { |