-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: better implementation of initial scan and render
- Loading branch information
1 parent
5713891
commit d201840
Showing
17 changed files
with
227 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use tauri::{command, AppHandle, Runtime}; | ||
|
||
use super::error::CmdResult; | ||
use crate::states::StatesExtRenderReady; | ||
|
||
/// Emit the `render` event to the canvas when the listener is ready. | ||
/// | ||
/// This is a wrapper command for | ||
/// [`emit_on_render_ready`](StatesExtRenderReady::emit_on_render_ready) | ||
/// to be invoked by the frontend. | ||
/// | ||
/// ### Errors | ||
/// | ||
/// - Failed to emit the `render` event to the canvas. | ||
#[command] | ||
pub async fn emit_on_render_ready<R: Runtime>( | ||
app_handle: AppHandle<R>, | ||
payload: serde_json::Value, | ||
) -> CmdResult<()> { | ||
Ok(app_handle.emit_on_render_ready(payload)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use tauri::{command, AppHandle, Runtime}; | ||
|
||
use super::error::CmdResult; | ||
use crate::states::StatesExtRenderReady; | ||
|
||
/// Set the `render` listener as ready. | ||
/// | ||
/// This is a wrapper command for | ||
/// [`set_render_ready`](StatesExtRenderReady::set_render_ready) to be invoked | ||
/// by the frontend. | ||
/// | ||
/// ### Errors | ||
/// | ||
/// - Failed to emit the `render` event to the canvas. | ||
#[command] | ||
pub async fn set_render_ready<R: Runtime>(app_handle: AppHandle<R>) -> CmdResult<()> { | ||
Ok(app_handle.set_render_ready()?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
//! Deskulpt runtime state management. | ||
mod canvas_click_through; | ||
mod render_ready; | ||
mod widget_config_map; | ||
|
||
#[doc(hidden)] | ||
pub use canvas_click_through::StatesExtCanvasClickThrough; | ||
#[doc(hidden)] | ||
pub use render_ready::StatesExtRenderReady; | ||
#[doc(hidden)] | ||
pub use widget_config_map::StatesExtWidgetConfigMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! State management for whether the `render` listener is ready. | ||
use std::sync::Mutex; | ||
|
||
use anyhow::Result; | ||
use tauri::{App, AppHandle, Manager, Runtime}; | ||
|
||
use crate::EventsExt; | ||
|
||
/// Managed state for whether the `render` listener is ready. | ||
/// | ||
/// The first parameter indicates whether the listener (on the canvas window) | ||
/// for the `render` event is ready. The second parameter is an optional pending | ||
/// payload for the `render` event. In particular, the manager window will emit | ||
/// a `render` event on startup, at which point the listener may not be ready | ||
/// yet. In this case we need to store the payload and emit it later when the | ||
/// listener is ready. | ||
#[derive(Default)] | ||
struct RenderReadyState(Mutex<(bool, Option<serde_json::Value>)>); | ||
|
||
/// Extension trait for operations related to the `render` listener readiness. | ||
pub trait StatesExtRenderReady<R: Runtime>: Manager<R> + EventsExt<R> { | ||
/// Initialize state management for whether the `render` listener is ready. | ||
fn manage_render_ready(&self) { | ||
self.manage(RenderReadyState::default()); | ||
} | ||
|
||
/// Set the `render` listener as ready. | ||
/// | ||
/// If there is a pending payload, emit a `render` event with that payload | ||
/// to the canvas. | ||
fn set_render_ready(&self) -> Result<()> { | ||
let state = self.state::<RenderReadyState>(); | ||
let mut render_ready = state.0.lock().unwrap(); | ||
render_ready.0 = true; | ||
|
||
if let Some(payload) = render_ready.1.take() { | ||
self.emit_render_to_canvas(payload)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Emit the `render` event to the canvas when the listener is ready. | ||
/// | ||
/// If the `render` listener is not ready, store the given payload as | ||
/// pending so that it can be emitted later when the listener is ready. | ||
/// Otherwise, emit a `render` event with the given payload to the canvas | ||
/// immediately. | ||
fn emit_on_render_ready(&self, payload: serde_json::Value) -> Result<()> { | ||
let state = self.state::<RenderReadyState>(); | ||
let mut render_ready = state.0.lock().unwrap(); | ||
|
||
if !render_ready.0 { | ||
render_ready.1 = Some(payload); | ||
return Ok(()); | ||
} | ||
self.emit_render_to_canvas(payload) | ||
} | ||
} | ||
|
||
impl<R: Runtime> StatesExtRenderReady<R> for App<R> {} | ||
impl<R: Runtime> StatesExtRenderReady<R> for AppHandle<R> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.