fix: appload quirk workaround (#15475)

AppLoad's quirk of removing framebuffer when nothing's holding framebuffer even though app is running prevented crash handling and restarting KOReader to fail, so introduce a keep-alive process (which was LLM assisted, and it's very cursed, but it works!) to work around this issue.

It wasn't a problem for shimmed version since shim loaded even for sh handling shell script too, which acted as keep-alive.
This commit is contained in:
Noa Himesaka authored and GitHub committed 2026-05-31 12:09:04 +02:00
1 parent d246323ba2
commit 644a80bce1
4 files changed
+60 -1

No files matched your search

+1 -1
View File
@@ -39,6 +39,6 @@ if [ "${untagged_todo}" ]; then
fi fi
echo -e "\n${ANSI_GREEN}Luacheck results${ANSI_RESET}" echo -e "\n${ANSI_GREEN}Luacheck results${ANSI_RESET}"
luacheck ${PARALLEL_JOBS:+-j "${PARALLEL_JOBS}"} -q {reader,setupkoenv,datastorage}.lua frontend plugins spec || exit_code=1 luacheck ${PARALLEL_JOBS:+-j "${PARALLEL_JOBS}"} -q {reader,setupkoenv,datastorage}.lua frontend plugins spec platform/remarkable/qtfb_keep_alive.lua || exit_code=1
exit ${exit_code} exit ${exit_code}
+1
View File
@@ -14,6 +14,7 @@ update-prepare: all
# Remarkable scripts # Remarkable scripts
$(SYMLINK) $(COMMON_DIR)/spinning_zsync $(INSTALL_DIR)/koreader/ $(SYMLINK) $(COMMON_DIR)/spinning_zsync $(INSTALL_DIR)/koreader/
$(SYMLINK) $(REMARKABLE_DIR)/koreader.sh $(INSTALL_DIR)/koreader/ $(SYMLINK) $(REMARKABLE_DIR)/koreader.sh $(INSTALL_DIR)/koreader/
$(SYMLINK) $(REMARKABLE_DIR)/qtfb_keep_alive.lua $(INSTALL_DIR)/koreader/
$(SYMLINK) resources/koreader.png $(INSTALL_DIR)/koreader/icon.png $(SYMLINK) resources/koreader.png $(INSTALL_DIR)/koreader/icon.png
$(SYMLINK) $(REMARKABLE_DIR)/external.manifest.json $(INSTALL_DIR)/koreader/ $(SYMLINK) $(REMARKABLE_DIR)/external.manifest.json $(INSTALL_DIR)/koreader/
$(SYMLINK) $(REMARKABLE_DIR)/external.manifest.shim.json $(INSTALL_DIR)/koreader/ $(SYMLINK) $(REMARKABLE_DIR)/external.manifest.shim.json $(INSTALL_DIR)/koreader/
+13
View File
@@ -166,6 +166,14 @@ if [ -e crash.log ]; then
mv -f crash.log.new crash.log mv -f crash.log.new crash.log
fi fi
# since AppLoad unloads framebuffer when first launched app using QTFB exits, run a keep-alive process to prevent this from happening.
BG_KEEP_ALIVE_PID=""
if [ -n "${KO_USE_QTFB}" ] && [ -n "${QTFB_KEY}" ]; then
echo "Starting QTFB connection keep-alive..." >>crash.log 2>&1
./luajit qtfb_keep_alive.lua >/dev/null 2>&1 &
BG_KEEP_ALIVE_PID=$!
fi
CRASH_COUNT=0 CRASH_COUNT=0
CRASH_TS=0 CRASH_TS=0
CRASH_PREV_TS=0 CRASH_PREV_TS=0
@@ -277,4 +285,9 @@ if [ -z "${KO_DONT_SET_DEPTH}" ] && [ -z "${KO_USE_QTFB}" ]; then
fi fi
fi fi
if [ -n "${BG_KEEP_ALIVE_PID}" ]; then
echo "Stopping QTFB connection keep-alive..." >>crash.log 2>&1
kill "${BG_KEEP_ALIVE_PID}" >>crash.log 2>&1
fi
exit ${RETURN_VALUE} exit ${RETURN_VALUE}
+45
View File
@@ -0,0 +1,45 @@
-- qtfb_keep_alive.lua
-- Background process to keep the QTFB socket connection active across KOReader restarts.
-- This prevents the rm-appload launcher from destroying the QML window canvas.
local ffi = require("ffi")
require("ffi/posix_h")
local qtfb = require("ffi/qtfb")
local C = ffi.C
local key_str = os.getenv("QTFB_KEY")
local key = key_str and tonumber(key_str) or 245209899 -- QTFB_DEFAULT_FRAMEBUFFER
local shmType = 0 -- FBFMT_RM2FB as default
if qtfb.is_rmpp then
shmType = 3 -- FBFMT_RMPP_RGB565
elseif qtfb.is_rmppm then
shmType = 6 -- FBFMT_RMPPM_RGB565
end
-- Create UNIX domain socket
local sock = C.socket(C.AF_UNIX, C.SOCK_SEQPACKET, 0)
assert(sock >= 0, "Failed to create UNIX socket")
local addr = ffi.new("struct sockaddr_un", C.AF_UNIX, "/tmp/qtfb.sock")
-- Retry loop to wait for the QTFB server (xochitl/rm-appload) to start listening
while C.connect(sock, ffi.cast("const struct sockaddr *", addr), ffi.sizeof(addr)) ~= 0 do
C.sleep(1)
end
-- Send MESSAGE_INITIALIZE (0)
local initMsg = ffi.new("struct ClientMessage")
initMsg.type = qtfb.MESSAGE_INITIALIZE
initMsg.init.framebufferKey = key
initMsg.init.framebufferType = shmType
local bytes_sent = C.send(sock, initMsg, ffi.sizeof(initMsg), 0)
assert(bytes_sent >= 0, "Failed to send init message to QTFB server")
-- Keep the socket open indefinitely until killed by the parent process.
-- pause() blocks the process indefinitely until a signal is received.
ffi.cdef[[int pause(void);]]
while true do
C.pause()
end