Browse Source

refactor: Remove obsolete analysis file and improve Windows admin privilege check in main.go

- Deleted the outdated analysis file that contained error diagnostics and solutions.
- Updated the checkAdminPrivileges function in main.go to use a more reliable method for checking Windows administrator privileges, enhancing security and accuracy.
- Fixed a minor display issue in the success message output.
- Added "apprun" to the cSpell dictionary in .vscode/settings.json for improved spell checking.

These changes streamline the codebase and enhance the functionality of the application.
pull/30/head
Xx 6 months ago
parent
commit
24287ac575
  1. 1
      .vscode/settings.json
  2. 8
      analysis
  3. 17
      main.go

1
.vscode/settings.json

@ -1,5 +1,6 @@
{ {
"cSpell.words": [ "cSpell.words": [
"apprun",
"buildmode", "buildmode",
"dylib", "dylib",
"endlocal", "endlocal",

8
analysis

@ -1,8 +0,0 @@
1. 问题定位
- 错误发生在第68行附近的 `}` 处
- 这是一个 shell 脚本语法错误
- 检查发现是 check_requirements 函数中的花括号闭合问题
2. 解决方案
- 移除多余的花括号
- 确保函数语法正确

17
main.go

@ -482,7 +482,7 @@ func showSuccess() {
successColor.Printf("%s\n", text.SuccessMessage) successColor.Printf("%s\n", text.SuccessMessage)
fmt.Println() fmt.Println()
warningColor.Printf("%s\n", text.RestartMessage) warningColor.Printf("%s\n", text.RestartMessage)
successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━���━━━")
successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
} }
// Add spacing before config location // Add spacing before config location
@ -527,13 +527,14 @@ func showPrivilegeError() {
func checkAdminPrivileges() (bool, error) { func checkAdminPrivileges() (bool, error) {
switch runtime.GOOS { switch runtime.GOOS {
case "windows": case "windows":
cmd := exec.Command("whoami", "/groups")
output, err := cmd.Output()
if err != nil {
return false, err
// 使用更可靠的方法检查Windows管理员权限
cmd := exec.Command("net", "session")
err := cmd.Run()
if err == nil {
return true, nil
} }
return strings.Contains(string(output), "S-1-16-12288") ||
strings.Contains(string(output), "S-1-5-32-544"), nil
// 如果命令执行失败,说明没有管理员权限
return false, nil
case "darwin", "linux": case "darwin", "linux":
currentUser, err := user.Current() currentUser, err := user.Current()
@ -841,7 +842,7 @@ func main() {
// Progress spinner functions / 进度条函数 // Progress spinner functions / 进度条函数
func NewProgressSpinner(message string) *ProgressSpinner { func NewProgressSpinner(message string) *ProgressSpinner {
return &ProgressSpinner{ return &ProgressSpinner{
frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "", "⠏"},
frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "��", "⠏"},
message: message, message: message,
} }
} }

Loading…
Cancel
Save