Browse Source

【综合】分割窗口设配暗黑模式

tangchao 1 year ago
parent
commit
687831387d

+ 2 - 0
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -16257,6 +16257,7 @@
 				INFOPLIST_KEY_NSMainStoryboardFile = Main;
 				INFOPLIST_KEY_NSPrincipalClass = NSApplication;
 				INFOPLIST_KEY_UILaunchStoryboardName = "";
+				INFOPLIST_KEY_UIUserInterfaceStyle = "";
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
 					"@executable_path/../Frameworks",
@@ -16345,6 +16346,7 @@
 				INFOPLIST_KEY_NSMainStoryboardFile = Main;
 				INFOPLIST_KEY_NSPrincipalClass = NSApplication;
 				INFOPLIST_KEY_UILaunchStoryboardName = "";
+				INFOPLIST_KEY_UIUserInterfaceStyle = "";
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
 					"@executable_path/../Frameworks",

+ 0 - 16
PDF Office/PDF Master.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -452,21 +452,5 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "84E7A3E1-21B1-4C0A-BF78-861FADE48861"
-            shouldBeEnabled = "No"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFTools/PageEdit/Window/SplitWindowController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "102"
-            endingLineNumber = "102"
-            landmarkName = "windowDidLoad()"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

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

@@ -51,7 +51,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         KMAdvertisementManager.manager.debug = true
                 
         // 初版不支持暗黑模式
-//        NSApp.appearance = NSAppearance(named: .aqua)
+        NSApp.appearance = NSAppearance.current
         KMAnalytics.configure()
 
         //第一次开启app
@@ -87,6 +87,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
                                           andSelector: #selector(handleGetURLEvent(_:withReplyEvent:)),
                                           forEventClass: AEEventClass(kInternetEventClass),
                                           andEventID: AEEventID(kAEGetURL))
+        
+        DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
     }
     
     @objc func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
@@ -232,6 +234,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         browser.windowController.showWindow(self)
     }
     
+    @objc private func _themeChanged(_ sender: Notification) {
+        if let data = NSApp.appearance?.name, data == .darkAqua {
+            NSApp.appearance = .init(named: .aqua)
+        } else {
+            NSApp.appearance = .init(named: .darkAqua)
+        }
+    }
+    
     // MARK: Menu
     func initMainMenu() {
         // 处理菜单栏多语

+ 34 - 1
PDF Office/PDF Master/Class/Common/Base/KMBaseWindowController.swift

@@ -15,6 +15,8 @@ class KMBaseWindowController: NSWindowController {
     var isBatch: Bool = false  //是否批量模块进入
     deinit {
         Swift.debugPrint(self.className + "已释放")
+        
+        self.removeNotification()
     }
     
     override func windowDidLoad() {
@@ -23,10 +25,41 @@ class KMBaseWindowController: NSWindowController {
         // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
         self.initSubViews()
         self.initDefaultValue()
+        self.initNotification()
     }
     
     func initSubViews() {}
-    func initDefaultValue() {}
+    func initDefaultValue() {
+        self.window?.appearance = NSApp.appearance
+    }
+    
+    func initNotification() {
+        DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
+    }
+    
+    func removeNotification() {
+        DistributedNotificationCenter.default().removeObserver(self)
+    }
+    
+    func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
+        
+    }
+}
+
+// MARK: - Private Methods
+
+extension KMBaseWindowController {
+    @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)
+        }
+    }
 }
 
 extension KMBaseWindowController {

+ 4 - 0
PDF Office/PDF Master/Class/PDFTools/PageEdit/Window/SplitWindowController.swift

@@ -106,6 +106,10 @@ class SplitWindowController: KMBaseWindowController {
         self._configuViews()
     }
     
+    override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
+//        KMPrint("appearance")
+    }
+    
     @IBAction func byPageStepperAction(_ sender: AnyObject) {
         self.byPageText.stringValue = String(format: "%ld", self.byPageStepper.integerValue)
     }

+ 2 - 0
PDF Office/PDF Master/Info.plist

@@ -334,5 +334,7 @@
 		<string>SF-Pro-Text-Semibold.otf</string>
 		<string>SF-Pro-Text-Bold.otf</string>
 	</array>
+	<key>UIUserInterfaceStyle</key>
+	<string></string>
 </dict>
 </plist>