Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit a7735d7

Browse files
authored
Merge pull request #43 from GTP95/open_files
file-explorer opens files
2 parents 0c9135c + 9ca61c8 commit a7735d7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

file-explorer/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "File Explorer with Dioxus"
1010
dioxus = { version = "0.4.0" }
1111
dioxus-desktop = { version = "0.4.0" }
1212
log = "0.4.14"
13+
open = "5.0.0"
1314
simple_logger = "4.2.0"
1415

1516

file-explorer/src/main.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use dioxus::prelude::*;
1010
use dioxus_desktop::{Config, WindowBuilder};
1111

12+
1213
fn main() {
1314
// simple_logger::init_with_level(log::Level::Debug).unwrap();
1415
dioxus_desktop::launch_cfg(
@@ -87,11 +88,20 @@ impl Files {
8788
log::info!("Reloading path list for {:?}", cur_path);
8889
let paths = match std::fs::read_dir(cur_path) {
8990
Ok(e) => e,
90-
Err(err) => {
91-
let err = format!("An error occurred: {:?}", err);
92-
self.err = Some(err);
93-
self.path_stack.pop();
94-
return;
91+
Err(err) => { //Likely we're trying to open a file, so let's open it!
92+
match open::that(cur_path){
93+
Ok(_) => {
94+
log::info!("Opened file");
95+
return;
96+
},
97+
Err(err) => {
98+
let err = format!("An error occurred: {:?}", err);
99+
self.err = Some(err);
100+
self.path_stack.pop();
101+
return;
102+
}
103+
}
104+
95105
}
96106
};
97107
let collected = paths.collect::<Vec<_>>();
@@ -105,7 +115,7 @@ impl Files {
105115
self.path_names
106116
.push(path.unwrap().path().display().to_string());
107117
}
108-
log::info!("path namees are {:#?}", self.path_names);
118+
log::info!("path names are {:#?}", self.path_names);
109119
}
110120

111121
fn go_up(&mut self) {

0 commit comments

Comments
 (0)