mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
* removed all use of document indicies * -add u64 support for wasm bridge * fixed rust formating * Cleaned up FrontendDocumentState in js-messages * Tiny tweaks from code review * - moved more of closeDocumentWithConfirmation to rust - updated serde_wasm_bindgen to add feature flag * working initial auto save impl * auto save is a lifetime file * - cargo fmt - fixc error message - move document version constant * code review round 1 * generate seed for uuid in js when wasm is initialized * Resolve PR feedback * Further address PR feedback * Fix failing test Co-authored-by: Keavon Chambers <keavon@keavon.com> Co-authored-by: otdavies <oliver@psyfer.io>
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
pub mod dispatcher;
|
|
pub mod message;
|
|
use crate::message_prelude::*;
|
|
pub use dispatcher::*;
|
|
use rand_chacha::{
|
|
rand_core::{RngCore, SeedableRng},
|
|
ChaCha20Rng,
|
|
};
|
|
use spin::Mutex;
|
|
|
|
pub use crate::input::InputPreprocessor;
|
|
use std::{cell::Cell, collections::VecDeque};
|
|
|
|
pub type ActionList = Vec<Vec<MessageDiscriminant>>;
|
|
|
|
static RNG: Mutex<Option<ChaCha20Rng>> = Mutex::new(None);
|
|
|
|
// TODO: Add Send + Sync requirement
|
|
// Use something like rw locks for synchronization
|
|
pub trait MessageHandlerData {}
|
|
|
|
pub trait MessageHandler<A: ToDiscriminant, T>
|
|
where
|
|
A::Discriminant: AsMessage,
|
|
<A::Discriminant as TransitiveChild>::TopParent: TransitiveChild<Parent = <A::Discriminant as TransitiveChild>::TopParent, TopParent = <A::Discriminant as TransitiveChild>::TopParent> + AsMessage,
|
|
{
|
|
/// Return true if the Action is consumed.
|
|
fn process_action(&mut self, action: A, data: T, responses: &mut VecDeque<Message>);
|
|
fn actions(&self) -> ActionList;
|
|
}
|
|
|
|
thread_local! {
|
|
pub static UUID_SEED: Cell<Option<u64>> = Cell::new(None);
|
|
}
|
|
|
|
pub fn set_uuid_seed(random_seed: u64) {
|
|
UUID_SEED.with(|seed| seed.set(Some(random_seed)))
|
|
}
|
|
|
|
pub fn generate_uuid() -> u64 {
|
|
let mut lock = RNG.lock();
|
|
if lock.is_none() {
|
|
UUID_SEED.with(|seed| {
|
|
let random_seed = seed.get().expect("random seed not set before editor was initialized");
|
|
*lock = Some(ChaCha20Rng::seed_from_u64(random_seed));
|
|
})
|
|
}
|
|
lock.as_mut().map(ChaCha20Rng::next_u64).unwrap()
|
|
}
|