|
@@ -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 {
|