Skip to content

Commit

Permalink
update: swift
Browse files Browse the repository at this point in the history
  • Loading branch information
阿宝(陈徐挺) committed Dec 16, 2019
1 parent e9927a4 commit 2c3e85a
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 117 deletions.
23 changes: 14 additions & 9 deletions PicU.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
TargetAttributes = {
DD7B7E5B1D322CC700B68805 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = G47J9W9F35;
DevelopmentTeam = 44QSUE25K9;
LastSwiftMigration = 0810;
ProvisioningStyle = Automatic;
SystemCapabilities = {
Expand All @@ -181,6 +181,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -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",
Expand All @@ -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 */ = {
Expand Down Expand Up @@ -369,18 +370,20 @@
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;
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 = Debug;
};
Expand All @@ -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;
};
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,7 +25,7 @@ DEPENDENCIES:
- TMCache

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- AFNetworking
- HappyDNS
- MASPreferences
Expand All @@ -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
4 changes: 2 additions & 2 deletions UPImage/AppCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
50 changes: 24 additions & 26 deletions UPImage/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}


Expand All @@ -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")
Expand All @@ -76,18 +76,18 @@ 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) {
// Insert code here to tear down your application
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()
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -228,7 +226,7 @@ extension AppDelegate: NSUserNotificationCenterDelegate, PasteboardObserverSubsc
GetEventParameter(theEvent, EventParamName(kEventParamDirectObject), EventParamType(typeEventHotKeyID), nil, MemoryLayout<EventHotKeyID>.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):

Expand All @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions UPImage/AppHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions UPImage/DragDestinationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DragDestinationView: NSView {
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
// 注册接受文件拖入的类型
register(forDraggedTypes: [NSFilenamesPboardType])
registerForDraggedTypes([kUTTypeFileURL as NSPasteboard.PasteboardType])

}

Expand All @@ -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")
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions UPImage/GeneralViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions UPImage/GeneralViewController.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="GeneralViewController" customModule="U图床" customModuleProvider="target">
<customObject id="-2" userLabel="File's Owner" customClass="GeneralViewController" customModule="PicU" customModuleProvider="target">
<connections>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
Expand All @@ -16,15 +18,15 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Mnm-Uf-4z3">
<rect key="frame" x="105" y="245" width="43" height="17"/>
<rect key="frame" x="104" y="246" width="44" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="支持我" id="tZ4-yv-nPe">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Kwx-A5-mg1">
<rect key="frame" x="51" y="75" width="150" height="150"/>
<rect key="frame" x="51" y="76" width="150" height="150"/>
<constraints>
<constraint firstAttribute="width" constant="150" id="7ee-jF-916"/>
<constraint firstAttribute="height" constant="150" id="H24-63-rOe"/>
Expand Down
13 changes: 6 additions & 7 deletions UPImage/ImagePreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 2c3e85a

Please sign in to comment.