summaryrefslogtreecommitdiff
path: root/.config/awesome/dbus_test.lua
blob: 439402940c5b0a41096dabe15ebfc9dafb7de3e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- see: https://github.com/awesomeWM/awesome/issues/1093
local lgi = require("lgi")
local Gio = lgi.require("Gio")
local GLib = lgi.require("GLib")

-- Workaround for https://github.com/pavouk/lgi/issues/142
local function bus_get_async(type)
	Gio.bus_get(type, nil, coroutine.running())
	local a, b = coroutine.yield()
	return Gio.bus_get_finish(b)
end

local function method_call(bus_type, name, object, interface, method, ...)
    -- args
	local bus = bus_get_async(bus_type)

	local result, err = bus:async_call(name, object, interface, method,
		GLib.Variant("(s)", { "org.freedesktop.systemd1.Manager" }), -- Arguments
		nil, Gio.DBusCallFlags.NONE,
		-1) -- Use default timeout

	if not result then
		return nil, tostring(err)
	end

	-- Get (only?!?) entry in the array
	local res = result:get_child_value(0)
	-- Get entries from the dictionary
	for i = 0, res:n_children() - 1 do
		local value = res:get_child_value(i)
		local key, val = value:get_child_value(0), value:get_child_value(1)
		print(key.value, val.value.value)
	end
end

Gio.Async.call(function()
	method_call(
        Gio.BusType.SESSION,
        "org.freedesktop.systemd1",
        "/org/freedesktop/systemd1",
        "org.freedesktop.DBus.Properties",
        "GetAll"
    )
end)()