56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"embed"
|
|
"jws/internal/dependency"
|
|
"jws/internal/logger"
|
|
"jws/internal/project"
|
|
"log/slog"
|
|
"runtime"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/data/binding"
|
|
"fyne.io/fyne/v2/dialog"
|
|
"fyne.io/fyne/v2/widget"
|
|
)
|
|
|
|
var (
|
|
// Global variables available to the package
|
|
mainWindow fyne.Window
|
|
dependencies []dependency.Dependency
|
|
projects []project.Project
|
|
projectsFS embed.FS
|
|
log *slog.Logger
|
|
)
|
|
|
|
// Init initializes the GUI package with required dependencies
|
|
func Init(window fyne.Window, deps []dependency.Dependency, projs []project.Project, fs embed.FS) {
|
|
log = logger.GetChildLogger("gui")
|
|
mainWindow = window
|
|
dependencies = deps
|
|
projects = projs
|
|
projectsFS = fs
|
|
}
|
|
|
|
// ShowPasswordDialog shows a dialog to enter sudo password for installations
|
|
func ShowPasswordDialog(index int) {
|
|
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
|
|
password := binding.NewString()
|
|
entry := widget.NewEntryWithData(password)
|
|
entry.Password = true
|
|
|
|
dialog.NewForm("Sudo Password", "ok", "cancel",
|
|
[]*widget.FormItem{widget.NewFormItem("password", entry)},
|
|
func(b bool) {
|
|
pass, err := password.Get()
|
|
if err == nil {
|
|
if b {
|
|
dependency.InstallDependency(index, pass, dependencies, mainWindow)
|
|
}
|
|
}
|
|
},
|
|
mainWindow).Show()
|
|
} else {
|
|
dependency.InstallDependency(index, "", dependencies, mainWindow)
|
|
}
|
|
}
|