From f18545b7319a651b4d37b231261a67c36f50b984 Mon Sep 17 00:00:00 2001 From: nekename <63245705+nekename@users.noreply.github.com> Date: Wed, 20 Aug 2025 20:03:07 +0100 Subject: [PATCH] feat: isolate product name so it can be changed by downstreams --- product_name.txt | 1 + src-tauri/src/events/frontend/settings.rs | 3 ++- src-tauri/src/main.rs | 19 ++++++++++--------- src-tauri/src/plugins/webserver.rs | 2 +- src-tauri/src/shared.rs | 4 +++- src/components/ActionList.svelte | 3 ++- src/components/NoDevicesDetected.svelte | 4 +++- src/components/SettingsView.svelte | 10 ++++++---- src/lib/singletons.ts | 3 +++ 9 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 product_name.txt diff --git a/product_name.txt b/product_name.txt new file mode 100644 index 0000000..6866c8f --- /dev/null +++ b/product_name.txt @@ -0,0 +1 @@ +OpenDeck diff --git a/src-tauri/src/events/frontend/settings.rs b/src-tauri/src/events/frontend/settings.rs index 5174d90..612fcb5 100644 --- a/src-tauri/src/events/frontend/settings.rs +++ b/src-tauri/src/events/frontend/settings.rs @@ -55,10 +55,11 @@ pub fn get_build_info() -> String { format!( r#"
- OpenDeck v{} ({}) on {} + {} v{} ({}) on {} {}
"#, + crate::shared::PRODUCT_NAME, built_info::PKG_VERSION, built_info::GIT_COMMIT_HASH_SHORT.unwrap_or("commit hash unknown"), built_info::TARGET, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 9ef9394..ae74691 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -14,6 +14,7 @@ mod built_info { } use events::frontend; +use shared::PRODUCT_NAME; use once_cell::sync::OnceCell; use tauri::{ @@ -88,11 +89,11 @@ async fn main() { app.get_webview_window("main").unwrap().close().unwrap(); app.dialog() .message(format!( - "A newer version of OpenDeck created configuration files on this device. This version is v{}; please upgrade to v{} or newer.", + "A newer version of {PRODUCT_NAME} created configuration files on this device. This version is v{}; please upgrade to v{} or newer.", built_info::PKG_VERSION, settings.value.version )) - .title("OpenDeck upgrade required") + .title(format!("{PRODUCT_NAME} upgrade required")) .kind(MessageDialogKind::Error) .show(|_| APP_HANDLE.get().unwrap().exit(1)); return Ok(()); @@ -103,16 +104,16 @@ async fn main() { settings.save()?; if old_version == "0.0.0" { app.dialog() - .message( - r#"Thanks for installing OpenDeck! + .message(format!( + r#"Thanks for installing {PRODUCT_NAME}! If you have any issues, please reach out on any of the support channels listed on GitHub (and make sure to star the project while you're there!). Some minimal statistics (such as operating system and plugins installed) will be collected from the next time the app starts. If you do not wish to support development in this way, please disable statistics in the settings. Enjoy!"#, - ) - .title("OpenDeck has successfully been installed") + )) + .title(format!("{PRODUCT_NAME} has successfully been installed")) .kind(MessageDialogKind::Info) .show(|_| ()); settings.value.statistics = false; @@ -141,7 +142,7 @@ Enjoy!"#, plugins::initialise_plugins(); application_watcher::init_application_watcher(); - let label = IconMenuItemBuilder::with_id("label", "OpenDeck") + let label = IconMenuItemBuilder::with_id("label", PRODUCT_NAME) .icon(app.default_window_icon().unwrap().clone()) .enabled(false) .build(app)?; @@ -201,11 +202,11 @@ Enjoy!"#, let app = APP_HANDLE.get().unwrap(); app.dialog() .message(format!( - "A new version of OpenDeck, {}, is available.\nUpdate description:\n\n{}", + "A new version of {PRODUCT_NAME}, {}, is available.\nUpdate description:\n\n{}", tag_name, res.get("body").map(|v| v.as_str().unwrap()).unwrap_or("No description").trim() )) - .title("OpenDeck update available") + .title(format!("{PRODUCT_NAME} update available")) .show(|_| ()); } diff --git a/src-tauri/src/plugins/webserver.rs b/src-tauri/src/plugins/webserver.rs index e2b0726..e6d6943 100644 --- a/src-tauri/src/plugins/webserver.rs +++ b/src-tauri/src/plugins/webserver.rs @@ -25,7 +25,7 @@ pub async fn init_webserver(prefix: PathBuf) { #[cfg(target_os = "windows")] let url = url[1..].replace('/', "\\"); - // Ensure the requested path is within the OpenDeck config directory to prevent unrestricted access to the filesystem. + // Ensure the requested path is within the config directory to prevent unrestricted access to the filesystem. let developer = match crate::store::Store::new("settings", &prefix, crate::store::Settings::default()) { Ok(store) => store.value.developer, Err(_) => false, diff --git a/src-tauri/src/shared.rs b/src-tauri/src/shared.rs index 5285d88..b802d6f 100644 --- a/src-tauri/src/shared.rs +++ b/src-tauri/src/shared.rs @@ -10,6 +10,8 @@ use once_cell::sync::Lazy; use tauri::Manager; use tokio::sync::RwLock; +pub const PRODUCT_NAME: &str = include_str!("../../product_name.txt").trim_ascii(); + pub fn copy_dir(src: impl AsRef, dst: impl AsRef) -> Result<(), std::io::Error> { use std::fs; fs::create_dir_all(&dst)?; @@ -298,7 +300,7 @@ pub struct Profile { pub static CATEGORIES: Lazy>> = Lazy::new(|| { let mut hashmap = HashMap::new(); hashmap.insert( - "OpenDeck".to_owned(), + PRODUCT_NAME.to_owned(), Category { icon: None, actions: vec![ diff --git a/src/components/ActionList.svelte b/src/components/ActionList.svelte index dbe16e3..2575286 100644 --- a/src/components/ActionList.svelte +++ b/src/components/ActionList.svelte @@ -2,6 +2,7 @@ import type { Action } from "$lib/Action"; import { localisations } from "$lib/settings"; + import { PRODUCT_NAME } from "$lib/singletons"; import { invoke } from "@tauri-apps/api/core"; @@ -15,7 +16,7 @@
- {#each Object.entries(categories).sort((a, b) => a[0] == "OpenDeck" ? -1 : b[0] == "OpenDeck" ? 1 : a[0].localeCompare(b[0])) as [name, { icon, actions }]} + {#each Object.entries(categories).sort((a, b) => a[0] == PRODUCT_NAME ? -1 : b[0] == PRODUCT_NAME ? 1 : a[0].localeCompare(b[0])) as [name, { icon, actions }]}
{#if icon || (actions[0] && plugins.find((x) => x.id == actions[0].plugin) && actions.every((x) => x.plugin == actions[0].plugin))} diff --git a/src/components/NoDevicesDetected.svelte b/src/components/NoDevicesDetected.svelte index b4b7fcc..07c15a1 100644 --- a/src/components/NoDevicesDetected.svelte +++ b/src/components/NoDevicesDetected.svelte @@ -1,4 +1,6 @@