Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
674b7b9
MAS
gee1k Jan 15, 2021
725f135
删除打赏、重启 Finder
gee1k Jan 16, 2021
15e9ece
修改一些信息
L1cardo Jan 16, 2021
96e67cc
Merge branch 'feature/mas' into feature/mas
L1cardo Jan 16, 2021
71be7e4
Merge pull request #169 from L1cardo/feature/mas
gee1k Jan 16, 2021
f8229e8
增加 自定义输出格式配置
L1cardo Jan 17, 2021
e9f6e80
输出格式支持自定义、上传记录图床、大小、时间
gee1k Jan 18, 2021
601e275
修正 Share 分享路径
gee1k Jan 18, 2021
cef4c05
添加磁盘访问授权
L1cardo Jan 18, 2021
ba9dba0
授权磁盘访问
gee1k Jan 19, 2021
a443774
添加欢迎界面,优化数据库页面
L1cardo Jan 20, 2021
3ff0689
接入欢迎页、改造磁盘授权逻辑
gee1k Jan 20, 2021
9ba3447
releasing v1.1.0
gee1k Jan 20, 2021
d55d5d0
添加重启 finder 的帮助
L1cardo Jan 20, 2021
cc8c139
Releasing v1.1.0 build 7
gee1k Jan 20, 2021
9b26605
增加截图权限获取教程、首次请求磁盘权限改为用户主目录
gee1k Jan 21, 2021
62111f7
修复问题
gee1k Jan 23, 2021
765fe5e
数据库界面增加新功能
L1cardo Jan 24, 2021
a48dd1f
录屏权限页面添加约束
L1cardo Jan 24, 2021
467d42a
修复 Bugs 和更新阿里云区域数据
gee1k Jan 25, 2021
be36231
更新命令行参数
gee1k Feb 18, 2021
9cbefbe
移除 Finder Toolbar
gee1k Apr 25, 2021
2f0b4b0
添加 apple script支持
L1cardo Jun 6, 2021
9fe4ab0
升级LoginServiceKit 到版本2.2.1,修复问题#180
L1cardo Jun 6, 2021
ba8d8ac
v1.2.0
gee1k Jun 7, 2021
4d548d2
Add ImageCodec #194
bqlin Jun 15, 2021
832dfe5
Remove ImageCodec meta files
bqlin Jun 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
添加磁盘访问授权
  • Loading branch information
L1cardo authored and gee1k committed Jan 19, 2021
commit cef4c058dab400771b415eb6288e4fe281798629
20 changes: 10 additions & 10 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- Alamofire (5.0.5)
- CryptoSwift (1.3.3)
- Kingfisher (5.15.4):
- Kingfisher/Core (= 5.15.4)
- Kingfisher/Core (5.15.4)
- Alamofire (5.4.0)
- CryptoSwift (1.3.8)
- Kingfisher (5.15.7):
- Kingfisher/Core (= 5.15.7)
- Kingfisher/Core (5.15.7)
- libminipng (0.5.6)
- LoginServiceKit (2.2.0)
- MASShortcut (2.4.0)
Expand Down Expand Up @@ -52,7 +52,7 @@ EXTERNAL SOURCES:

CHECKOUT OPTIONS:
CryptoSwift:
:commit: e2bc81be54d71d566a52ca17c3983d141c30aa70
:commit: e7459377e0f48779c69a9b20da21fb9224d94ac8
:git: https://github.com/krzyzanowskim/CryptoSwift
LoginServiceKit:
:commit: cf58b91b0ac247bd8bf5dccb5434ca60a930c1e1
Expand All @@ -62,9 +62,9 @@ CHECKOUT OPTIONS:
:git: https://github.com/yahoojapan/SwiftyXMLParser.git

SPEC CHECKSUMS:
Alamofire: df2f8f826963b08b9a870791ad48e07a10090b2e
CryptoSwift: fedfc9f8362163ca381a78897ad810982e18d464
Kingfisher: 657dc1077e5bbbfff864194c79f29e35b722d062
Alamofire: 3b6a534a3df22db367e4dedeeca73d1ddfcf0e2f
CryptoSwift: 01b0f0cba1d5c212e5a335ff6c054fb75a204f00
Kingfisher: 6e1a13523fcb1c86924ce53affe4ac957e544d59
libminipng: a44c35d06b9d54d6640acdf97f4500c034748abb
LoginServiceKit: 3c86ce2f2bcd1e373326839d6d863d8a6a5915b4
MASShortcut: d9e4909e878661cc42877cc9d6efbe638273ab57
Expand All @@ -77,4 +77,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 5805b359b360efbaba02725567dda3b519766521

