mirror of
https://github.com/zoriya/astal.git
synced 2026-06-03 18:31:16 +00:00
docs: lib examples consistency
This commit is contained in:
+20
-25
@@ -63,46 +63,41 @@ astal-apps --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Apps from "gi://AstalApps";
|
||||
import Apps from "gi://AstalApps"
|
||||
|
||||
const apps = new Apps.Apps({
|
||||
includeEntry: true,
|
||||
includeExecutable: true,
|
||||
});
|
||||
|
||||
print(apps.fuzzy_query("spotify")
|
||||
.map(app => app.name)
|
||||
.join("\n"))
|
||||
includeEntry: true,
|
||||
includeExecutable: true,
|
||||
})
|
||||
|
||||
for (const app of apps.fuzzy_query("spotify")) {
|
||||
print(app.name)
|
||||
}
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalApps as Apps
|
||||
|
||||
gi.require_version("AstalApps", "0.1")
|
||||
apps = Apps.Apps(
|
||||
include_entry=True,
|
||||
include_executable=True,
|
||||
)
|
||||
|
||||
from gi.repository import AstalApps
|
||||
for app in apps.fuzzy_query("obsidian"):
|
||||
print(app.get_name())
|
||||
|
||||
apps = AstalApps.Apps(include_entry = True, include_executable = True )
|
||||
|
||||
match = apps.fuzzy_query("obsidian")
|
||||
print("\n".join(app.get_name() for app in match))
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Apps = require("lgi").require("AstalApps")
|
||||
|
||||
local AstalApps = lgi.require("AstalApps", "0.1")
|
||||
|
||||
local apps = AstalApps.Apps({
|
||||
include_entry = true,
|
||||
include_executable = true,
|
||||
local apps = Apps.Apps({
|
||||
include_entry = true,
|
||||
include_executable = true,
|
||||
})
|
||||
|
||||
local match = apps:fuzzy_query("lutris")
|
||||
|
||||
for _, app in ipairs(match) do
|
||||
print(app.name)
|
||||
for _, app in ipairs(apps:fuzzy_query("lutris")) do
|
||||
print(app.name)
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
+20
-24
@@ -73,45 +73,41 @@ astal-auth --password my-password
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Auth from "gi://AstalAuth";
|
||||
import Gio from "gi://Gio";
|
||||
import Auth from "gi://AstalAuth"
|
||||
|
||||
Gio._promisify(Auth.Pam, "authenticate");
|
||||
|
||||
await Auth.Pam.authenticate("password")
|
||||
.then(_ => print("authentication sucessful"))
|
||||
.catch(logError);
|
||||
Auth.Pam.authenticate("password", (_, task) => {
|
||||
try {
|
||||
AstalAuth.Pam.authenticate_finish(task)
|
||||
print("authentication sucessful")
|
||||
} catch (error) {
|
||||
print(error)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalAuth", "0.1")
|
||||
|
||||
from gi.repository import AstalAuth
|
||||
from gi.repository import AstalAuth as Auth
|
||||
|
||||
def callback(_, task) -> None:
|
||||
try:
|
||||
AstalAuth.Pam.authenticate_finish(task)
|
||||
Auth.Pam.authenticate_finish(task)
|
||||
print("success")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
AstalAuth.Pam.authenticate("password", callback)
|
||||
Auth.Pam.authenticate("password", callback)
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Auth = require("lgi").require("AstalAuth")
|
||||
|
||||
local AstalAuth = lgi.require("AstalAuth", "0.1")
|
||||
|
||||
AstalAuth.Pam.authenticate("password", function(_, task)
|
||||
local status, err = AstalAuth.Pam.authenticate_finish(task)
|
||||
if status == 0 then
|
||||
print("success")
|
||||
else
|
||||
print(err)
|
||||
end
|
||||
Auth.Pam.authenticate("password", function(_, task)
|
||||
local status, err = Auth.Pam.authenticate_finish(task)
|
||||
if err ~= nil then
|
||||
print(err)
|
||||
else
|
||||
print("success")
|
||||
end
|
||||
end)
|
||||
```
|
||||
|
||||
|
||||
@@ -67,29 +67,26 @@ astal-battery --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Battery from "gi://AstalBattery";
|
||||
import Battery from "gi://AstalBattery"
|
||||
|
||||
const battery = Battery.get_default();
|
||||
const battery = Battery.get_default()
|
||||
|
||||
console.log(battery.percentage);
|
||||
print(battery.percentage)
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
gi.require_version("AstalBattery", "0.1")
|
||||
from gi.repository import AstalBattery as Battery
|
||||
|
||||
from gi.repository import AstalBattery
|
||||
|
||||
battery = AstalBattery.get_default()
|
||||
battery = Battery.get_default()
|
||||
|
||||
print(battery.get_percentage())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local AstalBattery = lgi.require("AstalBattery", "0.1")
|
||||
local Battery = require("lgi").require("AstalBattery")
|
||||
|
||||
local battery = Battery.get_default()
|
||||
|
||||
local battery = AstalBattery.get_default()
|
||||
print(battery.percentage)
|
||||
```
|
||||
|
||||
|
||||
+12
-15
@@ -69,34 +69,31 @@ bluetoothctl --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Bluetooth from "gi://AstalBluetooth";
|
||||
import Bluetooth from "gi://AstalBluetooth"
|
||||
|
||||
const bluetooth = Bluetooth.get_default();
|
||||
const bluetooth = Bluetooth.get_default()
|
||||
|
||||
console.log(bluetooth.get_devices().map((d) => d.name));
|
||||
for (const device of bluetooth.get_devices()) {
|
||||
print(device.name)
|
||||
}
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalBluetooth as Bluetooth
|
||||
|
||||
gi.require_version("AstalBluetooth", "0.1")
|
||||
bluetooth = Bluetooth.get_default()
|
||||
|
||||
from gi.repository import AstalBluetooth
|
||||
|
||||
bluetooth = AstalBluetooth.get_default()
|
||||
|
||||
print("\n".join(d.get_name() for d in bluetooth.get_devices()))
|
||||
for device in bluetooth.get_devices():
|
||||
print(device.get_name())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Bluetooth = require("lgi").require("AstalBluetooth")
|
||||
|
||||
local AstalBluetooth = lgi.require("AstalBluetooth", "0.1")
|
||||
|
||||
local bluetooth = AstalBluetooth.get_default()
|
||||
local bluetooth = Bluetooth.get_default()
|
||||
|
||||
for _, d in ipairs(bluetooth.devices) do
|
||||
print(d.name)
|
||||
print(d.name)
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
+12
-15
@@ -62,34 +62,31 @@ astal-hyprland # starts monitoring
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Hyprland from "gi://AstalHyprland";
|
||||
import Hyprland from "gi://AstalHyprland"
|
||||
|
||||
const hyprland = Hyprland.get_default();
|
||||
const hyprland = Hyprland.get_default()
|
||||
|
||||
console.log(hyprland.get_clients().map((c) => c.title));
|
||||
for (const client of hyprland.get_clients()) {
|
||||
print(client.title)
|
||||
}
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalHyprland as Hyprland
|
||||
|
||||
gi.require_version("AstalHyprland", "0.1")
|
||||
hyprland = Hyprland.get_default()
|
||||
|
||||
from gi.repository import AstalHyprland
|
||||
|
||||
hyprland = AstalHyprland.get_default()
|
||||
|
||||
print("\n".join(c.get_title() for c in hyprland.get_clients()))
|
||||
for client in hyprland.get_clients():
|
||||
print(client.get_title())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Hyprland = require("lgi").require("AstalHyprland")
|
||||
|
||||
local AstalHyprland = lgi.require("AstalHyprland", "0.1")
|
||||
|
||||
local hyprland = AstalHyprland.get_default()
|
||||
local hyprland = Hyprland.get_default()
|
||||
|
||||
for _, c in ipairs(hyprland.clients) do
|
||||
print(c.title)
|
||||
print(c.title)
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
+9
-14
@@ -66,35 +66,30 @@ astal-mpris --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Mpris from "gi://AstalMpris";
|
||||
import Mpris from "gi://AstalMpris"
|
||||
|
||||
const spotify = Mpris.Player.new("spotify");
|
||||
const spotify = Mpris.Player.new("spotify")
|
||||
|
||||
if (spotify.available) console.log(spotify.title);
|
||||
if (spotify.available)
|
||||
print(spotify.title)
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalMpris as Mpris
|
||||
|
||||
gi.require_version("AstalMpris", "0.1")
|
||||
|
||||
from gi.repository import AstalMpris
|
||||
|
||||
spotify = AstalMpris.Player.new("spotify")
|
||||
spotify = Mpris.Player.new("spotify")
|
||||
|
||||
if spotify.get_available():
|
||||
print(spotify.get_title())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Mpris = require("lgi").require("AstalMpris")
|
||||
|
||||
local AstalMpris = lgi.require("AstalMpris", "0.1")
|
||||
|
||||
local spotify = AstalMpris.Player.new("spotify")
|
||||
local Mpris = Mpris.Player.new("spotify")
|
||||
|
||||
if spotify.available then
|
||||
print(spotify.title)
|
||||
print(spotify.title)
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
@@ -64,31 +64,25 @@ nmcli --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Network from "gi://AstalNetwork";
|
||||
import Network from "gi://AstalNetwork"
|
||||
|
||||
const network = Network.get_default();
|
||||
const network = Network.get_default()
|
||||
|
||||
console.log(network.wifi.ssid);
|
||||
print(network.wifi.ssid)
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalNetwork as Network
|
||||
|
||||
gi.require_version("AstalNetwork", "0.1")
|
||||
|
||||
from gi.repository import AstalNetwork
|
||||
|
||||
network = AstalNetwork.get_default()
|
||||
network = Network.get_default()
|
||||
|
||||
print(network.get_wifi().get_ssid())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Network = require("lgi").require("AstalNetwork")
|
||||
|
||||
local AstalNetwork = lgi.require("AstalNetwork", "0.1")
|
||||
|
||||
local network = AstalNetwork.get_default()
|
||||
local network = Network.get_default()
|
||||
|
||||
print(network.wifi.ssid)
|
||||
```
|
||||
|
||||
+11
-17
@@ -66,24 +66,20 @@ astal-notifd --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Notifd from "gi://AstalNotifd";
|
||||
import Notifd from "gi://AstalNotifd"
|
||||
|
||||
const notifd = Notifd.get_default();
|
||||
const notifd = Notifd.get_default()
|
||||
|
||||
notifd.connect("notified", (_, id) => {
|
||||
const n = notifd.get_notification(id);
|
||||
console.log(n.summary, n.body);
|
||||
});
|
||||
const n = notifd.get_notification(id)
|
||||
print(n.summary, n.body)
|
||||
})
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalNotifd as Notifd
|
||||
|
||||
gi.require_version("AstalNotifd", "0.1")
|
||||
|
||||
from gi.repository import AstalNotifd
|
||||
|
||||
notifd = AstalNotifd.get_default()
|
||||
notifd = Notifd.get_default()
|
||||
|
||||
def on_notified(_, id):
|
||||
n = notifd.get_notification(id)
|
||||
@@ -93,15 +89,13 @@ notifd.connect("notified", on_notified)
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Notifd = require("lgi").require("AstalNotifd")
|
||||
|
||||
local AstalNotifd = lgi.require("AstalNotifd", "0.1")
|
||||
|
||||
local notifd = AstalNotifd.get_default()
|
||||
local notifd = Notifd.get_default()
|
||||
|
||||
notifd.on_notified = function(_, id)
|
||||
local n = notifd.get_notification(id)
|
||||
print(n.body, n.summary)
|
||||
local n = notifd.get_notification(id)
|
||||
print(n.body, n.summary)
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
@@ -67,31 +67,25 @@ astal-power-profiles --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import PowerProfiles from "gi://AstalPowerProfiles";
|
||||
import PowerProfiles from "gi://AstalPowerProfiles"
|
||||
|
||||
const powerprofiles = PowerProfiles.get_default();
|
||||
const powerprofiles = PowerProfiles.get_default()
|
||||
|
||||
console.log(powerprofiles.activeProfile);
|
||||
print(powerprofiles.activeProfile)
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalPowerProfiles as PowerProfiles
|
||||
|
||||
gi.require_version("AstalPowerProfiles", "0.1")
|
||||
|
||||
from gi.repository import AstalPowerProfiles
|
||||
|
||||
powerprofiles = AstalPowerProfiles.get_default()
|
||||
powerprofiles = PowerProfiles.get_default()
|
||||
|
||||
print(powerprofiles.get_active_profile())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local PowerProfiles = require("lgi").require("AstalPowerProfiles")
|
||||
|
||||
local AstalPowerProfiles = lgi.require("AstalPowerProfiles", "0.1")
|
||||
|
||||
local powerprofiles = AstalPowerProfiles.get_default()
|
||||
local powerprofiles = PowerProfiles.get_default()
|
||||
|
||||
print(powerprofiles.active_profile)
|
||||
```
|
||||
|
||||
+12
-15
@@ -62,34 +62,31 @@ astal-river --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import River from "gi://AstalRiver";
|
||||
import River from "gi://AstalRiver"
|
||||
|
||||
const river = River.get_default();
|
||||
const river = River.get_default()
|
||||
|
||||
console.log(river.get_outputs().map((o) => o.name));
|
||||
for (const output of river.get_outputs()) {
|
||||
print(output.name)
|
||||
}
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalRiver as River
|
||||
|
||||
gi.require_version("AstalRiver", "0.1")
|
||||
river = River.get_default()
|
||||
|
||||
from gi.repository import AstalRiver
|
||||
|
||||
river = AstalRiver.get_default()
|
||||
|
||||
print("\n".join(o.get_name() for o in river.get_outputs()))
|
||||
for output in river.get_outputs():
|
||||
print(output.get_name())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local River = require("lgi").require("AstalRiver")
|
||||
|
||||
local AstalRiver = lgi.require("AstalRiver", "0.1")
|
||||
|
||||
local river = AstalRiver.River.get_default()
|
||||
local river = River.River.get_default()
|
||||
|
||||
for _, o in ipairs(river.outputs) do
|
||||
print(o.name)
|
||||
print(o.name)
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
+12
-15
@@ -62,34 +62,31 @@ astal-tray --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Tray from "gi://AstalTray";
|
||||
import Tray from "gi://AstalTray"
|
||||
|
||||
const tray = Tray.get_default();
|
||||
const tray = Tray.get_default()
|
||||
|
||||
console.log(tray.get_items().map((i) => i.title));
|
||||
for (const item of tray.get_items()) {
|
||||
print(item.title)
|
||||
}
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalTray as Tray
|
||||
|
||||
gi.require_version("AstalTray", "0.1")
|
||||
tray = Tray.get_default()
|
||||
|
||||
from gi.repository import AstalTray
|
||||
|
||||
tray = AstalTray.get_default()
|
||||
|
||||
print("\n".join(i.title for i in tray.get_items()))
|
||||
for item in tray.get_items():
|
||||
print(item.title)
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Tray = require("lgi").require("AstalTray")
|
||||
|
||||
local AstalTray = lgi.require("AstalTray", "0.1")
|
||||
|
||||
local tray = AstalTray.get_default()
|
||||
local tray = Tray.get_default()
|
||||
|
||||
for _, i in ipairs(tray.items) do
|
||||
print(i.title)
|
||||
print(i.title)
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
@@ -64,31 +64,25 @@ wpctl --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Wp from "gi://AstalWp";
|
||||
import Wp from "gi://AstalWp"
|
||||
|
||||
const audio = Wp.get_default_wp().audio;
|
||||
const audio = Wp.get_default_wp().audio
|
||||
|
||||
console.log(audio.default_speaker.volume);
|
||||
print(audio.default_speaker.volume)
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
import gi
|
||||
from gi.repository import AstalWp as Wp
|
||||
|
||||
gi.require_version("AstalWp", "0.1")
|
||||
|
||||
from gi.repository import AstalWp
|
||||
|
||||
audio = AstalWp.get_default_wp().get_audio()
|
||||
audio = Wp.get_default_wp().get_audio()
|
||||
|
||||
print(audio.get_default_speaker().get_volume())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
local lgi = require("lgi")
|
||||
local Wp = require("lgi").require("AstalWp")
|
||||
|
||||
local AstalWp = lgi.require("AstalWp", "0.1")
|
||||
|
||||
local audio = AstalWp.get_default_wp().audio
|
||||
local audio = Wp.get_default_wp().audio
|
||||
|
||||
print(audio.default_speaker.volume)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user