From e024e98860f01bb090382b43600d5caf3c3270aa Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Oct 2022 14:21:47 +0200 Subject: [PATCH 1/2] Expect `Model` in `fj_window::run` Initialize the `Watcher` in `run`, from the `Model`. This is the cleaner way to do it, as `fj-app` really has nothing to do with the watcher. --- crates/fj-app/src/main.rs | 5 ++--- crates/fj-window/src/run.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/fj-app/src/main.rs b/crates/fj-app/src/main.rs index 6a96e86b5..b5eed4bec 100644 --- a/crates/fj-app/src/main.rs +++ b/crates/fj-app/src/main.rs @@ -19,7 +19,7 @@ use std::path::PathBuf; use anyhow::{anyhow, Context as _}; use fj_export::export; -use fj_host::{Model, Parameters, Watcher}; +use fj_host::{Model, Parameters}; use fj_interop::status_report::StatusReport; use fj_operations::shape_processor::ShapeProcessor; use fj_window::run::run; @@ -90,8 +90,7 @@ fn main() -> anyhow::Result<()> { let invert_zoom = config.invert_zoom.unwrap_or(false); - let watcher = Watcher::watch_model(model)?; - run(watcher, shape_processor, status, invert_zoom)?; + run(model, shape_processor, status, invert_zoom)?; Ok(()) } diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index ad6bd589b..f7d8c2f67 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -5,7 +5,7 @@ use std::error; -use fj_host::{Watcher, WatcherEvent}; +use fj_host::{Model, Watcher, WatcherEvent}; use fj_interop::status_report::StatusReport; use fj_operations::shape_processor::ShapeProcessor; use fj_viewer::{ @@ -27,11 +27,13 @@ use crate::window::{self, Window}; /// Initializes a model viewer for a given model and enters its process loop. pub fn run( - watcher: Watcher, + model: Model, shape_processor: ShapeProcessor, mut status: StatusReport, invert_zoom: bool, ) -> Result<(), Error> { + let watcher = Watcher::watch_model(model)?; + let event_loop = EventLoop::new(); let window = Window::new(&event_loop)?; let mut viewer = block_on(Viewer::new(&window))?; @@ -289,6 +291,10 @@ fn input_event( /// Error in main loop #[derive(Debug, thiserror::Error)] pub enum Error { + /// Error loading model + #[error("Error loading model")] + Model(#[from] fj_host::Error), + /// Error initializing window #[error("Error initializing window")] WindowInit(#[from] window::Error), From c7377cc83bcbcad77e46817c637433011c264198 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Oct 2022 14:53:43 +0200 Subject: [PATCH 2/2] Remove `StatusUpdate` argument from `run` --- crates/fj-app/src/main.rs | 4 +--- crates/fj-window/src/run.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/fj-app/src/main.rs b/crates/fj-app/src/main.rs index b5eed4bec..423862147 100644 --- a/crates/fj-app/src/main.rs +++ b/crates/fj-app/src/main.rs @@ -20,7 +20,6 @@ use std::path::PathBuf; use anyhow::{anyhow, Context as _}; use fj_export::export; use fj_host::{Model, Parameters}; -use fj_interop::status_report::StatusReport; use fj_operations::shape_processor::ShapeProcessor; use fj_window::run::run; use tracing_subscriber::fmt::format; @@ -29,7 +28,6 @@ use tracing_subscriber::EnvFilter; use crate::{args::Args, config::Config}; fn main() -> anyhow::Result<()> { - let status = StatusReport::new(); // Respect `RUST_LOG`. If that's not defined or erroneous, log warnings and // above. // @@ -90,7 +88,7 @@ fn main() -> anyhow::Result<()> { let invert_zoom = config.invert_zoom.unwrap_or(false); - run(model, shape_processor, status, invert_zoom)?; + run(model, shape_processor, invert_zoom)?; Ok(()) } diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index f7d8c2f67..37ef1fc4d 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -29,9 +29,9 @@ use crate::window::{self, Window}; pub fn run( model: Model, shape_processor: ShapeProcessor, - mut status: StatusReport, invert_zoom: bool, ) -> Result<(), Error> { + let mut status = StatusReport::new(); let watcher = Watcher::watch_model(model)?; let event_loop = EventLoop::new();