Skip to content

Commit

Permalink
double keepalive interval to 2000ms
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Feb 7, 2024
1 parent 03f065c commit f252c93
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
18 changes: 11 additions & 7 deletions ahk/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2806,7 +2806,7 @@

HOTKEYS_SCRIPT_TEMPLATE = r"""#Requires AutoHotkey v1.1.17+
#Persistent
#Warn
{% for directive in directives %}
{% if directive.apply_to_hotkeys_process %}
Expand All @@ -2819,7 +2819,7 @@
{% endif %}
KEEPALIVE := Chr(57344)
stdin := FileOpen("*", "r `n", "UTF-8")
SetTimer, keepalive, 1000
SetTimer, keepalive, 2000
Crypt32 := DllCall("LoadLibrary", "Str", "Crypt32.dll", "Ptr")
Expand Down Expand Up @@ -2907,8 +2907,10 @@
global KEEPALIVE
global stdin
FileAppend, %KEEPALIVE%`n, *, UTF-8
alivesignal := RTrim(stdin.ReadLine(), "`n")
if (alivesignal = "") {
alive_message := RTrim(stdin.ReadLine(), "`n")
if (alive_message != KEEPALIVE) {
; The parent Python process has terminated unexpectedly
; Exit to avoid leaving the hotkey process around
ExitApp
}
return
Expand Down Expand Up @@ -5910,14 +5912,16 @@
OnClipboardChange(ClipChanged)
{% endif %}
SetTimer KeepAliveFunc, 1000
SetTimer KeepAliveFunc, 2000
KeepAliveFunc() {
global stdin
global KEEPALIVE
WriteStdout(Format("{}`n", KEEPALIVE))
alivesignal := RTrim(stdin.ReadLine(), "`n")
if (alivesignal = "") {
alive_message := RTrim(stdin.ReadLine(), "`n")
if (alive_message != KEEPALIVE) {
; The parent Python process has terminated unexpectedly
; Exit to avoid leaving the hotkey process around
ExitApp
}
return
Expand Down
2 changes: 1 addition & 1 deletion ahk/_hotkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def listener(self) -> None:
line = self._proc.stdout.readline()
if line.rstrip(b'\n') == _KEEPALIVE_SENTINEL:
logging.debug('keepalive received')
self._proc.stdin.write(b'alive\n')
self._proc.stdin.write(b'\xee\x80\x80\n')
self._proc.stdin.flush()
continue
if not line.strip():
Expand Down
8 changes: 5 additions & 3 deletions ahk/templates/hotkeys-v2.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ ClipChanged(Type) {
OnClipboardChange(ClipChanged)

{% endif %}
SetTimer KeepAliveFunc, 1000
SetTimer KeepAliveFunc, 2000

KeepAliveFunc() {
global stdin
global KEEPALIVE
WriteStdout(Format("{}`n", KEEPALIVE))
alivesignal := RTrim(stdin.ReadLine(), "`n")
if (alivesignal = "") {
alive_message := RTrim(stdin.ReadLine(), "`n")
if (alive_message != KEEPALIVE) {
; The parent Python process has terminated unexpectedly
; Exit to avoid leaving the hotkey process around
ExitApp
}
return
Expand Down
10 changes: 6 additions & 4 deletions ahk/templates/hotkeys.ahk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Requires AutoHotkey v1.1.17+
#Persistent
#Warn

{% for directive in directives %}
{% if directive.apply_to_hotkeys_process %}

Expand All @@ -13,7 +13,7 @@ OnClipboardChange("ClipChanged")
{% endif %}
KEEPALIVE := Chr(57344)
stdin := FileOpen("*", "r `n", "UTF-8")
SetTimer, keepalive, 1000
SetTimer, keepalive, 2000

Crypt32 := DllCall("LoadLibrary", "Str", "Crypt32.dll", "Ptr")

Expand Down Expand Up @@ -101,8 +101,10 @@ keepalive:
global KEEPALIVE
global stdin
FileAppend, %KEEPALIVE%`n, *, UTF-8
alivesignal := RTrim(stdin.ReadLine(), "`n")
if (alivesignal = "") {
alive_message := RTrim(stdin.ReadLine(), "`n")
if (alive_message != KEEPALIVE) {
; The parent Python process has terminated unexpectedly
; Exit to avoid leaving the hotkey process around
ExitApp
}
return

0 comments on commit f252c93

Please sign in to comment.