port dbox handler, not found message
This commit is contained in:
parent
896cd0a160
commit
1b2d3751f5
3 changed files with 85 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/target
|
||||
.vscode
|
||||
sync.sh
|
||||
|
|
|
@ -134,9 +134,74 @@ pub fn open_terminal_in_box(box_name: String) {
|
|||
|
||||
pub fn export_app_from_box(app_name: String, box_name: String) -> String {
|
||||
let output = get_command_output(
|
||||
String::from("distrobox"),
|
||||
Some(&["enter", &box_name, "--", "distrobox-export", &app_name])
|
||||
String::from("distrobox"),
|
||||
Some(&["enter", &box_name, "--", "distrobox-export", &app_name]),
|
||||
);
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
pub fn upgrade_box(box_name: String) {
|
||||
let (term, sep) = get_terminal_and_separator_arg();
|
||||
|
||||
Command::new(term)
|
||||
.arg(sep)
|
||||
.arg("distrobox")
|
||||
.arg("upgrade")
|
||||
.arg(box_name)
|
||||
.spawn()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn delete_box(box_name: String) -> String {
|
||||
let output = get_command_output(String::from("distrobox"), Some(&["rm", &box_name, "-f"]));
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
pub fn create_box(box_name: String, image: String) -> String {
|
||||
let output = get_command_output(
|
||||
String::from("distrobox"),
|
||||
Some(&["create", "-n", &box_name, "-i", &image, "-Y"]),
|
||||
);
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
pub fn init_new_box(box_name: String) -> String {
|
||||
let output = get_command_output(
|
||||
String::from("setsid"),
|
||||
Some(&["distrobox", "enter", &box_name, "--", "ls"]),
|
||||
);
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
pub fn get_available_images_with_distro_name() -> Vec<String> {
|
||||
let output = get_command_output(
|
||||
String::from("distrobox"),
|
||||
Some(&["create", "-C"]),
|
||||
);
|
||||
|
||||
let mut imgs: Vec<String> = Vec::new();
|
||||
|
||||
for line in output.split("\n") {
|
||||
if line.is_empty() || line == "Images" {
|
||||
continue;
|
||||
}
|
||||
|
||||
let distro = try_parse_distro_name_from_url(line);
|
||||
let mut pretty_line = String::from("");
|
||||
if distro != "zunknown" {
|
||||
pretty_line = format!("{} - {}", distro, line);
|
||||
} else {
|
||||
pretty_line = format!("Unknown - {}", line);
|
||||
}
|
||||
|
||||
imgs.push(pretty_line);
|
||||
}
|
||||
|
||||
imgs.sort();
|
||||
|
||||
imgs
|
||||
}
|
20
src/main.rs
20
src/main.rs
|
@ -50,8 +50,11 @@ fn build_ui(app: &Application) {
|
|||
toast_overlay.set_child(Some(&main_box));
|
||||
window.set_child(Some(&toast_overlay));
|
||||
|
||||
has_distrobox_installed();
|
||||
load_boxes(&window, &main_box);
|
||||
if has_distrobox_installed() {
|
||||
load_boxes(&main_box);
|
||||
} else {
|
||||
render_not_installed(&main_box);
|
||||
}
|
||||
|
||||
// Present window
|
||||
window.present();
|
||||
|
@ -77,7 +80,18 @@ fn make_titlebar(window: &ApplicationWindow) {
|
|||
window.set_titlebar(Some(&titlebar))
|
||||
}
|
||||
|
||||
fn load_boxes(_window: &ApplicationWindow, main_box: >k::Box) {
|
||||
fn render_not_installed(main_box: >k::Box) {
|
||||
let not_installed_lbl = gtk::Label::new(Some("Distrobox not found!"));
|
||||
not_installed_lbl.add_css_class("title-1");
|
||||
|
||||
let not_installed_lbl_two = gtk::Label::new(Some("Distrobox could not be found, please ensure it is installed!"));
|
||||
not_installed_lbl_two.add_css_class("title-2");
|
||||
|
||||
main_box.append(¬_installed_lbl);
|
||||
main_box.append(¬_installed_lbl_two);
|
||||
}
|
||||
|
||||
fn load_boxes(main_box: >k::Box) {
|
||||
let tabs = Notebook::new();
|
||||
tabs.set_tab_pos(PositionType::Left);
|
||||
tabs.set_hexpand(true);
|
||||
|
|
Loading…
Reference in a new issue