Skip to content

Commit

Permalink
fix(flatimage): handle flatimage portable config and non-existent des…
Browse files Browse the repository at this point in the history
…ktop
  • Loading branch information
QaidVoid committed Nov 4, 2024
1 parent 70c9fd1 commit 33448e2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Soar is a fast Linux package manager that doesn't suck. Works with static binari
[![Documentation](https://img.shields.io/badge/docs-soar.qaidvoid.dev-blue)](https://soar.qaidvoid.dev)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

<center>
<p align="center">
<img src="icons/hicolor/scalable/apps/soar.svg" alt="soar" width="256"/>
</center>
</p>

## 🌟 Key Features
- [Universal Package Support](https://soar.qaidvoid.dev/#universal-package-support)
Expand Down
47 changes: 37 additions & 10 deletions src/package/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,31 @@ pub async fn integrate_using_remote_files(package: &Package, file_path: &Path) -
let desktop_output_path = file_path.with_extension("desktop");

let icon_url = &package.icon;
let (base_url, _) = package.icon.rsplit_once('/').unwrap();
let desktop_url = format!("{}/{}.desktop", base_url, &package.bin_name);
let desktop_url = &package.desktop;

let (icon_content, desktop_content) = try_join!(
download(icon_url, "image", false),
download(&desktop_url, "desktop file", false)
)?;
let icon_content = download(icon_url, "image", false).await?;

try_join!(
fs::write(&icon_output_path, &icon_content),
fs::write(&desktop_output_path, &desktop_content)
)?;
fs::write(&icon_output_path, &icon_content).await?;

let desktop_content = if let Some(desktop_url) = desktop_url {
match download(desktop_url, "desktop file", false).await {
Ok(content) => Some(content),
Err(_) => None,
}
} else {
None
};

let desktop_content = match desktop_content {
Some(content) => content,
None => create_default_desktop_entry(
&package.bin_name,
&package.name,
&package.category.replace(',', ";"),
),
};

fs::write(&desktop_output_path, &desktop_content).await?;

try_join!(
process_icon(&icon_output_path, &package.bin_name, data_path),
Expand All @@ -323,6 +336,20 @@ pub async fn integrate_using_remote_files(package: &Package, file_path: &Path) -
Ok(())
}

fn create_default_desktop_entry(bin_name: &str, name: &str, categories: &str) -> Vec<u8> {
format!(
"[Desktop Entry]\n\
Type=Application\n\
Name={}\n\
Icon={}\n\
Exec={}\n\
Categories={};\n",
name, bin_name, bin_name, categories
)
.as_bytes()
.to_vec()
}

pub async fn setup_portable_dir(
bin_name: &str,
package_path: &Path,
Expand Down
13 changes: 11 additions & 2 deletions src/package/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
fs::{File, Permissions},
io::{BufReader, Write},
os::unix::fs::PermissionsExt,
path::PathBuf,
path::{Path, PathBuf},
sync::Arc,
};

Expand Down Expand Up @@ -192,8 +192,17 @@ impl Installer {
FileType::FlatImage => {
if integrate_using_remote_files(package, &self.install_path)
.await
.is_err()
.is_ok()
{
setup_portable_dir(
&package.bin_name,
Path::new(&format!(".{}", self.install_path.display())),
None,
None,
portable_config,
)
.await?;
} else {
warn!("{}: Failed to integrate FlatImage", prefix);
};
}
Expand Down
1 change: 1 addition & 0 deletions src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct Package {
pub category: String,
pub extra_bins: String,
pub icon: String,
pub desktop: Option<String>,
pub bin_id: Option<String>,
pub family: Option<String>,
}
Expand Down

0 comments on commit 33448e2

Please sign in to comment.