Skip to content

Commit

Permalink
Merge pull request #66 from Aylur/feat/greetd
Browse files Browse the repository at this point in the history
feat: greetd ipc client
  • Loading branch information
Aylur authored Nov 5, 2024
2 parents 8c6d218 + 524030a commit ca6a37c
Show file tree
Hide file tree
Showing 12 changed files with 569 additions and 1 deletion.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Planned features, you could help with:

- [niri ipc library](https://github.com/Aylur/astal/issues/8)
- sway ipc library
- greetd ipc library
- http request library abstraction over libsoup (mostly to be used in gjs and lua)
- notification sending libnotify clone [#26](https://github.com/Aylur/astal/issues/26)
- setting up [uncrustify](https://github.com/uncrustify/uncrustify) for Vala
Expand Down
6 changes: 6 additions & 0 deletions docs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ in
version = ../lib/cava/version;
authors = "kotontrion";
}}
${genLib {
flakepkg = "greet";
gir = "Greet";
description = "IPC client for greetd";
version = ../lib/greet/version;
}}
${genLib {
flakepkg = "hyprland";
gir = "Hyprland";
Expand Down
94 changes: 94 additions & 0 deletions docs/guide/libraries/greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Greet

Library and CLI tool for sending requests to [greetd](https://sr.ht/~kennylevinsen/greetd/).

## Installation

1. install dependencies

:::code-group

```sh [<i class="devicon-archlinux-plain"></i> Arch]
sudo pacman -Syu meson vala json-glib gobject-introspection
```

```sh [<i class="devicon-fedora-plain"></i> Fedora]
sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel
```

```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu]
sudo apt install meson valac libjson-glib-dev gobject-introspection
```

:::

::: info
Although `greetd` is not a direct build dependency,
it should be self-explanatory that the daemon is required to be available at runtime.
:::

2. clone repo

```sh
git clone https://github.com/aylur/astal.git
cd astal/lib/greet
```

3. install

```sh
meson setup --prefix /usr build
meson install -C build
```

## Usage

You can browse the [Greet reference](https://aylur.github.io/libastal/greet).

### CLI

```sh
astal-greet --help
```

### Library

:::code-group

```js [<i class="devicon-javascript-plain"></i> JavaScript]
import Greet from "gi://AstalGreet"

Greet.login("username", "password", "compositor", (_, res) => {
try {
Greet.login_finish(res)
} catch (err) {
printerr(err)
}
})
```

```py [<i class="devicon-python-plain"></i> Python]
# Not yet documented

```

```lua [<i class="devicon-lua-plain"></i> Lua]
local Greet = require("lgi").require("AstalGreet")

Greet.login("username", "password", "compositor", function (_, res)
local err = Greet.login_finish(res)
if err ~= nil then
print(err)
end
end)
```

```vala [<i class="devicon-vala-plain"></i> Vala]
try {
yield AstalGreet.login("username", "password", "compositor");
} catch (Error err) {
printerr(err.message);
}
```

:::
1 change: 1 addition & 0 deletions docs/vitepress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default defineConfig({
{ text: "Battery", link: "/guide/libraries/battery" },
{ text: "Bluetooth", link: "/guide/libraries/bluetooth" },
{ text: "Cava", link: "/guide/libraries/cava" },
{ text: "Greet", link: "/guide/libraries/greet" },
{ text: "Hyprland", link: "/guide/libraries/hyprland" },
{ text: "Mpris", link: "/guide/libraries/mpris" },
{ text: "Network", link: "/guide/libraries/network" },
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
battery = mkPkg "astal-battery" ./lib/battery [json-glib];
bluetooth = mkPkg "astal-bluetooth" ./lib/bluetooth [];
cava = mkPkg "astal-cava" ./lib/cava [(pkgs.callPackage ./nix/libcava.nix {})];
greet = mkPkg "astal-greet" ./lib/greet [json-glib];
hyprland = mkPkg "astal-hyprland" ./lib/hyprland [json-glib];
mpris = mkPkg "astal-mpris" ./lib/mpris [gvfs json-glib];
network = mkPkg "astal-network" ./lib/network [networkmanager];
Expand Down
72 changes: 72 additions & 0 deletions lib/greet/cli.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
static bool help;
static bool version;
static string username;
static string password;
static string cmd;
[CCode (array_length = false, array_null_terminated = true)]
static string[] env;

const OptionEntry[] options = {
{ "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, null, null },
{ "help", 'h', OptionFlags.NONE, OptionArg.NONE, ref help, null, null },
{ "username", 'u', OptionFlags.NONE, OptionArg.STRING, ref username, null, null },
{ "password", 'p', OptionFlags.NONE, OptionArg.STRING, ref password, null, null },
{ "cmd", 'c', OptionFlags.NONE, OptionArg.STRING, ref cmd, null, null },
{ "env", 'e', OptionFlags.NONE, OptionArg.STRING_ARRAY, ref env, null, null },
{ null },
};

async int main(string[] argv) {
try {
var opts = new OptionContext();
opts.add_main_entries(options, null);
opts.set_help_enabled(false);
opts.set_ignore_unknown_options(false);
opts.parse(ref argv);
} catch (OptionError err) {
printerr (err.message);
return 1;
}

if (help) {
print("Usage:\n");
print(" %s [flags]\n\n", argv[0]);
print("Flags:\n");
print(" -h, --help Print this help and exit\n");
print(" -v, --version Print version number and exit\n");
print(" -u, --username User to login to\n");
print(" -p, --password Password of the user\n");
print(" -c, --cmd Command to start the session with\n");
print(" -e, --env Additional env vars to set for the session\n");
return 0;
}

if (version) {
printerr(AstalGreet.VERSION);
return 0;
}

if (username == null) {
printerr("missing username\n");
return 1;
}

if (password == null) {
printerr("missing password\n");
return 1;
}

if (cmd == null) {
printerr("missing cmd\n");
return 1;
}

try {
yield AstalGreet.login_with_env(username, password, cmd, env);
} catch (Error err) {
printerr(err.message);
return 1;
}

return 0;
}
Loading

0 comments on commit ca6a37c

Please sign in to comment.