summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/darwin/include/MGLOfflinePack.h34
-rw-r--r--platform/darwin/src/MGLOfflinePack.mm3
-rw-r--r--platform/darwin/src/MGLOfflinePack_Private.h12
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm3
-rw-r--r--platform/ios/app/MBXOfflinePacksTableViewController.m7
-rw-r--r--platform/osx/app/AppDelegate.m12
-rw-r--r--platform/osx/app/MainMenu.xib3
7 files changed, 50 insertions, 24 deletions
diff --git a/platform/darwin/include/MGLOfflinePack.h b/platform/darwin/include/MGLOfflinePack.h
index b65fed3849..783650590a 100644
--- a/platform/darwin/include/MGLOfflinePack.h
+++ b/platform/darwin/include/MGLOfflinePack.h
@@ -11,9 +11,11 @@ typedef NS_ENUM (NSInteger, MGLOfflinePackState) {
/**
It is unknown whether the pack is inactive, active, or complete.
- This is the initial state of a pack. The state becomes known by the time
- the shared `MGLOfflineStorage` object sends its first
- `MGLOfflinePackProgressChangedNotification`.
+ This is the initial state of a pack. The state of a pack becomes known by
+ the time the shared `MGLOfflineStorage` object sends the first
+ `MGLOfflinePackProgressChangedNotification` about the pack. For inactive
+ packs, you must explicitly request a progress update using the
+ `-[MGLOfflinePack requestProgress]` method.
An invalid pack always has a state of `MGLOfflinePackStateInvalid`, never
`MGLOfflinePackStateUnknown`.
@@ -107,9 +109,10 @@ typedef struct MGLOfflinePackProgress {
The pack’s current state.
The state of an inactive or completed pack is computed lazily and is set to
- `MGLOfflinePackStateUnknown` by default. To get notified when the state becomes
- known, observe KVO change notifications on this pack’s `state` key path.
- Alternatively, you can add an observer for
+ `MGLOfflinePackStateUnknown` by default. To request the pack’s status, use the
+ `-requestProgress` method. To get notified when the state becomes known and
+ when it changes, observe KVO change notifications on this pack’s `state` key
+ path. Alternatively, you can add an observer for
`MGLOfflinePackProgressChangedNotification`s about this pack that come from the
default notification center.
*/
@@ -119,9 +122,10 @@ typedef struct MGLOfflinePackProgress {
The pack’s current progress.
The progress of an inactive or completed pack is computed lazily, and all its
- fields are set to 0 by default. To get notified when the progress becomes
- known, observe KVO change notifications on this pack’s `state` key path.
- Alternatively, you can add an observer for
+ fields are set to 0 by default. To request the pack’s progress, use the
+ `-requestProgress` method. To get notified when the progress becomes
+ known and when it changes, observe KVO change notifications on this pack’s
+ `state` key path. Alternatively, you can add an observer for
`MGLOfflinePackProgressChangedNotification`s about this pack that come from the
default notification center.
*/
@@ -159,6 +163,18 @@ typedef struct MGLOfflinePackProgress {
*/
- (void)suspend;
+/**
+ Request an asynchronous update to the pack’s `state` and `progress` properties.
+
+ The state and progress of an inactive or completed pack are computed lazily. If
+ you need the state or progress of a pack whose `state` property is currently
+ set to `MGLOfflinePackStateUnknown`, observe KVO change notifications on this
+ pack’s `state` key path, then call this method. Alternatively, you can add an
+ observer for `MGLOfflinePackProgressChangedNotification` about this pack that
+ come from the default notification center.
+ */
+- (void)requestProgress;
+
@end
/**
diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm
index 05ff35ec7f..9775f1cfca 100644
--- a/platform/darwin/src/MGLOfflinePack.mm
+++ b/platform/darwin/src/MGLOfflinePack.mm
@@ -40,7 +40,6 @@ private:
@property (nonatomic, weak, nullable) id <MGLOfflinePackDelegate> delegate;
@property (nonatomic, nullable, readwrite) mbgl::OfflineRegion *mbglOfflineRegion;
-@property (nonatomic, readwrite) MGLOfflinePackState state;
@property (nonatomic, readwrite) MGLOfflinePackProgress progress;
@end
@@ -123,7 +122,7 @@ private:
}
- (void)requestProgress {
- NSAssert(_state != MGLOfflinePackStateInvalid, @"Cannot request progress from an invalid offline pack.");
+ MGLAssertOfflinePackIsValid();
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
diff --git a/platform/darwin/src/MGLOfflinePack_Private.h b/platform/darwin/src/MGLOfflinePack_Private.h
index 0e92655406..95d8ba4323 100644
--- a/platform/darwin/src/MGLOfflinePack_Private.h
+++ b/platform/darwin/src/MGLOfflinePack_Private.h
@@ -19,17 +19,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) mbgl::OfflineRegion *mbglOfflineRegion;
-- (instancetype)initWithMBGLRegion:(mbgl::OfflineRegion *)region;
+@property (nonatomic, readwrite) MGLOfflinePackState state;
-/**
- Request an asynchronous update to the pack’s `state` and `progress` properties.
-
- The state and progress of an inactive or completed pack are computed lazily. If
- you need the state or progress of a pack inside an
- `MGLOfflinePackListingCompletionHandler`, set the `delegate` property then call
- this method.
- */
-- (void)requestProgress;
+- (instancetype)initWithMBGLRegion:(mbgl::OfflineRegion *)region;
/**
Invalidates the pack and ensures that no future progress update can ever
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index 3d171ca203..89bf050249 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -130,10 +130,10 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
- (void)addPackForRegion:(id <MGLOfflineRegion>)region withContext:(NSData *)context completionHandler:(MGLOfflinePackAdditionCompletionHandler)completion {
__weak MGLOfflineStorage *weakSelf = self;
[self _addPackForRegion:region withContext:context completionHandler:^(MGLOfflinePack * _Nullable pack, NSError * _Nullable error) {
+ pack.state = MGLOfflinePackStateInactive;
MGLOfflineStorage *strongSelf = weakSelf;
[[strongSelf mutableArrayValueForKey:@"packs"] addObject:pack];
pack.delegate = strongSelf;
- [pack requestProgress];
if (completion) {
completion(pack, error);
}
@@ -208,7 +208,6 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
for (MGLOfflinePack *pack in packs) {
pack.delegate = self;
- [pack requestProgress];
}
}];
}
diff --git a/platform/ios/app/MBXOfflinePacksTableViewController.m b/platform/ios/app/MBXOfflinePacksTableViewController.m
index f4a2917d60..8aad4fbbf8 100644
--- a/platform/ios/app/MBXOfflinePacksTableViewController.m
+++ b/platform/ios/app/MBXOfflinePacksTableViewController.m
@@ -70,6 +70,13 @@ static NSString * const MBXOfflinePacksTableViewActiveCellReuseIdentifier = @"Ac
default:
[self.tableView reloadData];
+
+ for (MGLOfflinePack *pack in [MGLOfflineStorage sharedOfflineStorage].packs) {
+ if (pack.state == MGLOfflinePackStateUnknown) {
+ [pack requestProgress];
+ }
+ }
+
break;
}
} else {
diff --git a/platform/osx/app/AppDelegate.m b/platform/osx/app/AppDelegate.m
index 186a3a1ab3..d9fd967410 100644
--- a/platform/osx/app/AppDelegate.m
+++ b/platform/osx/app/AppDelegate.m
@@ -58,6 +58,7 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask";
@interface AppDelegate ()
@property (weak) IBOutlet NSArrayController *offlinePacksArrayController;
+@property (weak) IBOutlet NSPanel *offlinePacksPanel;
@end
@@ -177,6 +178,14 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask";
#pragma mark Offline pack management
+- (IBAction)showOfflinePacksPanel:(id)sender {
+ [self.offlinePacksPanel makeKeyAndOrderFront:sender];
+
+ for (MGLOfflinePack *pack in self.offlinePacksArrayController.arrangedObjects) {
+ [pack requestProgress];
+ }
+}
+
- (IBAction)delete:(id)sender {
for (MGLOfflinePack *pack in self.offlinePacksArrayController.selectedObjects) {
[[MGLOfflineStorage sharedOfflineStorage] removePack:pack withCompletionHandler:^(NSError * _Nullable error) {
@@ -247,6 +256,9 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask";
if (menuItem.action == @selector(showPreferences:)) {
return YES;
}
+ if (menuItem.action == @selector(showOfflinePacksPanel:)) {
+ return YES;
+ }
if (menuItem.action == @selector(delete:)) {
return self.offlinePacksArrayController.selectedObjects.count;
}
diff --git a/platform/osx/app/MainMenu.xib b/platform/osx/app/MainMenu.xib
index c408bdc568..646c4ae40d 100644
--- a/platform/osx/app/MainMenu.xib
+++ b/platform/osx/app/MainMenu.xib
@@ -18,6 +18,7 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="offlinePacksArrayController" destination="dWe-R6-sRz" id="Ar5-xu-ABm"/>
+ <outlet property="offlinePacksPanel" destination="Jjv-gs-Tx6" id="0vK-rR-3ZX"/>
<outlet property="preferencesWindow" destination="UWc-yQ-qda" id="Ota-aT-Mz2"/>
</connections>
</customObject>
@@ -527,7 +528,7 @@
<menuItem title="Offline Packs" id="YW3-jR-knj">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
- <action selector="makeKeyAndOrderFront:" target="Jjv-gs-Tx6" id="cJK-pv-fl5"/>
+ <action selector="showOfflinePacksPanel:" target="Voe-Tx-rLC" id="kj9-ht-KmF"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>