-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
66 lines (58 loc) · 1.26 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"os"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) makeMenu() *menu.Menu {
AppMenu := menu.NewMenu()
FileMenu := AppMenu.AddSubmenu("File")
FileMenu.Append(&menu.MenuItem{
Label: "Open XML file",
Type: menu.TextType,
Click: func(cd *menu.CallbackData) {
runtime.EventsEmit(a.ctx, "open")
},
})
FileMenu.Append(&menu.MenuItem{
Label: "Paste from clipboard",
Type: menu.TextType,
Click: func(cd *menu.CallbackData) {
runtime.EventsEmit(a.ctx, "paste")
},
})
return AppMenu
}
func (a *App) OpenVault() string {
selection, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
Filters: []runtime.FileFilter{{
Pattern: "*.*",
}},
})
if err == nil {
return selection
}
return ""
}
func (a *App) LoadTextFile(name string) string {
dat, err := os.ReadFile(name)
if err == nil {
fileContent := string(dat)
return fileContent
}
return ""
}