Skip to content
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

fix: shortcut filename #1136

Merged
merged 4 commits into from
Mar 4, 2025
Merged
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
26 changes: 2 additions & 24 deletions crates/rattler_menuinst/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ pub struct Directories {
windows_terminal_settings_files: Vec<PathBuf>,
}

fn shortcut_filename(name: &str, env_name: Option<&String>, ext: Option<&str>) -> String {
let env = if let Some(env_name) = env_name {
format!(" ({env_name})")
} else {
"".to_string()
};

let ext = ext.unwrap_or("lnk");
format!("{name}{env}{ext}")
}

/// On Windows we can create shortcuts in several places:
/// - Start Menu
/// - Desktop
Expand Down Expand Up @@ -138,18 +127,13 @@ impl WindowsMenu {
) -> Self {
let name = command.name.resolve(Environment::Base, placeholders);

let shortcut_name = shortcut_filename(
&name,
placeholders.as_ref().get("ENV_NAME"),
Some(SHORTCUT_EXTENSION),
);
let shortcut_name = format!("{name}.{SHORTCUT_EXTENSION}");

let location = directories
.start_menu
.join(&shortcut_name)
.with_extension(SHORTCUT_EXTENSION);

// self.menu.start_menu_location / self._shortcut_filename()
Self {
prefix: prefix.to_path_buf(),
name,
Expand Down Expand Up @@ -194,10 +178,6 @@ impl WindowsMenu {
Ok(lines.join("\n"))
}

fn shortcut_filename(&self, ext: Option<&str>) -> String {
shortcut_filename(&self.name, self.placeholders.as_ref().get("ENV_NAME"), ext)
}

fn write_script(&self, path: &Path) -> Result<(), MenuInstError> {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
Expand All @@ -210,9 +190,7 @@ impl WindowsMenu {
}

fn path_for_script(&self) -> PathBuf {
self.prefix
.join("Menu")
.join(self.shortcut_filename(Some("bat")))
self.prefix.join("Menu").join(format!("{}.bat", &self.name))
}

fn build_command(&self, with_arg1: bool) -> Result<Vec<String>, MenuInstError> {
Expand Down