@@ -42,15 +42,15 @@ import (
42
42
"golang.org/x/sys/windows"
43
43
)
44
44
45
- var osThreadId atomic.Uint32
45
+ var osThreadID atomic.Uint32
46
46
47
47
// Start the device add/remove notification process, at every event a call to eventCB will be performed.
48
48
// This function will block until interrupted by the given context. Errors will be passed to errorCB.
49
49
// Returns error if sync process can't be started.
50
50
func Start (ctx context.Context , eventCB func (), errorCB func (msg string )) error {
51
51
runtime .LockOSThread ()
52
52
defer runtime .UnlockOSThread ()
53
- osThreadId .Store (windows .GetCurrentThreadId ())
53
+ osThreadID .Store (windows .GetCurrentThreadId ())
54
54
55
55
eventsChan := make (chan bool , 1 )
56
56
var eventsChanLock sync.Mutex
@@ -108,24 +108,24 @@ func Start(ctx context.Context, eventCB func(), errorCB func(msg string)) error
108
108
109
109
go func () {
110
110
<- ctx .Done ()
111
- _ = win32 .PostMessage (windowHandle , win32 .WM_Quit , 0 , 0 )
111
+ _ = win32 .PostMessage (windowHandle , win32 .WMQuit , 0 , 0 )
112
112
}()
113
113
114
114
for {
115
115
// Verify running thread prerequisites
116
- if currThreadId := windows .GetCurrentThreadId (); currThreadId != osThreadId .Load () {
117
- panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadId , osThreadId ))
116
+ if currThreadID := windows .GetCurrentThreadId (); currThreadID != osThreadID .Load () {
117
+ panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadID , osThreadID ))
118
118
}
119
119
120
120
var m win32.TagMSG
121
- if res := win32 .GetMessage (& m , windowHandle , win32 .WM_Quit , win32 .WM_Quit ); res == 0 { // 0 means we got a WM_QUIT
121
+ if res := win32 .GetMessage (& m , windowHandle , win32 .WMQuit , win32 .WMQuit ); res == 0 { // 0 means we got a WMQUIT
122
122
break
123
123
} else if res == - 1 { // -1 means that an error occurred
124
124
err := windows .GetLastError ()
125
125
errorCB ("error consuming messages: " + err .Error ())
126
126
break
127
127
} else {
128
- // we got a message != WM_Quit , it should not happen but, just in case...
128
+ // we got a message != WMQuit , it should not happen but, just in case...
129
129
win32 .TranslateMessage (& m )
130
130
win32 .DispatchMessage (& m )
131
131
}
@@ -136,8 +136,8 @@ func Start(ctx context.Context, eventCB func(), errorCB func(msg string)) error
136
136
137
137
func createWindow (windowCallback win32.WindowProcCallback ) (syscall.Handle , * byte , error ) {
138
138
// Verify running thread prerequisites
139
- if currThreadId := windows .GetCurrentThreadId (); currThreadId != osThreadId .Load () {
140
- panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadId , osThreadId .Load ()))
139
+ if currThreadID := windows .GetCurrentThreadId (); currThreadID != osThreadID .Load () {
140
+ panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadID , osThreadID .Load ()))
141
141
}
142
142
143
143
moduleHandle , err := win32 .GetModuleHandle (nil )
@@ -167,8 +167,8 @@ func createWindow(windowCallback win32.WindowProcCallback) (syscall.Handle, *byt
167
167
168
168
func destroyWindow (windowHandle syscall.Handle , className * byte ) error {
169
169
// Verify running thread prerequisites
170
- if currThreadId := windows .GetCurrentThreadId (); currThreadId != osThreadId .Load () {
171
- panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadId , osThreadId .Load ()))
170
+ if currThreadID := windows .GetCurrentThreadId (); currThreadID != osThreadID .Load () {
171
+ panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadID , osThreadID .Load ()))
172
172
}
173
173
174
174
if err := win32 .DestroyWindowEx (windowHandle ); err != nil {
@@ -182,8 +182,8 @@ func destroyWindow(windowHandle syscall.Handle, className *byte) error {
182
182
183
183
func registerNotifications (windowHandle syscall.Handle ) (syscall.Handle , error ) {
184
184
// Verify running thread prerequisites
185
- if currThreadId := windows .GetCurrentThreadId (); currThreadId != osThreadId .Load () {
186
- panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadId , osThreadId .Load ()))
185
+ if currThreadID := windows .GetCurrentThreadId (); currThreadID != osThreadID .Load () {
186
+ panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadID , osThreadID .Load ()))
187
187
}
188
188
189
189
notificationFilter := win32.DevBroadcastDeviceInterface {
@@ -203,8 +203,8 @@ func registerNotifications(windowHandle syscall.Handle) (syscall.Handle, error)
203
203
204
204
func unregisterNotifications (notificationsDevHandle syscall.Handle ) error {
205
205
// Verify running thread prerequisites
206
- if currThreadId := windows .GetCurrentThreadId (); currThreadId != osThreadId .Load () {
207
- panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadId , osThreadId .Load ()))
206
+ if currThreadID := windows .GetCurrentThreadId (); currThreadID != osThreadID .Load () {
207
+ panic (fmt .Sprintf ("this function must run on the main OS Thread: currThread=%d, osThread=%d" , currThreadID , osThreadID .Load ()))
208
208
}
209
209
210
210
if err := win32 .UnregisterDeviceNotification (notificationsDevHandle ); err != nil {
0 commit comments