Procházet zdrojové kódy

Merge branch 'develop_v1.2' of git.kdan.cc:Mac_PDF/PDF_Office into develop_v1.2

tangchao před 1 rokem
rodič
revize
6526a01105

+ 2 - 2
PDF Office/PDF Master/Class/KMLightMember/Controller/AccountInfo/KMAccountInfoWindowController.swift

@@ -70,7 +70,7 @@ class KMAccountInfoWindowController: NSWindowController {
         return false
         return false
     }
     }
     
     
-    static func fetchSampleController() -> KMAccountInfoWindowController {
+    static func fetchSampleController() -> KMAccountInfoWindowController? {
         for window in NSApp.windows {
         for window in NSApp.windows {
             let controller = window.windowController
             let controller = window.windowController
             if controller is KMAccountInfoWindowController {
             if controller is KMAccountInfoWindowController {
@@ -78,7 +78,7 @@ class KMAccountInfoWindowController: NSWindowController {
             }
             }
         }
         }
         
         
-        return NSWindowController() as! KMAccountInfoWindowController
+        return nil
     }
     }
     
     
     func setup() {
     func setup() {

+ 11 - 0
PDF Office/PDF Master/Class/KMLightMember/Controller/Login&Register/KMLoginWindowController.swift

@@ -356,6 +356,17 @@ class KMLoginWindowController: NSWindowController {
         loginMainWindow = nil
         loginMainWindow = nil
     }
     }
     
     
+    static func fetchSampleController() -> KMLoginWindowController? {
+        for window in NSApp.windows {
+            let controller = window.windowController
+            if controller is KMLoginWindowController {
+                return controller as! KMLoginWindowController
+            }
+        }
+        
+        return nil
+    }
+    
 }
 }
 
 
 
 

+ 1 - 1
PDF Office/PDF Master/Class/KMLightMember/Controller/Login&Register/KMLoginWindowController.xib

@@ -22,7 +22,7 @@
         </customObject>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
-        <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
+        <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5">
             <windowStyleMask key="styleMask" titled="YES"/>
             <windowStyleMask key="styleMask" titled="YES"/>
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
             <rect key="contentRect" x="196" y="240" width="664" height="420"/>
             <rect key="contentRect" x="196" y="240" width="664" height="420"/>

+ 83 - 21
PDF Office/PDF Master/Class/KMLightMember/Manager/KMRequestServerManager.swift

@@ -143,6 +143,8 @@ typealias KMRequestServerComplete = (_ success: Bool, _ result: Result?) -> Void
 
 
 class KMRequestServerManager: NSObject {
 class KMRequestServerManager: NSObject {
     static let manager = KMRequestServerManager()
     static let manager = KMRequestServerManager()
+    
+    var loginAlert: NSAlert? = nil
 }
 }
 
 
 //MARK: - 会员
 //MARK: - 会员
@@ -519,6 +521,25 @@ extension KMRequestServerManager {
             }
             }
         }
         }
     }
     }
+    
+    func checkDeviceStatus(complete: @escaping KMRequestServerComplete) {
+        var urlString = KMLightMemberManager.manager.config.kServerURL + "/pdf-office-sso/auth/checkDeviceStatus"
+        
+        let uuid: String = GetHardwareUUID() ?? ""
+//        let params: [String: Any] = ["appId": "16",
+//                                     "deviceSign": uuid]
+        urlString = urlString + (NSString(format: "?appId=16&deviceSign=%@", uuid) as String)
+        KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
+            requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
+        } completion: { [unowned self] (task, responseObject, error) in
+            let result = self.dealData(responseObject: responseObject as? NSDictionary, error: error)
+            if result.code == 200 {
+                complete(true, result)
+            } else {
+                complete(false, result)
+            }
+        }
+    }
 }
 }
 
 
 //MARK: - 数据处理
 //MARK: - 数据处理
