add config
This commit is contained in:
parent
88a1f0f50f
commit
3330006c3f
@ -1,6 +1,10 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
@ -9,6 +13,8 @@ import (
|
||||
"gitea.unprism.ru/KRBL/FemaInstaller/pkg/config"
|
||||
)
|
||||
|
||||
var mu = sync.Mutex{}
|
||||
|
||||
// MainWindow represents the main application window
|
||||
type MainWindow struct {
|
||||
Window fyne.Window
|
||||
@ -24,6 +30,26 @@ type MainWindow struct {
|
||||
InstallButton *widget.Button
|
||||
}
|
||||
|
||||
func loadConfig() *config.SSHConfig {
|
||||
fileName := "config.json"
|
||||
if _, err := os.Stat(fileName); os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(fileName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var cfg config.SSHConfig
|
||||
err = json.Unmarshal(data, &cfg)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &cfg
|
||||
}
|
||||
|
||||
// NewMainWindow creates a new main window for the application
|
||||
func NewMainWindow(app fyne.App, installHandler func(*config.SSHConfig) error) *MainWindow {
|
||||
window := app.NewWindow("Fema Installer")
|
||||
@ -42,6 +68,19 @@ func NewMainWindow(app fyne.App, installHandler func(*config.SSHConfig) error) *
|
||||
StatusLabel: widget.NewLabel(""),
|
||||
}
|
||||
|
||||
cfg := loadConfig()
|
||||
|
||||
if cfg != nil {
|
||||
mainWindow.IPEntry.SetText(cfg.IP)
|
||||
mainWindow.PortEntry.SetText(cfg.Port)
|
||||
mainWindow.LoginEntry.SetText(cfg.Login)
|
||||
mainWindow.PasswordEntry.SetText(cfg.Password)
|
||||
mainWindow.SerialEntry.SetText(cfg.Serial)
|
||||
mainWindow.TailNumberEntry.SetText(cfg.TailNumber)
|
||||
mainWindow.DefaultHostEntry.SetText(cfg.DefaultHost)
|
||||
mainWindow.ArchivePathEntry.SetText(cfg.ArchivePath)
|
||||
}
|
||||
|
||||
// Disable archive path entry (will be set by file selector)
|
||||
mainWindow.ArchivePathEntry.Disable()
|
||||
|
||||
@ -73,7 +112,13 @@ func NewMainWindow(app fyne.App, installHandler func(*config.SSHConfig) error) *
|
||||
dialog.ShowInformation("Error", "Serial number must be 16 characters", window)
|
||||
return
|
||||
}
|
||||
mu.Lock()
|
||||
jsonData, _ := json.MarshalIndent(config, "", " ")
|
||||
|
||||
// Записываем JSON в файл
|
||||
fileName := "config.json"
|
||||
os.WriteFile(fileName, jsonData, 0644)
|
||||
mu.Unlock()
|
||||
// Perform installation
|
||||
err := installHandler(config)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user