From 234dbffa3dbd0d7418585acd7e051685a1e57a06 Mon Sep 17 00:00:00 2001 From: Aylur Date: Fri, 7 Jun 2024 02:54:37 +0200 Subject: add client capabilities breaking change for App.start --- lua/astal/application.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'lua/astal/application.lua') diff --git a/lua/astal/application.lua b/lua/astal/application.lua index 8402a59..f738c09 100644 --- a/lua/astal/application.lua +++ b/lua/astal/application.lua @@ -26,14 +26,22 @@ local app = AstalLua() ---@field css? string ---@field hold? boolean ---@field request_handler? fun(msg: string, response: fun(res: any)) +---@field main? fun(...): unknown +---@field client? fun(message: fun(msg: string): string, ...): unknown ---@param config StartConfig | nil ----@param callback function | nil -function Astal.Application:start(config, callback) +function Astal.Application:start(config) if config == nil then config = {} end + if config.client == nil then + config.client = function() + print('Astal instance "' .. app.instance_name .. '" is already running') + os.exit(1) + end + end + if config.hold == nil then config.hold = true end @@ -57,17 +65,18 @@ function Astal.Application:start(config, callback) end app.on_activate = function() + if type(config.main) == "function" then + config.main(table.unpack(arg)) + end if config.hold then self:hold() end - if type(callback) == "function" then - callback() - end end if not app:acquire_socket() then - print('Astal instance "' .. app.instance_name .. '" is already running') - os.exit(1) + config.client(function(msg) + return app:message(msg) + end, table.unpack(arg)) end self:run(nil) -- cgit v1.2.3