Skip to content

Commit 087f86d

Browse files
Use taskbar icon and window title from server
1 parent 7cac8a6 commit 087f86d

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

src-tauri/src/endpoint.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::Result;
1212
#[allow(dead_code)]
1313
#[derive(Serialize, Deserialize, Clone, Debug)]
1414
pub struct InfoResponse {
15+
pub server_name: String,
1516
pub api_version: String,
1617
pub secure_apis_enabled: bool,
1718
game_version: Option<String>,
@@ -125,6 +126,16 @@ pub async fn get_status(endpoint_host: &str) -> Result<StatusResponse> {
125126
Ok(status)
126127
}
127128

129+
pub async fn get_custom_icon_url(endpoint_host: &str) -> Result<Option<String>> {
130+
let url = format!("https://{}/launcher/icon.ico", endpoint_host);
131+
let res = util::get_http_client().head(&url).send().await?;
132+
if res.status() == StatusCode::OK {
133+
Ok(Some(url))
134+
} else {
135+
Ok(None)
136+
}
137+
}
138+
128139
pub async fn register_user(
129140
username: &str,
130141
password: &str,

src-tauri/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,11 @@ async fn prep_launch(
407407
.ok_or(format!("Server {} not found", server_uuid))?
408408
.clone();
409409

410+
let mut server_name = server.get_description();
410411
let addr;
411412
let mut versions = Vec::new();
412413
let mut custom_loading_screen = false;
414+
let mut custom_icon_url = None;
413415
match &server.info {
414416
ServerInfo::Simple { ip, version } => {
415417
addr = ip.clone();
@@ -425,6 +427,11 @@ async fn prep_launch(
425427
custom_loading_screen = true;
426428
}
427429

430+
if let Ok(icon_url) = endpoint::get_custom_icon_url(endpoint).await {
431+
custom_icon_url = icon_url;
432+
}
433+
434+
server_name = Some(format!("\"{}\"", api_info.server_name));
428435
addr = api_info.login_address.clone();
429436
versions = api_info.get_supported_versions();
430437
}
@@ -575,6 +582,16 @@ async fn prep_launch(
575582
.args(["--asseturl", &format!("{}/", asset_url)])
576583
.args(["-l", &log_file_path]);
577584

585+
if let Some(server_name) = server_name {
586+
// window title
587+
cmd.args(["-n", &server_name]);
588+
}
589+
590+
if let Some(icon_url) = custom_icon_url {
591+
// window icon
592+
cmd.args(["-i", &icon_url]);
593+
}
594+
578595
if let ServerInfo::Endpoint { endpoint, .. } = &server.info {
579596
match session_token {
580597
None => {

src-tauri/src/state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ impl From<FlatServer> for Server {
477477
}
478478
}
479479
}
480+
impl Server {
481+
pub fn get_description(&self) -> Option<String> {
482+
self.description.clone()
483+
}
484+
}
480485

481486
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
482487
pub struct Servers {

0 commit comments

Comments
 (0)