Skip to content

Commit 6c5d765

Browse files
authored
Merge pull request #5 from Aylur/nix/lua-builder
lua example, nix builder
2 parents d203255 + 8b75dad commit 6c5d765

File tree

18 files changed

+531
-80
lines changed

18 files changed

+531
-80
lines changed

core/gjs/src/variable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Binding, { type Connectable } from "./binding.js"
22
import { Astal } from "./imports.js"
3-
import { interval } from "./time.js"
3+
import { interval, idle } from "./time.js"
44
import { execAsync, subprocess } from "./process.js"
55

66
class VariableWrapper<T> extends Function {
@@ -101,7 +101,7 @@ class VariableWrapper<T> extends Function {
101101

102102
drop() {
103103
this.variable.emit("dropped")
104-
this.variable.run_dispose()
104+
idle(() => this.variable.run_dispose())
105105
}
106106

107107
onDropped(callback: () => void) {

core/lua/astal/binding.lua

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ function Binding:__tostring()
2929
end
3030

3131
function Binding:get()
32+
if self.property ~= nil and GObject.Object:is_type_of(self.emitter) then
33+
return self.transformFn(self.emitter[self.property])
34+
end
3235
if type(self.emitter.get) == "function" then
3336
return self.transformFn(self.emitter:get())
3437
end
35-
return self.transformFn(self.emitter[self.property])
38+
error("can not get: Not a GObject or a Variable " + self)
3639
end
3740

3841
---@param transform fun(value: any): any
@@ -48,17 +51,20 @@ end
4851
---@param callback fun(value: any)
4952
---@return function
5053
function Binding:subscribe(callback)
54+
if self.property ~= nil and GObject.Object:is_type_of(self.emitter) then
55+
local id = self.emitter.on_notify:connect(function()
56+
callback(self:get())
57+
end, self.property, false)
58+
return function()
59+
GObject.signal_handler_disconnect(self.emitter, id)
60+
end
61+
end
5162
if type(self.emitter.subscribe) == "function" then
5263
return self.emitter:subscribe(function()
5364
callback(self:get())
5465
end)
5566
end
56-
local id = self.emitter.on_notify:connect(function()
57-
callback(self:get())
58-
end, self.property, false)
59-
return function()
60-
GObject.signal_handler_disconnect(self.emitter, id)
61-
end
67+
error("can not subscribe: Not a GObject or a Variable " + self)
6268
end
6369

6470
Binding.__index = Binding

core/lua/astal/process.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function M.exec_async(commandline, on_stdout, on_stderr)
7272
local out, err = defualt_proc_args(on_stdout, on_stderr)
7373
if type(commandline) == "table" then
7474
Astal.Process.exec_asyncv(commandline, function(_, res)
75-
local stdout, fail = Astal.exec_asyncv_finish(res)
75+
local stdout, fail = Astal.Process.exec_asyncv_finish(res)
7676
if fail ~= nil then
7777
err(fail)
7878
else
@@ -81,7 +81,7 @@ function M.exec_async(commandline, on_stdout, on_stderr)
8181
end)
8282
else
8383
Astal.Process.exec_async(commandline, function(_, res)
84-
local stdout, fail = Astal.exec_finish(res)
84+
local stdout, fail = Astal.Process.exec_finish(res)
8585
if fail ~= nil then
8686
err(fail)
8787
else

core/lua/astal/variable.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ end
123123

124124
function Variable:drop()
125125
self.variable.emit_dropped()
126-
self.variable.run_dispose()
126+
Astal.Time.idle(GObject.Closure(function()
127+
self.variable.run_dispose()
128+
end))
127129
end
128130

129131
---@param callback function

core/lua/test.lua

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/getting-started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
maintainer: [@Aylur](https://github.com/Aylur)
66

7-
Read more about it on the [nix page](./nix)
7+
Read more about it on the [nix page](./nix#astal)
88

99
## Arch
1010

docs/getting-started/nix.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,32 @@ Using Astal on Nix will require you to package your project.
66

77
:::code-group
88

9-
```nix [typescript.nix]
10-
# Not documented yet
11-
```
9+
```nix [<i class="devicon-lua-plain"></i> Lua]
10+
{
11+
inputs = {
12+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
13+
astal = {
14+
inputs.nixpkgs.follows = "nixpkgs";
15+
url = "github:nixos/nixpkgs/nixos-unstable";
16+
};
17+
};
1218
13-
```nix [lua.nix]
14-
# Not documented yet
19+
outputs = { self, nixpkgs, astal }: let
20+
system = "x86_64-linux";
21+
pkgs = nixpkgs.legacyPackages.${system};
22+
in {
23+
packages.${system}.default = astal.lib.mkLuaPacakge {
24+
inherit pkgs;
25+
};
26+
};
27+
}
1528
```
1629

17-
```nix [python.nix]
30+
```nix [<i class="devicon-python-plain"></i> Python]
1831
# Not documented yet
1932
```
2033

21-
```nix [vala.nix]
34+
```nix [<i class="devicon-vala-plain"></i> Vala]
2235
# Not documented yet
2336
```
2437

@@ -34,7 +47,7 @@ Example content of a `flake.nix` file that contains your `homeConfigurations`.
3447

3548
:::code-group
3649

37-
```nix [flake.nix]
50+
```nix [<i class="devicon-nixos-plain"></i> flake.nix]
3851
{
3952
inputs = {
4053
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
@@ -71,7 +84,7 @@ Example content of `home.nix` file
7184

7285
:::code-group
7386

74-
```nix [home.nix]
87+
```nix [<i class="devicon-nixos-plain"></i> home.nix]
7588
{ inputs, pkgs, ... }:
7689
{
7790
# add the home manager module

docs/getting-started/supported-languages.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ components that don't render child nodes dynamically, bars and panels for exampl
2525

2626
Examples:
2727

28-
- TODO
28+
- [Simple Bar](https://github.com/Aylur/astal/tree/main/examples/lua/simple-bar)
29+
![simple-bar](https://github.com/user-attachments/assets/a306c864-56b7-44c4-8820-81f424f32b9b)
2930

3031
## Python
3132

examples/js/simple-bar/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Simple Bar Example
22

3-
![sime-bar](https://github.com/user-attachments/assets/a306c864-56b7-44c4-8820-81f424f32b9b)
3+
![simple-bar](https://github.com/user-attachments/assets/a306c864-56b7-44c4-8820-81f424f32b9b)
44

55
A simple bar for Hyprland using
66

examples/js/simple-bar/widget/Bar.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function SysTray() {
2222
onClickRelease={self => {
2323
menu?.popup_at_widget(self, Gdk.Gravity.SOUTH, Gdk.Gravity.NORTH, null)
2424
}}>
25-
<icon g_icon={bind(item, "gicon")}/>
25+
<icon gIcon={bind(item, "gicon")} />
2626
</button>
2727
}))}
2828
</box>
@@ -64,21 +64,27 @@ function BatteryLevel() {
6464
}
6565

6666
function Media() {
67-
const player = Mpris.Player.new("spotify")
67+
const mpris = Mpris.get_default()
6868

6969
return <box className="Media">
70-
<box
71-
className="Cover"
72-
valign={Gtk.Align.CENTER}
73-
css={bind(player, "coverArt").as(cover =>
74-
`background-image: url('${cover}');`
75-
)}
76-
/>
77-
<label
78-
label={bind(player, "title").as(() =>
79-
`${player.title} - ${player.artist}`
80-
)}
81-
/>
70+
{bind(mpris, "players").as(ps => ps[0] ? (
71+
<box>
72+
<box
73+
className="Cover"
74+
valign={Gtk.Align.CENTER}
75+
css={bind(ps[0], "coverArt").as(cover =>
76+
`background-image: url('${cover}');`
77+
)}
78+
/>
79+
<label
80+
label={bind(ps[0], "title").as(() =>
81+
`${ps[0].title} - ${ps[0].artist}`
82+
)}
83+
/>
84+
</box>
85+
) : (
86+
"Nothing Playing"
87+
))}
8288
</box>
8389
}
8490

0 commit comments

Comments
 (0)