-
Notifications
You must be signed in to change notification settings - Fork 1
CLI and App
Kevin edited this page Jun 16, 2026
·
3 revisions
App is a singleton instance of an AstalLua.Application.
Depending on gtk version require paths will differ
local Application = require('astal.application') -- Base class
local App = require('astal.gtk3.app')
local App = require('astal.gtk4.app')App:start is a wrapper function for App:run that will only run the application if there is no instance already running with the specified name.
App:start {
instance_name = 'my-instance', -- defaults to "astal"
main = function()
-- setup anything
-- instantiate widgets
end,
}If you want to interact with an instance from the CLI, you can do so by sending a request.
App:start {
main = function() end,
---@param args string[]
---@param res fun(response: any)
request_handler = function(args, res)
for _, arg in ipairs(args) do
if arg == 'ping' then return res('pong!') end
end
res('unknown command')
end,
}astal-lua request ping
# pong!
gdbus call --session \
--dest io.Astal.lua \
--object-path /io/Astal/Application \
--method io.Astal.Application.Request "['ping']"
# pong!In order for Astal to know about your windows, you have to register them. You can do this by specifying a unique name and calling App:add_window.
local function Bar()
return Widget.Window {
name = 'Bar',
setup = function(self) App:add_window(self) end,
Widget.Box(),
}
endYou can also invoke App:add_window by simply passing the App to the application prop.
local function Bar()
return Widget.Window {
name = 'Bar',
application = App,
Widget.Box(),
}
endastal-lua request -t Bar
# or
gdbus call --session \
--dest io.Astal.lua \
--object-path /io/Astal/Application \
--method io.Astal.Application.ToggleWindow 'Bar'