Skip to content

Commit

Permalink
feat: large text, small text
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Aug 4, 2024
1 parent d07f60e commit 35a0c5c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ You can configure state, details and git integration by changing Discord Presenc
"state": "Working on {filename}",
"details": "In {workspace}",
// URL for large image
"large_image": "{base_icons_url}/{language_icon}.png",
"large_image": "{base_icons_url}/{language}.png",
// URL for small image
"small_image": "{base_icons_url}/zed.png",
"git_integration": true
Expand Down
16 changes: 15 additions & 1 deletion lsp/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ pub struct Configuration {

pub state: String,
pub details: String,

pub large_image: Option<String>,
pub large_text: Option<String>,
pub small_image: Option<String>,
pub small_text: Option<String>,

pub git_integration: bool,
}

Expand All @@ -36,8 +40,10 @@ impl Configuration {
base_icons_url: String::from("https://raw.githubusercontent.com/xhyrom/zed-discord-presence/feat/recognize-languages/assets/icons/"),
state: String::from("Working on {filename}"),
details: String::from("In {workspace}"),
large_image: Some(String::from("{base_icons_url}/{language_icon}.png")),
large_image: Some(String::from("{base_icons_url}/{language}.png")),
large_text: Some(String::from("{language}")),
small_image: Some(String::from("{base_icons_url}/zed.png")),
small_text: Some(String::from("Zed")),
git_integration: true,
}
}
Expand Down Expand Up @@ -65,10 +71,18 @@ impl Configuration {
self.large_image = Some(large_image.as_str().unwrap().to_string())
}

if let Some(large_text) = initialization_options.get("large_text") {
self.large_text = Some(large_text.as_str().unwrap().to_string())
}

if let Some(small_image) = initialization_options.get("small_image") {
self.small_image = Some(small_image.as_str().unwrap().to_string())
}

if let Some(small_text) = initialization_options.get("small_text") {
self.small_text = Some(small_text.as_str().unwrap().to_string())
}

if let Some(git_integration) = initialization_options.get("git_integration") {
self.git_integration = git_integration.as_bool().unwrap_or(true);
}
Expand Down
10 changes: 10 additions & 0 deletions lsp/src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ impl Discord {
state: String,
details: String,
large_image: Option<String>,
large_text: Option<String>,
small_image: Option<String>,
small_text: Option<String>,
git_remote_url: Option<String>,
) {
let mut client = self.get_client();
Expand All @@ -81,10 +83,18 @@ impl Discord {
assets = assets.large_image(large_image);
}

if let Some(large_text) = large_text.as_ref() {
assets = assets.large_text(large_text);
}

if let Some(small_image) = small_image.as_ref() {
assets = assets.small_image(small_image);
}

if let Some(small_text) = small_text.as_ref() {
assets = assets.small_text(small_text);
}

let mut buttons: Vec<Button> = Vec::new();

if let Some(git_remote_url) = git_remote_url.as_ref() {
Expand Down
20 changes: 18 additions & 2 deletions lsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,40 @@ impl Backend {
let large_image = config.large_image.as_ref().map(|img| {
img.replace("{base_icons_url}", &config.base_icons_url)
.replace(
"{language_icon}",
"{language}",
&get_language(&doc).unwrap_or(String::from("")),
)
});

let large_text = config.large_text.as_ref().map(|text| {
text.replace(
"{language}",
&get_language(&doc).unwrap_or(String::from("")),
)
});

let small_image = config.small_image.as_ref().map(|img| {
img.replace("{base_icons_url}", &config.base_icons_url)
.replace(
"{language_icon}",
"{language}",
&get_language(&doc).unwrap_or(String::from("")),
)
});

let small_text = config.small_text.as_ref().map(|text| {
text.replace(
"{language}",
&get_language(&doc).unwrap_or(String::from("")),
)
});

self.discord.change_activity(
state,
details,
large_image,
large_text,
small_image,
small_text,
if config.git_integration {
self.get_git_remote_url()
} else {
Expand Down

0 comments on commit 35a0c5c

Please sign in to comment.