11use crate :: StoreKey ;
22use tauri_plugin_store2:: { ScopedStore , Store2PluginExt } ;
3+
4+ #[ derive( Clone , Debug , Default , serde:: Serialize , serde:: Deserialize , specta:: Type ) ]
5+ #[ serde( default , rename_all = "camelCase" ) ]
6+ pub struct OnboardingSurveyState {
7+ pub launch_count : u32 ,
8+ pub done : bool ,
9+ }
10+
311pub trait AppExt < R : tauri:: Runtime > {
412 fn desktop_store ( & self ) -> Result < ScopedStore < R , crate :: StoreKey > , String > ;
513
@@ -18,6 +26,12 @@ pub trait AppExt<R: tauri::Runtime> {
1826 fn get_recently_opened_sessions ( & self ) -> Result < Option < String > , String > ;
1927 fn set_recently_opened_sessions ( & self , v : String ) -> Result < ( ) , String > ;
2028
29+ fn get_onboarding_survey_state ( & self ) -> Result < OnboardingSurveyState , String > ;
30+ fn set_onboarding_survey_state ( & self , state : OnboardingSurveyState ) -> Result < ( ) , String > ;
31+ fn record_onboarding_survey_launch ( & self ) -> Result < OnboardingSurveyState , String > ;
32+ fn finish_onboarding_survey ( & self ) -> Result < OnboardingSurveyState , String > ;
33+ fn reset_onboarding_survey ( & self ) -> Result < OnboardingSurveyState , String > ;
34+
2135 fn get_char_v1p1_preview ( & self ) -> Result < bool , String > ;
2236 fn set_char_v1p1_preview ( & self , v : bool ) -> Result < ( ) , String > ;
2337}
@@ -115,6 +129,47 @@ impl<R: tauri::Runtime, T: tauri::Manager<R>> AppExt<R> for T {
115129 store. save ( ) . map_err ( |e| e. to_string ( ) )
116130 }
117131
132+ #[ tracing:: instrument( skip_all) ]
133+ fn get_onboarding_survey_state ( & self ) -> Result < OnboardingSurveyState , String > {
134+ let store = self . desktop_store ( ) ?;
135+ store
136+ . get ( StoreKey :: OnboardingSurvey )
137+ . map ( |opt| opt. unwrap_or_default ( ) )
138+ . map_err ( |e| e. to_string ( ) )
139+ }
140+
141+ #[ tracing:: instrument( skip_all) ]
142+ fn set_onboarding_survey_state ( & self , state : OnboardingSurveyState ) -> Result < ( ) , String > {
143+ let store = self . desktop_store ( ) ?;
144+ store
145+ . set ( StoreKey :: OnboardingSurvey , state)
146+ . map_err ( |e| e. to_string ( ) ) ?;
147+ store. save ( ) . map_err ( |e| e. to_string ( ) )
148+ }
149+
150+ #[ tracing:: instrument( skip_all) ]
151+ fn record_onboarding_survey_launch ( & self ) -> Result < OnboardingSurveyState , String > {
152+ let mut state = self . get_onboarding_survey_state ( ) ?;
153+ state. launch_count = state. launch_count . saturating_add ( 1 ) ;
154+ self . set_onboarding_survey_state ( state. clone ( ) ) ?;
155+ Ok ( state)
156+ }
157+
158+ #[ tracing:: instrument( skip_all) ]
159+ fn finish_onboarding_survey ( & self ) -> Result < OnboardingSurveyState , String > {
160+ let mut state = self . get_onboarding_survey_state ( ) ?;
161+ state. done = true ;
162+ self . set_onboarding_survey_state ( state. clone ( ) ) ?;
163+ Ok ( state)
164+ }
165+
166+ #[ tracing:: instrument( skip_all) ]
167+ fn reset_onboarding_survey ( & self ) -> Result < OnboardingSurveyState , String > {
168+ let state = OnboardingSurveyState :: default ( ) ;
169+ self . set_onboarding_survey_state ( state. clone ( ) ) ?;
170+ Ok ( state)
171+ }
172+
118173 #[ tracing:: instrument( skip_all) ]
119174 fn get_char_v1p1_preview ( & self ) -> Result < bool , String > {
120175 if cfg ! ( feature = "new" ) {
0 commit comments