Browse Source

【安全】首页入口新增权益弹窗限制

tangchao 1 year ago
parent
commit
894890baa6

+ 1 - 51
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -1057,57 +1057,7 @@ extension KMHomeViewController {
     }
     
     func fastTool_Security() {  // 安全
-        Task { @MainActor in
-            if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
-                let _ = KMComparativeTableViewController.show(window: self.view.window!, .secure)
-                return
-            }
-            
-            NSOpenPanel.km_secure_openPanel(window: self.view.window!, needOwner: true) { url, result, passowrd in
-                if (url == nil) {
-                    return
-                }
-
-                if (result != nil && result! == .cancel) {
-                    return
-                }
-
-                let windowController = KMSecureEncryptWindowController(windowNibName: "KMSecureEncryptWindowController")
-                windowController.documentURL = url!
-                windowController.myDocument = CPDFDocument(url: url!)
-                if (passowrd != nil) {
-                    windowController.myDocument.unlock(withPassword: passowrd)
-                }
-                self.currentWindowController = windowController
-
-                let newDocument: CPDFDocument = CPDFDocument(url: url!)
-                windowController.itemClick = { [weak self] (index: Int) -> () in
-                    self!.view.window?.endSheet((self?.currentWindowController?.window!)!)
-                    self?.currentWindowController = nil
-                }
-                
-                windowController.resultCallback = { [weak self] (result: Bool) -> () in
-                    let windowController_secure: KMSecureEncryptWindowController = self?.currentWindowController as! KMSecureEncryptWindowController
-                    self!.view.window?.endSheet((self?.currentWindowController?.window!)!)
-                    self!.currentWindowController = nil
-                    if (passowrd != nil) {
-                        newDocument.unlock(withPassword: passowrd)
-                    }
-                    
-                    newDocument.setPasswordOptions(windowController_secure.options)
-                    let result = KMPasswordInputWindow.saveDocument(newDocument)
-                    if result {
-                        NSWorkspace.shared.activateFileViewerSelecting([newDocument.documentURL])
-                    } else {
-                        let alert = NSAlert()
-                        alert.messageText = NSLocalizedString("Failure", comment: "")
-                        alert.runModal()
-                    }
-                }
-                
-                self.view.window?.beginSheet(windowController.window!)
-            }
-        }
+        self.showSecurityWindow()
     }
     
     func fastTool_FileCompare() {   // 文件对比

+ 89 - 0
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+UI.swift

@@ -208,6 +208,35 @@ extension KMHomeViewController {
         }
     }
     
+    func showSecurityWindow() {
+        Task { @MainActor in
+            if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
+                let _ = KMComparativeTableViewController.show(window: self.view.window!, .secure)
+                return
+            }
+            
+            if await (KMLightMemberManager.manager.canPayFunction() == false) {
+                let _ = KMSubscribeWaterMarkWindowController.show(window: self.view.window!) { isSubscribeSuccess, isWaterMarkExport, isClose in
+                    if (isClose) {
+                        return
+                    }
+                    self.km_secure_openPanel_security(limit: true)
+                }
+                return
+            }
+            
+            self.km_secure_openPanel_security()
+        }
+    }
+    
+    func km_secure_openPanel_security(limit: Bool = false) {
+        DispatchQueue.main.async {
+            NSOpenPanel.km_secure_openPanel_success(window: self.view.window!, needOwner: true) { url, password in
+                self._showSecurityWindow(url: url, password: password, limit: limit)
+            }
+        }
+    }
+    
     // MARK: - Private Methods
     
     fileprivate func _showConvertWindow(type: KMPDFConvertType, url: URL, password: String? = nil) {
@@ -250,6 +279,66 @@ extension KMHomeViewController {
         self.view.window?.beginSheet((windowController?.window)!)
         self.currentWindowController = windowController
     }
+    
+    fileprivate func _showSecurityWindow(url: URL, password: String?, limit: Bool = false) {  // 安全
+        let windowC = KMSecureEncryptWindowController(windowNibName: "KMSecureEncryptWindowController")
+        windowC.documentURL = url
+        windowC.myDocument = CPDFDocument(url: url)
+        if let _password = password {
+            windowC.myDocument.unlock(withPassword: _password)
+        }
+        self.currentWindowController = windowC
+        
+        let newDocument: CPDFDocument = CPDFDocument(url: url)
+        windowC.itemClick = { [weak self] _ in
+            if let _currentWindow = self?.currentWindowController?.window {
+                self?.view.window?.endSheet(_currentWindow)
+            }
+            self?.currentWindowController = nil
+        }
+        
+        windowC.resultCallback = { [weak self] _ in
+            let windowController_secure: KMSecureEncryptWindowController = self?.currentWindowController as! KMSecureEncryptWindowController
+            if let _currentWindow = self?.currentWindowController?.window {
+                self?.view.window?.endSheet(_currentWindow)
+            }
+            self?.currentWindowController = nil
+            if let _password = password {
+                newDocument.unlock(withPassword: _password)
+            }
+            
+            if (!limit) {
+                newDocument.setPasswordOptions(windowController_secure.options)
+                let result = KMPasswordInputWindow.saveDocument(newDocument)
+                if result {
+                    NSWorkspace.shared.activateFileViewerSelecting([newDocument.documentURL])
+                } else {
+                    let alert = NSAlert()
+                    alert.messageText = NSLocalizedString("Failure", comment: "")
+                    alert.runModal()
+                }
+                return
+            }
+            
+            NSPanel.savePanel((self?.view.window)!, panel: { panel in
+                panel.nameFieldStringValue = url.lastPathComponent
+            }) { response, saveUrl in
+                if (response == .cancel) {
+                    return
+                }
+                
+                if let fileUrl = KMTools.saveWatermarkDocument(document: newDocument, to: saveUrl!, secureOptions: windowController_secure.options) {
+                    NSWorkspace.shared.activateFileViewerSelecting([fileUrl])
+                } else {
+                    let alert = NSAlert()
+                    alert.messageText = NSLocalizedString("Failure", comment: "")
+                    alert.runModal()
+                }
+            }
+        }
+        
+        self.view.window?.beginSheet(windowC.window!)
+    }
 }
 
 // MARK: - NSSplitViewDelegate