fix(windows): make installer upgrades version aware
This commit is contained in:
1 parent
6906ed52f2
commit
ee7844cb40
14 files changed
+824
-51
No files matched your search
@@ -21,4 +21,6 @@ func Run(context.Context, string, io.Writer) error { return ErrUnsupported }
|
||||
|
||||
func WaitReady(context.Context) error { return ErrUnsupported }
|
||||
|
||||
func IsReady() bool { return false }
|
||||
|
||||
func CloseCurrent(context.Context) error { return ErrUnsupported }
|
||||
@@ -493,25 +493,11 @@ func (window *trayWindow) applyResponse() {
|
||||
// session. It confirms Shell has accepted an actual icon, not merely that a
|
||||
// child process was spawned. It never opens daemon config or state.
|
||||
func WaitReady(ctx context.Context) error {
|
||||
class, _ := winapi.UTF16PtrFromString("RVBoxTrayWindowV1")
|
||||
type identifier struct {
|
||||
Size uint32
|
||||
HWnd uintptr
|
||||
UID uint32
|
||||
GUID [16]byte
|
||||
}
|
||||
type rectangle struct{ Left, Top, Right, Bottom int32 }
|
||||
timer := time.NewTicker(50 * time.Millisecond)
|
||||
defer timer.Stop()
|
||||
for {
|
||||
hwnd, _, _ := procFindWindow.Call(uintptr(unsafe.Pointer(class)), 0)
|
||||
if hwnd != 0 {
|
||||
id := identifier{Size: uint32(unsafe.Sizeof(identifier{})), HWnd: hwnd, UID: trayIconID}
|
||||
var rect rectangle
|
||||
result, _, _ := procShellIconRect.Call(uintptr(unsafe.Pointer(&id)), uintptr(unsafe.Pointer(&rect)))
|
||||
if iconQuerySucceeded(result) {
|
||||
return nil
|
||||
}
|
||||
if IsReady() {
|
||||
return nil
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -521,23 +507,64 @@ func WaitReady(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// IsReady probes this desktop once; it neither contacts SCM nor starts a tray.
|
||||
func IsReady() bool {
|
||||
class, _ := winapi.UTF16PtrFromString("RVBoxTrayWindowV1")
|
||||
type identifier struct {
|
||||
Size uint32
|
||||
HWnd uintptr
|
||||
UID uint32
|
||||
GUID [16]byte
|
||||
}
|
||||
type rectangle struct{ Left, Top, Right, Bottom int32 }
|
||||
hwnd, _, _ := procFindWindow.Call(uintptr(unsafe.Pointer(class)), 0)
|
||||
if hwnd != 0 {
|
||||
id := identifier{Size: uint32(unsafe.Sizeof(identifier{})), HWnd: hwnd, UID: trayIconID}
|
||||
var rect rectangle
|
||||
result, _, _ := procShellIconRect.Call(uintptr(unsafe.Pointer(&id)), uintptr(unsafe.Pointer(&rect)))
|
||||
if iconQuerySucceeded(result) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CloseCurrent lets an elevated installer update the canonical executable
|
||||
// without leaving this desktop's old frontend holding the image open. It is
|
||||
// deliberately a same-session window message, not service session injection.
|
||||
// a same-session window message followed by waiting for process exit.
|
||||
func CloseCurrent(ctx context.Context) error {
|
||||
class, _ := winapi.UTF16PtrFromString("RVBoxTrayWindowV1")
|
||||
timer := time.NewTicker(50 * time.Millisecond)
|
||||
defer timer.Stop()
|
||||
for {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
hwnd, _, _ := procFindWindow.Call(uintptr(unsafe.Pointer(class)), 0)
|
||||
if hwnd == 0 {
|
||||
return nil
|
||||
}
|
||||
var pid uint32
|
||||
_, _, _ = user32Tray.NewProc("GetWindowThreadProcessId").Call(hwnd, uintptr(unsafe.Pointer(&pid)))
|
||||
process, err := winapi.OpenProcess(winapi.SYNCHRONIZE, false, pid)
|
||||
if err != nil {
|
||||
if errors.Is(err, winapi.ERROR_INVALID_PARAMETER) {
|
||||
continue
|
||||
}
|
||||
return fmt.Errorf("wait for old tray process: %w", err)
|
||||
}
|
||||
_, _, _ = procPostMessage.Call(hwnd, wmClose, 0, 0)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-timer.C:
|
||||
for {
|
||||
result, waitErr := winapi.WaitForSingleObject(process, 50)
|
||||
if waitErr != nil || result == winapi.WAIT_OBJECT_0 {
|
||||
_ = winapi.CloseHandle(process)
|
||||
if waitErr != nil {
|
||||
return waitErr
|
||||
}
|
||||
break
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
_ = winapi.CloseHandle(process)
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user