added installation progress tab
This commit is contained in:
parent
9e5457c2ec
commit
ad826b3b43
3 changed files with 254 additions and 76 deletions
49
installer.go
49
installer.go
|
@ -13,11 +13,12 @@ type Installer struct {
|
|||
Task string
|
||||
|
||||
// Internal states
|
||||
IsDownloading bool
|
||||
IsInstalling bool
|
||||
DoneDownload bool
|
||||
DoneInstall bool
|
||||
LastError error
|
||||
IsDownloading bool
|
||||
IsInstalling bool
|
||||
DoneDownload bool
|
||||
DoneInstall bool
|
||||
LastError error
|
||||
PendingInstall bool
|
||||
|
||||
// Paths
|
||||
DownloadDir string
|
||||
|
@ -36,13 +37,18 @@ func (inst *Installer) StartDownloadDecompress() {
|
|||
defer func() {
|
||||
inst.IsDownloading = false
|
||||
inst.DoneDownload = (inst.LastError == nil)
|
||||
|
||||
// If user requested install while we were downloading (PendingInstall),
|
||||
// automatically do the install now that we're done decompressing.
|
||||
if inst.PendingInstall && inst.DoneDownload && !inst.IsInstalling && !inst.DoneInstall {
|
||||
inst.doFinalInstall()
|
||||
}
|
||||
}()
|
||||
|
||||
// Prepare download directory
|
||||
spm.UpdateProgress(0, "Preparing to download...")
|
||||
inst.DownloadDir = spm.GetTempDownloadDir()
|
||||
|
||||
// Download APPINDEX
|
||||
// 1) Download APPINDEX
|
||||
appIndexPath := filepath.Join(inst.DownloadDir, "APPINDEX")
|
||||
spm.UpdateProgress(0, "Downloading APPINDEX")
|
||||
if err := spm.DownloadAppIndex(appIndexPath); err != nil {
|
||||
|
@ -50,7 +56,7 @@ func (inst *Installer) StartDownloadDecompress() {
|
|||
return
|
||||
}
|
||||
|
||||
// Download package
|
||||
// 2) Download package
|
||||
packageName := "spitfire-browser"
|
||||
release := "nightly"
|
||||
spm.UpdateProgress(0, "Downloading package...")
|
||||
|
@ -59,7 +65,7 @@ func (inst *Installer) StartDownloadDecompress() {
|
|||
return
|
||||
}
|
||||
|
||||
// Decompress
|
||||
// 3) Decompress
|
||||
spm.UpdateProgress(0, "Decompressing...")
|
||||
packagePath := filepath.Join(inst.DownloadDir, "browser-amd64-nightly-linux.tar.gz")
|
||||
tempDir, err := spm.DecompressToTemp(packagePath)
|
||||
|
@ -67,19 +73,34 @@ func (inst *Installer) StartDownloadDecompress() {
|
|||
inst.LastError = err
|
||||
return
|
||||
}
|
||||
|
||||
inst.TempDir = tempDir
|
||||
}()
|
||||
}
|
||||
|
||||
// FinalInstall moves files to the final install directory in a background goroutine.
|
||||
// FinalInstall is called by the UI to request installation.
|
||||
// If download is done, it runs immediately, otherwise sets PendingInstall=true.
|
||||
func (inst *Installer) FinalInstall() {
|
||||
if !inst.DoneDownload {
|
||||
inst.LastError = fmt.Errorf("Cannot install: download and decompression are not complete")
|
||||
// Already installed or installing => ignore repeated calls
|
||||
if inst.IsInstalling || inst.DoneInstall {
|
||||
return
|
||||
}
|
||||
|
||||
// If not done downloading, just mark that we want to install once finished
|
||||
if !inst.DoneDownload {
|
||||
fmt.Println("Cannot install now: download and decompression not complete -> pending install.")
|
||||
inst.PendingInstall = true
|
||||
return
|
||||
}
|
||||
|
||||
// Otherwise, go ahead and install now
|
||||
inst.doFinalInstall()
|
||||
}
|
||||
|
||||
// doFinalInstall does the actual file move and sets states
|
||||
func (inst *Installer) doFinalInstall() {
|
||||
inst.IsInstalling = true
|
||||
inst.PendingInstall = false // we are fulfilling the install now
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
inst.IsInstalling = false
|
||||
|
@ -93,6 +114,8 @@ func (inst *Installer) FinalInstall() {
|
|||
return
|
||||
}
|
||||
|
||||
// Move files
|
||||
spm.UpdateProgress(0, "Installing...")
|
||||
if err := spm.MoveFilesToInstallDir(inst.TempDir, installDir); err != nil {
|
||||
inst.LastError = err
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue