Skip to content

Commit 2cf9297

Browse files
authored
fix(package_info_plus): incorrect install time on macOS when app sandbox disabled (#3638)
1 parent 643e12d commit 2cf9297

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

packages/package_info_plus/package_info_plus/lib/package_info_plus.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ class PackageInfo {
154154
/// The time when the application was installed.
155155
///
156156
/// - On Android, returns `PackageManager.firstInstallTime`
157-
/// - On iOS and macOS, return the creation date of the app default `NSDocumentDirectory`
157+
/// - On iOS, return the creation date of the app default `NSDocumentDirectory`
158+
/// - On macOS, if the app is running in sandbox, return the creation date of the app default `NSDocumentDirectory`;
159+
/// If the app is not running in sandbox, return the last modified date of the app main bundle
158160
/// - On Windows and Linux, returns the creation date of the app executable.
159161
/// If the creation date is not available, returns the last modified date of the app executable.
160162
/// If the last modified date is not available, returns `null`.

packages/package_info_plus/package_info_plus/macos/package_info_plus/Sources/package_info_plus/FPPPackageInfoPlusPlugin.m

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
1616
- (void)handleMethodCall:(FlutterMethodCall *)call
1717
result:(FlutterResult)result {
1818
if ([call.method isEqualToString:@"getAll"]) {
19-
NSDate *installDate = [self getInstallDate];
20-
NSDate *updateDate = [self getUpdateDate];
19+
NSString *installDateStr = [self getTimeMillisStringFromDate:[self getInstallDate]];
20+
NSString *updateDateStr = [self getTimeMillisStringFromDate:[self getUpdateDate]];
2121

2222
result(@{
2323
@"appName" : [[NSBundle mainBundle]
@@ -33,15 +33,19 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
3333
objectForInfoDictionaryKey:@"CFBundleVersion"]
3434
?: [NSNull null],
3535
@"installerStore" : [NSNull null],
36-
@"installTime" : [self getTimeMillisStringFromDate:installDate] ?: [NSNull null],
37-
@"updateTime" : [self getTimeMillisStringFromDate:updateDate] ?: [NSNull null]
36+
@"installTime" : installDateStr ?: updateDateStr ?: [NSNull null],
37+
@"updateTime" : updateDateStr ?: [NSNull null]
3838
});
3939
} else {
4040
result(FlutterMethodNotImplemented);
4141
}
4242
}
4343

4444
- (NSDate *)getInstallDate {
45+
if (![self isRunningInSandbox]) {
46+
return nil;
47+
}
48+
4549
NSURL* urlToDocumentsFolder = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
4650
__autoreleasing NSError *error;
4751
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:urlToDocumentsFolder.path error:&error];
@@ -74,4 +78,9 @@ - (NSString *)getTimeMillisStringFromDate:(NSDate *)date {
7478
return [timeMillis stringValue];
7579
}
7680

81+
- (BOOL)isRunningInSandbox {
82+
NSString *sandboxContainerId = [[[NSProcessInfo processInfo] environment] objectForKey:@"APP_SANDBOX_CONTAINER_ID"];
83+
return sandboxContainerId != nil;
84+
}
85+
7786
@end

packages/package_info_plus/package_info_plus_platform_interface/lib/package_info_data.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class PackageInfoData {
3535
/// The time when the application was installed.
3636
///
3737
/// - On Android, returns `PackageManager.firstInstallTime`
38-
/// - On iOS and macOS, return the creation date of the app default `NSDocumentDirectory`
38+
/// - On iOS, return the creation date of the app default `NSDocumentDirectory`
39+
/// - On macOS, if the app is running in sandbox, return the creation date of the app default `NSDocumentDirectory`;
40+
/// If the app is not running in sandbox, return the last modified date of the app main bundle
3941
/// - On Windows and Linux, returns the creation date of the app executable.
4042
/// If the creation date is not available, returns the last modified date of the app executable.
4143
/// If the last modified date is not available, returns `null`.

0 commit comments

Comments
 (0)