mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 13:16:53 +00:00
GODT-1523: Reduce unnecessary shell executions. Inspired by @kortschak.
This commit is contained in:
@ -28,10 +28,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/internal/config/useragent"
|
||||
"github.com/ProtonMail/proton-bridge/internal/frontend/types"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/mobileconfig"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/config/useragent"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/frontend/types"
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/mobileconfig"
|
||||
"golang.org/x/sys/execabs"
|
||||
)
|
||||
|
||||
|
||||
@ -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