From 661bc5daa1ff0217da9e8ad9d92b976515e6075f Mon Sep 17 00:00:00 2001 From: Slendi Date: Sat, 20 Sep 2025 02:03:34 +0300 Subject: [PATCH] irc: keep session alive when closing UI; reuse background session on reopen; rename Leave->Close Signed-off-by: Slendi --- main.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main.lua b/main.lua index 53f010a..7e12438 100644 --- a/main.lua +++ b/main.lua @@ -26,6 +26,7 @@ local IrcChatView = TextViewer:extend{ add_default_buttons = true, monospace_font = true, text_type = "code", + keep_running = true, -- keep connection alive when UI is closed _connected = false, _closing = false, _receive_task = nil, @@ -56,7 +57,7 @@ function IrcChatView:init() end, }, { - text = _("Leave"), + text = _("Close"), callback = function() self:onClose() end, @@ -597,6 +598,11 @@ function IrcChatView:handleLine(line) end function IrcChatView:onClose() + -- If keep_running, only close the UI; keep socket and receive loop alive in background + if self.keep_running then + TextViewer.onClose(self) + return + end if self._closing then return end self._closing = true if self._receive_task then @@ -998,6 +1004,11 @@ function IRC:connectToServer(server) local function open_chat(channel) local function do_open() local nick = server.nick or self.username or "koreader" + -- Reuse background session if already running for this host/port + if self._bg_view and self._bg_view._sock then + UIManager:show(self._bg_view) + return + end local view = IrcChatView:new{ _server = { name = server.name, @@ -1008,7 +1019,9 @@ function IRC:connectToServer(server) }, _channel = channel, _nick = nick, + keep_running = true, } + self._bg_view = view UIManager:show(view) end -- Ensure wifi/network is up before proceeding