-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
58 lines (46 loc) · 1.4 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
package main
import (
"context"
"fmt"
"github.com/google/uuid"
"github.com/wailsapp/wails/v2/pkg/runtime"
"hypeworks.com/yozora/plugins"
base64plugin "hypeworks.com/yozora/plugins/base64"
loremipsumplugin "hypeworks.com/yozora/plugins/lorem-ipsum"
mockhttpplugin "hypeworks.com/yozora/plugins/mock-http"
qrcodeplugin "hypeworks.com/yozora/plugins/qr-code"
)
// App struct
type App struct {
ctx context.Context
pluginManager *plugins.PluginManager
}
// 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
a.pluginManager = plugins.NewPluginManager(a.ctx)
// Register the plugins
base64plugin.Register(a.pluginManager)
loremipsumplugin.Register(a.pluginManager)
qrcodeplugin.Register(a.pluginManager)
mockhttpplugin.Register(a.pluginManager)
}
func (a *App) OnAppStarted() {
fmt.Println("App started!")
runtime.WindowShow(a.ctx)
}
func (a *App) GenerateUUID() string {
return uuid.New().String()
}
// Get a list of registered plugin ids so that we know what we can call
func (a *App) GetRegisteredPlugins() []string {
return a.pluginManager.GetRegisteredPlugins()
}
func (a *App) CallPlugin(pluginID, functionName string, args string) string {
return a.pluginManager.Call(pluginID, functionName, args)
}