summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2018-08-09 04:10:06 -0700
committerMinh Nguyễn <mxn@1ec5.org>2018-08-09 19:23:42 -0700
commitc2f7d8a9fd8d59499379dac20b50dab79be5e2f9 (patch)
treeac7c27da5d798d30f995b5a1b304970fdfc47ef8
parentbd2062f006a13e82e30619e55c77f867b1ed6e0e (diff)
downloadqtlocation-mapboxgl-c2f7d8a9fd8d59499379dac20b50dab79be5e2f9.tar.gz
[macos] Play sound when offline pack completes or errors
Play a sound when an offline pack being added finishes downloading or encounters an error.
-rw-r--r--platform/macos/app/AppDelegate.h2
-rw-r--r--platform/macos/app/AppDelegate.m26
-rw-r--r--platform/macos/app/MapDocument.m1
3 files changed, 29 insertions, 0 deletions
diff --git a/platform/macos/app/AppDelegate.h b/platform/macos/app/AppDelegate.h
index a1d9297b2f..87b7514292 100644
--- a/platform/macos/app/AppDelegate.h
+++ b/platform/macos/app/AppDelegate.h
@@ -21,4 +21,6 @@ extern NSString * const MGLMapboxAccessTokenDefaultsKey;
@property (copy) NSURL *pendingStyleURL;
@property (assign) MGLMapDebugMaskOptions pendingDebugMask;
+- (void)watchOfflinePack:(MGLOfflinePack *)pack;
+
@end
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 {
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index 805ffe35f0..447929201c 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -953,6 +953,7 @@ NSArray<id <MGLAnnotation>> *MBXFlattenedShapes(NSArray<id <MGLAnnotation>> *sha
if (error) {
[[NSAlert alertWithError:error] runModal];
} else {
+ [(AppDelegate *)NSApp.delegate watchOfflinePack:pack];
[pack resume];
}
}];