COCOAPODS: 1.9.3
COCOAPODS: 1.10.0
8 changes: 4 additions & 4 deletions uPic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
96B6C41425AD8AFF00B1A584 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
96B6C41825AD8B0000B1A584 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
96CA5B8925B41B1F00855629 /* OutputFormatCustomization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutputFormatCustomization.swift; sourceTree = "<group>"; };
96CA5B9325B4446E00855629 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Preferences.strings; sourceTree = "<group>"; };
96CF336325B5F20800265690 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Preferences.strings; sourceTree = "<group>"; };
96F633ED25AEBE5E005514EB /* DatabaseWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseWindowController.swift; sourceTree = "<group>"; };
96F633F525AEC3C6005514EB /* DatabaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseViewController.swift; sourceTree = "<group>"; };
96F633FE25AF0066005514EB /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Main.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -655,7 +655,6 @@
16A6DC5622AA375700813706 /* uPic */ = {
isa = PBXGroup;
children = (
16A0480325B18300000F1323 /* uPicDebug.entitlements */,
1648A214238E742600B99B9D /* Main.storyboard */,
16BDDE0222EAA2920080E467 /* Assets.xcassets */,
16A6DC5722AA375700813706 /* AppDelegate.swift */,
Expand All @@ -677,6 +676,7 @@
children = (
16A6DC6022AA375800813706 /* Info.plist */,
16A6DC6122AA375800813706 /* uPic.entitlements */,
16A0480325B18300000F1323 /* uPicDebug.entitlements */,
);
path = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -1225,7 +1225,7 @@
169F073C22AF53DE008E8525 /* Base */,
161ABBE323B212C800805C5B /* zh-Hans */,
1605DDD9246D993C00262C89 /* zh-Hant */,
96CA5B9325B4446E00855629 /* en */,
96CF336325B5F20800265690 /* en */,
);
name = Preferences.storyboard;
sourceTree = "<group>";
Expand Down Expand Up @@ -1398,7 +1398,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = uPic/uPicDebug.entitlements;
CODE_SIGN_ENTITLEMENTS = "uPic/Supporting Files/uPicDebug.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
Expand Down
9 changes: 9 additions & 0 deletions uPic/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
ConfigManager.shared.firstSetup()

if Defaults[.firstUsage] == BoolType._true.rawValue {
saveBookmark(url: promptForWorkingDirectoryPermission())
}

let url = loadBookmark(data: Defaults[.workingDirectoryBookmark])!
print(url)
_ = url.startAccessingSecurityScopedResource()
//url.stopAccessingSecurityScopedResource()
}

func applicationWillTerminate(_ notification: Notification) {
Expand Down
53 changes: 53 additions & 0 deletions uPic/General/Utils/AppPublic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,56 @@ func alertInfo(withText messageText: String, withMessage message: String, oKButt
okHandler()
}
}

func promptForWorkingDirectoryPermission() -> URL? {
let openPanel = NSOpenPanel()
openPanel.prompt = "Authorize".localized
openPanel.allowedFileTypes = ["none"]
openPanel.allowsOtherFileTypes = false
openPanel.canChooseFiles = false
openPanel.canCreateDirectories = false
openPanel.canChooseDirectories = true
openPanel.directoryURL = URL(fileURLWithPath: "file://")

openPanel.runModal()
print(openPanel.urls) // this contains the chosen folder
return openPanel.urls.first
}

func saveBookmark(url: URL?) {
guard let url = url else { return }
do {
let bookmarkData = try url.bookmarkData(
options: .withSecurityScope,
includingResourceValuesForKeys: nil,
relativeTo: nil
)

Defaults[.workingDirectoryBookmark] = bookmarkData
} catch {
print("Failed to save bookmark data for \(url)", error)
}
}

