tiny-rdm/backend/services/system_dialog.go

48 lines
834 B
Go
Raw Normal View History

2023-10-15 02:27:23 +08:00
package services
import (
"context"
"github.com/wailsapp/wails/v2/pkg/runtime"
"log"
"sync"
"tinyrdm/backend/types"
)
type systemService struct {
ctx context.Context
}
var system *systemService
var onceSystem sync.Once
func System() *systemService {
if system == nil {
onceSystem.Do(func() {
system = &systemService{}
})
}
return system
}
func (s *systemService) Start(ctx context.Context) {
s.ctx = ctx
}
// SelectFile open file dialog to select a file
func (s *systemService) SelectFile(title string) (resp types.JSResp) {
filepath, err := runtime.OpenFileDialog(s.ctx, runtime.OpenDialogOptions{
Title: title,
ShowHiddenFiles: true,
})
if err != nil {
log.Println(err)
resp.Msg = err.Error()
return
}
resp.Success = true
resp.Data = map[string]any{
"path": filepath,
}
return
}