0.2.1 changes

This commit is contained in:
KaitlynEthylia 2023-09-23 13:12:47 +01:00
parent 14c0362d73
commit 148d6617de
7 changed files with 88 additions and 36 deletions

View file

@ -1,38 +1,18 @@
# 0.2.0
# 0.2.1
## Added
- Lua values may now be set to functions that will return the desired
type. This prevents code being run multiple times when multiple Lua
VMs are spawned.
- The `watch` function has been added as a builtin helper function
for executing a shell command and following the output. The
function takes a shell command as the first arg, and optionally a
value to use if the command fails to start.
- When built with the `unsafe` feature flag, the `--safe` flag can be
passed to the command line to only load safe libraries anyway.
- The `--dry-run` command line flag can be passed to prevent
attempting to connect to Discord.
- Fish and Zsh completions are now provided with the release.
- Systemd, Runit, and OpenRC template services can be found in the
[etc](/etc) directory.
I originally planned this as a 0.3.0 release with some more fixes, but
as this currently doesn't work on windows at all, I decided it would
be better to release this now.
## Changed
- ClientID has been renamed to ApplicationID to better reflect
Discord's own usage and reduce ambiguity.
- Output has been cleaned up, making use of
[simplelog](https://lib.rs/simplelog).
- Command help text has been improved.
- `watch` function now accepts a function as a third argument to
manipulate each line
## Fixed
- The output binary is now named `disco`. Previously it was
mistakenly called `disco-rpc` by default.
- Switched to vendored Lua application.
- Systemd Unit missing `[Install]` section.
- Fixed setting values to functions

38
Cargo.lock generated
View file

@ -191,6 +191,12 @@ dependencies = [
"uuid",
]
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "errno"
version = "0.3.2"
@ -270,6 +276,25 @@ version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "lua-src"
version = "546.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c26d4af78361e025a3d03a2b964cd1592aff7495f4d4f7947218c084c6fdca8"
dependencies = [
"cc",
]
[[package]]
name = "luajit-src"
version = "210.4.8+resty107baaf"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e05167e8b2a2185758d83ed23541e5bd8bce37072e4204e0ef2c9b322bc87c4e"
dependencies = [
"cc",
"which",
]
[[package]]
name = "memchr"
version = "2.5.0"
@ -284,6 +309,8 @@ checksum = "07366ed2cd22a3b000aed076e2b68896fb46f06f1f5786c5962da73c0af01577"
dependencies = [
"bstr",
"cc",
"lua-src",
"luajit-src",
"num-traits",
"once_cell",
"pkg-config",
@ -531,6 +558,17 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "which"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
dependencies = [
"either",
"libc",
"once_cell",
]
[[package]]
name = "winapi"
version = "0.3.9"

View file

@ -1,6 +1,6 @@
[package]
name = "disco-rpc"
version = "0.2.0"
version = "0.2.1"
description = "A customisable client for Discord rich presence using simple Lua configuration."
authors = ["Kaitlyn~Ethylia <kaitlyyn.ethylia@proton.me>"]
edition = "2021"
@ -13,7 +13,7 @@ clap = { version = "4.3.21", features = ["derive", "env", "string"] }
dirs = "5.0.1"
discord-rich-presence = "0.2.3"
log = "0.4.20"
mlua = { version = "0.8.9", features = ["lua54", "send"] }
mlua = { version = "0.8.9", features = ["lua54", "send", "vendored"] }
simplelog = "0.12.1"
[features]

View file

@ -3,3 +3,6 @@ Description=Disco - Discord Rich Presence client
[Service]
ExecStart=/path/to/disco --retry-after <int>
[Install]
WantedBy=default.target

View file

@ -1,9 +1,10 @@
pub static DISCO_LIB: &str = "
function watch(command, err)
function watch(command, err, linefn)
return coroutine.create(function()
local handle = io.popen(_)
if not handle then return err end
for line in handle:lines() do
if linefn then line = linefn(line) end
coroutine.yield(line)
end
end)

View file

@ -61,7 +61,13 @@ impl<T: Clone + for<'lua> FromLua<'lua> + Send + 'static> Variable<T> {
let fun: LuaFunction = lua
.globals()
.get::<_, LuaTable>(name)
.unwrap()
.unwrap_or_else(|_| {
lua.globals()
.get::<_, LuaFunction>(name)
.unwrap()
.call::<_, LuaTable>(())
.unwrap()
})
.get(2)
.unwrap();
loop {
@ -76,7 +82,13 @@ impl<T: Clone + for<'lua> FromLua<'lua> + Send + 'static> Variable<T> {
safe,
);
lua.load(&data).exec().unwrap();
let thread: LuaThread = lua.globals().get(name).unwrap();
let thread: LuaThread = lua.globals().get(name).unwrap_or_else(|_| {
lua.globals()
.get::<_, LuaFunction>(name)
.unwrap()
.call::<_, LuaThread>(())
.unwrap()
});
loop {
match thread.resume::<_, Option<T>>(()) {
Ok(Some(val)) => dofun(val),

View file

@ -77,6 +77,12 @@ fn main() {
None
},
};
match client {
Some(_) => println!("AAA"),
None => println!("BBB"),
};
if let Some(ref mut client) = client {
let mut ret = client.connect();
match args.retry_after {
@ -186,14 +192,17 @@ impl DiscoActivity {
}
fn process(&self, client: &mut DiscordIpcClient) {
println!("processing: {self:#?}");
if self.active {
let mut activity = Activity::new();
if let Some(val) = &self.state {
activity = activity.state(val);
print!("0");
}
if let Some(val) = &self.details {
activity = activity.details(val);
print!("1");
}
if let Some(val) = &self.timestamp {
@ -205,6 +214,7 @@ impl DiscoActivity {
timestamps = timestamps.end(val);
}
activity = activity.timestamps(timestamps);
print!("2");
}
let mut buttons = Vec::with_capacity(2);
@ -212,13 +222,16 @@ impl DiscoActivity {
if let Some(val) = &self.button1 {
buttons.push(Button::new(&val.text, &val.url));
buttons_set = true;
print!("3");
}
if let Some(val) = &self.button2 {
buttons.push(Button::new(&val.text, &val.url));
buttons_set = true;
print!("4");
}
if buttons_set {
activity = activity.buttons(buttons);
print!("5");
}
let mut assets = Assets::new();
@ -229,6 +242,7 @@ impl DiscoActivity {
}
assets = assets.large_image(&val.asset);
assets_set = true;
print!("6");
}
if let Some(val) = &self.small_image {
if let Some(val) = &val.text {
@ -236,12 +250,16 @@ impl DiscoActivity {
}
assets = assets.small_image(&val.asset);
assets_set = true;
print!("7");
}
if assets_set {
activity = activity.assets(assets);
print!("8");
}
println!("setting activity");
client.set_activity(activity).unwrap();
print!("9");
}
}
}