소스 검색

【主页】黑暗模式兼容

lizhe 1 년 전
부모
커밋
99829e6b7e
1개의 변경된 파일14개의 추가작업 그리고 1개의 파일을 삭제
  1. 14 1
      PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

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

@@ -99,6 +99,7 @@ import Cocoa
     
     var currentController: NSWindowController?
     deinit {
+        NotificationCenter.default.removeObserver(self)
     }
     
     override func viewWillAppear() {
@@ -138,9 +139,10 @@ import Cocoa
         self.setup()
 //        refreshUI()
         self.updateUI()
+        self.changeEffectiveAppearance()
         
         NotificationCenter.default.addObserver(self, selector: #selector(homeFileRectChange(_:)), name: Notification.Name("KMHomeFileRectChange"), object: nil)
-        
+        NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), 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)
@@ -380,6 +382,17 @@ import Cocoa
         self.homeSplitView.backgroundColor(KMAppearance.Layout.l0Color())
     }
     
+    @objc func changeEffectiveAppearance() {
+        let isDarkModel = KMAdvertisementConfig.isDarkModel()
+        if isDarkModel {
+            self.view.appearance = NSAppearance(named: .darkAqua)
+        } else {
+            self.view.appearance = NSAppearance(named: .aqua)
+        }
+        self.updateUI()
+        self.advertisementTableView.reloadData()
+    }
+    
     // MARK: Public Methods
     
     func savePDFDocument(_ pdf: CPDFDocument, password: String) -> Void {