Skip to content

Commit 69ccc4f

Browse files
committed
refactor: improve Discord API usage and method call idioms
1 parent 6465ab7 commit 69ccc4f

4 files changed

Lines changed: 127 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 118 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ tray-icon = "0.19"
3737
ksni = { version = "0.3", features = ["blocking"] }
3838

3939
[target.'cfg(target_os = "macos")'.dependencies]
40-
objc2-app-kit = "0.2"
41-
objc2-foundation = "0.2"
40+
objc2-app-kit = "0.3"
41+
objc2-foundation = "0.3"
4242

4343
[target.'cfg(target_os = "windows")'.build-dependencies]
4444
winresource = "0.1.28"

src/discord.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ pub struct Payload {
2828
}
2929

3030
impl Discord {
31-
/// Creates a new Discord client with the given application ID.
32-
///
33-
/// Note: discord-rich-presence 1.0.0 changed the API - `DiscordIpcClient::new()`
34-
/// now returns the client directly (not a Result).
3531
pub fn new(discord_client_id: String) -> Discord {
3632
Discord {
3733
client: DiscordIpcClient::new(&discord_client_id),
@@ -40,10 +36,9 @@ impl Discord {
4036
}
4137

4238
/// Switch to a different Discord application ID if needed.
43-
/// Returns true if a switch occurred.
44-
fn switch_app_id(&mut self, new_app_id: &str) -> bool {
39+
fn switch_app_id(&mut self, new_app_id: &str) {
4540
if self.current_app_id == new_app_id {
46-
return false;
41+
return;
4742
}
4843

4944
tracing::info!(
@@ -56,11 +51,9 @@ impl Discord {
5651
let _ = self.client.close();
5752

5853
// Create new client with new app ID
59-
// Note: discord-rich-presence 1.0.0 - new() no longer returns Result
6054
self.client = DiscordIpcClient::new(new_app_id);
6155
self.current_app_id = new_app_id.to_string();
6256
self.connect();
63-
true
6457
}
6558

6659
pub fn connect(&mut self) {

src/main.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
121121

122122
// Spawn background polling thread
123123
let polling_handle = thread::spawn(move || {
124-
// discord-rich-presence 1.0.0: new() no longer returns Result
125124
let mut discord = Discord::new(DEFAULT_DISCORD_APP_ID.to_string());
126125
let mut trakt = Trakt::new(trakt_client_id, trakt_username, trakt_access_token);
127126

128-
Discord::connect(&mut discord);
127+
discord.connect();
129128

130129
// Update state: Discord connected
131130
if let Ok(mut state) = app_state_clone.write() {
@@ -149,7 +148,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
149148
let is_paused = app_state_clone.read().map(|s| s.is_paused).unwrap_or(false);
150149

151150
if is_paused {
152-
Discord::close(&mut discord);
151+
discord.close();
153152
continue;
154153
}
155154

@@ -161,7 +160,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
161160
if let Ok(mut state) = app_state_clone.write() {
162161
state.clear_watching();
163162
}
164-
Discord::close(&mut discord);
163+
discord.close();
165164
continue;
166165
}
167166
};
@@ -193,10 +192,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
193192
state.set_watching(title, details, watch_stats.watch_percentage);
194193
}
195194

196-
Discord::set_activity(&mut discord, &response, &mut trakt, tmdb_token.clone());
195+
discord.set_activity(&response, &mut trakt, tmdb_token.clone());
197196
}
198197

199-
Discord::close(&mut discord);
198+
discord.close();
200199
tracing::info!("Polling thread stopped");
201200
});
202201

0 commit comments

Comments
 (0)