Skip to content

Commit

Permalink
feat: use relative path instead of cwd for credentials.ini file (#78
Browse files Browse the repository at this point in the history
)
  • Loading branch information
afonsojramos committed Mar 12, 2024
2 parents a13703f + 2574ddb commit b6606f8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Plex Rich Presence alternatives:
4. In the [Discord Developer Dashboard](https://discord.com/developers/applications), within your application and under **Rich Presence** -> **Art Assets**, upload the application images, either the ones located in `/images` or ones that you choose to submit (as long as the keys for those images stay `shows` and `movies`).
5. Run the respective executable, and you're ready to start sharing your progress!

*P.S.* Discord needs to be running on the machine Discrakt is running on.
*P.S.* Discord needs to be running on the machine Discrakt is running on.
*P.P.S.* Place the `credentials.ini` file in the same directory as the executable.

## Running executables

Expand All @@ -55,7 +56,7 @@ You can now use the silent Windows executable, and now you only need to follow [

#### Scoop

You can install discrakt in [Scoop](https://scoop.sh/) via the [Extras](https://github.com/ScoopInstaller/Extras) bucket:
You can install Discrakt in [Scoop](https://scoop.sh/) via the [Extras](https://github.com/ScoopInstaller/Extras) bucket:
```powershell
scoop bucket add extras # Ensure bucket is added first
scoop install discrakt
Expand Down
Binary file modified images/demo/profile-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Discord {
Assets::new()
.large_image(&img)
.small_image("trakt")
.small_text("Trakt.tv"),
.small_text("Discrakt"),
)
.timestamps(
Timestamps::new()
Expand Down
18 changes: 12 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::{DateTime, FixedOffset, SecondsFormat, Utc};
use configparser::ini::Ini;
use serde::Deserialize;
use std::{io, time::Duration};
use std::{env, io, time::Duration};
use ureq::AgentBuilder;

#[derive(Deserialize)]
Expand Down Expand Up @@ -143,7 +143,11 @@ impl Env {

pub fn load_config() -> Env {
let mut config = Ini::new();
config.load("credentials.ini").unwrap();
let mut path = env::current_exe().unwrap();
path.pop();
path.push("credentials.ini");

config.load(path).expect("Failed to load credentials.ini");

Env {
discord_client_id: "826189107046121572".to_string(),
Expand Down Expand Up @@ -171,8 +175,12 @@ pub fn load_config() -> Env {

fn set_oauth_tokens(json_response: &TraktAccessToken) {
let mut config = Ini::new_cs();
let mut path = env::current_exe().unwrap();
path.pop();
path.push("credentials.ini");

config
.load("credentials.ini")
.load(path.clone())
.expect("Failed to load credentials.ini");
config.setstr(
"Trakt API",
Expand All @@ -189,9 +197,7 @@ fn set_oauth_tokens(json_response: &TraktAccessToken) {
"OAuthRefreshTokenExpiresAt",
Some(json_response.created_at.to_string()),
);
config
.write("credentials.ini")
.expect("Failed to write credentials.ini");
config.write(path).expect("Failed to write credentials.ini");
}

pub fn log(message: &str) {
Expand Down

0 comments on commit b6606f8

Please sign in to comment.