Skip to content

Commit ebe60cd

Browse files
committed
fix: split isAdmin to platform files
1 parent 54f4cad commit ebe60cd

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

spicetify.go

+2-32
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/spicetify/cli/src/cmd"
1818
spotifystatus "github.com/spicetify/cli/src/status/spotify"
1919
"github.com/spicetify/cli/src/utils"
20-
"golang.org/x/sys/windows"
20+
"github.com/spicetify/cli/src/utils/isAdmin"
2121
)
2222

2323
var (
@@ -36,36 +36,6 @@ var (
3636
bypassAdminCheck = false
3737
)
3838

39-
func isAdmin(bypassAdminCheck bool) bool {
40-
if bypassAdminCheck {
41-
return false
42-
}
43-
44-
switch runtime.GOOS {
45-
case "windows":
46-
var sid *windows.SID
47-
err := windows.AllocateAndInitializeSid(
48-
&windows.SECURITY_NT_AUTHORITY,
49-
2,
50-
windows.SECURITY_BUILTIN_DOMAIN_RID,
51-
windows.DOMAIN_ALIAS_RID_ADMINS,
52-
0, 0, 0, 0, 0, 0,
53-
&sid)
54-
if err != nil {
55-
return false
56-
}
57-
defer windows.FreeSid(sid)
58-
59-
token := windows.Token(0)
60-
member, err := token.IsMember(sid)
61-
return err == nil && member
62-
63-
case "linux", "darwin":
64-
return os.Geteuid() == 0
65-
}
66-
return false
67-
}
68-
6939
func init() {
7040
if runtime.GOOS != "windows" &&
7141
runtime.GOOS != "darwin" &&
@@ -144,7 +114,7 @@ func init() {
144114
os.Stdout = nil
145115
}
146116

147-
if isAdmin(bypassAdminCheck) {
117+
if isAdmin.Check(bypassAdminCheck) {
148118
utils.PrintError("Spicetify should not be run with administrator/root privileges")
149119
utils.PrintError("Running as admin can cause Spotify to show a black/blank window after applying spicetify")
150120
utils.PrintError("This happens because Spotify (running as a normal user) can't access files modified with admin privileges")

src/utils/isAdmin/unix.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package isAdmin
5+
6+
import "os"
7+
8+
func Check(bypassAdminCheck bool) bool {
9+
if bypassAdminCheck {
10+
return false
11+
}
12+
return os.Geteuid() == 0
13+
}

src/utils/isAdmin/windows.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package isAdmin
5+
6+
import (
7+
"golang.org/x/sys/windows"
8+
)
9+
10+
func Check(bypassAdminCheck bool) bool {
11+
if bypassAdminCheck {
12+
return false
13+
}
14+
15+
var sid *windows.SID
16+
err := windows.AllocateAndInitializeSid(
17+
&windows.SECURITY_NT_AUTHORITY,
18+
2,
19+
windows.SECURITY_BUILTIN_DOMAIN_RID,
20+
windows.DOMAIN_ALIAS_RID_ADMINS,
21+
0, 0, 0, 0, 0, 0,
22+
&sid)
23+
if err != nil {
24+
return false
25+
}
26+
defer windows.FreeSid(sid)
27+
28+
token := windows.Token(0)
29+
member, err := token.IsMember(sid)
30+
return err == nil && member
31+
}

0 commit comments

Comments
 (0)