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
gee1k committed Jan 19, 2021
commit ba9dba0bf487c952a2ea81405609cfac3f2e4084
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 5805b359b360efbaba02725567dda3b519766521

COCOAPODS: 1.10.0
COCOAPODS: 1.9.3
28 changes: 16 additions & 12 deletions uPic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
161C3BE522C4870C0092114F /* CustomConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 161C3BE422C4870B0092114F /* CustomConfigView.swift */; };
1623612322AB951E00E4025C /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1623612522AB951E00E4025C /* Localizable.strings */; };
16248E32230673B6002131BB /* NotificationExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16248E31230673B6002131BB /* NotificationExt.swift */; };
1629470B25B672CF00CCB3C8 /* DiskPermissionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1629470A25B672CF00CCB3C8 /* DiskPermissionManager.swift */; };
163632EF22B2749000805E7F /* NSTextFieldCell+VerticallyCentered.swift in Sources */ = {isa = PBXBuildFile; fileRef = 163632EE22B2749000805E7F /* NSTextFieldCell+VerticallyCentered.swift */; };
163632F122B274B400805E7F /* Date+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 163632F022B274B400805E7F /* Date+Extension.swift */; };
163632F322B2751D00805E7F /* BoolType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 163632F222B2751D00805E7F /* BoolType.swift */; };
Expand Down Expand Up @@ -220,6 +221,7 @@
1623612622AB951F00E4025C /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
16248E31230673B6002131BB /* NotificationExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationExt.swift; sourceTree = "<group>"; };
1626E8C622AAB6B1006DCF0F /* Alamofire.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Alamofire.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1629470A25B672CF00CCB3C8 /* DiskPermissionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiskPermissionManager.swift; sourceTree = "<group>"; };
163632EE22B2749000805E7F /* NSTextFieldCell+VerticallyCentered.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSTextFieldCell+VerticallyCentered.swift"; sourceTree = "<group>"; };
163632F022B274B400805E7F /* Date+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extension.swift"; sourceTree = "<group>"; };
163632F222B2751D00805E7F /* BoolType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoolType.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -458,6 +460,7 @@
163F241F22B12EAE00F81D03 /* Managers */ = {
isa = PBXGroup;
children = (
1629470A25B672CF00CCB3C8 /* DiskPermissionManager.swift */,
16EA205B22AF8FB90006FB9C /* ConfigManager.swift */,
161ABBDC23B1F1EB00805C5B /* DBManager.swift */,
);
Expand Down Expand Up @@ -1150,6 +1153,7 @@
1660FCBC22C11C7500372950 /* TencentUtil.swift in Sources */,
1660FCBA22C11C2300372950 /* TencentHostConfig.swift in Sources */,
16248E32230673B6002131BB /* NotificationExt.swift in Sources */,
1629470B25B672CF00CCB3C8 /* DiskPermissionManager.swift in Sources */,
16F04EE423BCC45F00CCA2FE /* Console.swift in Sources */,
167DDBEF22C7722200B03357 /* GithubUtil.swift in Sources */,
16F04EEE23BCC4C500CCA2FE /* URLSchemeExt.swift in Sources */,
Expand Down Expand Up @@ -1402,7 +1406,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/uPic/Supporting Files/Info.plist";
Expand All @@ -1411,7 +1415,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.macos;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1432,7 +1436,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/uPic/Supporting Files/Info.plist";
Expand All @@ -1441,7 +1445,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.macos;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1458,7 +1462,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = uPicFinderExtension/Info.plist;
Expand All @@ -1468,7 +1472,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.macos.uPicFinderExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1485,7 +1489,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = uPicFinderExtension/Info.plist;
Expand All @@ -1495,7 +1499,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.macos.uPicFinderExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1511,7 +1515,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = uPicShareExtension/Info.plist;
Expand All @@ -1521,7 +1525,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.macos.uPicShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1537,7 +1541,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = uPicShareExtension/Info.plist;
Expand All @@ -1547,7 +1551,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.macos.uPicShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down
23 changes: 12 additions & 11 deletions uPic/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {


func applicationWillFinishLaunching(_ notification: Notification) {
let isCommandLineState = Cli.shared.handleCommandLine()
if isCommandLineState {

if let paths = Cli.shared.getFilePaths() {
DiskPermissionManager.shared.initializeRequestDiskPermissions()
Cli.shared.startUpload(paths)
return
}

Expand All @@ -75,17 +77,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Insert code here to initialize your application
ConfigManager.shared.firstSetup()

if Defaults[.firstUsage] == BoolType._true.rawValue {
saveBookmark(url: promptForWorkingDirectoryPermission())
DispatchQueue.main.async {
// 状态栏不为空,代表是正常启动程序。即需要请求权限
if self.statusItem != nil {
DiskPermissionManager.shared.initializeRequestDiskPermissions()
}
}

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

func applicationWillTerminate(_ notification: Notification) {

DiskPermissionManager.shared.stopFullDiskAccessing()

if let statusItem = statusItem {
NSStatusBar.system.removeStatusItem(statusItem)
}
Expand All @@ -106,7 +109,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@objc func handleGetURLEvent(event: NSAppleEventDescriptor!, withReplyEvent: NSAppleEventDescriptor!) {
if let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue{
debugPrint(urlString)
URLSchemeExt.shared.handleURL(urlString)
}
}
Expand Down Expand Up @@ -348,7 +350,6 @@ extension AppDelegate {
var uploadUrls: [URL] = []
for url in urls {
let path = url.path
debugPrint(path)

if !FileManager.default.isReadableFile(atPath: path) {
NotificationExt.shared.postFileNoAccessNotice()
Expand Down
18 changes: 8 additions & 10 deletions uPic/Cli/Cli.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Cli {

private var resultUrls: [String] = []

func handleCommandLine() -> Bool {
func getFilePaths() -> [String]? {
let arguments = CommandLine.arguments
guard arguments.count > 1 else { return false }
guard arguments.count > 1 else { return nil }

cliKit = CommandLineKit(arguments: arguments)

Expand All @@ -48,25 +48,22 @@ class Cli {
try cliKit.parse()
} catch {
cliKit.printUsage(error)
return false
return nil
}

if let paths = upload.value {
startUpload(paths)
return true
} else {
guard let paths = upload.value else {
cliKit.printUsage()
return nil
}

return false
return paths
}
}

// MARK: - Upload
extension Cli {
/// start upload
/// - Parameter paths: file paths or URLs
private func startUpload(_ paths: [String]) {
func startUpload(_ paths: [String]) {
allPathList = paths

for path in paths {
Expand Down Expand Up @@ -118,6 +115,7 @@ extension Cli {
Console.write(resultUrls.joined(separator: "\n"))
DBManager.shared.close()
DispatchQueue.main.async {
DiskPermissionManager.shared.stopFullDiskAccessing()
exit(EX_OK)
}
}
Expand Down
115 changes: 115 additions & 0 deletions uPic/General/Managers/DiskPermissionManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// DiskPermissionManager.swift
// uPic
//
// Created by Svend Jin on 2021/01/19.
// Copyright © 2021 Svend Jin. All rights reserved.
//

import Foundation
import Cocoa

public class DiskPermissionManager {

// static
public static var shared = DiskPermissionManager()


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

openPanel.runModal()
return openPanel.urls.first
}

private func saveBookmarkData(for workDir: URL) {
do {
let bookmarkData = try workDir.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)

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

private func restoreFileAccess(with bookmarkData: Data) -> URL? {
do {
var isStale = false
let url = try URL(resolvingBookmarkData: bookmarkData, 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... ")
saveBookmarkData(for: url)
}
return url
} catch {
print("Error resolving bookmark:", error)
return nil
}
}

}

// Utils
extension DiskPermissionManager {

func initializeRequestDiskPermissions() {
if !Defaults[.requestedAuthorization] {
Defaults[.requestedAuthorization] = true
alertInfo(withText: "Full Disk Access".localized, withMessage: "Full Disk Access Message".localized, oKButtonTitle: "Authorize".localized, cancelButtonTitle: "Later".localized){ [self] in
requestFullDiskPermissions()
}
} else {
guard let data = Defaults[.workingDirectoryBookmark], let url = restoreFileAccess(with: data) else {
return
}
_ = url.startAccessingSecurityScopedResource()
}

}

func checkFullDiskAuthorizationStatus() -> Bool {
guard let data = Defaults[.workingDirectoryBookmark] else {
return false
}
do {
var isStale = true
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... ")
return false
}
return url.path == "/"
} catch {
print("Error resolving bookmark:", error)
return false
}


}

func requestFullDiskPermissions() {
guard let url = self.promptForWorkingDirectoryPermission() else {
return
}
self.saveBookmarkData(for: url)
_ = url.startAccessingSecurityScopedResource()
}

func stopFullDiskAccessing() {
guard let data = Defaults[.workingDirectoryBookmark], let url = restoreFileAccess(with: data) else {
return
}
url.stopAccessingSecurityScopedResource()
}
}
9 changes: 9 additions & 0 deletions uPic/General/Managers/emplate/DiskPermissionManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// DiskPermissionManager.swift
// uPic
//
// Created by Svend Jin on 2021/1/19.
// Copyright © 2021 Svend Jin. All rights reserved.
//

import Foundation
Loading