diff --git a/packages/desktop/src/config.rs b/packages/desktop/src/config.rs index 02e8c35e..5558c6f9 100644 --- a/packages/desktop/src/config.rs +++ b/packages/desktop/src/config.rs @@ -564,6 +564,20 @@ impl Config { .into() } + /// Formats a widget's config path for display. + /// + /// Returns relative path without the `.zebar.json` suffix (e.g. + /// `starter/vanilla`). + pub fn formatted_widget_path(&self, config_path: &PathBuf) -> String { + let path = self.to_relative_path(config_path).to_unicode_string(); + + // Ensure path delimiters are forward slashes on Windows. + #[cfg(windows)] + let path = path.replace('\\', "/"); + + path.strip_suffix(".zebar.json").unwrap_or(&path).into() + } + /// Returns the widget config at the given path. /// /// Config path can be either absolute or relative. diff --git a/packages/desktop/src/sys_tray.rs b/packages/desktop/src/sys_tray.rs index 5061a16e..b804f06c 100644 --- a/packages/desktop/src/sys_tray.rs +++ b/packages/desktop/src/sys_tray.rs @@ -406,13 +406,14 @@ impl SysTray { widget_states: &HashMap>, startup_configs: &HashMap, ) -> anyhow::Result> { - let formatted_config_path = - Self::format_config_path(&self.config, config_path); - let label = match widget_states.get(config_path) { - None => formatted_config_path, + None => self.config.formatted_widget_path(config_path), Some(states) => { - format!("({}) {}", states.len(), formatted_config_path) + format!( + "({}) {}", + states.len(), + self.config.formatted_widget_path(config_path) + ) } }; @@ -495,14 +496,4 @@ impl SysTray { Ok(config_menu.build()?) } - - /// Formats the config path for display in the system tray. - fn format_config_path( - config: &Arc, - config_path: &PathBuf, - ) -> String { - let path = config.to_relative_path(config_path).to_unicode_string(); - - path.strip_suffix(".zebar.json").unwrap_or(&path).into() - } } diff --git a/packages/desktop/src/widget_factory.rs b/packages/desktop/src/widget_factory.rs index 3b7c66aa..7480fac9 100644 --- a/packages/desktop/src/widget_factory.rs +++ b/packages/desktop/src/widget_factory.rs @@ -261,7 +261,10 @@ impl WidgetFactory { widget_id.clone(), webview_url, ) - .title("Zebar") + .title(format!( + "Zebar - {}", + self.config.formatted_widget_path(&config_path) + )) .focused(widget_config.focused) .skip_taskbar(!widget_config.shown_in_taskbar) .visible_on_all_workspaces(true)