mirror of
https://github.com/kepler155c/opus
synced 2025-10-24 12:17:40 +00:00
simplify ui
This commit is contained in:
58
sys/services/chat.lua
Normal file
58
sys/services/chat.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
local device = _G.device
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
local parallel = _G.parallel
|
||||
|
||||
if device.wireless_modem then
|
||||
|
||||
multishell.setTitle(multishell.getCurrent(), 'Chat Daemon')
|
||||
|
||||
local tab
|
||||
|
||||
local function chatClient()
|
||||
|
||||
_G.requireInjector()
|
||||
|
||||
local Event = require('event')
|
||||
local Util = require('util')
|
||||
|
||||
local h = Event.addRoutine(function()
|
||||
while true do
|
||||
Util.run(_ENV, 'rom/programs/rednet/chat',
|
||||
'join', 'opusChat-' .. os.getComputerID(), 'owner')
|
||||
end
|
||||
end)
|
||||
|
||||
while true do
|
||||
local e = { os.pullEventRaw() }
|
||||
if e[1] == 'terminate' then
|
||||
multishell.hideTab(tab.tabId)
|
||||
else
|
||||
if e[1] == 'rednet_message' and e[4] == 'chat' and e[3].sType == 'chat' then
|
||||
if tab.hidden then
|
||||
multishell.unhideTab(tab.tabId)
|
||||
end
|
||||
end
|
||||
h:resume(unpack(e))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
parallel.waitForAll(
|
||||
function()
|
||||
os.run(_ENV, 'rom/programs/rednet/chat',
|
||||
'host', 'opusChat-' .. os.getComputerID())
|
||||
end,
|
||||
function()
|
||||
os.sleep(3)
|
||||
local tabId = multishell.openTab({
|
||||
fn = chatClient,
|
||||
title = 'Chatroom',
|
||||
hidden = true,
|
||||
})
|
||||
tab = multishell.getTab(tabId)
|
||||
end
|
||||
)
|
||||
|
||||
print('Chat daemon stopped')
|
||||
end
|
||||
Reference in New Issue
Block a user