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:
Jakub
2022-05-26 11:35:15 +02:00
committed by Jakub Cuth
parent f40f002bf9
commit e3fe33245e
18 changed files with 245 additions and 125 deletions

View File

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