🐛 Fixed hotkey crashes
This commit is contained in:
@@ -66,6 +66,7 @@ int isHotkeyRegistered() {
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -115,14 +116,16 @@ func (hs *HotkeyService) setCancelFunc(cancel context.CancelFunc) {
|
||||
// getCancelFunc 原子地获取cancel函数
|
||||
func (hs *HotkeyService) getCancelFunc() context.CancelFunc {
|
||||
if cancel := hs.cancelFunc.Load(); cancel != nil {
|
||||
return cancel.(context.CancelFunc)
|
||||
if cancelFunc, ok := cancel.(context.CancelFunc); ok {
|
||||
return cancelFunc
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// clearCancelFunc 原子地清除cancel函数
|
||||
func (hs *HotkeyService) clearCancelFunc() {
|
||||
hs.cancelFunc.Store((*context.CancelFunc)(nil))
|
||||
hs.cancelFunc.Store((context.CancelFunc)(nil))
|
||||
}
|
||||
|
||||
// NewHotkeyService 创建新的热键服务实例
|
||||
|
||||
Reference in New Issue
Block a user