1529e55d25
Nuevo agente para crear y compilar aplicaciones Wails (Go + React). Soporta compilación cross-platform: Linux, Windows, macOS. Incluye script de creación de proyecto con DevFactory y frontend-lib integrados.
112 lines
2.7 KiB
Go
112 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"runtime"
|
|
|
|
"github.com/lucasdataproyects/devfactory/core"
|
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
|
)
|
|
|
|
// App struct - métodos públicos se exponen al frontend
|
|
type App struct {
|
|
ctx context.Context
|
|
}
|
|
|
|
// NewApp crea una nueva instancia de App
|
|
func NewApp() *App {
|
|
return &App{}
|
|
}
|
|
|
|
// startup se llama cuando la app inicia
|
|
func (a *App) startup(ctx context.Context) {
|
|
a.ctx = ctx
|
|
}
|
|
|
|
// domReady se llama cuando el DOM está listo
|
|
func (a *App) domReady(ctx context.Context) {
|
|
// Inicializaciones que requieren el DOM
|
|
}
|
|
|
|
// shutdown se llama cuando la app se cierra
|
|
func (a *App) shutdown(ctx context.Context) {
|
|
// Cleanup resources
|
|
}
|
|
|
|
// ============================================
|
|
// MÉTODOS EXPUESTOS AL FRONTEND
|
|
// ============================================
|
|
|
|
// Greet retorna un saludo
|
|
func (a *App) Greet(name string) string {
|
|
return fmt.Sprintf("Hello %s, from Go!", name)
|
|
}
|
|
|
|
// GetSystemInfo retorna información del sistema
|
|
func (a *App) GetSystemInfo() map[string]string {
|
|
return map[string]string{
|
|
"os": runtime.GOOS,
|
|
"arch": runtime.GOARCH,
|
|
"cpus": fmt.Sprintf("%d", runtime.NumCPU()),
|
|
"goVersion": runtime.Version(),
|
|
}
|
|
}
|
|
|
|
// OpenFileDialog abre un diálogo para seleccionar archivo
|
|
func (a *App) OpenFileDialog() core.Result[string] {
|
|
file, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
|
|
Title: "Seleccionar archivo",
|
|
Filters: []runtime.FileFilter{
|
|
{DisplayName: "Todos los archivos", Pattern: "*.*"},
|
|
},
|
|
})
|
|
if err != nil {
|
|
return core.Err[string](err)
|
|
}
|
|
return core.Ok(file)
|
|
}
|
|
|
|
// SaveFileDialog abre un diálogo para guardar archivo
|
|
func (a *App) SaveFileDialog(defaultFilename string) core.Result[string] {
|
|
file, err := runtime.SaveFileDialog(a.ctx, runtime.SaveDialogOptions{
|
|
Title: "Guardar archivo",
|
|
DefaultFilename: defaultFilename,
|
|
})
|
|
if err != nil {
|
|
return core.Err[string](err)
|
|
}
|
|
return core.Ok(file)
|
|
}
|
|
|
|
// ShowMessage muestra un mensaje al usuario
|
|
func (a *App) ShowMessage(title, message string) {
|
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
|
Type: runtime.InfoDialog,
|
|
Title: title,
|
|
Message: message,
|
|
})
|
|
}
|
|
|
|
// ShowError muestra un error al usuario
|
|
func (a *App) ShowError(title, message string) {
|
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
|
Type: runtime.ErrorDialog,
|
|
Title: title,
|
|
Message: message,
|
|
})
|
|
}
|
|
|
|
// Confirm muestra un diálogo de confirmación
|
|
func (a *App) Confirm(title, message string) bool {
|
|
result, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
|
Type: runtime.QuestionDialog,
|
|
Title: title,
|
|
Message: message,
|
|
Buttons: []string{"Sí", "No"},
|
|
DefaultButton: "Sí",
|
|
CancelButton: "No",
|
|
})
|
|
return result == "Sí"
|
|
}
|