|
@@ -9,6 +9,20 @@ use url::Url;
|
|
|
|
|
|
|
|
const ID_HEX_LEN: usize = 12;
|
|
const ID_HEX_LEN: usize = 12;
|
|
|
|
|
|
|
|
|
|
+/// Prefix for desktop file names and GApplication IDs.
|
|
|
|
|
+const APP_ID_PREFIX: &str = "dev.appiphany";
|
|
|
|
|
+
|
|
|
|
|
+/// Build a valid GApplication ID for the given launcher hash.
|
|
|
|
|
+/// Result looks like `dev.appiphany.e8009ee032e7`.
|
|
|
|
|
+pub fn app_id_for_launcher(id: &str) -> String {
|
|
|
|
|
+ format!("{APP_ID_PREFIX}.{id}")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// Desktop file stem for the given launcher hash (also used as `StartupWMClass`).
|
|
|
|
|
+fn desktop_stem(id: &str) -> String {
|
|
|
|
|
+ app_id_for_launcher(id)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#[derive(Clone, Debug)]
|
|
#[derive(Clone, Debug)]
|
|
|
pub enum LauncherIcon {
|
|
pub enum LauncherIcon {
|
|
|
/// Load via `gtk::Image::from_file`
|
|
/// Load via `gtk::Image::from_file`
|
|
@@ -37,7 +51,7 @@ pub fn run_install(
|
|
|
let data_home = xdg_data_home();
|
|
let data_home = xdg_data_home();
|
|
|
let apps_dir = data_home.join("applications");
|
|
let apps_dir = data_home.join("applications");
|
|
|
let icon_dir = appiphany_icon_dir(&data_home);
|
|
let icon_dir = appiphany_icon_dir(&data_home);
|
|
|
- let desktop_path = apps_dir.join(format!("appiphany-{id}.desktop"));
|
|
|
|
|
|
|
+ let desktop_path = apps_dir.join(format!("{}.desktop", desktop_stem(&id)));
|
|
|
|
|
|
|
|
if desktop_path.exists() && !force {
|
|
if desktop_path.exists() && !force {
|
|
|
return Err(format!(
|
|
return Err(format!(
|
|
@@ -83,7 +97,7 @@ pub fn run_install(
|
|
|
"applications-internet".to_string()
|
|
"applications-internet".to_string()
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- let desktop_body = build_desktop_file(&name, exe_str, &url, &icon_value);
|
|
|
|
|
|
|
+ let desktop_body = build_desktop_file(&name, exe_str, &url, &icon_value, &id);
|
|
|
std::fs::write(&desktop_path, desktop_body).map_err(|e| e.to_string())?;
|
|
std::fs::write(&desktop_path, desktop_body).map_err(|e| e.to_string())?;
|
|
|
|
|
|
|
|
eprintln!("Wrote {}", desktop_path.display());
|
|
eprintln!("Wrote {}", desktop_path.display());
|
|
@@ -105,17 +119,19 @@ pub fn run_uninstall(
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
let data_home = xdg_data_home();
|
|
let data_home = xdg_data_home();
|
|
|
- let desktop_path = data_home
|
|
|
|
|
- .join("applications")
|
|
|
|
|
- .join(format!("appiphany-{id}.desktop"));
|
|
|
|
|
|
|
+ let apps_dir = data_home.join("applications");
|
|
|
|
|
+ let desktop_path = apps_dir.join(format!("{}.desktop", desktop_stem(&id)));
|
|
|
|
|
+ let legacy_desktop_path = apps_dir.join(format!("appiphany-{id}.desktop"));
|
|
|
let legacy_icon_path = legacy_hicolor_icon_path(&data_home, &id);
|
|
let legacy_icon_path = legacy_hicolor_icon_path(&data_home, &id);
|
|
|
let icon_dir = appiphany_icon_dir(&data_home);
|
|
let icon_dir = appiphany_icon_dir(&data_home);
|
|
|
|
|
|
|
|
let mut removed = false;
|
|
let mut removed = false;
|
|
|
- if desktop_path.exists() {
|
|
|
|
|
- std::fs::remove_file(&desktop_path).map_err(|e| e.to_string())?;
|
|
|
|
|
- eprintln!("Removed {}", desktop_path.display());
|
|
|
|
|
- removed = true;
|
|
|
|
|
|
|
+ for path in [&desktop_path, &legacy_desktop_path] {
|
|
|
|
|
+ if path.exists() {
|
|
|
|
|
+ std::fs::remove_file(path).map_err(|e| e.to_string())?;
|
|
|
|
|
+ eprintln!("Removed {}", path.display());
|
|
|
|
|
+ removed = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if legacy_icon_path.exists() {
|
|
if legacy_icon_path.exists() {
|
|
|
std::fs::remove_file(&legacy_icon_path).map_err(|e| e.to_string())?;
|
|
std::fs::remove_file(&legacy_icon_path).map_err(|e| e.to_string())?;
|
|
@@ -162,15 +178,19 @@ pub fn list_launchers() -> Result<Vec<DesktopLauncher>, String> {
|
|
|
let Some(name) = path.file_name().and_then(|n| n.to_str()) else {
|
|
let Some(name) = path.file_name().and_then(|n| n.to_str()) else {
|
|
|
continue;
|
|
continue;
|
|
|
};
|
|
};
|
|
|
- if !(name.starts_with("appiphany-") && name.ends_with(".desktop")) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- let id = name
|
|
|
|
|
- .strip_prefix("appiphany-")
|
|
|
|
|
- .and_then(|s| s.strip_suffix(".desktop"))
|
|
|
|
|
- .unwrap_or_default()
|
|
|
|
|
- .to_string();
|
|
|
|
|
|
|
+ let new_prefix = format!("{APP_ID_PREFIX}.");
|
|
|
|
|
+ let id = if let Some(rest) = name.strip_prefix(&new_prefix) {
|
|
|
|
|
+ rest.strip_suffix(".desktop")
|
|
|
|
|
+ .unwrap_or_default()
|
|
|
|
|
+ .to_string()
|
|
|
|
|
+ } else if let Some(rest) = name.strip_prefix("appiphany-") {
|
|
|
|
|
+ rest.strip_suffix(".desktop")
|
|
|
|
|
+ .unwrap_or_default()
|
|
|
|
|
+ .to_string()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ };
|
|
|
if id.len() != ID_HEX_LEN || !id.chars().all(|c| c.is_ascii_hexdigit()) {
|
|
if id.len() != ID_HEX_LEN || !id.chars().all(|c| c.is_ascii_hexdigit()) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -259,10 +279,12 @@ fn escape_desktop_exec_component(s: &str) -> String {
|
|
|
out
|
|
out
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-fn build_desktop_file(name: &str, exe: &str, page_url: &str, icon: &str) -> String {
|
|
|
|
|
|
|
+fn build_desktop_file(name: &str, exe: &str, page_url: &str, icon: &str, id: &str) -> String {
|
|
|
|
|
+ let app_id = app_id_for_launcher(id);
|
|
|
let exec_line = format!(
|
|
let exec_line = format!(
|
|
|
- "{} {}",
|
|
|
|
|
|
|
+ "{} --app-id {} {}",
|
|
|
escape_desktop_exec_component(exe),
|
|
escape_desktop_exec_component(exe),
|
|
|
|
|
+ escape_desktop_exec_component(&app_id),
|
|
|
escape_desktop_exec_component(page_url)
|
|
escape_desktop_exec_component(page_url)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -278,6 +300,7 @@ fn build_desktop_file(name: &str, exe: &str, page_url: &str, icon: &str) -> Stri
|
|
|
),
|
|
),
|
|
|
&format!("Exec={exec_line}"),
|
|
&format!("Exec={exec_line}"),
|
|
|
&format!("Icon={}", escape_desktop_value(icon)),
|
|
&format!("Icon={}", escape_desktop_value(icon)),
|
|
|
|
|
+ &format!("StartupWMClass={app_id}"),
|
|
|
]
|
|
]
|
|
|
.join("\n")
|
|
.join("\n")
|
|
|
+ "\n"
|
|
+ "\n"
|