Repository: versotile-org/verso
File: verso/src/lib.rs (Rust)

Code before:
                            sender.send(scale_factor).unwrap();
                        }
                    }
                    ToControllerMessage::GetCurrentUrlResponse(id, url) => {
                        if let Some(sender) = get_url_response.lock().unwrap().get(&id).take() {
                            sender.send(url).unwrap();
                        }
                    }
                    _ => {}
                },
                Err(e) => error!("Error while receiving VersoMessage: {e}"),
            }),
        );
        Self {
            sender,
            event_listeners,
        }
    }

    /// Create a new verso instance with default settings and get the controller to it
    pub fn new(verso_path: impl AsRef<Path>, initial_url: url::Url) -> Self {
        Self::create(verso_path, initial_url, VersoviewSettings::default())
    }

    /// Create a new verso instance with custom settings and get the controller to it
    #[deprecated = "Use VersoBuilder instead"]
    pub fn new_with_settings(
        verso_path: impl AsRef<Path>,
        initial_url: url::Url,
        settings: VersoviewSettings,
    ) -> Self {
        Self::create(verso_path, initial_url, settings)
    }

    /// Exit
    pub fn exit(&self) -> Result<(), Box<ipc_channel::ErrorKind>> {
        self.sender.send(ToVersoMessage::Exit)
    }

    /// Listen on close requested from the OS,
    /// if you decide to use it, verso will not close the window by itself anymore,
    /// so make sure you handle it properly by either do your own logic or call [`Self::exit`] as a fallback
    pub fn on_close_requested(
        &self,
        callback: impl Fn() + Send + 'static,
    ) -> Result<(), Box<ipc_channel::ErrorKind>> {
        let old_listener = self
            .event_listeners
            .on_close_requested
            .lock()
            .unwrap()

Review comment (suggestion):
I think we can remove `new_with_settings` directly since it's in a very early stage. A builder pattern is much better

Code after:
                            sender.send(scale_factor).unwrap();
                        }
                    }
                    ToControllerMessage::GetCurrentUrlResponse(id, url) => {
                        if let Some(sender) = get_url_response.lock().unwrap().get(&id).take() {
                            sender.send(url).unwrap();
                        }
                    }
                    _ => {}
                },
                Err(e) => error!("Error while receiving VersoMessage: {e}"),
            }),
        );
        Self {
            sender,
            event_listeners,
        }
    }

    /// Create a new verso instance with default settings and get the controller to it
    pub fn new(verso_path: impl AsRef<Path>, initial_url: url::Url) -> Self {
        Self::create(verso_path, initial_url, VersoviewSettings::default())
    }

    /// Exit
    pub fn exit(&self) -> Result<(), Box<ipc_channel::ErrorKind>> {
        self.sender.send(ToVersoMessage::Exit)
    }

    /// Listen on close requested from the OS,
    /// if you decide to use it, verso will not close the window by itself anymore,
    /// so make sure you handle it properly by either do your own logic or call [`Self::exit`] as a fallback
    pub fn on_close_requested(
        &self,
        callback: impl Fn() + Send + 'static,
    ) -> Result<(), Box<ipc_channel::ErrorKind>> {
        let old_listener = self
            .event_listeners
            .on_close_requested
            .lock()
            .unwrap()
            .replace(Box::new(callback));
        if old_listener.is_none() {
            self.sender.send(ToVersoMessage::ListenToOnCloseRequested)?;
        }
        Ok(())
    }

    /// Execute script
    pub fn execute_script(&self, script: String) -> Result<(), Box<ipc_channel::ErrorKind>> {
        self.sender.send(ToVersoMessage::ExecuteScript(script))