12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- //
- // KMBaseWindowController.swift
- // PDF Master
- //
- // Created by tangchao on 2023/5/11.
- //
- import Cocoa
- class KMBaseWindowController: NSWindowController {
-
- 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
- passwordWindowController.beginSheetModalForWindow(NSWindow.currentWindow()) { passwordString in
- if passwordString.count != 0 {
- document?.unlock(withPassword: passwordString)
- completion(true, passwordString)
- } else {
- completion(false, "")
- }
- }
- }
- }
- } else {
- completion(true, "")
- }
- }
- }
|