[macos] Play sound when offline pack completes or errors
Play a sound when an offline pack being added finishes downloading or encounters an error.
This commit is contained in:
committed by
Minh Nguyễn
parent
bd2062f006
commit
c2f7d8a9fd
@@ -21,4 +21,6 @@ extern NSString * const MGLMapboxAccessTokenDefaultsKey;
|
||||
@property (copy) NSURL *pendingStyleURL;
|
||||
@property (assign) MGLMapDebugMaskOptions pendingDebugMask;
|
||||
|
||||
- (void)watchOfflinePack:(MGLOfflinePack *)pack;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user