Skip to content

Commit

Permalink
gui: Introduces a pre-check page
Browse files Browse the repository at this point in the history
Fixes #416.
After the language is selected, the pre-check page checks if the
prerequisites for the installation are met.
Currently the checks include system compatibility and network
connectivity.

Fixes the progress failure status to show a different color.

Refactored to remove redundant code.

Displays the system check error.

Signed-off-by: Reagan Lopez <[email protected]>gui: Fixes window resize due to error message
  • Loading branch information
reaganlo committed Jun 27, 2019
1 parent eb019bc commit d65510b
Show file tree
Hide file tree
Showing 13 changed files with 541 additions and 138 deletions.
17 changes: 12 additions & 5 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ var (
NetworkPassing bool
)

const (
// NetWorkManager is the application to manage network.
NetWorkManager = "Network Manager"
)

func sortMountPoint(bds []*storage.BlockDevice) []*storage.BlockDevice {
sort.Slice(bds[:], func(i, j int) bool {
return filepath.HasPrefix(bds[j].MountPoint, bds[i].MountPoint)
Expand Down Expand Up @@ -568,11 +573,11 @@ func configureNetwork(model *model.SystemInstall) (progress.Progress, error) {
}

msg := utils.Locale.Get("Testing connectivity")
prg := progress.NewLoop(msg)
attempts := 3
prg := progress.MultiStep(attempts, msg)
ok := false

// 3 attempts to test connectivity
for i := 0; i < 3; i++ {
for i := 0; i < attempts; i++ {
time.Sleep(2 * time.Second)

log.Info(msg)
Expand All @@ -589,10 +594,13 @@ func configureNetwork(model *model.SystemInstall) (progress.Progress, error) {
ok = false
break
}
prg.Partial(i + 1)
}

if !ok {
return prg, errors.Errorf(utils.Locale.Get("Network is not working."))
msg = utils.Locale.Get("Network check failed.")
msg += " " + utils.Locale.Get("Use %s to configure network.", NetWorkManager)
return prg, errors.Errorf(msg)
}

prg.Success()
Expand Down Expand Up @@ -654,7 +662,6 @@ func configureLanguage(rootDir string, model *model.SystemInstall) error {
log.Info(msg)

err := language.SetTargetLanguage(rootDir, model.Language.Code)
//utils.SetLocale(model.Language.Code)
if err != nil {
prg.Failure()
return err
Expand Down
10 changes: 10 additions & 0 deletions gui/common/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package common

import (
"time"

"github.com/gotk3/gotk3/gtk"

"github.com/clearlinux/clr-installer/log"
Expand All @@ -17,6 +19,14 @@ const (
ButtonSpacing int = 4
)

var (
// LoopWaitDuration is a common loop wait duration used in pages
LoopWaitDuration = 200 * time.Millisecond

// LoopTimeOutDuration is a common loop timeout duration used in pages
LoopTimeOutDuration = 10000 * time.Millisecond // 10 seconds
)

// CreateDialog creates a gtk dialog with no buttons
func CreateDialog(contentBox *gtk.Box, title string) (*gtk.Dialog, error) {
var err error
Expand Down
10 changes: 3 additions & 7 deletions gui/pages/disk_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import (
"github.com/clearlinux/clr-installer/utils"
)

var (
loopTimeOutDuration = 10000 * time.Millisecond // 10 seconds
)

// DiskConfig is a simple page to help with DiskConfig settings
type DiskConfig struct {
devs []*storage.BlockDevice
Expand Down Expand Up @@ -276,11 +272,11 @@ func (disk *DiskConfig) runScanLoop() {
case <-disk.controller.GetScanChannel():
return
default:
time.Sleep(loopWaitDuration)
duration += loopWaitDuration
time.Sleep(common.LoopWaitDuration)
duration += common.LoopWaitDuration
// Safety check. In case reading the channel gets delayed for some reason,
// do not hold up loading the page.
if duration > loopTimeOutDuration {
if duration > common.LoopTimeOutDuration {
return
}
}
Expand Down
3 changes: 3 additions & 0 deletions gui/pages/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const (
// PageIDWelcome is the language page key
PageIDWelcome = iota

// PageIDPreCheck is the pre-check page key
PageIDPreCheck = iota

// PageIDTimezone is the timezone page key
PageIDTimezone = iota

Expand Down
7 changes: 2 additions & 5 deletions gui/pages/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ import (
"github.com/gotk3/gotk3/gtk"

ctrl "github.com/clearlinux/clr-installer/controller"
"github.com/clearlinux/clr-installer/gui/common"
"github.com/clearlinux/clr-installer/log"
"github.com/clearlinux/clr-installer/model"
"github.com/clearlinux/clr-installer/network"
"github.com/clearlinux/clr-installer/progress"
"github.com/clearlinux/clr-installer/utils"
)

var (
loopWaitDuration = 200 * time.Millisecond
)

// InstallPage is a specialised page type with no corresponding
// ContentView summary. It handles the actual install routine.
type InstallPage struct {
Expand Down Expand Up @@ -279,7 +276,7 @@ func (page *InstallPage) Success() {

// LoopWaitDuration will return the duration for step-waits
func (page *InstallPage) LoopWaitDuration() time.Duration {
return loopWaitDuration
return common.LoopWaitDuration
}

// Partial handles an actual progress update
Expand Down
18 changes: 10 additions & 8 deletions gui/pages/install_widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package pages

import (
"github.com/gotk3/gotk3/gtk"

"github.com/clearlinux/clr-installer/log"
)

// InstallWidget provides a description with tickes/crosses to let the user
Expand Down Expand Up @@ -57,14 +59,14 @@ func NewInstallWidget(desc string) (*InstallWidget, error) {
func (widget *InstallWidget) MarkStatus(success bool) {
if success {
widget.image.SetFromIconName("object-select-symbolic", gtk.ICON_SIZE_BUTTON)
return
}

widget.image.SetFromIconName("window-close-symbolic", gtk.ICON_SIZE_BUTTON)
// Make it red.
st, err := widget.image.GetStyleContext()
if err == nil {
st.AddClass("destructive-action")
} else {
widget.image.SetFromIconName("window-close-symbolic", gtk.ICON_SIZE_BUTTON)
sc, err := widget.image.GetStyleContext()
if err != nil {
log.Warning("Error getting style context: ", err) // Just log trivial error
} else {
sc.AddClass("label-warning")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gui/pages/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (page *LanguagePage) GetTitle() string {

// StoreChanges will store this pages changes into the model
func (page *LanguagePage) StoreChanges() {
page.controller.SetButtonState(ButtonNext, false) // TODO: Determine why the button is not actually being disabled
page.controller.SetButtonState(ButtonNext, false)
page.model.Language = page.selected
language.SetSelectionLanguage(page.model.Language.Code)
utils.SetLocale(page.model.Language.Code)
Expand Down
Loading

0 comments on commit d65510b

Please sign in to comment.