Files
rvbox/cmd/rvbox/installer_flow.go
T

60 lines
1.7 KiB
Go

package main
import (
"fmt"
"github.com/rvbox/rvbox/internal/client/windowsservice"
)
type installerSnapshot struct {
Installed bool
SameVersion bool
ServiceState windowsservice.State
TrayReady bool
}
type installerActions struct {
Inspect func() (installerSnapshot, error)
Install func() error
StartService func() error
StartTray func() error
}
// A true result means a fresh install/upgrade completed and may show its one
// success dialog. Same-version activation and the healthy no-op stay silent.
func ensureInstallerRunning(actions installerActions) (bool, error) {
state, err := actions.Inspect()
if err != nil {
return false, fmt.Errorf("inspect installed RVBox: %w", err)
}
if !state.Installed || !state.SameVersion {
if err := runInstallerSteps(actions.Install, actions.StartTray); err != nil {
return false, err
}
return true, nil
}
if state.ServiceState != windowsservice.StateRunning {
if err := actions.StartService(); err != nil {
return false, fmt.Errorf("start installed RVBox service: %w", err)
}
}
if !state.TrayReady {
if err := actions.StartTray(); err != nil {
return false, fmt.Errorf("start installed notification-area icon: %w", err)
}
}
return false, nil
}
// Keep the original (normally unelevated) interactive process alive while its
// UAC child installs. Only successful installation may start the user frontend.
func runInstallerSteps(install func() error, startTray func() error) error {
if err := install(); err != nil {
return fmt.Errorf("install RVBox: %w", err)
}
if err := startTray(); err != nil {
return fmt.Errorf("RVBox is installed, but its notification-area icon could not start: %w", err)
}
return nil
}