forked from wailsapp/wails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemcalls.go
52 lines (42 loc) · 1.12 KB
/
systemcalls.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
package dispatcher
import (
"fmt"
"strings"
"github.com/frankfang/wails/v2/pkg/runtime"
"github.com/frankfang/wails/v2/internal/frontend"
)
const systemCallPrefix = ":wails:"
type position struct {
X int `json:"x"`
Y int `json:"y"`
}
type size struct {
W int `json:"w"`
H int `json:"h"`
}
func (d *Dispatcher) processSystemCall(payload callMessage, sender frontend.Frontend) (interface{}, error) {
// Strip prefix
name := strings.TrimPrefix(payload.Name, systemCallPrefix)
switch name {
case "WindowGetPos":
x, y := sender.WindowGetPosition()
return &position{x, y}, nil
case "WindowGetSize":
w, h := sender.WindowGetSize()
return &size{w, h}, nil
case "ScreenGetAll":
return sender.ScreenGetAll()
case "WindowIsMaximised":
return sender.WindowIsMaximised(), nil
case "WindowIsMinimised":
return sender.WindowIsMinimised(), nil
case "WindowIsNormal":
return sender.WindowIsNormal(), nil
case "WindowIsFullscreen":
return sender.WindowIsFullscreen(), nil
case "Environment":
return runtime.Environment(d.ctx), nil
default:
return nil, fmt.Errorf("unknown systemcall message: %s", payload.Name)
}
}