Skip to content

Commit

Permalink
feat: canonicalize project root path
Browse files Browse the repository at this point in the history
  • Loading branch information
Cubxity committed May 8, 2023
1 parent 18b5e4d commit 58d39e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/ipc/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct ProjectChangeEvent {

#[derive(Serialize, Clone, Debug)]
pub struct ProjectModel {
pub root: String,
pub root: PathBuf,
}

#[derive(Serialize, Clone, Debug)]
Expand Down
7 changes: 4 additions & 3 deletions src-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ pub fn handle_menu_event<R: Runtime>(e: WindowMenuEvent<R>) {
.set_title("Open Project")
.pick_folder(move |path| {
if let Some(path) = path {
let path = fs::canonicalize(&path).unwrap_or(path);

let window = e.window();
let project_manager: State<'_, Arc<ProjectManager<_>>> = window.state();
let path_clone = path.clone();
let project = Arc::new(Project {
root: path,
world: ProjectWorld::new(path_clone).into(),
world: ProjectWorld::new(path.clone()).into(),
cache: RwLock::new(Default::default()),
root: path,
});
project_manager.set_project(window, Some(project));
}
Expand Down
8 changes: 2 additions & 6 deletions src-tauri/src/project/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<R: Runtime> ProjectManager<R> {
pub fn set_project(&self, window: &Window<R>, project: Option<Arc<Project>>) {
let mut projects = self.projects.write().unwrap();
let model = project.as_ref().map(|p| ProjectModel {
root: p.root.clone().into_os_string().into_string().unwrap(),
root: p.root.clone(),
});
match project {
None => {
Expand All @@ -92,11 +92,7 @@ impl<R: Runtime> ProjectManager<R> {
}
};

info!(
"project set for window {}: {:?}",
window.label(),
model.as_ref().map(|m| &m.root)
);
info!("project set for window {}: {:?}", window.label(), model);
let _ = window.emit("project_changed", ProjectChangeEvent { project: model });
}

Expand Down

0 comments on commit 58d39e3

Please sign in to comment.