Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DiscordRPC to plugins v4 #17

Merged
merged 7 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 148 additions & 114 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
[package]
name = "northstar-discord-rpc"
version = "0.1.0"
version = "0.4.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rrplug = "=3.0.0"
rrplug = { git = "https://github.com/R2NorthstarTools/rrplug.git", rev = "209a8b4b478ab095e3186dd32a3ed29dc9dbffee" }
discord-sdk = "0.3.2"
tokio = "1.26.0"
parking_lot = "0.12.1"

[build-dependencies]
windres = "0.2.2"

[lib]
name = "DiscordRPC"
crate-type = ["cdylib"]
8 changes: 0 additions & 8 deletions build.rs

This file was deleted.

95 changes: 0 additions & 95 deletions manifest/Resource.rc

This file was deleted.

10 changes: 0 additions & 10 deletions manifest/manifest.json

This file was deleted.

11 changes: 0 additions & 11 deletions manifest/resource.h

This file was deleted.

3 changes: 2 additions & 1 deletion src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub async fn async_main() {
large_text: data.large_text,
small_image: data.small_image,
small_text: data.small_text,
});
})
.secrets(data.secrets);

if let Some(start) = data.start {
activity_builder = activity_builder.start_timestamp(if start == 0 { 1 } else { start });
Expand Down
18 changes: 13 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(non_snake_case)]

use discord_sdk::activity::Secrets;
use parking_lot::Mutex;
use rrplug::prelude::*;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -28,6 +29,7 @@ pub struct ActivityData {
end: Option<i64>,
start: Option<i64>,
last_state: GameState,
secrets: Secrets,
}

#[deny(non_snake_case)]
Expand All @@ -38,8 +40,15 @@ pub struct DiscordRpcPlugin {

#[deny(non_snake_case)]
impl Plugin for DiscordRpcPlugin {
fn new(plugin_data: &PluginData) -> Self {
plugin_data.register_sq_functions(presence::fetch_presence);
const PLUGIN_INFO: PluginInfo = PluginInfo::new(
"DISCORDRPC\0",
"DSCRD-RPC\0",
"DISCORDRPC\0",
PluginContext::CLIENT,
);

fn new(_: bool) -> Self {
register_sq_functions(presence::fetch_presence);

let activity = Mutex::new(ActivityData {
large_image: Some("northstar".to_string()),
Expand All @@ -51,7 +60,6 @@ impl Plugin for DiscordRpcPlugin {
Ok(rt) => rt.block_on(async_main()),
Err(err) => {
log::error!("failed to create a runtime; {:?}", err);
return;
}
});

Expand All @@ -61,9 +69,9 @@ impl Plugin for DiscordRpcPlugin {
}
}

fn on_sqvm_created(&self, sqvm_handle: &CSquirrelVMHandle) {
fn on_sqvm_created(&self, sqvm_handle: &CSquirrelVMHandle, _: EngineToken) {
match sqvm_handle.get_context() {
ScriptVmType::Client | ScriptVmType::Ui => {
ScriptContext::CLIENT | ScriptContext::UI => {
run_presence_updates(unsafe { sqvm_handle.get_sqvm() })
}
_ => {}
Expand Down
4 changes: 2 additions & 2 deletions src/presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ pub fn run_presence_updates(sqvm: UnsafeHandle<*mut HSquirrelVM>) {
"#,
) {
err.log()
}
};
}

/// function to pull presence from the sqvm since in runframe it's impossibke to get the output of a function back
#[rrplug::sqfunction(VM = "UiClient", ExportName = "FetchPresence")]
#[rrplug::sqfunction(VM = "UI | CLIENT", ExportName = "FetchPresence")]
pub fn fetch_presence() -> Result<(), String> {
let plugin = crate::PLUGIN.wait();
let mut presence_lock = plugin.presence_data.lock();
Expand Down
Loading