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:
15
main.lua
15
main.lua
@@ -26,6 +26,7 @@ local IrcChatView = TextViewer:extend{
|
|||||||
add_default_buttons = true,
|
add_default_buttons = true,
|
||||||
monospace_font = true,
|
monospace_font = true,
|
||||||
text_type = "code",
|
text_type = "code",
|
||||||
|
keep_running = true, -- keep connection alive when UI is closed
|
||||||
_connected = false,
|
_connected = false,
|
||||||
_closing = false,
|
_closing = false,
|
||||||
_receive_task = nil,
|
_receive_task = nil,
|
||||||
@@ -56,7 +57,7 @@ function IrcChatView:init()
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text = _("Leave"),
|
text = _("Close"),
|
||||||
callback = function()
|
callback = function()
|
||||||
self:onClose()
|
self:onClose()
|
||||||
end,
|
end,
|
||||||
@@ -597,6 +598,11 @@ function IrcChatView:handleLine(line)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function IrcChatView:onClose()
|
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
|
if self._closing then return end
|
||||||
self._closing = true
|
self._closing = true
|
||||||
if self._receive_task then
|
if self._receive_task then
|
||||||
@@ -998,6 +1004,11 @@ function IRC:connectToServer(server)
|
|||||||
local function open_chat(channel)
|
local function open_chat(channel)
|
||||||
local function do_open()
|
local function do_open()
|
||||||
local nick = server.nick or self.username or "koreader"
|
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{
|
local view = IrcChatView:new{
|
||||||
_server = {
|
_server = {
|
||||||
name = server.name,
|
name = server.name,
|
||||||
@@ -1008,7 +1019,9 @@ function IRC:connectToServer(server)
|
|||||||
},
|
},
|
||||||
_channel = channel,
|
_channel = channel,
|
||||||
_nick = nick,
|
_nick = nick,
|
||||||
|
keep_running = true,
|
||||||
}
|
}
|
||||||
|
self._bg_view = view
|
||||||
UIManager:show(view)
|
UIManager:show(view)
|
||||||
end
|
end
|
||||||
-- Ensure wifi/network is up before proceeding
|
-- Ensure wifi/network is up before proceeding
|
||||||
|
|||||||
Reference in New Issue
Block a user