-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
151 lines (129 loc) · 3.38 KB
/
handler.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
139
140
141
142
143
144
145
146
147
148
149
150
151
package mac_switch_watch
import "C"
import "golang.org/x/net/context"
var HandlerCtx = context.Background()
type EventKey int
const (
KeyOnCanDevicePowerOff EventKey = iota
KeyOnCanSystemPowerOff
KeyOnCanSystemSleep
KeyOnDeviceHasPoweredOff
KeyOnDeviceHasPoweredOn
KeyOnDeviceWillNotPowerOff
KeyOnDeviceWillPowerOff
KeyOnDeviceWillPowerOn
KeyOnSystemHasPoweredOn
KeyOnSystemPagingOff
KeyOnSystemWillNotPowerOff
KeyOnSystemWillNotSleep
KeyOnSystemWillPowerOff
KeyOnSystemWillPowerOn
KeyOnSystemWillRestart
KeyOnSystemWillSleep
)
//SetHandler
func SetHandler(key EventKey, handler func()) context.Context {
HandlerCtx = context.WithValue(HandlerCtx, key, handler)
return HandlerCtx
}
//RemoveHandler
func RemoveHandler(key EventKey) context.Context {
HandlerCtx = context.WithValue(HandlerCtx, key, nil)
return HandlerCtx
}
//export CallbackOnCanDevicePowerOff
func CallbackOnCanDevicePowerOff() {
if hdr, ok := HandlerCtx.Value(KeyOnCanDevicePowerOff).(func()); ok {
go hdr()
}
}
//export CallbackOnCanSystemPowerOff
func CallbackOnCanSystemPowerOff() {
if hdr, ok := HandlerCtx.Value(KeyOnCanSystemPowerOff).(func()); ok {
go hdr()
}
}
//export CallbackOnCanSystemSleep
func CallbackOnCanSystemSleep() {
if hdr, ok := HandlerCtx.Value(KeyOnCanSystemSleep).(func()); ok {
go hdr()
}
}
//export CallbackOnDeviceHasPoweredOff
func CallbackOnDeviceHasPoweredOff() {
if hdr, ok := HandlerCtx.Value(KeyOnDeviceHasPoweredOff).(func()); ok {
go hdr()
}
}
//export CallbackOnDeviceHasPoweredOn
func CallbackOnDeviceHasPoweredOn() {
if hdr, ok := HandlerCtx.Value(KeyOnDeviceHasPoweredOn).(func()); ok {
go hdr()
}
}
//export CallbackOnDeviceWillNotPowerOff
func CallbackOnDeviceWillNotPowerOff() {
if hdr, ok := HandlerCtx.Value(KeyOnDeviceWillNotPowerOff).(func()); ok {
go hdr()
}
}
//export CallbackOnDeviceWillPowerOff
func CallbackOnDeviceWillPowerOff() {
if hdr, ok := HandlerCtx.Value(KeyOnDeviceWillPowerOff).(func()); ok {
go hdr()
}
}
//export CallbackOnDeviceWillPowerOn
func CallbackOnDeviceWillPowerOn() {
if hdr, ok := HandlerCtx.Value(KeyOnDeviceWillPowerOn).(func()); ok {
go hdr()
}
}
//export CallbackOnSystemHasPoweredOn
func CallbackOnSystemHasPoweredOn() {
if hdr, ok := HandlerCtx.Value(KeyOnSystemHasPoweredOn).(func()); ok {
go hdr()
}
}
//export CallbackOnSystemPagingOff
func CallbackOnSystemPagingOff() {
if hdr, ok := HandlerCtx.Value(KeyOnSystemPagingOff).(func()); ok {
go hdr()
}
}
//export CallbackOnSystemWillNotPowerOff
func CallbackOnSystemWillNotPowerOff() {
if hdr, ok := HandlerCtx.Value(KeyOnSystemWillNotPowerOff).(func()); ok {
go hdr()
}
}
//export CallbackOnSystemWillNotSleep
func CallbackOnSystemWillNotSleep() {
if hdr, ok := HandlerCtx.Value(KeyOnSystemWillNotSleep).(func()); ok {
go hdr()
}
}
//export CallbackOnSystemWillPowerOff
func CallbackOnSystemWillPowerOff() {
if hdr, ok := HandlerCtx.Value(KeyOnSystemWillPowerOff).(func()); ok {
go hdr()
}
}
//export CallbackOnSystemWillPowerOn
func CallbackOnSystemWillPowerOn() {
if hdr, ok := HandlerCtx.Value(KeyOnSystemWillPowerOn).(func()); ok {
go hdr()
}
}
//export CallbackOnSystemWillRestart
func CallbackOnSystemWillRestart() {
if hdr, ok := HandlerCtx.Value(KeyOnSystemWillRestart).(func()); ok {
go hdr()
}
}
//export CallbackOnSystemWillSleep
func CallbackOnSystemWillSleep() {
if hdr, ok := HandlerCtx.Value(KeyOnSystemWillSleep).(func()); ok {
go hdr()
}
}