Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
hopefully fix autoupdater when running in program files
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsMePepijn committed Nov 1, 2023
1 parent a1b697a commit 76ffffb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions helpers/updateServiceHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"os"
"slices"
"strings"
"syscall"

"github.com/hashicorp/go-version"
"github.com/inconshreveable/go-update"
"github.com/sqweek/dialog"
"golang.org/x/sys/windows"
)

type Asset struct {
Expand Down Expand Up @@ -125,6 +127,11 @@ func CheckForUpdates(WailsConfigFile []byte) {
}

func DownladAndInstallUpdate(source string) {
if !IsAdmin() {
RunMeElevated()
return
}

println("Installing new release...")
res, err := http.Get(source)

Expand All @@ -145,3 +152,29 @@ func DownladAndInstallUpdate(source string) {
dialog.Message("%s", "Successfully installed new release!").Title("Update installed!").Info()
os.Exit(0)
}

func RunMeElevated() {
verb := "runas"
exe, _ := os.Executable()
cwd, _ := os.Getwd()
args := strings.Join(os.Args[1:], " ")

verbPtr, _ := syscall.UTF16PtrFromString(verb)
exePtr, _ := syscall.UTF16PtrFromString(exe)
cwdPtr, _ := syscall.UTF16PtrFromString(cwd)
argPtr, _ := syscall.UTF16PtrFromString(args)

var showCmd int32 = 1 //SW_NORMAL

err := windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, showCmd)
if err != nil {
fmt.Println(err)
}
os.Exit(0)
}

func IsAdmin() bool {
elevated := windows.GetCurrentProcessToken().IsElevated()
fmt.Printf("admin %v\n", elevated)
return elevated
}

0 comments on commit 76ffffb

Please sign in to comment.