split host and home access, put back window size on create popup
Some checks failed
Publish Release / Publish binaries (push) Has been cancelled

This commit is contained in:
Dvlv 2024-02-10 10:13:01 +00:00
parent a9e4f7cdbd
commit 989566f758
No known key found for this signature in database
GPG key ID: 1F4BD7220B7FDCFA
2 changed files with 51 additions and 12 deletions

View file

@ -19,7 +19,8 @@ use distrobox_handler::*;
mod utils;
use utils::{
get_assemble_icon, get_distro_img, get_supported_terminals_list,
get_terminal_and_separator_arg, has_distrobox_installed, has_host_access, set_up_localisation,
get_terminal_and_separator_arg, has_distrobox_installed, has_home_or_host_access,
has_host_access, set_up_localisation,
};
const APP_ID: &str = "io.github.dvlv.boxbuddyrs";
@ -103,7 +104,7 @@ fn make_titlebar(window: &ApplicationWindow) {
assemble_btn_clone.set_child(Some(&new_image));
});
if has_host_access() {
if has_home_or_host_access() {
// TRANSLATORS: Button tooltip
assemble_btn.set_tooltip_text(Some(&gettext("Assemble A Distrobox")));
@ -150,7 +151,7 @@ fn make_titlebar(window: &ApplicationWindow) {
let titlebar = adw::HeaderBar::builder().title_widget(&title_lbl).build();
titlebar.pack_start(&add_btn);
if has_host_access() {
if has_home_or_host_access() {
titlebar.pack_start(&assemble_btn);
}
titlebar.pack_end(&about_btn);
@ -391,6 +392,7 @@ fn create_new_distrobox(window: &ApplicationWindow) {
let new_box_popup = gtk::Window::new();
new_box_popup.set_transient_for(Some(window));
new_box_popup.set_modal(true);
new_box_popup.set_default_size(700, 350);
// TRANSLATORS: Button Label
let title_lbl = gtk::Label::new(Some(&gettext("Create New Distrobox")));
@ -419,7 +421,7 @@ fn create_new_distrobox(window: &ApplicationWindow) {
new_box_titlebar.pack_end(&create_btn);
new_box_titlebar.pack_start(&cancel_btn);
if !has_host_access() {
if !has_home_or_host_access() {
new_box_titlebar.pack_end(&info_btn);
}
@ -589,7 +591,7 @@ fn create_new_distrobox(window: &ApplicationWindow) {
boxed_list.append(&image_select_row);
boxed_list.append(&init_row);
if has_host_access() {
if has_home_or_host_access() {
boxed_list.append(&home_select_row);
}

View file

@ -5,6 +5,20 @@ use std::env;
use std::path::Path;
use std::process::Command;
pub struct FilesystemAccess {
pub home: bool,
pub host: bool,
}
impl FilesystemAccess {
fn new() -> Self {
FilesystemAccess {
home: false,
host: false,
}
}
}
pub fn run_command(
cmd_to_run: std::string::String,
args_for_cmd: Option<&[&str]>,
@ -279,7 +293,8 @@ pub fn get_host_desktop_files() -> Vec<String> {
host_apps
}
pub fn has_flatpak_filesystem_override() -> bool {
pub fn get_flatpak_filesystem_permissions() -> FilesystemAccess {
let mut access = FilesystemAccess::new();
// this will check for BoxBuddy installed as a system flatpak
let sys_output = get_command_output(
String::from("flatpak"),
@ -289,8 +304,14 @@ pub fn has_flatpak_filesystem_override() -> bool {
if line.starts_with("filesystems=") {
let fs_overrides = line.replace("filesystems=", "");
for ovr in fs_overrides.split(';') {
if ovr == "host" || ovr == "home" {
return true;
match ovr {
"host" => {
access.host = true;
}
"home" => {
access.home = true;
}
_ => {}
}
}
}
@ -305,19 +326,35 @@ pub fn has_flatpak_filesystem_override() -> bool {
if line.starts_with("filesystems=") {
let fs_overrides = line.replace("filesystems=", "");
for ovr in fs_overrides.split(';') {
if ovr == "host" || ovr == "home" {
return true;
match ovr {
"host" => {
access.host = true;
}
"home" => {
access.home = true;
}
_ => {}
}
}
}
}
false
access
}
pub fn has_host_access() -> bool {
if is_flatpak() {
return has_flatpak_filesystem_override();
let access = get_flatpak_filesystem_permissions();
return access.host;
}
true
}
pub fn has_home_or_host_access() -> bool {
if is_flatpak() {
let access = get_flatpak_filesystem_permissions();
return access.host || access.home;
}
true