Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/desktop/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,31 @@ pub async fn set_recently_opened_sessions<R: tauri::Runtime>(
app.set_recently_opened_sessions(v)
}

#[tauri::command]
#[specta::specta]
pub async fn increment_app_open_count<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
) -> Result<u32, String> {
app.increment_app_open_count()
}

#[tauri::command]
#[specta::specta]
pub async fn get_survey_dismissed<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
) -> Result<bool, String> {
app.get_survey_dismissed()
}

#[tauri::command]
#[specta::specta]
pub async fn set_survey_dismissed<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
v: bool,
) -> Result<(), String> {
app.set_survey_dismissed(v)
}

#[tauri::command]
#[specta::specta]
pub async fn list_plugins<R: tauri::Runtime>(
Expand Down
45 changes: 45 additions & 0 deletions apps/desktop/src-tauri/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ pub trait AppExt<R: tauri::Runtime> {

fn get_recently_opened_sessions(&self) -> Result<Option<String>, String>;
fn set_recently_opened_sessions(&self, v: String) -> Result<(), String>;

fn get_app_open_count(&self) -> Result<u32, String>;
fn increment_app_open_count(&self) -> Result<u32, String>;

fn get_survey_dismissed(&self) -> Result<bool, String>;
fn set_survey_dismissed(&self, v: bool) -> Result<(), String>;
}

impl<R: tauri::Runtime, T: tauri::Manager<R>> AppExt<R> for T {
Expand Down Expand Up @@ -111,4 +117,43 @@ impl<R: tauri::Runtime, T: tauri::Manager<R>> AppExt<R> for T {
.map_err(|e| e.to_string())?;
store.save().map_err(|e| e.to_string())
}

#[tracing::instrument(skip_all)]
fn get_app_open_count(&self) -> Result<u32, String> {
let store = self.desktop_store()?;
store
.get(StoreKey::AppOpenCount)
.map(|opt: Option<u32>| opt.unwrap_or(0))
.map_err(|e| e.to_string())
}

#[tracing::instrument(skip_all)]
fn increment_app_open_count(&self) -> Result<u32, String> {
let current = self.get_app_open_count()?;
let new_count = current + 1;
let store = self.desktop_store()?;
store
.set(StoreKey::AppOpenCount, new_count)
.map_err(|e| e.to_string())?;
store.save().map_err(|e| e.to_string())?;
Ok(new_count)
}

#[tracing::instrument(skip_all)]
fn get_survey_dismissed(&self) -> Result<bool, String> {
let store = self.desktop_store()?;
store
.get(StoreKey::SurveyDismissed)
.map(|opt| opt.unwrap_or(false))
.map_err(|e| e.to_string())
}

#[tracing::instrument(skip_all)]
fn set_survey_dismissed(&self, v: bool) -> Result<(), String> {
let store = self.desktop_store()?;
store
.set(StoreKey::SurveyDismissed, v)
.map_err(|e| e.to_string())?;
store.save().map_err(|e| e.to_string())
}
}
3 changes: 3 additions & 0 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> {
commands::set_pinned_tabs::<tauri::Wry>,
commands::get_recently_opened_sessions::<tauri::Wry>,
commands::set_recently_opened_sessions::<tauri::Wry>,
commands::increment_app_open_count::<tauri::Wry>,
commands::get_survey_dismissed::<tauri::Wry>,
commands::set_survey_dismissed::<tauri::Wry>,
commands::list_plugins::<tauri::Wry>,
])
.error_handling(tauri_specta::ErrorHandlingMode::Result)
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src-tauri/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub enum StoreKey {
TinybaseValues,
PinnedTabs,
RecentlyOpenedSessions,
AppOpenCount,
SurveyDismissed,
}

impl ScopedStoreKey for StoreKey {}
3 changes: 2 additions & 1 deletion apps/desktop/src/services/event-listeners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getOrCreateSessionForEventId,
} from "~/store/tinybase/store/sessions";
import { useTabs } from "~/store/zustand/tabs";
import { SurveyModal } from "~/survey/survey-modal";

function useUpdaterEvents() {
const openNew = useTabs((state) => state.openNew);
Expand Down Expand Up @@ -145,5 +146,5 @@ export function EventListeners() {
useUpdaterEvents();
useNotificationEvents();

return null;
return <SurveyModal />;
}
Loading
Loading