Skip to content

Commit

Permalink
Fix LTN build on web, skipping home directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed May 9, 2023
1 parent 7e327eb commit b386521
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apps/ltn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib", "lib"]

[features]
default = ["map_gui/native", "widgetry/native-backend"]
default = ["home", "map_gui/native", "widgetry/native-backend"]
wasm = ["getrandom/js", "map_gui/wasm", "wasm-bindgen", "widgetry/wasm-backend"]

[dependencies]
Expand All @@ -24,7 +24,7 @@ geo = { workspace = true }
geojson = { workspace = true }
geom = { path = "../../geom" }
getrandom = { workspace = true, optional = true }
home = "0.5.5"
home = { version = "0.5.5", optional = true }
lazy_static = "1.4.0"
log = { workspace = true }
maplit = "1.0.2"
Expand Down
10 changes: 10 additions & 0 deletions apps/ltn/src/save/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,13 @@ impl PreserveState {
}
}
}

#[cfg(not(target_arch = "wasm32"))]
fn start_dir() -> Option<String> {
home::home_dir().map(|x| x.display().to_string())
}

#[cfg(target_arch = "wasm32")]
fn start_dir() -> Option<String> {
None
}
4 changes: 2 additions & 2 deletions apps/ltn/src/save/proposals_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Proposals {
Ok(contents) => FileSaver::with_default_messages(
ctx,
format!("ltn_{}.geojson", app.per_map.map.get_name().map),
home::home_dir().map(|x| x.display().to_string()),
super::start_dir(),
FileSaverContents::String(contents),
),
Err(err) => PopupMsg::new_state(ctx, "Export failed", vec![err.to_string()]),
Expand Down Expand Up @@ -185,7 +185,7 @@ fn load_picker_ui(
if name == "Load from file on your computer" {
Transition::Replace(FilePicker::new_state(
ctx,
home::home_dir().map(|x| x.display().to_string()),
super::start_dir(),
Box::new(move |ctx, app, maybe_file| {
match maybe_file {
Ok(Some((path, bytes))) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/ltn/src/save/save_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl State<App> for SaveDialog {
Ok(contents) => FileSaver::with_default_messages(
ctx,
format!("{}.json.gz", proposal.edits.edits_name),
home::home_dir().map(|x| x.display().to_string()),
super::start_dir(),
FileSaverContents::Bytes(contents),
),
Err(err) => PopupMsg::new_state(ctx, "Save failed", vec![err.to_string()]),
Expand Down

0 comments on commit b386521

Please sign in to comment.