Skip to content

Commit

Permalink
Makefile updates, check for host or home override before showing cust…
Browse files Browse the repository at this point in the history
…om home picker on create box
  • Loading branch information
Dvlv committed Jan 21, 2024
1 parent 56a0fe6 commit 85b5265
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
.DEFAULT_GOAL := run

# Define the targets
build-flatpak:
flatpak:
mkdir -p repo
flatpak-builder --repo=repo --force-clean build-dir io.github.dvlv.boxbuddyrs.json
flatpak build-bundle repo boxbuddy.flatpak io.github.dvlv.boxbuddyrs

run:
cargo run

make-potfile:
lint:
cargo fmt
cargo clippy

potfile:
xtr src/main.rs -o po/boxbuddy.pot

# Declare a phony target for clean
Expand All @@ -19,3 +23,9 @@ make-potfile:
clean:
rm -rf build-dir/*
rm -rf target/*
rm -rf .flatpak-builder/*

clean-flatpak:
rm -rf build-dir/*
rm -rf .flatpak-builder/*

15 changes: 10 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use distrobox_handler::*;
mod utils;
use utils::{
get_distro_img, get_supported_terminals_list, get_terminal_and_separator_arg,
has_distrobox_installed, set_up_localisation,
has_distrobox_installed, set_up_localisation,has_host_access
};

const APP_ID: &str = "io.github.dvlv.boxbuddyrs";
Expand Down Expand Up @@ -293,7 +293,7 @@ fn create_new_distrobox(window: &ApplicationWindow) {
name_entry_row.set_hexpand(true);
name_entry_row.set_title(&gettext("Name"));

//custom home
// custom home
let choose_home_btn = gtk::Button::from_icon_name("document-open-symbolic");
let home_select_row = adw::ActionRow::new();
home_select_row.set_activatable_widget(Some(&choose_home_btn));
Expand Down Expand Up @@ -399,7 +399,10 @@ fn create_new_distrobox(window: &ApplicationWindow) {

boxed_list.append(&name_entry_row);
boxed_list.append(&image_select_row);
boxed_list.append(&home_select_row);

if has_host_access() {
boxed_list.append(&home_select_row);
}

main_box.append(&boxed_list);
main_box.append(&loading_spinner);
Expand All @@ -421,9 +424,11 @@ fn show_about_popup(window: &ApplicationWindow) {
\nTrademarks, service marks, and logos are the property of their respective owners.",
);
d.set_website("https://github.com/Dvlv/BoxBuddyRS");
d.add_credit_section(Some("Contributors"), &["Dvlv"]);
d.set_developers(&["Dvlv"]);
d.set_issue_url("https://github.com/Dvlv/BoxBuddyRS/issues");
d.set_support_url("https://dvlv.github.io/BoxBuddyRS");
d.set_developers(&["Dvlv", "VortexAcherontic"]);
d.set_application_icon("io.github.dvlv.boxbuddyrs");
d.set_translator_credits("Vovkiv - RU and UK\nalbanobattistella - IT\nVortexAcherontic - DE");
d.present();
}

Expand Down
45 changes: 45 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,48 @@ pub fn get_host_desktop_files() -> Vec<String> {

host_apps
}

pub fn has_flatpak_filesystem_override() -> bool {
// this will check for BoxBuddy installed as a system flatpak
let sys_output = get_command_output(
String::from("flatpak"),
Some(&["override", "--show", "io.github.dvlv.boxbuddyrs"]),
);
for line in sys_output.split('\n') {
if line.starts_with("filesystems=") {
let fs_overrides = line.replace("filesystems=", "");
for ovr in fs_overrides.split(';') {
if ovr == "host" || ovr == "home" {
return true;
}
}
}
}

// check for BoxBuddy as a user flatpak
let user_output = get_command_output(
String::from("flatpak"),
Some(&["override", "--user", "--show", "io.github.dvlv.boxbuddyrs"]),
);
for line in user_output.split('\n') {
if line.starts_with("filesystems=") {
let fs_overrides = line.replace("filesystems=", "");
for ovr in fs_overrides.split(';') {
if ovr == "host" || ovr == "home" {
return true;
}
}
}
}

false
}


pub fn has_host_access() -> bool {
if is_flatpak() {
return has_flatpak_filesystem_override();
}

true
}

0 comments on commit 85b5265

Please sign in to comment.