-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.go
79 lines (67 loc) · 1.98 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
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"git-helper/repository"
"git-helper/utils"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
"github.com/wailsapp/wails/v2/pkg/runtime"
"os/user"
)
// App struct
type App struct {
ctx context.Context
repository *repository.Repository
dataSaveJson string
}
// 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
u, err := user.Current()
if err != nil {
panic(err)
}
a.dataSaveJson = u.HomeDir + "/Git_Helper.json"
}
func (a *App) setRepository(r *repository.Repository) {
a.repository = r
}
// Greet returns a greeting for the given name
func (a *App) menu() *menu.Menu {
appMenu := menu.NewMenu()
appMenu.Append(menu.EditMenu())
repo := appMenu.AddSubmenu("Repository")
repo.AddText("Add local repository", keys.CmdOrCtrl("r"), func(_ *menu.CallbackData) {
path, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select Local Git Repository",
})
if err != nil || len(path) == 0 {
return
}
id := utils.Sha256(path)
runtime.EventsEmit(a.ctx, "Repository_A", id, path)
})
repo.AddText("Repository manage", keys.CmdOrCtrl("m"), func(_ *menu.CallbackData) {
runtime.EventsEmit(a.ctx, "Repository_M")
})
bt := appMenu.AddSubmenu("Branch&Tag")
bt.AddText("Branch manage", keys.CmdOrCtrl("b"), func(_ *menu.CallbackData) {
runtime.EventsEmit(a.ctx, "Branch_M")
})
bt.AddText("Tag manage", keys.CmdOrCtrl("t"), func(_ *menu.CallbackData) {
runtime.EventsEmit(a.ctx, "Tag_M")
})
other := appMenu.AddSubmenu("Other")
other.AddText("Theme", keys.CmdOrCtrl(""), func(_ *menu.CallbackData) {
runtime.EventsEmit(a.ctx, "Settings_Theme")
})
other.AddText("About", keys.CmdOrCtrl(""), func(_ *menu.CallbackData) {
runtime.EventsEmit(a.ctx, "Settings_About")
})
return appMenu
}