-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
darkMode.go
34 lines (29 loc) · 859 Bytes
/
darkMode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"os/exec"
"runtime"
"strings"
)
func isDarkMode() bool {
switch runtime.GOOS {
case "darwin":
cmd := exec.Command("defaults", "read", "-g", "AppleInterfaceStyle")
output, err := cmd.Output()
if err == nil && strings.TrimSpace(string(output)) == "Dark" {
return true
}
case "windows":
cmd := exec.Command("reg", "query", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "/v", "AppsUseLightTheme")
output, err := cmd.Output()
if err == nil && strings.Contains(string(output), "REG_DWORD") && strings.Contains(string(output), "0x0") {
return true
}
case "linux":
cmd := exec.Command("gsettings", "get", "org.gnome.desktop.interface", "gtk-theme")
output, err := cmd.Output()
if err == nil && strings.Contains(string(output), "-dark") {
return true
}
}
return false
}