Skip to content

Commit

Permalink
Bug Fix
Browse files Browse the repository at this point in the history
程序不会在保存路径被删除时崩溃
  • Loading branch information
iewnfod committed May 26, 2023
1 parent 9a7fd30 commit cf39bf2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 1 addition & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
// main
#[tokio::main]
async fn main() {
// 初始化一些东西
let save_path = std::path::Path::new(ui::data::SAVE_DIR);
if !save_path.exists() {
std::fs::create_dir(ui::data::SAVE_DIR).unwrap();
}

let mut app = fltk::app::App::default();
app.set_scheme(fltk::app::Scheme::Gtk);
let (sender, receiver) = fltk::app::channel::<ui::Message>();
Expand All @@ -36,7 +30,7 @@ async fn main() {
buffer.status_bar.set_value(unsafe { &ui::STATUS_BAR_CONTENT });

// 刷新文件系统
ui::refresh_file_system(&mut file_system, ui::data::SAVE_DIR);
ui::refresh_file_system(&mut file_system);

if let Some(msg) = receiver.recv() {
match msg {
Expand Down
10 changes: 7 additions & 3 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ fn double_click_status_clear() {
// println!("Lose Item.");
}

pub fn refresh_file_system(file_system: &mut tree::Tree, root_path: &str) {
pub fn refresh_file_system(file_system: &mut tree::Tree) {
// self.file_system.clear();
for f_result in walkdir::WalkDir::new(root_path) {
// 如果不存在,那就创建
if !std::path::PathBuf::from_str(data::SAVE_DIR).unwrap().exists() {
std::fs::create_dir(data::SAVE_DIR).unwrap();
}
for f_result in walkdir::WalkDir::new(data::SAVE_DIR) {
let f = f_result.unwrap();
if f.file_name() == ".DS_Store" {
continue;
Expand Down Expand Up @@ -236,7 +240,7 @@ pub fn add_widgets(root: &mut window::Window, sender: app::Sender<Message>) -> (

root.end();

refresh_file_system(&mut file_system, data::SAVE_DIR);
refresh_file_system(&mut file_system);
close_all_nodes(&mut file_system);

(buffer, file_system)
Expand Down

0 comments on commit cf39bf2

Please sign in to comment.