mirror of
https://github.com/jahruz67/wisp-open.git
synced 2026-08-08 18:14:08 +00:00
feat: implement enhanced Linux hotkey handling and add command copying functionality
This commit is contained in:
+72
-15
@@ -13,9 +13,21 @@ import (
|
||||
const linuxPressAddr = "127.0.0.1:9876"
|
||||
|
||||
var (
|
||||
linuxPressMu sync.Mutex
|
||||
linuxPressTimer *time.Timer
|
||||
linuxPressRecording bool
|
||||
linuxPressMu sync.Mutex
|
||||
linuxPressReleaseTimer *time.Timer
|
||||
linuxPressDetectTimer *time.Timer
|
||||
linuxPressRecording bool
|
||||
linuxPressHoldMode bool
|
||||
linuxPressDetectingHold bool
|
||||
)
|
||||
|
||||
const (
|
||||
// GNOME custom shortcuts commonly auto-repeat while the key is held.
|
||||
// If we see a second ping quickly, treat the shortcut as push-to-talk.
|
||||
linuxPressHoldDetectWindow = 1200 * time.Millisecond
|
||||
|
||||
// Once hold mode is confirmed, lack of fresh pings means the key was released.
|
||||
linuxPressReleaseGrace = 450 * time.Millisecond
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -58,22 +70,36 @@ func (a *App) startLinuxPressDaemon() {
|
||||
|
||||
if !linuxPressRecording {
|
||||
linuxPressRecording = true
|
||||
linuxPressHoldMode = false
|
||||
linuxPressDetectingHold = true
|
||||
go a.StartRecording()
|
||||
}
|
||||
|
||||
if linuxPressTimer != nil {
|
||||
linuxPressTimer.Stop()
|
||||
}
|
||||
|
||||
linuxPressTimer = time.AfterFunc(300*time.Millisecond, func() {
|
||||
linuxPressMu.Lock()
|
||||
defer linuxPressMu.Unlock()
|
||||
if linuxPressRecording {
|
||||
linuxPressRecording = false
|
||||
go a.StopRecording()
|
||||
if linuxPressDetectTimer != nil {
|
||||
linuxPressDetectTimer.Stop()
|
||||
}
|
||||
})
|
||||
linuxPressDetectTimer = time.AfterFunc(linuxPressHoldDetectWindow, func() {
|
||||
linuxPressMu.Lock()
|
||||
defer linuxPressMu.Unlock()
|
||||
linuxPressDetectingHold = false
|
||||
})
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
if linuxPressDetectingHold || linuxPressHoldMode {
|
||||
linuxPressHoldMode = true
|
||||
linuxPressDetectingHold = false
|
||||
if linuxPressDetectTimer != nil {
|
||||
linuxPressDetectTimer.Stop()
|
||||
linuxPressDetectTimer = nil
|
||||
}
|
||||
resetLinuxPressReleaseTimer(a)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
stopLinuxPressRecording(a)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
|
||||
@@ -81,3 +107,34 @@ func (a *App) startLinuxPressDaemon() {
|
||||
_ = http.ListenAndServe(linuxPressAddr, mux)
|
||||
}()
|
||||
}
|
||||
|
||||
func resetLinuxPressReleaseTimer(a *App) {
|
||||
if linuxPressReleaseTimer != nil {
|
||||
linuxPressReleaseTimer.Stop()
|
||||
}
|
||||
|
||||
linuxPressReleaseTimer = time.AfterFunc(linuxPressReleaseGrace, func() {
|
||||
linuxPressMu.Lock()
|
||||
defer linuxPressMu.Unlock()
|
||||
if linuxPressRecording && linuxPressHoldMode {
|
||||
stopLinuxPressRecording(a)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func stopLinuxPressRecording(a *App) {
|
||||
if linuxPressReleaseTimer != nil {
|
||||
linuxPressReleaseTimer.Stop()
|
||||
linuxPressReleaseTimer = nil
|
||||
}
|
||||
if linuxPressDetectTimer != nil {
|
||||
linuxPressDetectTimer.Stop()
|
||||
linuxPressDetectTimer = nil
|
||||
}
|
||||
if linuxPressRecording {
|
||||
linuxPressRecording = false
|
||||
linuxPressHoldMode = false
|
||||
linuxPressDetectingHold = false
|
||||
go a.StopRecording()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user