|
@@ -25,12 +25,16 @@ class KMAITranslationVC: NSViewController {
|
|
@IBOutlet weak var selectYourFilesImageView: NSImageView!
|
|
@IBOutlet weak var selectYourFilesImageView: NSImageView!
|
|
@IBOutlet weak var orDropFileHereLabel: NSTextField!
|
|
@IBOutlet weak var orDropFileHereLabel: NSTextField!
|
|
|
|
|
|
|
|
+ @IBOutlet weak var errorView: NSView!
|
|
|
|
+ @IBOutlet weak var errorLabel: NSTextField!
|
|
|
|
+
|
|
var fromStr: String = "auto"
|
|
var fromStr: String = "auto"
|
|
var toStr: String = "en"
|
|
var toStr: String = "en"
|
|
var fromLanguages: [String] = ["Automatic", "English", "Simplified Chinese", "Traditional Chinese", "Japanese", "Korean", "French", "Spanish", "Italian", "German", "Portuguese", "Russian", "Vietnamese", "Thai", "Arabic", "Greek", "Bulgarian", "Finnish", "Slovene", "Dutch", "Czech", "Swedish", "Polish", "Danish", "Romanian", "Hungarian"]
|
|
var fromLanguages: [String] = ["Automatic", "English", "Simplified Chinese", "Traditional Chinese", "Japanese", "Korean", "French", "Spanish", "Italian", "German", "Portuguese", "Russian", "Vietnamese", "Thai", "Arabic", "Greek", "Bulgarian", "Finnish", "Slovene", "Dutch", "Czech", "Swedish", "Polish", "Danish", "Romanian", "Hungarian"]
|
|
var toLanguages: [String] = ["English", "Simplified Chinese", "Traditional Chinese", "Japanese", "Korean", "French", "Spanish", "Italian", "German", "Portuguese", "Russian", "Vietnamese", "Thai", "Arabic", "Greek", "Bulgarian", "Finnish", "Slovene", "Dutch", "Czech", "Swedish", "Polish", "Danish", "Romanian", "Hungarian"]
|
|
var toLanguages: [String] = ["English", "Simplified Chinese", "Traditional Chinese", "Japanese", "Korean", "French", "Spanish", "Italian", "German", "Portuguese", "Russian", "Vietnamese", "Thai", "Arabic", "Greek", "Bulgarian", "Finnish", "Slovene", "Dutch", "Czech", "Swedish", "Polish", "Danish", "Romanian", "Hungarian"]
|
|
|
|
|
|
var popover: NSPopover?
|
|
var popover: NSPopover?
|
|
|
|
+ var progressController: SKProgressController?
|
|
|
|
|
|
override func viewDidLoad() {
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
super.viewDidLoad()
|
|
@@ -40,6 +44,12 @@ class KMAITranslationVC: NSViewController {
|
|
self.initializeUI()
|
|
self.initializeUI()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ override func viewDidAppear() {
|
|
|
|
+ super.viewDidAppear()
|
|
|
|
+
|
|
|
|
+ self.errorView.isHidden = true
|
|
|
|
+ }
|
|
|
|
+
|
|
// MARK: initialize
|
|
// MARK: initialize
|
|
|
|
|
|
func initializeUI() -> Void {
|
|
func initializeUI() -> Void {
|
|
@@ -94,6 +104,8 @@ class KMAITranslationVC: NSViewController {
|
|
}
|
|
}
|
|
self.selectYourFilesBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
|
|
self.selectYourFilesBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
|
|
if downEntered {
|
|
if downEntered {
|
|
|
|
+ self.errorView.isHidden = true
|
|
|
|
+
|
|
let openPanel = NSOpenPanel()
|
|
let openPanel = NSOpenPanel()
|
|
openPanel.allowedFileTypes = ["pdf", "PDF", "docx", "doc"]
|
|
openPanel.allowedFileTypes = ["pdf", "PDF", "docx", "doc"]
|
|
openPanel.allowsMultipleSelection = false
|
|
openPanel.allowsMultipleSelection = false
|
|
@@ -106,10 +118,16 @@ class KMAITranslationVC: NSViewController {
|
|
alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
|
|
alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
|
|
alert.runModal()
|
|
alert.runModal()
|
|
} else {
|
|
} else {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.showProgressWindow()
|
|
|
|
+// self.progressController?.message = NSLocalizedString("Uploading...", comment: "")
|
|
|
|
+ }
|
|
|
|
+
|
|
let infoDictionary = Bundle .main.infoDictionary!
|
|
let infoDictionary = Bundle .main.infoDictionary!
|
|
let majorVersion = infoDictionary["CFBundleShortVersionString"]
|
|
let majorVersion = infoDictionary["CFBundleShortVersionString"]
|
|
|
|
|
|
KMRequestServerManager.manager.aiTranslationFileUpload(file: url.path, version: "1.0.1") { [unowned self] success, result in
|
|
KMRequestServerManager.manager.aiTranslationFileUpload(file: url.path, version: "1.0.1") { [unowned self] success, result in
|
|
|
|
+// self.hiddenProgressWindow()
|
|
if success {
|
|
if success {
|
|
let result: NSDictionary = result!.result
|
|
let result: NSDictionary = result!.result
|
|
|
|
|
|
@@ -120,7 +138,13 @@ class KMAITranslationVC: NSViewController {
|
|
self.fileTranslateHandle(fileKey as! String)
|
|
self.fileTranslateHandle(fileKey as! String)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
|
|
+ let result: String = result!.message
|
|
|
|
+
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.hiddenProgressWindow()
|
|
|
|
+ self.errorView.isHidden = false
|
|
|
|
+ self.errorLabel.stringValue = result
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -130,6 +154,13 @@ class KMAITranslationVC: NSViewController {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ self.errorView.isHidden = true
|
|
|
|
+ self.errorView.wantsLayer = true
|
|
|
|
+ self.errorView.layer?.backgroundColor = NSColor(hex: "##36383B").cgColor
|
|
|
|
+ self.errorView.layer?.cornerRadius = 4.0
|
|
|
|
+ self.errorLabel.textColor = NSColor(hex: "#FFFFFF")
|
|
|
|
+ self.errorLabel.font = NSFont.SFProTextRegular(14.0)
|
|
}
|
|
}
|
|
|
|
|
|
func initLocalization() -> Void {
|
|
func initLocalization() -> Void {
|
|
@@ -148,7 +179,10 @@ class KMAITranslationVC: NSViewController {
|
|
func fileTranslateHandle(_ fileKey: String) -> Void {
|
|
func fileTranslateHandle(_ fileKey: String) -> Void {
|
|
let infoDictionary = Bundle .main.infoDictionary!
|
|
let infoDictionary = Bundle .main.infoDictionary!
|
|
let majorVersion = infoDictionary["CFBundleShortVersionString"]
|
|
let majorVersion = infoDictionary["CFBundleShortVersionString"]
|
|
-
|
|
|
|
|
|
+// DispatchQueue.main.async {
|
|
|
|
+// self.showProgressWindow()
|
|
|
|
+// }
|
|
|
|
+
|
|
KMRequestServerManager.manager.aiTranslationFileTranslateHandle(fileKey: fileKey, from: self.fromStr, to: self.toStr, version: "1.0.1") { success, result in
|
|
KMRequestServerManager.manager.aiTranslationFileTranslateHandle(fileKey: fileKey, from: self.fromStr, to: self.toStr, version: "1.0.1") { success, result in
|
|
if success {
|
|
if success {
|
|
let result: NSDictionary = result!.result
|
|
let result: NSDictionary = result!.result
|
|
@@ -162,6 +196,15 @@ class KMAITranslationVC: NSViewController {
|
|
let to: String = result["to"] as! String
|
|
let to: String = result["to"] as! String
|
|
|
|
|
|
self.downloadFile(filePath: ossDownUrl, downFileName: downFileName)
|
|
self.downloadFile(filePath: ossDownUrl, downFileName: downFileName)
|
|
|
|
+ } else {
|
|
|
|
+ let result: String = result!.message
|
|
|
|
+
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.hiddenProgressWindow()
|
|
|
|
+
|
|
|
|
+ self.errorView.isHidden = false
|
|
|
|
+ self.errorLabel.stringValue = result
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -204,11 +247,14 @@ class KMAITranslationVC: NSViewController {
|
|
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.hiddenProgressWindow()
|
|
|
|
+ }
|
|
|
|
+
|
|
do {
|
|
do {
|
|
try FileManager.default.moveItem(at: tempLocalURL, to: destinationURL)
|
|
try FileManager.default.moveItem(at: tempLocalURL, to: destinationURL)
|
|
-
|
|
|
|
|
|
+
|
|
NSDocumentController.shared.openDocument(withContentsOf: destinationURL, display: true) { document, documentWasAlreadyOpen, error in
|
|
NSDocumentController.shared.openDocument(withContentsOf: destinationURL, display: true) { document, documentWasAlreadyOpen, error in
|
|
if error != nil {
|
|
if error != nil {
|
|
NSApp.presentError(error!)
|
|
NSApp.presentError(error!)
|
|
@@ -283,6 +329,29 @@ class KMAITranslationVC: NSViewController {
|
|
return "auto"
|
|
return "auto"
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func showProgressWindow() {
|
|
|
|
+ let progress = SKProgressController()
|
|
|
|
+ progress.message = NSLocalizedString("translation...", comment: "")
|
|
|
|
+ progress.window?.backgroundColor = NSColor(hex: "#36383B")
|
|
|
|
+ progress.window?.contentView?.wantsLayer = true
|
|
|
|
+ progress.window?.contentView?.layer?.backgroundColor = NSColor(hex: "#36383B").cgColor
|
|
|
|
+ progress.progressField.textColor = NSColor.white
|
|
|
|
+
|
|
|
|
+ progress.closeBlock = { [unowned self] in
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ self.progressController = progress
|
|
|
|
+ self.view.window?.beginSheet(progress.window!)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func hiddenProgressWindow() {
|
|
|
|
+ if (self.progressController != nil) {
|
|
|
|
+ self.view.window?.endSheet((self.progressController?.window)!)
|
|
|
|
+ self.progressController = nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// MARK: Action Methods
|
|
// MARK: Action Methods
|
|
|
|
|
|
func languageAction(_ isFromLanguage: Bool) -> Void {
|
|
func languageAction(_ isFromLanguage: Bool) -> Void {
|