diff --git a/docker.go b/docker.go index b5b99d1..e3ee0b1 100644 --- a/docker.go +++ b/docker.go @@ -46,13 +46,13 @@ services: return dockerComposeFile } -func batchCreateDockerContainers(menuItems []MenuItem, logView *tview.TextView) []error { +func batchCreateDockerContainers(menuItems []MenuItem, frame *tview.Frame) []error { var errors []error for _, item := range menuItems { if !item.Config.IsConfigured() { continue } - _, err := item.Config.ConfigureDocker(KIND_DIRECTLY_CONFIGURE_DOCKER, logView) + _, err := item.Config.ConfigureDocker(KIND_DIRECTLY_CONFIGURE_DOCKER, frame) if err != nil { errors = append(errors, err) } @@ -94,12 +94,14 @@ func pullImageBlocking(imageName string, logView *tview.TextView) error { return nil } -func createContainer(name string, containerConfig *container.Config, hostConfig *container.HostConfig, logView *tview.TextView) error { +func createContainer(name string, containerConfig *container.Config, hostConfig *container.HostConfig, frame *tview.Frame) error { client, err := getDockerClient() if err != nil { return err } + logView := frame.GetPrimitive().(*tview.TextView) + if err := pullImageBlocking(containerConfig.Image, logView); err != nil { return err } diff --git a/earnapp.go b/earnapp.go index 1f45aea..001cc41 100644 --- a/earnapp.go +++ b/earnapp.go @@ -64,7 +64,7 @@ func (i *EarnAppConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app }) } -func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) { +func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) { switch kind { case KIND_DOCKER_COMPOSE: return `earnapp: @@ -96,7 +96,7 @@ func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.Te }, }, } - return "", createContainer("earnapp", containerConfig, hostConfig, logView) + return "", createContainer("earnapp", containerConfig, hostConfig, frame) default: return "", errors.New("unknown kind") } diff --git a/grass.go b/grass.go index 3632d13..000aed8 100644 --- a/grass.go +++ b/grass.go @@ -51,7 +51,7 @@ func (i *GrassConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app *t }) } -func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) { +func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) { switch kind { case KIND_DOCKER_COMPOSE: return `grass: @@ -74,7 +74,7 @@ func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.Text Name: "unless-stopped", }, } - return "", createContainer("grass", containerConfig, hostConfig, logView) + return "", createContainer("grass", containerConfig, hostConfig, frame) default: return "", errors.New("unknown kind") } diff --git a/honeygain.go b/honeygain.go index 9c54d12..13d2464 100644 --- a/honeygain.go +++ b/honeygain.go @@ -57,7 +57,7 @@ func (i *HoneygainConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, ap }) } -func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) { +func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) { switch kind { case KIND_DOCKER_COMPOSE: return `honeygain: @@ -87,7 +87,7 @@ func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, logView *tview. i.DeviceName, }, } - return "", createContainer("honeygain", containerConfig, hostConfig, logView) + return "", createContainer("honeygain", containerConfig, hostConfig, frame) default: return "", errors.New("unknown kind") } diff --git a/main.go b/main.go index 60392af..42845a0 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ func main() { form := tview.NewForm() - frame := tview.NewFrame(list). + mainFrame := tview.NewFrame(list). AddText("Passive Machine", true, tview.AlignCenter, tview.Styles.PrimaryTextColor). AddText("Tip: Use the Register button to sign up for the service", true, tview.AlignCenter, tview.Styles.ContrastSecondaryTextColor) @@ -32,7 +32,7 @@ func main() { for _, item := range menuItems { list.AddItem(item.GetName(), item.GetDescription(), 0, func() { form.Clear(true) - item.Config.ConfigureForm(form, frame, app) + item.Config.ConfigureForm(form, mainFrame, app) app.SetRoot(form, true) }) } @@ -49,28 +49,35 @@ func main() { } }) form.AddButton("Return", func() { - returnToMenu(frame, app) + returnToMenu(mainFrame, app) }) app.SetRoot(form, true) }) list.AddItem("[*] Create Docker Containers", "Create docker containers from the selected items (Recommended)", 0, func() { - logView := tview.NewTextView() - form.Clear(true) - form.AddFormItem(logView) - errors := batchCreateDockerContainers(menuItems, logView) - if len(errors) == 0 { - form.AddTextView("Success", "All containers created successfully", 0, 0, true, false) - } else { - form.AddTextView("Errors", "Some containers failed to create", 0, 0, true, false) - for _, err := range errors { - form.AddTextView("Error", err.Error(), 0, 1, true, false) + dockerFrame := tview.NewFrame(tview.NewTextView(). + SetDynamicColors(true). + SetChangedFunc(func() { + app.Draw() + })). + AddText("Creating Docker Containers", true, tview.AlignCenter, tview.Styles.PrimaryTextColor). + AddText("This may take a while", true, tview.AlignCenter, tview.Styles.ContrastSecondaryTextColor) + + go func() { + errors := batchCreateDockerContainers(menuItems, dockerFrame) + if len(errors) == 0 { + form.AddTextView("Success", "All containers created successfully", 0, 0, true, false) + } else { + form.AddTextView("Errors", "Some containers failed to create", 0, 0, true, false) + for _, err := range errors { + form.AddTextView("Error", err.Error(), 0, 1, true, false) + } } - } - form.AddButton("Return", func() { - returnToMenu(frame, app) - }) - app.SetRoot(form, true) + form.AddButton("Return", func() { + returnToMenu(mainFrame, app) + }) + }() + app.SetRoot(dockerFrame, true) }) - app.SetRoot(frame, true).Run() + app.SetRoot(mainFrame, true).Run() } diff --git a/menuItem.go b/menuItem.go index d6349a7..fbdd6fe 100644 --- a/menuItem.go +++ b/menuItem.go @@ -4,7 +4,7 @@ import "github.com/rivo/tview" type MenuItemConfig interface { ConfigureForm(form *tview.Form, frame *tview.Frame, app *tview.Application) - ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) + ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) IsConfigured() bool } diff --git a/mystnode.go b/mystnode.go index 84aabbe..36f024c 100644 --- a/mystnode.go +++ b/mystnode.go @@ -34,7 +34,7 @@ func (i *MystConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app *tv }) } -func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) { +func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) { switch kind { case KIND_DOCKER_COMPOSE: return `myst: @@ -73,7 +73,7 @@ func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextV }, }, } - return "", createContainer("myst", containerConfig, hostConfig, logView) + return "", createContainer("myst", containerConfig, hostConfig, frame) } return "", errors.New("unknown kind") } diff --git a/packetstream.go b/packetstream.go index 7c3927f..2c82be1 100644 --- a/packetstream.go +++ b/packetstream.go @@ -45,7 +45,7 @@ func (i *PacketStreamConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, }) } -func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) { +func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) { switch kind { case KIND_DOCKER_COMPOSE: return `packetstream: @@ -66,7 +66,7 @@ func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, logView *tvi Name: "unless-stopped", }, } - return "", createContainer("packetstream", containerConfig, hostConfig, logView) + return "", createContainer("packetstream", containerConfig, hostConfig, frame) default: return "", errors.New("unknown kind") } diff --git a/pawnsapp.go b/pawnsapp.go index d2d683c..c9ef5ff 100644 --- a/pawnsapp.go +++ b/pawnsapp.go @@ -57,7 +57,7 @@ func (i *PawnsAppConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app }) } -func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) { +func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) { switch kind { case KIND_DOCKER_COMPOSE: return `pawnsapp: @@ -80,7 +80,7 @@ func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.T Name: "unless-stopped", }, } - return "", createContainer("pawnsapp", containerConfig, hostConfig, logView) + return "", createContainer("pawnsapp", containerConfig, hostConfig, frame) default: return "", errors.New("unknown kind") } diff --git a/peer2profit.go b/peer2profit.go index b4acdc3..bd2a0b7 100644 --- a/peer2profit.go +++ b/peer2profit.go @@ -46,7 +46,7 @@ func (i *Peer2ProfitConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, }) } -func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) { +func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) { switch kind { case KIND_DOCKER_COMPOSE: compose := `peer2profit: @@ -80,7 +80,7 @@ func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, logView *tvie Name: "unless-stopped", }, } - if err := createContainer("binfmt", containerConfig, hostConfig, logView); err != nil { + if err := createContainer("binfmt", containerConfig, hostConfig, frame); err != nil { return "", err } } @@ -96,7 +96,7 @@ func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, logView *tvie Name: "unless-stopped", }, } - return "", createContainer("peer2profit", containerConfig, hostConfig, logView) + return "", createContainer("peer2profit", containerConfig, hostConfig, frame) } return "", errors.New("unknown kind") } diff --git a/watchtower.go b/watchtower.go index 67f8fc8..dfab11b 100644 --- a/watchtower.go +++ b/watchtower.go @@ -29,7 +29,7 @@ func (i *WatchtowerConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, a }) } -func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, logView *tview.TextView) (string, error) { +func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) { switch kind { case KIND_DOCKER_COMPOSE: return `watchtower: @@ -50,7 +50,7 @@ func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, logView *tview Name: "always", }, } - return "", createContainer("watchtower", containerConfig, hostConfig, logView) + return "", createContainer("watchtower", containerConfig, hostConfig, frame) default: return "", errors.New("unknown kind") }