@@ -548,28 +569,69 @@ extension KMRequestServerManager {
         }
         }
         
         
         if code == 318 {
         if code == 318 {
-            let alert = NSAlert()
-            alert.messageText = NSLocalizedString("Unable to Log in", comment: "")
-            alert.informativeText = NSLocalizedString("Your account is currently being canceled and cannot be logged in. If you have any questions, please contact us at support@pdfreaderpro.com", comment: "")
-            alert.addButton(withTitle: NSLocalizedString("Contact Us", comment: ""))
-            alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
-            var window = NSApp.mainWindow
-            if NSApp.mainWindow?.sheets.first != nil {
-                window = NSApp.mainWindow?.sheets.first
-            }
-            alert.beginSheetModal(for: window!) { result in
-                if (result == .alertFirstButtonReturn) {
-//                    KMMailHelper.newEmail(withContacts: "support@pdfreaderpro.com", andSubjects: "")
-//                    NSWorkspace.shared.launchApplication("Mailto:support@pdfreaderpro.com")
-//                    NSWorkspace.shared.open(URL(string: "mailto:support@pdfreaderpro.com")!)
-                    NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/contact")!)
-//                    let service = NSSharingService(named: NSSharingService.Name.composeEmail)
-//                    service?.recipients = ["support@pdfreaderpro.com"]
-//                    service?.subject = "Test Mail"
-//                    service?.perform(withItems: ["Test Mail body"])
-                } else if result == .alertSecondButtonReturn {
-                    return
+            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1, execute: {
+                let alert = NSAlert()
+                alert.messageText = NSLocalizedString("Unable to Log in", comment: "")
+                alert.informativeText = NSLocalizedString("Your account is currently being canceled and cannot be logged in. If you have any questions, please contact us at support@pdfreaderpro.com", comment: "")
+                alert.addButton(withTitle: NSLocalizedString("Contact Us", comment: ""))
+                alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
+                var window = NSApp.mainWindow
+                if NSApp.mainWindow?.sheets.first != nil {
+                    window = NSApp.mainWindow?.sheets.first
+                }
+                if window != nil {
+                    alert.beginSheetModal(for: window!) { result in
+                        if (result == .alertFirstButtonReturn) {
+                            //                    KMMailHelper.newEmail(withContacts: "support@pdfreaderpro.com", andSubjects: "")
+                            //                    NSWorkspace.shared.launchApplication("Mailto:support@pdfreaderpro.com")
+                            //                    NSWorkspace.shared.open(URL(string: "mailto:support@pdfreaderpro.com")!)
+                            NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/contact")!)
+                            //                    let service = NSSharingService(named: NSSharingService.Name.composeEmail)
+                            //                    service?.recipients = ["support@pdfreaderpro.com"]
+                            //                    service?.subject = "Test Mail"
+                            //                    service?.perform(withItems: ["Test Mail body"])
+                        } else if result == .alertSecondButtonReturn {
+                            return
+                        }
+                    }
                 }
                 }
+            })
+        }
+        
+        if code == 304 {
+            self.checkDeviceStatus { success, result in
+                
+            }
+        }
+        
+        if code == 330 {
+            if KMLoginWindowController.fetchSampleController() == nil {
+                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.2, execute: { [unowned self] in
+                    if loginAlert == nil {
+                        loginAlert = NSAlert()
+                        loginAlert?.messageText = NSLocalizedString("请重新登录", comment: "")
+                        loginAlert?.informativeText = NSLocalizedString("您的账号已在其他设备登录,若非本人操作,请尽快修改您的账号密码", comment: "")
+                        loginAlert?.addButton(withTitle: NSLocalizedString("登录", comment: ""))
+                        loginAlert?.addButton(withTitle: NSLocalizedString("取消", comment: ""))
+                        var window = NSApp.mainWindow
+                        if NSApp.mainWindow?.sheets.first != nil {
+                            window = NSApp.mainWindow?.sheets.first
+                        }
+                        if window != nil {
+                            loginAlert?.beginSheetModal(for: window!) { result in
+                                if (result == .alertFirstButtonReturn) {
+                                    KMLoginWindowController.show(window: window!)
+                                } else if result == .alertSecondButtonReturn {
+                                    self.loginAlert = nil
+                                    return
+                                }
+                                self.loginAlert = nil
+                            }
+                        } else {
+                            self.loginAlert = nil
+                        }
+                    }
+                })
             }
             }
         }
         }
         
         

+ 12 - 10
PDF Office/PDF Master/Class/PDFTools/Batch/KMBatchWindowController.swift

@@ -87,9 +87,10 @@ class KMBatchWindowController: NSWindowController {
     static func openFiles(window: NSWindow) {
     static func openFiles(window: NSWindow) {
         if KMBatchWindowController.isSampleController() {
         if KMBatchWindowController.isSampleController() {
             print("存在相同文件")
             print("存在相同文件")
-            let controller: KMBatchWindowController = self.fetchSampleController()
-            controller.inputType = .Batch
-            controller.showWindow(window)
+            if let controller: KMBatchWindowController = self.fetchSampleController() {
+                controller.inputType = .Batch
+                controller.showWindow(window)
+            }
         } else {
         } else {
             KMBatchProcessingView.openfiles(window: window) { openPanel in
             KMBatchProcessingView.openfiles(window: window) { openPanel in
                 openPanel.title = "选择图片"
                 openPanel.title = "选择图片"
@@ -111,11 +112,12 @@ class KMBatchWindowController: NSWindowController {
     //MARK: 打开文件
     //MARK: 打开文件
     static func openFile(_ url: URL?, _ type: DataNavigationViewButtonActionType, _ subType: Any = "") {
     static func openFile(_ url: URL?, _ type: DataNavigationViewButtonActionType, _ subType: Any = "") {
         if KMBatchWindowController.isSampleController() {
         if KMBatchWindowController.isSampleController() {
-            let controller: KMBatchWindowController = self.fetchSampleController()
-            print("存在相同文件")
-            controller.inputSubType = subType
-            controller.inputType = type
-            controller.showWindow(NSApp.mainWindow)
+            if let controller: KMBatchWindowController = self.fetchSampleController() {
+                print("存在相同文件")
+                controller.inputSubType = subType
+                controller.inputType = type
+                controller.showWindow(NSApp.mainWindow)
+            }
         } else {
         } else {
             let batchWindowController: KMBatchWindowController = KMBatchWindowController.init(windowNibName: "KMBatchWindowController")
             let batchWindowController: KMBatchWindowController = KMBatchWindowController.init(windowNibName: "KMBatchWindowController")
             batchWindowController.showWindow(NSApp.mainWindow)
             batchWindowController.showWindow(NSApp.mainWindow)
@@ -138,7 +140,7 @@ class KMBatchWindowController: NSWindowController {
         return false
         return false
     }
     }
     
     
-    static func fetchSampleController() -> KMBatchWindowController {
+    static func fetchSampleController() -> KMBatchWindowController? {
         for window in NSApp.windows {
         for window in NSApp.windows {
             let controller = window.windowController
             let controller = window.windowController
             if controller is KMBatchWindowController {
             if controller is KMBatchWindowController {
@@ -146,7 +148,7 @@ class KMBatchWindowController: NSWindowController {
             }
             }
         }
         }
         
         
-        return NSWindowController() as! KMBatchWindowController
+        return nil
     }
     }
 }
 }
 
 

+ 6 - 5
PDF Office/PDF Master/Class/PDFTools/ImageToPDF/KMImageToPDFWindowController.swift

@@ -83,9 +83,10 @@ class KMImageToPDFWindowController: NSWindowController {
     static func openFiles(window: NSWindow) {
     static func openFiles(window: NSWindow) {
         if KMImageToPDFWindowController.isSampleController() {
         if KMImageToPDFWindowController.isSampleController() {
             print("存在相同文件")
             print("存在相同文件")
-            let controller: KMImageToPDFWindowController = self.fetchSampleController()
-            controller.inputType = .ImageToPDF
-            controller.showWindow(window)
+            if let controller: KMImageToPDFWindowController = self.fetchSampleController() {
+                controller.inputType = .ImageToPDF
+                controller.showWindow(window)
+            }
         } else {
         } else {
             KMBatchProcessingView.openfiles(window: window) { openPanel in
             KMBatchProcessingView.openfiles(window: window) { openPanel in
                 openPanel.canChooseDirectories = false
                 openPanel.canChooseDirectories = false
@@ -136,7 +137,7 @@ class KMImageToPDFWindowController: NSWindowController {
         return false
         return false
     }
     }
     
     
-    static func fetchSampleController() -> KMImageToPDFWindowController {
+    static func fetchSampleController() -> KMImageToPDFWindowController? {
         for window in NSApp.windows {
         for window in NSApp.windows {
             let controller = window.windowController
             let controller = window.windowController
             if controller is KMImageToPDFWindowController {
             if controller is KMImageToPDFWindowController {
@@ -144,7 +145,7 @@ class KMImageToPDFWindowController: NSWindowController {
             }
             }
         }
         }
         
         
-        return NSWindowController() as! KMImageToPDFWindowController
+        return nil
     }
     }
     
     
     @objc func windowClose(notification: NSNotification) {
     @objc func windowClose(notification: NSNotification) {