Skip to content

Commit

Permalink
fix(App): bookmark restore permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
victorwads committed Apr 11, 2023
1 parent 0116592 commit 0cdf0d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
27 changes: 10 additions & 17 deletions Source/Providers/FilesProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ func bookmarkKey(_ path: String) -> String{
return "bm2:\(path)"
}

func bookmarkKey(url: URL) -> String{
return bookmarkKey(url.path)
}

class FilesProvider {
public static let shared = FilesProvider()

Expand All @@ -37,16 +33,12 @@ class FilesProvider {
openPanel.message = Strings.providerFilesOpenMessage.value
openPanel.showsHiddenFiles = true
openPanel.begin { (result) -> Void in
if result == NSApplication.ModalResponse.OK {
let url = openPanel.urls.first!
if result == NSApplication.ModalResponse.OK, let url = openPanel.urls.first {
do{
let bookmarkData = try url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)
UserDefaults.standard.setValue(bookmarkData, forKey: bookmarkKey(url: url))
self.resolveBookmark(data: bookmarkData)
callback(url.path)
} catch {
print(error.localizedDescription)
}
} catch {}
callback(url.path)
}
}
}
Expand All @@ -58,18 +50,19 @@ class FilesProvider {

if isStale.boolValue{
let bookmark = try url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)
UserDefaults.standard.setValue(bookmark, forKey:bookmarkKey(url.path!))
if let path = url.path {
UserDefaults.standard.setValue(bookmark, forKey:bookmarkKey(path))
}
}

if !url.startAccessingSecurityScopedResource(){
print("Failed to access sandbox files")
guard url.startAccessingSecurityScopedResource() else {
// Access was not granted, handle it here
return false
}

return FileManager.default.fileExists(atPath: url.path ?? "") &&
FileManager.default.isWritableFile(atPath: url.path ?? "")

FileManager.default.isReadableFile(atPath: url.path ?? "")
} catch {
print(error.localizedDescription)
return false
}
}
Expand Down
12 changes: 8 additions & 4 deletions UptimeLogger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = UptimeLogger/UptimeLogger.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"UptimeLogger/Preview Content\"";
DEVELOPMENT_TEAM = DU6489YN3U;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -499,9 +500,10 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = br.com.victorwads.UptimeLogger;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
};
Expand All @@ -513,10 +515,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = UptimeLogger/UptimeLogger.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"UptimeLogger/Preview Content\"";
DEVELOPMENT_TEAM = DU6489YN3U;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -530,9 +533,10 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = br.com.victorwads.UptimeLogger;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
};
Expand Down

0 comments on commit 0cdf0d0

Please sign in to comment.