1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // KMBaseWindowController.swift
- // PDF Master
- //
- // Created by tangchao on 2023/5/11.
- //
- import Cocoa
- class KMBaseWindowController: NSWindowController {
-
- var cancelAction: KMCommonBlock?
- var pdfDocument: CPDFDocument?
-
- deinit {
- Swift.debugPrint(self.className + "已释放")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- self.initSubViews()
- self.initDefaultValue()
- }
-
- func initSubViews() {}
- func initDefaultValue() {}
- }
- extension KMBaseWindowController {
- static func checkPassword(url: URL, password: String = "", completion: @escaping ((_ success: Bool, _ resultPassword: String) -> Void)) {
- let document = CPDFDocument.init(url: url)
- if document!.isLocked {
- if let unlockSuccess = document?.unlock(withPassword: password) {
- completion(true, password)
- } else {
- DispatchQueue.main.async {
- let passwordWindowController = PasswordWindowController(windowNibName: "PasswordWindowController")
- passwordWindowController.fileURL = url
- NSWindow.currentWindow().km_beginSheet(windowC: passwordWindowController)
- passwordWindowController.closeCallBack = { passwordString in
- if passwordString.count != 0 {
- document?.unlock(withPassword: passwordString)
- completion(true, passwordString)
- } else {
- completion(false, "")
- }
- }
- }
- }
- } else {
- completion(true, "")
- }
- }
- }
|