8000 feat: add config path to widget window title by lars-berger · Pull Request #164 · glzr-io/zebar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add config path to widget window title #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/desktop/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 6 additions & 15 deletions packages/desktop/src/sys_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,14 @@ impl SysTray {
widget_states: &HashMap<PathBuf, Vec<WidgetState>>,
startup_configs: &HashMap<PathBuf, StartupConfig>,
) -> anyhow::Result<Submenu<Wry>> {
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)
)
}
};

Expand Down Expand Up @@ -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>,
config_path: &PathBuf,
) -> String {
let path = config.to_relative_path(config_path).to_unicode_string();

path.strip_suffix(".zebar.json").unwrap_or(&path).into()
}
}
5 changes: 4 additions & 1 deletion packages/desktop/src/widget_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
0