Browse Source

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

tangchao 1 year ago
parent
commit
e8c30f19fc

+ 0 - 7
PDF Office/PDF Master.xcodeproj/xcshareddata/xcschemes/PDF Master.xcscheme

@@ -50,13 +50,6 @@
             ReferencedContainer = "container:PDF Master.xcodeproj">
          </BuildableReference>
       </BuildableProductRunnable>
-      <AdditionalOptions>
-         <AdditionalOption
-            key = "NSZombieEnabled"
-            value = "YES"
-            isEnabled = "YES">
-         </AdditionalOption>
-      </AdditionalOptions>
    </LaunchAction>
    <ProfileAction
       buildConfiguration = "Release"

+ 1 - 0
PDF Office/PDF Master/AppDelegate.swift

@@ -240,6 +240,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         } else {
             NSApp.appearance = .init(named: .darkAqua)
         }
+        NotificationCenter.default.post(name: Notification.Name(rawValue: "kEffectiveAppearance"), object: nil)
     }
     
     // MARK: Menu

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

@@ -740,27 +740,3 @@ extension KMHomeViewController {
 //        }
     }
 }
-
-extension KMHomeViewController {
-    // 监听系统外观模式变化的方法
-    @objc func appearanceChanged() {
-        // 根据当前的外观模式更新应用程序的外观
-//        print("appearanceChanged\(String(describing: self.view.appearance))")
-        if KMAdvertisementConfig.isDarkModel() && self.view.appearance == NSAppearance(named: .aqua) ||
-            (!KMAdvertisementConfig.isDarkModel() && self.view.appearance == NSAppearance(named: .darkAqua))  {
-            setAppearance(isDarkMode: KMAdvertisementConfig.isDarkModel())
-        }
-    }
-    
-    // 根据系统外观模式设置应用程序的外观
-    func setAppearance(isDarkMode: Bool) {
-        if isDarkMode {
-            self.view.appearance = NSAppearance(named: .darkAqua)
-//            NSApp.appearance = NSAppearance(named: .darkAqua)
-        } else {
-            self.view.appearance = NSAppearance(named: .aqua)
-//            NSApp.appearance = NSAppearance(named: .aqua)
-        }
-//        self.homeContentView?.qucikToolsView.updateUI()
-    }
-}

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/New/View/KMHeaderFooterView.swift

@@ -179,7 +179,7 @@ class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate
         didSet {
             self.pdfView.document = self.pdfDocument
             self.pdfView.headerFooter = self.headerFooterObj
-            
+            self.password = self.pdfDocument?.password ?? ""
             self._fileAttri = KMFileAttribute()
             self._fileAttri?.filePath = self.pdfDocument?.documentURL.path ?? ""
             

+ 1 - 0
PDF Office/PDF Master/Class/PDFTools/Background/New/View/KMAddBackgroundView.swift

@@ -87,6 +87,7 @@ class KMAddBackgroundView: KMBaseXibView, NSComboBoxDelegate {
     var type: KMBackgroundManagerType = .use
     var pdfDocument: CPDFDocument? {
         didSet {
+            self.password = pdfDocument?.password ?? ""
             self.pdfView.document = pdfDocument
             self.reloadData()
         }

+ 1 - 0
PDF Office/PDF Master/Class/PDFTools/Compare/View/KMCompareView.swift

@@ -292,6 +292,7 @@ extension KMCompareView {
             file.pdfDocument = cDocument
             file.myPDFDocument = document
             file.filePath = filePath
+            file.password = password
             
             document.unlock(withPassword: password)
             cDocument.unlock(withPassword: password)

+ 12 - 27
PDF Office/PDF Master/Class/PDFTools/Tools/KMBaseXibView/KMBaseXibView.swift

@@ -10,8 +10,7 @@ import Cocoa
 class KMBaseXibView: NSView {
 
     @IBOutlet var contentView: NSView!
-
-    var isObservingAppearance = false
+    
     deinit {
         self.removeNotification()
     }
@@ -24,6 +23,7 @@ class KMBaseXibView: NSView {
         self.updateLanguage()
         self.reloadData()
         self.addNotification()
+        self.changeEffectiveAppearance()
     }
     
     override init(frame frameRect: NSRect) {
@@ -34,6 +34,7 @@ class KMBaseXibView: NSView {
         self.updateLanguage()
         self.reloadData()
         self.addNotification()
+        self.changeEffectiveAppearance()
     }
     
     private func initContentView() {
@@ -90,36 +91,20 @@ class KMBaseXibView: NSView {
     }
     
     func addNotification() {
-        
-        self.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
-        isObservingAppearance = true
+        NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
     }
     
     func removeNotification() {
-        if isObservingAppearance {
-            self.removeObserver(self, forKeyPath: "effectiveAppearance")
-            NotificationCenter.default.removeObserver(self)
-        }
-        isObservingAppearance = false
+        NotificationCenter.default.removeObserver(self)
     }
     
-    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
-        if keyPath == "effectiveAppearance" {
-            let isDarkModel = KMAdvertisementConfig.isDarkModel()
-            if isDarkModel {
-                self.appearance = NSAppearance(named: .darkAqua)
-            } else {
-                self.appearance = NSAppearance(named: .aqua)
-            }
-            
-//            if isDarkModel {
-//                NSApp.appearance = NSAppearance(named: .darkAqua)
-//            } else {
-//                NSApp.appearance = NSAppearance(named: .aqua)
-//            }
-            
-            self.updateUI()
-            print("黑暗模式触发")
+    @objc func changeEffectiveAppearance() {
+        let isDarkModel = KMAdvertisementConfig.isDarkModel()
+        if isDarkModel {
+            self.appearance = NSAppearance(named: .darkAqua)
+        } else {
+            self.appearance = NSAppearance(named: .aqua)
         }
+        self.updateUI()
     }
 }

+ 3 - 2
PDF Office/PDF Master/Class/PDFTools/Watermark/New/View/KMWatermarkView.swift

@@ -99,10 +99,10 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
         didSet {
             self._fileAttri = KMFileAttribute()
             self._fileAttri?.filePath = self.pdfDocument?.documentURL?.path ?? ""
-            
+            self.password = pdfDocument?.password ?? ""
             DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
                 self.pdfView.watermark = self.watermark
-                self.pdfView.document = CPDFDocument(url: self.pdfDocument?.documentURL)
+                self.pdfView.document = self.pdfDocument
             }
 //            self.reloadData()
         }
@@ -1030,6 +1030,7 @@ extension KMWatermarkView {
         DispatchQueue.global().async {
             let waterDocument = CPDFDocument(url: self.pdfView.document.documentURL)
             guard let waterDocument = waterDocument else { return }
+            waterDocument.unlock(withPassword: self.password)
             var property: CPDFWatermark!
             var scale: CGFloat = model.scale
             if (!model.text.isEmpty) {

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -3516,7 +3516,7 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
             } else if type == .comparison {
                 let controller = KMCompareWindowController(windowNibName: "KMCompareWindowController")
                 self.currentWindowController = controller
-                
+                controller.password = self.document?.password ?? ""
                 controller.filePath = (self.document?.documentURL.path)!
                 
                 controller.cancelAction = { [unowned self] controller in