mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 23:56:56 +00:00
GODT-1523: Reduce unnecessary shell executions. Inspired by @kortschak.
- check opened file descriptors - detection of darwin version - detection of apple interface color theme - test for update sync (copy files) - replace exec with execabs
This commit is contained in:
@ -21,14 +21,34 @@
|
||||
package theme
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"howett.net/plist"
|
||||
)
|
||||
|
||||
func detectSystemTheme() Theme {
|
||||
out, err := exec.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