-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
103 lines (86 loc) · 2.9 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"context"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/wakelesstuna/backend"
"github.com/wakelesstuna/backend/collections"
"github.com/wakelesstuna/backend/config"
"github.com/wakelesstuna/backend/request"
"github.com/wakelesstuna/backend/utils"
)
// 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) SendRequest(input request.HttpRequest) string {
return request.SendRequest(input)
}
func (a *App) FetchConfig() config.Config {
return config.FetchConfig()
}
func (a *App) SelectFolder() string {
var options runtime.OpenDialogOptions
return utils.OpenFolderChooser(a.ctx, options)
}
func (a *App) GetCollection(path string) collections.Collection {
return collections.GetCollection(path)
}
func (a *App) GetCollections(dirPath string) []collections.Collection {
return collections.GetCollections()
}
func (a *App) CreateCollection(name string, dirPath string) backend.AppResponse {
response := collections.CreateCollection(name, dirPath)
runtime.EventsEmit(a.ctx, "collections", collections.GetCollections())
return response
}
func (a *App) RenameCollection(newName string, collectionId string) backend.AppResponse {
response := collections.RenameCollection(newName, collectionId)
if response.Status == 200 {
runtime.EventsEmit(a.ctx, "collections", collections.GetCollections())
}
return response
}
func (a *App) DeleteCollection(collectionId string) backend.AppResponse {
response := collections.DeleteCollection(collectionId)
if response.Status == 204 {
runtime.EventsEmit(a.ctx, "collections", collections.GetCollections())
}
return response
}
func (a *App) CreateNewFolder(folderName string, parentFolderId string, collectionId string) backend.AppResponse {
response := collections.NewFolder(folderName, parentFolderId, collectionId)
if response.Status == 201 {
runtime.EventsEmit(a.ctx, "collections", collections.GetCollections())
}
return response
}
func (a *App) CreateNewHttpRequest(request collections.CreateNewHttpRequest) backend.AppResponse {
response := collections.NewRequest(request)
if response.Status == 201 {
runtime.EventsEmit(a.ctx, "collections", collections.GetCollections())
}
return response
}
func (a *App) CreateItem(request collections.CreateItemRequest) backend.AppResponse {
resp := collections.CreateItem(request)
if resp.Status == 201 {
runtime.EventsEmit(a.ctx, "collections", collections.GetCollections())
}
return resp
}
func (a *App) DeleteItem(collectionId string, itemId string) backend.AppResponse {
resp := collections.DeleteItem(collectionId, itemId)
if resp.Status == 204 {
runtime.EventsEmit(a.ctx, "collections", collections.GetCollections())
}
return resp
}