Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Sky/ScriptMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ class ScriptMessageHandler: NSObject, WKScriptMessageHandler {
let darkMode = messageBody["darkMode"] as? Int,
let backgroundColor = messageBody["backgroundColor"] as? String
{
// NSLog("colorScheme: \(colorScheme), darkMode: \(darkMode), backgroundColor: \(backgroundColor)")
if darkMode == 1 {
viewController.updateTitleBar(.dark, backgroundColor: backgroundColor)
} else {
viewController.updateTitleBar(.light, backgroundColor: backgroundColor)
}
let colorMode = messageBody["colorMode"] as? String
// NSLog("colorScheme: \(colorScheme), darkMode: \(darkMode), backgroundColor: \(backgroundColor), colorMode: \(colorMode ?? "nil")")
let mode: ViewController.WindowColorScheme = darkMode == 1 ? .dark : .light
viewController.updateTitleBar(mode, backgroundColor: backgroundColor, colorMode: colorMode)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Sky/Scripts/hook_window_color_scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function updateColorSchemeWithBskyStorage(bskyStorage) {
colorScheme: match.name,
darkMode: match.darkMode,
backgroundColor: match.backgroundColor,
colorMode: colorMode,
});
return true;
}
Expand All @@ -106,6 +107,7 @@ function updateColorSchemeAuto() {
colorScheme: match.name,
darkMode: match.darkMode,
backgroundColor: match.backgroundColor,
colorMode: "system",
});
return true;
}
Expand Down
19 changes: 11 additions & 8 deletions Sky/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class ViewController: NSViewController {
NSLog("checkAppearance initSystemAppearanceValue = \(initSystemAppearanceValue)")
if self.webView != nil {
NSLog("checkAppearance setting local storage")
self.webView.evaluateJavaScript(
Scripts.localStorageSetItem(
key: LocalStorageKeys.initSystemAppearance,
value: initSystemAppearanceValue
)
)
// Chain updateColorScheme() so the title bar message sees the fresh localStorage.
let script = Scripts.localStorageSetItem(
key: LocalStorageKeys.initSystemAppearance,
value: initSystemAppearanceValue
) + "\nif (typeof updateColorScheme === 'function') { updateColorScheme(); }"
self.webView.evaluateJavaScript(script)
}
}

Expand Down Expand Up @@ -477,7 +477,7 @@ class ViewController: NSViewController {
case light
}

func updateTitleBar(_ mode: WindowColorScheme, backgroundColor: String) {
func updateTitleBar(_ mode: WindowColorScheme, backgroundColor: String, colorMode: String? = nil) {
if backgroundColor.starts(with:"rgb("),
let range = backgroundColor.range(of: #"\((.*?)\)"#, options: .regularExpression)
{
Expand All @@ -496,7 +496,10 @@ class ViewController: NSViewController {
)
}
}
if mode == .dark {
// Leave appearance unset for "system" so WKWebView's prefers-color-scheme follows macOS.
if colorMode == "system" {
self.webView.window!.appearance = nil
} else if mode == .dark {
self.webView.window!.appearance = NSAppearance(named: .darkAqua)
} else {
self.webView.window!.appearance = NSAppearance(named: .aqua)
Expand Down