func loadBookmark(data: Data?) -> URL? {
guard let data = data else { return nil }
do {
var isStale = false
let url = try URL(
resolvingBookmarkData: data,
options: .withSecurityScope,
relativeTo: nil,
bookmarkDataIsStale: &isStale
)

if isStale {
// bookmarks could become stale as the OS changes
print("Bookmark is stale, need to save a new one... ")
saveBookmark(url: url)
}
return url
} catch {
print("Error resolving bookmark:", error)
return nil
}
}
12 changes: 12 additions & 0 deletions uPic/General/Utils/PreferenceKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct Keys {
static let historyRecordPadding = "uPic_HistoryRecordPadding"
static let historyRecordFileNameScrollSpeed = "uPic_HistoryRecordFileNameScrollSpeed"
static let historyRecordFileNameScrollWaitTime = "uPic_HistoryRecordFileNameScrollWaitTime"

static let workingDirectoryBookmark = "uPic_WorkingDirectoryBookmark"
}

class DefaultsKeys {
Expand Down Expand Up @@ -59,6 +61,7 @@ extension DefaultsKeys {
static let historyRecordPadding = DefaultsKey<Float>(Keys.historyRecordPadding)
static let historyRecordFileNameScrollSpeed = DefaultsKey<Double>(Keys.historyRecordFileNameScrollSpeed)
static let historyRecordFileNameScrollWaitTime = DefaultsKey<Float>(Keys.historyRecordFileNameScrollWaitTime)
static let workingDirectoryBookmark = DefaultsKey<Data>(Keys.workingDirectoryBookmark)

}

Expand Down Expand Up @@ -109,6 +112,15 @@ extension UserDefaults {
set(newValue, forKey: key._key)
}
}

subscript(key: DefaultsKey<Data>) -> Data? {
get {
return data(forKey: key._key)
}
set {
set(newValue, forKey: key._key)
}
}

subscript(key: DefaultsKey<[Host]>) -> [Host]? {
get {
Expand Down
2 changes: 2 additions & 0 deletions uPic/Supporting Files/uPic.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</array>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.files.bookmarks.app-scope</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</array>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.files.bookmarks.app-scope</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class AdvancedPreferencesViewController: PreferencesViewController {
@IBOutlet weak var historyRecordFileNameScrollSpeed: NSTextField!
@IBOutlet weak var historyRecordFileNameScrollWaitTime: NSTextField!
@IBOutlet weak var finderExtensionIcon: NSPopUpButton!
@IBOutlet weak var fullDiskAuthorizationImage: NSImageView!
@IBOutlet weak var fullDiskAuthorizationButton: NSButton!
@IBOutlet weak var resetPreferencesButton: NSButton!

// MARK: Lifecycle
Expand All @@ -29,6 +31,7 @@ class AdvancedPreferencesViewController: PreferencesViewController {
super.viewDidLoad()

resetAllValues()
checkFullDiskAuthorizationStatus()
}

func resetAllValues() {
Expand Down Expand Up @@ -57,6 +60,19 @@ class AdvancedPreferencesViewController: PreferencesViewController {
}
}

func checkFullDiskAuthorizationStatus() {
let url = loadBookmark(data: Defaults[.workingDirectoryBookmark])!.absoluteString
print(url)

if url == "file:///" {
fullDiskAuthorizationImage.image = NSImage(named: NSImage.statusAvailableName)
fullDiskAuthorizationButton.title = "Authorized".localized
} else {
fullDiskAuthorizationImage.image = NSImage(named: NSImage.statusPartiallyAvailableName)
fullDiskAuthorizationButton.title = "Not Authorized".localized
}
}

@IBAction func didClickHistoryRecordConfigurationResetButton(_ sender: NSButton) {

Defaults.removeObject(forKey: Keys.historyRecordWidth)
Expand Down Expand Up @@ -94,6 +110,11 @@ class AdvancedPreferencesViewController: PreferencesViewController {
presentAsSheet(outputFormatCustomizationViewController)
}

@IBAction func didClickfullDiskAuthorizationButton(_ sender: NSButton) {
saveBookmark(url: promptForWorkingDirectoryPermission())
checkFullDiskAuthorizationStatus()
}

@IBAction func resetPreferencesButtonClicked(_ sender: NSButton) {
let alert = NSAlert()

Expand Down
Loading