irc: keep session alive when closing UI; reuse background session on reopen; rename Leave->Close

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-09-20 02:03:34 +03:00
parent 60db4a97c1
commit 661bc5daa1

View File

@@ -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