-
Notifications
You must be signed in to change notification settings - Fork 42
/
app.go
138 lines (132 loc) · 2.28 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
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
133
134
135
136
137
138
package main
import (
"changeme/CommAnd"
"context"
"encoding/json"
"github.com/qtgolang/SunnyNet/SunnyNet"
"github.com/qtgolang/SunnyNet/src/protobuf/JSON"
"github.com/wailsapp/wails/v2/pkg/runtime"
"strconv"
)
// App struct
type App struct {
ctx context.Context
App *SunnyNet.Sunny
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
type Command struct {
Command string
Args any
}
// 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) Do(arg any) any {
defer func() {
recover()
}()
as := arg.(map[string]any)
if as == nil {
return nil
}
_t := as["Command"]
if _t == nil {
return nil
}
command := _t.(string)
Args := as["Args"]
if Args == nil {
return event(command, nil)
}
bs, _ := json.Marshal(Args)
_json := string(bs)
sj := JSON.NewSyJson()
sj.Parse(_json)
return event(command, sj)
}
func (a *App) CallDo(arg ...any) {
runtime.EventsEmit(a.ctx, "Do", arg...)
}
func getFloat64(arg any) float64 {
switch v := arg.(type) {
case int:
return float64(v)
case int64:
return float64(v)
case int32:
return float64(v)
case int16:
return float64(v)
case int8:
return float64(v)
case uint:
return float64(v)
case uint64:
return float64(v)
case uint32:
return float64(v)
case uint16:
return float64(v)
case uint8:
return float64(v)
case string:
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return 0
}
return f
case float32:
return float64(v)
case float64:
return v
default:
return 0
}
}
func getInt64(arg any) int64 {
switch v := arg.(type) {
case int:
return int64(v)
case int64:
return int64(v)
case int32:
return int64(v)
case int16:
return int64(v)
case int8:
return int64(v)
case uint:
return int64(v)
case uint64:
return int64(v)
case uint32:
return int64(v)
case uint16:
return int64(v)
case uint8:
return int64(v)
case string:
i, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return 0
}
return i
case float32:
return int64(v)
case float64:
return int64(v)
default:
return 0
}
}
func getInt(arg any) int {
return int(getInt64(arg))
}
func ClipboardText(text string) error {
return CommAnd.ClipboardText(text)
}