From 2c3e85aa48ef47c9be5575e2b6cfeb82da687605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E5=AE=9D=EF=BC=88=E9=99=88=E5=BE=90=E6=8C=BA?= =?UTF-8?q?=EF=BC=89?= Date: Tue, 17 Dec 2019 01:10:33 +0800 Subject: [PATCH] update: swift --- PicU.xcodeproj/project.pbxproj | 23 +++--- Podfile.lock | 8 +- UPImage/AppCache.swift | 4 +- UPImage/AppDelegate.swift | 50 ++++++------- UPImage/AppHelper.swift | 8 +- UPImage/DragDestinationView.swift | 8 +- UPImage/GeneralViewController.swift | 5 +- UPImage/GeneralViewController.xib | 14 ++-- UPImage/ImagePreferencesViewController.swift | 13 ++-- UPImage/ImagePreferencesViewController.xib | 78 ++++++++++---------- UPImage/ImageService.swift | 13 ++-- UPImage/Info.plist | 4 +- UPImage/PasteboardObserver.swift | 2 +- UPImage/QNService.swift | 6 +- UPImage/SMMSService.swift | 6 +- 15 files changed, 125 insertions(+), 117 deletions(-) diff --git a/PicU.xcodeproj/project.pbxproj b/PicU.xcodeproj/project.pbxproj index 84808a5..2eeabf5 100644 --- a/PicU.xcodeproj/project.pbxproj +++ b/PicU.xcodeproj/project.pbxproj @@ -159,7 +159,7 @@ TargetAttributes = { DD7B7E5B1D322CC700B68805 = { CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = G47J9W9F35; + DevelopmentTeam = 44QSUE25K9; LastSwiftMigration = 0810; ProvisioningStyle = Automatic; SystemCapabilities = { @@ -181,6 +181,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -215,7 +216,7 @@ files = ( ); inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-PicU/Pods-PicU-frameworks.sh", + "${PODS_ROOT}/Target Support Files/Pods-PicU/Pods-PicU-frameworks.sh", "${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework", "${BUILT_PRODUCTS_DIR}/HappyDNS/HappyDNS.framework", "${BUILT_PRODUCTS_DIR}/MASPreferences/MASPreferences.framework", @@ -232,7 +233,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PicU/Pods-PicU-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-PicU/Pods-PicU-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; 6A8B62D9AF77E000A69C2630 /* [CP] Check Pods Manifest.lock */ = { @@ -369,10 +370,12 @@ CODE_SIGN_IDENTITY = "Mac Developer"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = G47J9W9F35; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 44QSUE25K9; INFOPLIST_FILE = UPImage/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; + MARKETING_VERSION = 1.6; OTHER_CODE_SIGN_FLAGS = "--deep"; OTHER_SWIFT_FLAGS = "$(inherited) -D DEBUG"; PRODUCT_BUNDLE_IDENTIFIER = com.chenxtdo.upi; @@ -380,7 +383,7 @@ PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "UPImage/OC-birdge.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -393,17 +396,19 @@ CODE_SIGN_IDENTITY = "Mac Developer"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = G47J9W9F35; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 44QSUE25K9; INFOPLIST_FILE = UPImage/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; + MARKETING_VERSION = 1.6; OTHER_CODE_SIGN_FLAGS = "--deep"; PRODUCT_BUNDLE_IDENTIFIER = com.chenxtdo.upi; PRODUCT_NAME = PicU; PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "UPImage/OC-birdge.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Podfile.lock b/Podfile.lock index a337480..d8977fd 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -13,7 +13,7 @@ PODS: - AFNetworking/Security (3.2.1) - AFNetworking/Serialization (3.2.1) - HappyDNS (0.3.14) - - MASPreferences (1.1.4) + - MASPreferences (1.3) - Qiniu (7.2.4): - HappyDNS (~> 0.3) - TMCache (2.1.0) @@ -25,7 +25,7 @@ DEPENDENCIES: - TMCache SPEC REPOS: - https://github.com/cocoapods/specs.git: + https://github.com/CocoaPods/Specs.git: - AFNetworking - HappyDNS - MASPreferences @@ -35,10 +35,10 @@ SPEC REPOS: SPEC CHECKSUMS: AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057 HappyDNS: dc6a164ee81979093123c241c6353bcf0218add6 - MASPreferences: 7bdcfe891d7840453cf48f95fa866c3e152ace7a + MASPreferences: c08b8622dd17b47da87669e741efd7c92e970e8c Qiniu: 65384bca1cdb0480a68d9b9b8f54db53418c0355 TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed PODFILE CHECKSUM: 118dcfb5abd42130dde389f59bb2b387ee43dbb4 -COCOAPODS: 1.5.2 +COCOAPODS: 1.8.4 diff --git a/UPImage/AppCache.swift b/UPImage/AppCache.swift index f6b77eb..1c6c431 100644 --- a/UPImage/AppCache.swift +++ b/UPImage/AppCache.swift @@ -46,11 +46,11 @@ class AppCache: NSObject{ func adduploadImageToCache(_ dic: [String: AnyObject]) { if imagesCacheArr.count < 5 { imagesCacheArr.append(dic) - TMCache.shared().setObject(imagesCacheArr as NSCoding!, forKey: "imageCache") + TMCache.shared().setObject(imagesCacheArr as NSCoding?, forKey: "imageCache") } else { imagesCacheArr.remove(at: 0) imagesCacheArr.append(dic) - TMCache.shared().setObject(imagesCacheArr as NSCoding!, forKey: "imageCache") + TMCache.shared().setObject(imagesCacheArr as NSCoding?, forKey: "imageCache") } } diff --git a/UPImage/AppDelegate.swift b/UPImage/AppDelegate.swift index 2175658..be989f2 100644 --- a/UPImage/AppDelegate.swift +++ b/UPImage/AppDelegate.swift @@ -37,8 +37,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { let generalViewController = GeneralViewController() let controllers = [imageViewController] let wc = MASPreferencesWindowController(viewControllers: controllers, title: "设置") - imageViewController.window = wc?.window - return wc! + imageViewController.window = wc.window + return wc }() func applicationDidFinishLaunching(_ aNotification: Notification) { @@ -49,9 +49,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { func initApp() { switch AppCache.shared.appConfig.linkType { case .markdown: - MarkdownItem.state = 1 + MarkdownItem.state = NSControl.StateValue(rawValue: 1) case .url: - MarkdownItem.state = 0 + MarkdownItem.state = NSControl.StateValue(rawValue: 0) } @@ -60,13 +60,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { if AppCache.shared.appConfig.autoUp { pasteboardObserver.startObserving() - autoUpItem.state = 1 + autoUpItem.state = NSControl.StateValue(rawValue: 1) } NotificationCenter.default.addObserver(self, selector: #selector(notification), name: NSNotification.Name(rawValue: "MarkdownState"), object: nil) window.center() appDelegate = self - statusItem = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength) + statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength) let statusBarButton = DragDestinationView(frame: (statusItem.button?.bounds)!) statusItem.button?.superview?.addSubview(statusBarButton, positioned: .below, relativeTo: statusItem.button) let iconImage = NSImage(named: "StatusIcon") @@ -76,8 +76,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { statusItem.button?.target = self } - func notification(_ notification: Notification) { - MarkdownItem.state = Int((notification.object as AnyObject) as! NSNumber) + @objc func notification(_ notification: Notification) { + MarkdownItem.state = NSControl.StateValue(rawValue: Int(truncating: (notification.object as AnyObject) as! NSNumber)) } func applicationWillTerminate(_ aNotification: Notification) { @@ -85,9 +85,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { AppCache.shared.appConfig.setInCache("appConfig") } - func showMenu() { - let pboard = NSPasteboard.general() - let files: NSArray? = pboard.propertyList(forType: NSFilenamesPboardType) as? NSArray + @objc func showMenu() { + let pboard = NSPasteboard.general + let files: NSArray? = pboard.propertyList(forType: NSPasteboard.PasteboardType(rawValue: "NSFilenamesPboardType")) as? NSArray if let files = files { let i = NSImage(contentsOfFile: files.firstObject as! String) i?.scalingImage() @@ -109,7 +109,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { switch sender.tag { // 上传 case 1: - let pboard = NSPasteboard.general() + let pboard = NSPasteboard.general ImageService.shared.uploadImg(pboard) // 设置 case 2: @@ -120,25 +120,23 @@ class AppDelegate: NSObject, NSApplicationDelegate { // 退出 NSApp.terminate(nil) //帮助 - case 4: - NSWorkspace.shared().open(URL(string: "http://lzqup.com")!) case 5: break //自动上传 case 6: - sender.state = 1 - sender.state; - AppCache.shared.appConfig.autoUp = sender.state == 1 ? true : false + sender.state = NSControl.StateValue(rawValue: 1 - sender.state.rawValue); + AppCache.shared.appConfig.autoUp = sender.state.rawValue == 1 ? true : false AppCache.shared.appConfig.autoUp ? pasteboardObserver.startObserving() : pasteboardObserver.stopObserving() AppCache.shared.appConfig.setInCache("appConfig") //切换markdown case 7: - sender.state = 1 - sender.state - AppCache.shared.appConfig.linkType = LinkType(rawValue: sender.state)! + sender.state = NSControl.StateValue(rawValue: 1 - sender.state.rawValue) + AppCache.shared.appConfig.linkType = LinkType(rawValue: sender.state.rawValue)! guard let imagesCache = AppCache.shared.imagesCacheArr.last else { return } let picUrl = imagesCache["url"] as! String - NSPasteboard.general().setString(LinkType.getLink(path: picUrl, type: AppCache.shared.appConfig.linkType), forType: NSStringPboardType) + NSPasteboard.general.setString(LinkType.getLink(path: picUrl, type: AppCache.shared.appConfig.linkType), forType: NSPasteboard.PasteboardType.string) AppCache.shared.appConfig.setInCache("appConfig") default: break @@ -149,7 +147,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBAction func btnClick(_ sender: NSButton) { switch sender.tag { case 1: - NSWorkspace.shared().open(URL(string: "http://blog.lzqup.com/tools/2016/07/10/Tools-UPImage.html")!) + NSWorkspace.shared.open(URL(string: "http://blog.lzqup.com/tools/2016/07/10/Tools-UPImage.html")!) self.window.close() case 2: self.window.close() @@ -178,10 +176,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { return menu } - func cacheImageClick(_ sender: NSMenuItem) { - NSPasteboard.general().clearContents() + @objc func cacheImageClick(_ sender: NSMenuItem) { + NSPasteboard.general.clearContents() let picUrl = AppCache.shared.imagesCacheArr[sender.tag]["url"] as! String - NSPasteboard.general().setString(LinkType.getLink(path: picUrl, type: AppCache.shared.appConfig.linkType), forType: NSStringPboardType) + NSPasteboard.general.setString(LinkType.getLink(path: picUrl, type: AppCache.shared.appConfig.linkType), forType: NSPasteboard.PasteboardType.string) NotificationMessage("图片链接获取成功", isSuccess: true) } @@ -228,7 +226,7 @@ extension AppDelegate: NSUserNotificationCenterDelegate, PasteboardObserverSubsc GetEventParameter(theEvent, EventParamName(kEventParamDirectObject), EventParamType(typeEventHotKeyID), nil, MemoryLayout.size, nil, &hkCom) switch hkCom.id { case UInt32(kVK_ANSI_U): - let pboard = NSPasteboard.general() + let pboard = NSPasteboard.general ImageService.shared.uploadImg(pboard) case UInt32(kVK_ANSI_M): @@ -238,9 +236,9 @@ extension AppDelegate: NSUserNotificationCenterDelegate, PasteboardObserverSubsc guard let imagesCache = AppCache.shared.imagesCacheArr.last else { return 33 } - NSPasteboard.general().clearContents() + NSPasteboard.general.clearContents() let picUrl = imagesCache["url"] as! String - NSPasteboard.general().setString(LinkType.getLink(path: picUrl, type: AppCache.shared.appConfig.linkType), forType: NSStringPboardType) + NSPasteboard.general.setString(LinkType.getLink(path: picUrl, type: AppCache.shared.appConfig.linkType), forType: NSPasteboard.PasteboardType.string) default: diff --git a/UPImage/AppHelper.swift b/UPImage/AppHelper.swift index 25306de..5a3559d 100644 --- a/UPImage/AppHelper.swift +++ b/UPImage/AppHelper.swift @@ -86,9 +86,11 @@ func getDateString() -> String { } func checkImageFile(_ pboard: NSPasteboard) -> Bool { - - let files: NSArray = pboard.propertyList(forType: NSFilenamesPboardType) as! NSArray - let image = NSImage(contentsOfFile: files.firstObject as! String) + guard let pasteboard = pboard.propertyList(forType: NSPasteboard.PasteboardType(rawValue: "NSFilenamesPboardType")) as? NSArray, + let path = pasteboard[0] as? String + else { return false } + + let image = NSImage(contentsOfFile: path) guard let _ = image else { return false } diff --git a/UPImage/DragDestinationView.swift b/UPImage/DragDestinationView.swift index 4aed37e..f5b14a0 100644 --- a/UPImage/DragDestinationView.swift +++ b/UPImage/DragDestinationView.swift @@ -19,7 +19,7 @@ class DragDestinationView: NSView { override init(frame frameRect: NSRect) { super.init(frame: frameRect) // 注册接受文件拖入的类型 - register(forDraggedTypes: [NSFilenamesPboardType]) + registerForDraggedTypes([kUTTypeFileURL as NSPasteboard.PasteboardType]) } @@ -28,7 +28,7 @@ class DragDestinationView: NSView { } override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation { - let pboard = sender.draggingPasteboard() + let pboard = sender.draggingPasteboard if checkImageFile(pboard) { statusItem.button?.image = NSImage(named: "upload") @@ -46,12 +46,12 @@ class DragDestinationView: NSView { } override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool { - let pboard = sender.draggingPasteboard() + let pboard = sender.draggingPasteboard return checkImageFile(pboard) } override func performDragOperation(_ sender: NSDraggingInfo) -> Bool { - let pboard = sender.draggingPasteboard() + let pboard = sender.draggingPasteboard ImageService.shared.uploadImg(pboard) return true } diff --git a/UPImage/GeneralViewController.swift b/UPImage/GeneralViewController.swift index 1c3441b..bd2e0c5 100644 --- a/UPImage/GeneralViewController.swift +++ b/UPImage/GeneralViewController.swift @@ -11,10 +11,9 @@ import MASPreferences class GeneralViewController: NSViewController, MASPreferencesViewController { - - override var identifier: String? { get { return "general" } set { super.identifier = newValue } } + var viewIdentifier: String = "general" var toolbarItemLabel: String? { get { return "基本" } } - var toolbarItemImage: NSImage? { get { return NSImage(named: NSImageNamePreferencesGeneral) } } + var toolbarItemImage: NSImage? { get { return NSImage(named: NSImage.preferencesGeneralName) } } override func viewDidLoad() { super.viewDidLoad() diff --git a/UPImage/GeneralViewController.xib b/UPImage/GeneralViewController.xib index 7a758f6..670c74d 100644 --- a/UPImage/GeneralViewController.xib +++ b/UPImage/GeneralViewController.xib @@ -1,10 +1,12 @@ - - + + - + + + - + @@ -16,7 +18,7 @@ - + @@ -24,7 +26,7 @@ - + diff --git a/UPImage/ImagePreferencesViewController.swift b/UPImage/ImagePreferencesViewController.swift index eb06e80..5150eea 100644 --- a/UPImage/ImagePreferencesViewController.swift +++ b/UPImage/ImagePreferencesViewController.swift @@ -10,10 +10,9 @@ import Cocoa import MASPreferences class ImagePreferencesViewController: NSViewController, MASPreferencesViewController { - - override var identifier: String? { get { return "image" } set { super.identifier = newValue } } + var viewIdentifier: String = "image" var toolbarItemLabel: String? { get { return "图床" } } - var toolbarItemImage: NSImage? { get { return NSImage(named: NSImageNameUser) } } + var toolbarItemImage: NSImage? { get { return NSImage(named: NSImage.userName) } } var window: NSWindow? @IBOutlet weak var statusLabel: NSTextField! @IBOutlet weak var accessKeyTextField: NSTextField! @@ -63,10 +62,10 @@ class ImagePreferencesViewController: NSViewController, MASPreferencesViewContro @IBAction func setQiniuConfig(_ sender: AnyObject) { - if (accessKeyTextField.cell?.title.characters.count == 0 || - secretKeyTextField.cell?.title.characters.count == 0 || - bucketTextField.cell?.title.characters.count == 0 || - urlPrefixTextField.cell?.title.characters.count == 0) { + if (accessKeyTextField.cell?.title.count == 0 || + secretKeyTextField.cell?.title.count == 0 || + bucketTextField.cell?.title.count == 0 || + urlPrefixTextField.cell?.title.count == 0) { showAlert("有配置信息未填写", informative: "请仔细填写") return } diff --git a/UPImage/ImagePreferencesViewController.xib b/UPImage/ImagePreferencesViewController.xib index b21da04..feb9fb9 100644 --- a/UPImage/ImagePreferencesViewController.xib +++ b/UPImage/ImagePreferencesViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -25,88 +25,88 @@ - - + + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - + -