Ver código fonte

【BOTA】暗黑设配

tangchao 1 ano atrás
pai
commit
6503d95a8b

+ 10 - 0
PDF Office/PDF Master/Class/Appearance/KMAppearance.swift

@@ -616,6 +616,16 @@ let KMImageNameElsei = "KMImageNameElsei";
         return NSColor.km_init(hex: "#DFE1E5")
     }
     
+    @objc class func controlBackgroundColor() -> NSColor {
+        if (!KMAppearance.isSupportNewColor()) {
+            return NSColor(white: 246/255.0, alpha: 1)
+        }
+        if let _color = NSColor(named: "KMControlBackgroundColor") {
+            return _color
+        }
+        return NSColor(white: 246/255.0, alpha: 1)
+    }
+    
     class func isSupportNewColor() -> Bool {
         if #available(macOS 10.14, *) {
             return true

+ 69 - 19
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift

@@ -20,12 +20,29 @@ import Cocoa
     var rightToolbarItemView: NSView!
     
     private var homeVC: KMHomeViewController?
+    
+    deinit {
+        KMPrint("KMBrowserWindowController deinit...")
+        
+//        self.removeObserverForAppearanceChange()
+        DistributedNotificationCenter.default().removeObserver(self)
+        NotificationCenter.default.removeObserver(self)
+    }
+    
+    override func loadWindow() {
+        super.loadWindow()
+        
+//        self.window?.titlebarAppearsTransparent = true
+    }
 
     override func windowDidLoad() {
         super.windowDidLoad()
         
         NSImage.makeTextAlignImages()
         window?.backgroundColor = NSColor.km_init(hex: "#DFE1E5")
+        self.window?.appearance = NSApp.appearance
+        self.window?.titlebarAppearsTransparent = true
+//        self.window?.standardWindowButton(.closeButton)?.superview?.needsLayout = true
         
 //        window?.setFrameAutosaveName("")
         rightTabStripView_.delete = self
@@ -35,12 +52,13 @@ import Cocoa
         homeRightTabStripView_.homeRightSearchField.delegate = self
         
         isMultiTabMode = true
-        addObserverForAppearanceChange()
+//        self.addObserverForAppearanceChange()
         
         refreshToolBar(homeToolState: .Home)
         
         NotificationCenter.default.addObserver(self, selector: #selector(closeAllTabs(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseAllTabs"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(openNewWindow(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerOpenNewWindow"), object: nil)
+        DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
         
 //        if (KMWelcomeWindowController.welcomeHasShow() == false) {
 //            //AI 版本禁掉首次开启帮助文档
@@ -101,30 +119,62 @@ import Cocoa
     override func layoutSubviews() {
         super.layoutSubviews()
         
-        if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.closeButton) {
-            button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
-        }
-        if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.zoomButton) {
-            button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
-        }
-        if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.miniaturizeButton) {
-            button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
-        }
+//        if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.closeButton) {
+//            button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
+//        }
+//        if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.zoomButton) {
+//            button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
+//        }
+//        if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.miniaturizeButton) {
+//            button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
+//        }
     }
     
     // MARK: Dark&Light
     
-    func addObserverForAppearanceChange() -> Void {
-        window?.contentView!.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
-    }
+//    func addObserverForAppearanceChange() -> Void {
+//        window?.contentView?.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
+//    }
     
-    func removeObserverForAppearanceChange() -> Void {
-        window?.contentView!.removeObserver(self, forKeyPath: "effectiveAppearance")
-    }
+//    func removeObserverForAppearanceChange() -> Void {
+//        window?.contentView?.removeObserver(self, forKeyPath: "effectiveAppearance")
+//    }
     
-    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
-        if keyPath == "effectiveAppearance" {
-            updateViewColor()
+//    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
+//        if keyPath == "effectiveAppearance" {
+//            self.updateViewColor()
+//        }
+//    }
+    
+    @objc private func _themeChanged(_ sender: Notification) {
+        if let data = self.window?.appearance?.name, data == .darkAqua {
+            self.window?.appearance = .init(named: .aqua)
+        } else {
+            self.window?.appearance = .init(named: .darkAqua)
+        }
+        
+        Task { @MainActor in
+//            self.interfaceThemeDidChanged(self.window?.appearance?.name ?? .aqua)
+            self.updateViewColor()
+            
+//            _themeChanged
+//            let selector = NSSelectorFromString("_themeChanged:")
+//            let mainWindow = self.window
+//            var responder = mainWindow?.firstResponder
+//            
+//            while (responder != nil) {
+//                KMPrint("res: \(responder)")
+//                
+//                if self.isEqual(to: responder) {
+//                    responder = responder?.nextResponder
+//                    continue
+//                }
+//                if let res = responder?.responds(to: selector), res {
+//                    responder?.perform(selector, with: sender)
+//                }
+//                
+//                responder = responder!.nextResponder
+//            }
         }
     }
     

+ 3 - 0
PDF Office/PDF Master/Class/Common/Category/NSObject+KMExtension.swift

@@ -671,6 +671,9 @@ extension NSApplication {
     }
 }
 
+@objc protocol KMInterfaceThemeChangedProtocol: NSObjectProtocol {
+    @objc optional func interfaceThemeChanged(_ appearance: NSAppearance.Name)
+}
 
 // MARK: - NSOutlineView
 

+ 7 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -40,6 +40,7 @@ class KMLeftSideViewController: KMSideViewController {
         KMPrint("KMLeftSideViewController deinit.")
         
         NotificationCenter.default.removeObserver(self)
+        DistributedNotificationCenter.default().removeObserver(self)
     }
     
     override var nibName: NSNib.Name? {
@@ -1123,6 +1124,8 @@ extension KMLeftSideViewController {
             self.snapshotSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
             self.outlineSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
             self.noteSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
+//            self.leftView.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
+//            self.leftView.layer?.backgroundColor = NSColor.red.cgColor
         } else {
             self.leftListView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
             self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
@@ -1144,7 +1147,11 @@ extension KMLeftSideViewController {
             self.snapshotSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
             self.outlineSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
             self.noteSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
+//            self.leftView.layer?.backgroundColor = .white
         }
+        
+        self.leftView.wantsLayer = true
+        self.leftView.layer?.backgroundColor = KMAppearance.controlBackgroundColor().cgColor
     }
     
     private func _hasContainString(_ searchString: String, rootOutline outline: CPDFOutline) -> Bool {

+ 100 - 4
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -110,8 +110,8 @@
             filePath = "PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "2146"
-            endingLineNumber = "2146"
+            startingLineNumber = "2196"
+            endingLineNumber = "2196"
             landmarkName = "savePDFSettingToDefaults(_:)"
             landmarkType = "7">
          </BreakpointContent>
@@ -526,8 +526,8 @@
             filePath = "PDF Master/Class/Common/Category/NSObject+KMExtension.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "805"
-            endingLineNumber = "805"
+            startingLineNumber = "808"
+            endingLineNumber = "808"
             landmarkName = "uniqueChewableItemsDirectoryURL()"
             landmarkType = "7">
          </BreakpointContent>
@@ -548,5 +548,101 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "877893A4-191F-4DC0-B4BA-6AD764BA2605"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "1101"
+            endingLineNumber = "1101"
+            landmarkName = "_themeChanged(_:)"
+            landmarkType = "7">
+            <Locations>
+               <Location
+                  uuid = "877893A4-191F-4DC0-B4BA-6AD764BA2605 - 3e436c85ec6693d0"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "PDF_Reader_Pro.KMLeftSideViewController._themeChanged(__C.NSNotification) -&gt; ()"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "1101"
+                  endingLineNumber = "1101"
+                  offsetFromSymbolStart = "277">
+               </Location>
+               <Location
+                  uuid = "877893A4-191F-4DC0-B4BA-6AD764BA2605 - b06821624ed6e2ad"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "closure #1 @Swift.MainActor () -&gt; () in PDF_Reader_Pro.KMLeftSideViewController._themeChanged(__C.NSNotification) -&gt; ()"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "1102"
+                  endingLineNumber = "1102"
+                  offsetFromSymbolStart = "22">
+               </Location>
+            </Locations>
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "DB926723-14B1-4358-AF9B-3BC932A40699"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "150"
+            endingLineNumber = "150"
+            landmarkName = "_themeChanged(_:)"
+            landmarkType = "7">
+            <Locations>
+               <Location
+                  uuid = "DB926723-14B1-4358-AF9B-3BC932A40699 - 74c2745fc2dd85a8"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "PDF_Reader_Pro.KMBrowserWindowController._themeChanged(Foundation.Notification) -&gt; ()"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "150"
+                  endingLineNumber = "150"
+                  offsetFromSymbolStart = "85">
+               </Location>
+               <Location
+                  uuid = "DB926723-14B1-4358-AF9B-3BC932A40699 - 74c2745fc2dd85a8"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "PDF_Reader_Pro.KMBrowserWindowController._themeChanged(Foundation.Notification) -&gt; ()"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "150"
+                  endingLineNumber = "150"
+                  offsetFromSymbolStart = "381">
+               </Location>
+            </Locations>
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>