Skip to content

Commit 651133c

Browse files
committed
Merge branch 'wincmd'
2 parents e288014 + 782bb28 commit 651133c

File tree

4 files changed

+151
-69
lines changed

4 files changed

+151
-69
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2023 Shift Crypto AG
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build darwin
16+
// +build darwin
17+
18+
package main
19+
20+
import (
21+
"os/exec"
22+
"strings"
23+
24+
"github.com/digitalbitbox/bitbox-wallet-app/util/logging"
25+
)
26+
27+
// detect theme used by OS and return true if it's dark
28+
func detectDarkTheme() bool {
29+
log := logging.Get().WithGroup("server")
30+
cmd := exec.Command("defaults", "read", "-g", "AppleInterfaceStyle")
31+
out, err := cmd.Output()
32+
if err == nil {
33+
log.Info("MacOS theme: " + string(out))
34+
if strings.TrimSpace(string(out)) == "Dark" {
35+
return true
36+
}
37+
}
38+
return false
39+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2023 Shift Crypto AG
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build linux
16+
// +build linux
17+
18+
package main
19+
20+
import (
21+
"os"
22+
"os/exec"
23+
24+
"github.com/digitalbitbox/bitbox-wallet-app/util/logging"
25+
)
26+
27+
func detectDarkTheme() bool {
28+
log := logging.Get().WithGroup("server")
29+
// Try KDE first, since Kubuntu can also have `gsettings` and that can lead to wrong results
30+
cmd := exec.Command("kreadconfig5", "--file", os.ExpandEnv("$HOME/.config/kdeglobals"), "--group", "General", "--key", "ColorScheme")
31+
out, err := cmd.Output()
32+
if err == nil {
33+
log.Info("kde theme: " + string(out))
34+
if matchDarkTheme(string(out)) {
35+
return true
36+
}
37+
}
38+
39+
// Try Gnome/Ubuntu
40+
cmd = exec.Command("gsettings", "get", "org.gnome.desktop.interface", "color-scheme")
41+
out, err = cmd.Output()
42+
if err == nil {
43+
log.Info("Gnome/Ubuntu theme: " + string(out))
44+
if matchDarkTheme(string(out)) {
45+
return true
46+
}
47+
}
48+
49+
// Try Cinnamon
50+
cmd = exec.Command("gsettings", "get", "org.cinnamon.desktop.interface", "gtk-theme")
51+
out, err = cmd.Output()
52+
if err == nil {
53+
log.Info("Cinnamon theme: " + string(out))
54+
if matchDarkTheme(string(out)) {
55+
return true
56+
}
57+
}
58+
59+
// Try XFCE4
60+
cmd = exec.Command("xfconf-query", "-c", "xsettings", "-p", "/Net/ThemeName")
61+
out, err = cmd.Output()
62+
if err == nil {
63+
log.Info("xfce theme: " + string(out))
64+
if matchDarkTheme(string(out)) {
65+
return true
66+
}
67+
}
68+
return false
69+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2023 Shift Crypto AG
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build windows
16+
// +build windows
17+
18+
package main
19+
20+
import (
21+
"os/exec"
22+
"strings"
23+
"syscall"
24+
25+
"github.com/digitalbitbox/bitbox-wallet-app/util/logging"
26+
)
27+
28+
// detect theme used by OS and return true if it's dark
29+
func detectDarkTheme() bool {
30+
log := logging.Get().WithGroup("server")
31+
const regKey = `HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize`
32+
const regName = `AppsUseLightTheme`
33+
cmd := exec.Command("reg", "query", regKey, "/v", regName)
34+
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
35+
out, err := cmd.Output()
36+
if err == nil {
37+
log.Info("windows theme: " + string(out))
38+
if strings.Contains(string(out), "0x0") {
39+
return true
40+
}
41+
}
42+
return false
43+
}

frontends/qt/server/server.go

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import "C"
5454
import (
5555
"flag"
5656
"os"
57-
"os/exec"
5857
"runtime"
5958
"strings"
6059
"unsafe"
@@ -96,74 +95,6 @@ func matchDarkTheme(themeName string) bool {
9695
return strings.Contains(strings.ToLower(themeName), "dark")
9796
}
9897

99-
// detect theme used by OS and return true if it's dark
100-
func detectDarkTheme() bool {
101-
log := logging.Get().WithGroup("server")
102-
switch myos := runtime.GOOS; myos {
103-
case "darwin":
104-
cmd := exec.Command("defaults", "read", "-g", "AppleInterfaceStyle")
105-
out, err := cmd.Output()
106-
if err == nil {
107-
log.Info("MacOS theme: " + string(out))
108-
if strings.TrimSpace(string(out)) == "Dark" {
109-
return true
110-
}
111-
}
112-
case "linux":
113-
// Try KDE first, since Kubuntu can also have `gsettings` and that can lead to wrong results
114-
cmd := exec.Command("kreadconfig5", "--file", os.ExpandEnv("$HOME/.config/kdeglobals"), "--group", "General", "--key", "ColorScheme")
115-
out, err := cmd.Output()
116-
if err == nil {
117-
log.Info("kde theme: " + string(out))
118-
if matchDarkTheme(string(out)) {
119-
return true
120-
}
121-
}
122-
123-
// Try Gnome/Ubuntu
124-
cmd = exec.Command("gsettings", "get", "org.gnome.desktop.interface", "color-scheme")
125-
out, err = cmd.Output()
126-
if err == nil {
127-
log.Info("Gnome/Ubuntu theme: " + string(out))
128-
if matchDarkTheme(string(out)) {
129-
return true
130-
}
131-
}
132-
133-
// Try Cinnamon
134-
cmd = exec.Command("gsettings", "get", "org.cinnamon.desktop.interface", "gtk-theme")
135-
out, err = cmd.Output()
136-
if err == nil {
137-
log.Info("Cinnamon theme: " + string(out))
138-
if matchDarkTheme(string(out)) {
139-
return true
140-
}
141-
}
142-
143-
// Try XFCE4
144-
cmd = exec.Command("xfconf-query", "-c", "xsettings", "-p", "/Net/ThemeName")
145-
out, err = cmd.Output()
146-
if err == nil {
147-
log.Info("xfce theme: " + string(out))
148-
if matchDarkTheme(string(out)) {
149-
return true
150-
}
151-
}
152-
case "windows":
153-
const regKey = `HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize`
154-
const regName = `AppsUseLightTheme`
155-
cmd := exec.Command("reg", "query", regKey, "/v", regName)
156-
out, err := cmd.Output()
157-
if err == nil {
158-
log.Info("windows theme: " + string(out))
159-
if strings.Contains(string(out), "0x0") {
160-
return true
161-
}
162-
}
163-
}
164-
return false
165-
}
166-
16798
//export serve
16899
func serve(
169100
cppHeapFreeFn C.cppHeapFree,

0 commit comments

Comments
 (0)