1+ use std:: sync:: OnceLock ;
2+
13use crate :: dispatcher:: Dispatcher ;
24use crate :: messages:: prelude:: * ;
35pub use graphene_std:: uuid:: * ;
@@ -8,8 +10,12 @@ pub struct Editor {
810}
911
1012impl Editor {
11- /// Construct the editor.
12- /// Remember to provide a random seed with `editor::set_uuid_seed(seed)` before any editors can be used.
13+ pub fn init ( enviroment : Environment , uuid_random_seed : u64 ) {
14+ ENVIROMENT . set ( enviroment) . expect ( "Editor shoud only be initialized once" ) ;
15+ graphene_std:: uuid:: init_rng ( uuid_random_seed) ;
16+ }
17+
18+ /// `Editor::init` must be called before this function
1319 pub fn new ( ) -> Self {
1420 Self { dispatcher : Dispatcher :: new ( ) }
1521 }
@@ -31,13 +37,57 @@ impl Editor {
3137 self . dispatcher . poll_node_graph_evaluation ( responses)
3238 }
3339}
34-
3540impl Default for Editor {
3641 fn default ( ) -> Self {
3742 Self :: new ( )
3843 }
3944}
4045
46+ static ENVIROMENT : OnceLock < Environment > = OnceLock :: new ( ) ;
47+ impl Editor {
48+ pub fn environment ( ) -> & ' static Environment {
49+ ENVIROMENT . get ( ) . expect ( "Editor environment accessed before initialization" )
50+ }
51+ }
52+
53+ #[ derive( Clone , Copy , Debug ) ]
54+ pub struct Environment {
55+ pub platform : Platform ,
56+ pub host : Host ,
57+ }
58+ #[ derive( Clone , Copy , Debug ) ]
59+ pub enum Platform {
60+ Desktop ,
61+ Web ,
62+ }
63+ #[ derive( Clone , Copy , Debug ) ]
64+ pub enum Host {
65+ Linux ,
66+ Mac ,
67+ Windows ,
68+ Unknown ,
69+ }
70+ impl Environment {
71+ pub fn is_desktop ( & self ) -> bool {
72+ matches ! ( self . platform, Platform :: Desktop )
73+ }
74+ pub fn is_web ( & self ) -> bool {
75+ matches ! ( self . platform, Platform :: Web )
76+ }
77+ pub fn is_linux ( & self ) -> bool {
78+ matches ! ( self . host, Host :: Linux )
79+ }
80+ pub fn is_mac ( & self ) -> bool {
81+ matches ! ( self . host, Host :: Mac )
82+ }
83+ pub fn is_windows ( & self ) -> bool {
84+ matches ! ( self . host, Host :: Windows )
85+ }
86+ pub fn is_unknown_host ( & self ) -> bool {
87+ matches ! ( self . host, Host :: Unknown )
88+ }
89+ }
90+
4191pub const GRAPHITE_RELEASE_SERIES : & str = env ! ( "GRAPHITE_RELEASE_SERIES" ) ;
4292pub const GRAPHITE_GIT_COMMIT_BRANCH : Option < & str > = option_env ! ( "GRAPHITE_GIT_COMMIT_BRANCH" ) ;
4393pub const GRAPHITE_GIT_COMMIT_HASH : & str = env ! ( "GRAPHITE_GIT_COMMIT_HASH" ) ;
0 commit comments