Skip to content

Commit

Permalink
feat: support Apple Silicon; update Alamofire; remove SwiftyJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang2 committed Dec 2, 2021
1 parent b841859 commit b1c9190
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

.DS_Store
20 changes: 10 additions & 10 deletions source/Podfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
platform :osx, '10.11'
platform :osx, '11.0'
use_frameworks!
inhibit_all_warnings!

target 'TinyPNG4Mac' do

pod 'Alamofire', '~> 4.8.2'
pod 'SwiftyJSON', '~> 5.0'
pod 'Alamofire', '~> 5.4.4'
#pod 'SwiftyJSON', '~> 5.0.1'

end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
#post_install do |installer|
# installer.pods_project.targets.each do |target|
# target.build_configurations.each do |config|
# config.build_settings['SWIFT_VERSION'] = '3.0'
# end
# end
#end
16 changes: 6 additions & 10 deletions source/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
PODS:
- Alamofire (4.8.2)
- SwiftyJSON (5.0.0)
- Alamofire (5.4.4)

DEPENDENCIES:
- Alamofire (~> 4.8.2)
- SwiftyJSON (~> 5.0)
- Alamofire (~> 5.4.4)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
trunk:
- Alamofire
- SwiftyJSON

SPEC CHECKSUMS:
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3
SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7
Alamofire: f3b09a368f1582ab751b3fff5460276e0d2cf5c9

PODFILE CHECKSUM: 1e14da6108c97041b7daef307aaa48a8f180f7a4
PODFILE CHECKSUM: ba7342ba781a97a73f99d2a9479ff133fb92db2a

COCOAPODS: 1.7.5
COCOAPODS: 1.11.2
12 changes: 6 additions & 6 deletions source/tinypng4mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,10 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-TinyPNG4Mac/Pods-TinyPNG4Mac-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -391,11 +389,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -441,10 +440,11 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -458,7 +458,7 @@
CURRENT_PROJECT_VERSION = 12;
INFOPLIST_FILE = tinypng4mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.0.4;
MARKETING_VERSION = 1.0.5;
PRODUCT_BUNDLE_IDENTIFIER = com.kyleduo.tinypngmac;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -475,7 +475,7 @@
CURRENT_PROJECT_VERSION = 12;
INFOPLIST_FILE = tinypng4mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.0.4;
MARKETING_VERSION = 1.0.5;
PRODUCT_BUNDLE_IDENTIFIER = com.kyleduo.tinypngmac;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
10 changes: 5 additions & 5 deletions source/tinypng4mac/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ class MainViewController: NSViewController, NSOpenSavePanelDelegate, NSTableView
openPanel.delegate = self;

openPanel.begin { (result) -> Void in
if(result.rawValue == NSFileHandlingPanelOKButton){
let path = openPanel.url!.path
debugPrint("selected folder is \(path)");
self.saveOutputPath(path)
}
if result == NSApplication.ModalResponse.OK {
let path = openPanel.url!.path
debugPrint("selected folder is \(path)");
self.saveOutputPath(path)
}
}
}

Expand Down
75 changes: 38 additions & 37 deletions source/tinypng4mac/tpclient/TPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import Alamofire
import SwiftyJSON

protocol TPClientCallback {
func taskStatusChanged(task: TPTaskInfo)
Expand Down Expand Up @@ -75,7 +74,7 @@ class TPClient {
"Authorization": authorizationHeader,
"Accept": "application/json"
]
Alamofire.upload(imageData, to: BASE_URL, method: .post, headers: headers)
AF.upload(imageData, to: BASE_URL, method: .post, headers: headers)
.uploadProgress(closure: { (progress) in
if progress.fractionCompleted == 1 {
self.updateStatus(task, newStatus: .processing)
Expand All @@ -84,31 +83,31 @@ class TPClient {
self.updateStatus(task, newStatus: .uploading, progress: progress)
}
})
.responseJSON(completionHandler: { (response) in
if let jsonstr = response.result.value {
let json = JSON(jsonstr)
if json != JSON.null {
if let error = json["error"].string {
debugPrint("error: " + task.fileInfo.relativePath + error)
self.markError(task, errorMessage: json["message"].string)
return
}
let output = json["output"]
if output != JSON.null {
let resultUrl = output["url"]
task.resultUrl = String(describing: resultUrl)
task.resultSize = output["size"].doubleValue
task.compressRate = task.resultSize / task.originSize
self.onUploadFinish(task)
} else {
self.markError(task, errorMessage: "response data error")
}
} else {
self.markError(task, errorMessage: "response format error")
}
} else {
self.markError(task, errorMessage: response.result.description)
}
.responseJSON(completionHandler: { response in
switch response.result {
case .success(let value):
let json = value as! [String: AnyObject]
if let error = json["error"] as? String {
debugPrint("error: " + task.fileInfo.relativePath + error)
self.markError(task, errorMessage: json["message"] as? String)
return
}
if let output = json["output"] as? [String: AnyObject] {
let resultUrl = output["url"] as? String ?? ""
task.resultUrl = resultUrl
task.resultSize = output["size"] as? Double ?? 0
task.compressRate = task.resultSize / task.originSize
self.onUploadFinish(task)
} else {
self.markError(task, errorMessage: "response data error")
}
break
case .failure(let error):
self.markError(task, errorMessage: error.errorDescription)
break
}
})
} catch {
self.markError(task, errorMessage: "execute error")
Expand All @@ -128,27 +127,29 @@ class TPClient {
}

fileprivate func downloadCompressImage(_ task: TPTaskInfo) {
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let destination: DownloadRequest.Destination = { _, _ in
return (task.outputFile!, [.createIntermediateDirectories, .removePreviousFile])
}

Alamofire.download(task.resultUrl, to: destination)
.downloadProgress(closure: { (progress) in
AF.download(task.resultUrl, to: destination)
.downloadProgress(closure: { progress in
self.updateStatus(task, newStatus: .downloading, progress: progress)
})
.response { response in
let error = response.error
if (error != nil) {
self.markError(task, errorMessage: "download error")
} else {
self.updateStatus(task, newStatus: .finish)
debugPrint("finish: " + task.fileInfo.relativePath + " tasks: " + String(self.runningTasks))
switch response.result {
case .success(_):
self.updateStatus(task, newStatus: .finish)
debugPrint("finish: " + task.fileInfo.relativePath + " tasks: " + String(self.runningTasks))
do {
try FileManager.default.setAttributes([FileAttributeKey.posixPermissions: task.filePermission], ofItemAtPath: task.fileInfo.filePath.path)
} catch {
debugPrint("FileManager set posixPermissions error")
}
}
break
case .failure(let error):
self.markError(task, errorMessage: error.errorDescription)
break
}

self.checkExecution()
}
Expand Down

0 comments on commit b1c9190

Please sign in to comment.