Repository navigation
Expand file tree
/
Copy pathapp.go
More file actions
132 lines (103 loc) · 3.14 KB
/
Copy pathapp.go
File metadata and controls
132 lines (103 loc) · 3.14 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"context"
"yagui/utils"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
type App struct {
ctx context.Context
}
func NewApp() *App {
return &App{}
}
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) GetVersion() string {
return AppVersion
}
// Shortcuts
func (a *App) GetShortcuts() (map[string]utils.ShortcutData, error) {
return utils.GetShortcuts()
}
// AddShortcut creates or replaces a shortcut. tags is comma-separated.
func (a *App) AddShortcut(name, command, description, tags string) (map[string]utils.ShortcutData, error) {
if err := utils.AddShortcut(name, command, description, tags); err != nil {
return nil, err
}
return utils.GetShortcuts()
}
// UpdateShortcut edits an existing shortcut. If newName differs from oldName
// the shortcut is renamed atomically.
func (a *App) UpdateShortcut(oldName, newName, command, description, tags string) error {
return utils.UpdateShortcut(oldName, newName, command, description, tags)
}
func (a *App) RemoveShortcut(name string) error {
return utils.RemoveShortcut(name)
}
func (a *App) TogglePinShortcut(name string) error {
return utils.TogglePinShortcut(name)
}
func (a *App) DuplicateShortcut(name string) (map[string]utils.ShortcutData, error) {
return utils.DuplicateShortcut(name)
}
func (a *App) ExportShortcuts() error {
return utils.ExportShortcuts(a.ctx)
}
func (a *App) ImportShortcuts() error {
err := utils.ImportShortcuts(a.ctx)
if a.ctx != nil {
runtime.EventsEmit(a.ctx, "shortcuts:changed")
}
return err
}
// Terminal & directory
// SelectDirectory opens the native directory picker and returns the chosen path.
func (a *App) SelectDirectory() (string, error) {
cfg, _ := utils.GetConfig()
opts := runtime.OpenDialogOptions{Title: "Select Directory"}
if cfg.DefaultDir != "" {
opts.DefaultDirectory = cfg.DefaultDir
}
return runtime.OpenDirectoryDialog(a.ctx, opts)
}
// ApplyShortcut launches shortcutName's command in dirPath, records history.
func (a *App) ApplyShortcut(shortcutName, command, dirPath string) bool {
cfg, _ := utils.GetConfig()
if err := utils.LaunchInTerminal(command, dirPath, cfg.PreferredTerminal); err != nil {
return false
}
_ = utils.UpdateDefaultDir(dirPath)
_ = utils.AddRunHistoryEntry(shortcutName, command, dirPath)
_ = utils.IncrementRunCount(shortcutName)
return true
}
func (a *App) CliExists(cmd string) bool {
return utils.CliExists(cmd)
}
// Config
func (a *App) GetConfig() (utils.AppConfig, error) {
return utils.GetConfig()
}
func (a *App) SetPreferredTerminal(terminal string) error {
return utils.SetPreferredTerminal(terminal)
}
func (a *App) SetStartOnBoot(enabled bool) error {
return utils.SetStartOnBoot(enabled)
}
func (a *App) GetStartOnBoot() bool {
return utils.GetStartOnBoot()
}
func (a *App) AddSavedDirectory(name, path string) error {
return utils.AddSavedDirectory(name, path)
}
func (a *App) RemoveSavedDirectory(name string) error {
return utils.RemoveSavedDirectory(name)
}
// History
func (a *App) GetRunHistory() ([]utils.RunHistoryEntry, error) {
return utils.GetRunHistory()
}
func (a *App) ClearRunHistory() error {
return utils.ClearRunHistory()
}