forked from Silverfish/proton-bridge
GODT-1523: Reduce unnecessary shell executions. Inspired by @kortschak.
This commit is contained in:
@ -21,15 +21,34 @@
|
||||
package theme
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"golang.org/x/sys/execabs"
|
||||
"howett.net/plist"
|
||||
)
|
||||
|
||||
func detectSystemTheme() Theme {
|
||||
out, err := execabs.Command("defaults", "read", "-g", "AppleInterfaceStyle").Output() //nolint:gosec
|
||||
if err == nil && strings.TrimSpace(string(out)) == "Dark" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return Light
|
||||
}
|
||||
|
||||
path := filepath.Join(home, "/Library/Preferences/.GlobalPreferences.plist")
|
||||
prefFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
return Light
|
||||
}
|
||||
defer prefFile.Close()
|
||||
|
||||
var data struct {
|
||||
AppleInterfaceStyle string `plist:AppleInterfaceStyle`
|
||||
}
|
||||
|
||||
dec := plist.NewDecoder(prefFile)
|
||||
err = dec.Decode(&data)
|
||||
if err == nil && data.AppleInterfaceStyle == "Dark" {
|
||||
return Dark
|
||||
}
|
||||
|
||||
return Light
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user