mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-30 20:34:49 +01:00
Add Pinnacle.run
and use for tests
This commit is contained in:
parent
535b441887
commit
8d3bbf28f8
3 changed files with 38 additions and 18 deletions
|
@ -35,23 +35,58 @@ function pinnacle.quit()
|
|||
})
|
||||
end
|
||||
|
||||
---Setup Pinnacle.
|
||||
---Setup a Pinnacle config.
|
||||
---
|
||||
---You must pass in a function that takes in the `Pinnacle` table. This table is how you'll access the other config modules.
|
||||
---
|
||||
---You can also `require` the other modules. Just be sure not to call any of their functions outside this
|
||||
---setup function.
|
||||
---
|
||||
---If you want to run a function with the config without blocking at the end, see `Pinnacle.run`.
|
||||
---
|
||||
---@param config_fn fun(pinnacle: Pinnacle)
|
||||
---
|
||||
---@see Pinnacle.run
|
||||
function pinnacle.setup(config_fn)
|
||||
require("pinnacle.grpc.protobuf").build_protos()
|
||||
|
||||
client.loop:wrap(function()
|
||||
while true do
|
||||
require("cqueues").sleep(60)
|
||||
local success, err, errno = client.conn:ping(10)
|
||||
if not success then
|
||||
print("Compositor ping failed:", err, errno)
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
config_fn(pinnacle)
|
||||
|
||||
local success, err = pcall(client.loop.loop, client.loop)
|
||||
local success, err = client.loop:loop()
|
||||
if not success then
|
||||
print(err)
|
||||
end
|
||||
end
|
||||
|
||||
---Run a function with the Pinnacle API.
|
||||
---
|
||||
---If you are writing a config, use `Pinnacle.setup` instead.
|
||||
---
|
||||
---Like `Pinnacle.setup`, this function takes in a function that takes in the `Pinnacle` table.
|
||||
---This allows you to run anything that `setup` can run.
|
||||
---
|
||||
---*Unlike* `setup`, this will **not** listen to the compositor for incoming key presses, signals, and the like.
|
||||
---This means that this function will not block and can be used to integrate with external applications
|
||||
---like taskbars and widget systems like eww, but it will not allow you to set usable keybinds or
|
||||
---call signal callbacks. This is useful for things like querying compositor information for outputs and
|
||||
---windows.
|
||||
---
|
||||
---@param run_fn fun(pinnacle: Pinnacle)
|
||||
function pinnacle.run(run_fn)
|
||||
require("pinnacle.grpc.protobuf").build_protos()
|
||||
|
||||
run_fn(pinnacle)
|
||||
end
|
||||
|
||||
return pinnacle
|
||||
|
|
|
@ -55,21 +55,6 @@ local client = {
|
|||
version = "v0alpha1",
|
||||
}
|
||||
|
||||
client.loop:wrap(function()
|
||||
while true do
|
||||
-- If the only managed coroutine is this ping loop, return to allow the config to exit
|
||||
if client.loop:count() == 1 then
|
||||
return
|
||||
end
|
||||
require("cqueues").sleep(60)
|
||||
local success, err, errno = client.conn:ping(10)
|
||||
if not success then
|
||||
print("Compositor ping failed:", err, errno)
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
---@class GrpcRequestParams
|
||||
---@field service string
|
||||
---@field method string
|
||||
|
|
|
@ -19,7 +19,7 @@ use test_log::test;
|
|||
fn run_lua(ident: &str, code: &str) {
|
||||
#[rustfmt::skip]
|
||||
let code = format!(r#"
|
||||
require("pinnacle").setup(function({ident})
|
||||
require("pinnacle").run(function({ident})
|
||||
local run = function({ident})
|
||||
{code}
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue