Browse Source

【主页】黑暗模式兼容

lizhe 1 year ago
parent
commit
1cc5fe09c0

+ 9 - 0
PDF Office/PDF Master/Class/Home/View/HomeContentView/KMHomeContentView.swift

@@ -65,6 +65,15 @@ class KMHomeContentView: KMBaseXibView {
     }
     
     override func setup() {
+        self.qucikToolsLabel.stringValue = NSLocalizedString("Advanced Editing Tools", comment: "")
+        self.qucikToolsLabel.textColor = KMAppearance.Layout.h0Color()
+        self.recentlyLabel.stringValue = NSLocalizedString("Recent", comment: "");
+        self.recentlyLabel.textColor = KMAppearance.Layout.h0Color()
+        
+        self.horizontalButton.toolTip = NSLocalizedString("Thumbnails", comment: "")
+        self.verticalButton.toolTip = NSLocalizedString("List", comment: "")
+        self.cleanButton.toolTip = NSLocalizedString("Delete",comment: "")
+        
         self.pageLabel.textColor = KMAppearance.Layout.h0Color()
         self.qucikToolsView.didSelect = { [unowned self] view, item in
             guard let callBack = qucikToolsDidSelect else { return }

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

@@ -140,6 +140,11 @@ import Cocoa
         self.updateUI()
         
         NotificationCenter.default.addObserver(self, selector: #selector(homeFileRectChange(_:)), name: Notification.Name("KMHomeFileRectChange"), object: nil)
+        
+        setAppearance(isDarkMode: KMAdvertisementConfig.isDarkModel())
+        NotificationCenter.default.addObserver(self, selector: #selector(appearanceChanged), name: NSNotification.Name(NSApplication.didUpdateNotification.rawValue), object: nil)
+//        NotificationCenter.default.addObserver(self, selector: #selector(appearanceChanged), name: NSNotification.Name(NSWindow.didBecomeMainNotification.rawValue), object: nil)
+//        NotificationCenter.default.addObserver(self, selector: #selector(appearanceChanged), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
     }
     
     override func viewDidAppear() {
@@ -370,6 +375,7 @@ import Cocoa
     
     func updateUI() {
         self.leftBox.fillColor = KMAppearance.Layout.l0Color()
+        self.homeSplitView.backgroundColor(KMAppearance.Layout.l0Color())
     }
     
     // MARK: Public Methods
@@ -727,3 +733,27 @@ 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()
+    }
+}

+ 15 - 4
PDF Office/PDF Master/Class/PDFTools/Watermark/New/View/KMWatermarkView.swift

@@ -128,9 +128,13 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
     }
     
     override func setup() {
-        pdfView.autoScales = true
-//        pdfView.documentView?.enclosingScrollView?.hasVerticalScroller = false
-//        pdfView.documentView?.enclosingScrollView?.hasHorizontalScroller = false
+        
+        if (pdfView.documentView() != nil) {
+            pdfView.setDisplay(.singlePage)
+            pdfView.documentView().enclosingScrollView?.scrollerStyle = .overlay
+            pdfView.documentView().enclosingScrollView?.hasVerticalScroller = false
+            pdfView.documentView().enclosingScrollView?.hasHorizontalScroller = false
+        }
         
         for i in 0..<3 {
             for j in 0..<3 {
@@ -347,8 +351,15 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
     }
     
     func updatePDFView() {
-//        pdfView.needsDisplay = true
+        //        pdfView.needsDisplay = true
         self.pdfView.setNeedsDisplayForVisiblePages()
+        
+        if self.pdfView.documentView() != nil {
+            self.pdfView.autoScales = true
+            self.pdfView.documentView().enclosingScrollView?.scrollerStyle = .overlay
+            self.pdfView.documentView().enclosingScrollView?.hasVerticalScroller = false
+            self.pdfView.documentView().enclosingScrollView?.hasHorizontalScroller = false
+        }
     }
     
     func checkAngle() {