mirror of
https://github.com/zoriya/astal.git
synced 2026-06-04 02:36:25 +00:00
Merge pull request #5 from Aylur/nix/lua-builder
lua example, nix builder
This commit is contained in:
@@ -29,10 +29,13 @@ function Binding:__tostring()
|
||||
end
|
||||
|
||||
function Binding:get()
|
||||
if self.property ~= nil and GObject.Object:is_type_of(self.emitter) then
|
||||
return self.transformFn(self.emitter[self.property])
|
||||
end
|
||||
if type(self.emitter.get) == "function" then
|
||||
return self.transformFn(self.emitter:get())
|
||||
end
|
||||
return self.transformFn(self.emitter[self.property])
|
||||
error("can not get: Not a GObject or a Variable " + self)
|
||||
end
|
||||
|
||||
---@param transform fun(value: any): any
|
||||
@@ -48,17 +51,20 @@ end
|
||||
---@param callback fun(value: any)
|
||||
---@return function
|
||||
function Binding:subscribe(callback)
|
||||
if self.property ~= nil and GObject.Object:is_type_of(self.emitter) then
|
||||
local id = self.emitter.on_notify:connect(function()
|
||||
callback(self:get())
|
||||
end, self.property, false)
|
||||
return function()
|
||||
GObject.signal_handler_disconnect(self.emitter, id)
|
||||
end
|
||||
end
|
||||
if type(self.emitter.subscribe) == "function" then
|
||||
return self.emitter:subscribe(function()
|
||||
callback(self:get())
|
||||
end)
|
||||
end
|
||||
local id = self.emitter.on_notify:connect(function()
|
||||
callback(self:get())
|
||||
end, self.property, false)
|
||||
return function()
|
||||
GObject.signal_handler_disconnect(self.emitter, id)
|
||||
end
|
||||
error("can not subscribe: Not a GObject or a Variable " + self)
|
||||
end
|
||||
|
||||
Binding.__index = Binding
|
||||
|
||||
@@ -72,7 +72,7 @@ function M.exec_async(commandline, on_stdout, on_stderr)
|
||||
local out, err = defualt_proc_args(on_stdout, on_stderr)
|
||||
if type(commandline) == "table" then
|
||||
Astal.Process.exec_asyncv(commandline, function(_, res)
|
||||
local stdout, fail = Astal.exec_asyncv_finish(res)
|
||||
local stdout, fail = Astal.Process.exec_asyncv_finish(res)
|
||||
if fail ~= nil then
|
||||
err(fail)
|
||||
else
|
||||
@@ -81,7 +81,7 @@ function M.exec_async(commandline, on_stdout, on_stderr)
|
||||
end)
|
||||
else
|
||||
Astal.Process.exec_async(commandline, function(_, res)
|
||||
local stdout, fail = Astal.exec_finish(res)
|
||||
local stdout, fail = Astal.Process.exec_finish(res)
|
||||
if fail ~= nil then
|
||||
err(fail)
|
||||
else
|
||||
|
||||
@@ -123,7 +123,9 @@ end
|
||||
|
||||
function Variable:drop()
|
||||
self.variable.emit_dropped()
|
||||
self.variable.run_dispose()
|
||||
Astal.Time.idle(GObject.Closure(function()
|
||||
self.variable.run_dispose()
|
||||
end))
|
||||
end
|
||||
|
||||
---@param callback function
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
local App = require("astal.application")
|
||||
|
||||
App:start({
|
||||
instance_name = "test",
|
||||
main = function()
|
||||
App:quit(1)
|
||||
end,
|
||||
})
|
||||
Reference in New Issue
Block a user