feat(desktop): embed icon, shorten keybind label, add toggle feedback

This commit is contained in:
objz committed 2026-04-05 16:05:31 +02:00
1 parent 86d217903a
commit ea093c044f
6 files changed
+57 -4

No files matched your search

+20 -1
View File
@@ -2,6 +2,8 @@ use std::path::{Path, PathBuf};
use crate::instance::models::InstanceConfig;
const ICON_BYTES: &[u8] = include_bytes!("../../assets/icon.png");
pub fn desktop_path(name: &str) -> Option<PathBuf> {
dirs_next::data_dir().map(|d| {
d.join("applications")
@@ -13,6 +15,23 @@ pub fn icon_path() -> Option<PathBuf> {
dirs_next::data_dir().map(|d| d.join("mcl").join("icon.png"))
}
fn ensure_icon() -> Option<PathBuf> {
let path = icon_path()?;
if path.exists() {
return Some(path);
}
let parent = path.parent()?;
if let Err(e) = std::fs::create_dir_all(parent) {
tracing::warn!("Failed to create icon directory: {}", e);
return None;
}
if let Err(e) = std::fs::write(&path, ICON_BYTES) {
tracing::warn!("Failed to write bundled icon: {}", e);
return None;
}
Some(path)
}
pub fn exists(name: &str) -> bool {
desktop_path(name).map(|p| p.exists()).unwrap_or(false)
}
@@ -25,7 +44,7 @@ pub fn create(config: &InstanceConfig) -> std::io::Result<PathBuf> {
std::fs::create_dir_all(parent)?;
}
let icon = icon_path().filter(|p| p.exists());
let icon = ensure_icon();
let content = build_content(&config.name, icon.as_deref());
std::fs::write(&path, content)?;
Ok(path)
+21 -2
View File
@@ -421,8 +421,27 @@ impl App {
}
widgets::details::SettingsAction::ToggleDesktop => {
if let Some(inst) = self.profiles_state.selected_instance() {
if let Err(e) = crate::instance::desktop::toggle(inst) {
tracing::error!("Failed to toggle desktop shortcut: {}", e);
let name = inst.name.clone();
match crate::instance::desktop::toggle(inst) {
Ok(true) => {
error_buffer::push_error(error_buffer::ErrorEvent {
id: 0,
level: tracing::Level::INFO,
message: format!("Desktop shortcut created for '{name}'"),
pushed_at: std::time::Instant::now(),
});
}
Ok(false) => {
error_buffer::push_error(error_buffer::ErrorEvent {
id: 0,
level: tracing::Level::INFO,
message: format!("Desktop shortcut removed for '{name}'"),
pushed_at: std::time::Instant::now(),
});
}
Err(e) => {
tracing::error!("Failed to toggle desktop shortcut: {}", e);
}
}
}
return Ok(());
+1 -1
View File
@@ -36,7 +36,7 @@ pub fn render(
&[
("e", " edit instance"),
("g", " edit global"),
("d", " desktop shortcut"),
("d", " desktop"),
],
area.width.saturating_sub(2),
);