Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(desktop): persist onboarding completion (#4022)

Mauro Pereira1aa883d3c7ca
diff --git a/harper-desktop/src-tauri/src/commands.rs b/harper-desktop/src-tauri/src/commands.rs
index c2c729a84..b0429abb7 100644
--- a/harper-desktop/src-tauri/src/commands.rs
+++ b/harper-desktop/src-tauri/src/commands.rs
@@ -26,6 +26,8 @@ pub fn application_message_handler<R: Runtime>() -> impl Fn(Invoke<R>) -> bool {
set_auto_update,
get_last_update_check,
set_last_update_check,
+ get_onboarding_completed,
+ set_onboarding_completed,
set_dialect,
set_lint_config,
get_dictionary,
@@ -121,6 +123,28 @@ async fn set_last_update_check(
Ok(())
}
+#[tauri::command]
+async fn get_onboarding_completed(config: State<'_, Arc<Mutex<Config>>>) -> Result<bool, String> {
+ Ok(config.lock().await.onboarding_completed)
+}
+
+#[tauri::command]
+async fn set_onboarding_completed(
+ onboarding_completed: bool,
+ config: State<'_, Arc<Mutex<Config>>>,
+) -> Result<(), String> {
+ let mut config = config.lock().await;
+ let previous_value = config.onboarding_completed;
+ config.onboarding_completed = onboarding_completed;
+
+ if let Err(error) = config.save_to_system().await {
+ config.onboarding_completed = previous_value;
+ return Err(error.to_string());
+ }
+
+ Ok(())
+}
+
#[tauri::command]
async fn set_dialect(
dialect: Dialect,
diff --git a/harper-desktop/src-tauri/src/config/mod.rs b/harper-desktop/src-tauri/src/config/mod.rs
index 66e228de3..c94733141 100644
--- a/harper-desktop/src-tauri/src/config/mod.rs
+++ b/harper-desktop/src-tauri/src/config/mod.rs
@@ -19,6 +19,7 @@ pub struct Config {
pub ignored_lints: IgnoredLints,
pub lint_config: FlatConfig,
pub integrations: Vec<Integration>,
+ pub onboarding_completed: bool,
pub debounce_ms: u64,
pub auto_update: bool,
pub last_update_check: Option<u64>,
@@ -33,6 +34,7 @@ impl Config {
ignored_lints: IgnoredLints::new(),
lint_config: FlatConfig::new_curated(),
integrations: Integration::curated_integrations(),
+ onboarding_completed: false,
debounce_ms: 0,
auto_update: true,
last_update_check: None,
@@ -161,6 +163,7 @@ impl Config {
"ignored_lints": &self.ignored_lints,
"lint_config": &self.lint_config,
"integrations": &self.integrations,
+ "onboarding_completed": self.onboarding_completed,
"debounce_ms": self.debounce_ms,
"auto_update": self.auto_update,
"last_update_check": self.last_update_check,
@@ -182,6 +185,8 @@ impl Config {
lint_config: deserialize_field(object, "lint_config")?,
integrations: deserialize_optional_field(object, "integrations")?
.unwrap_or_else(Integration::curated_integrations),
+ onboarding_completed: deserialize_optional_field(object, "onboarding_completed")?
+ .unwrap_or(true),
debounce_ms: deserialize_optional_field(object, "debounce_ms")?.unwrap_or(0),
auto_update: deserialize_optional_field(object, "auto_update")?.unwrap_or(true),
last_update_check: deserialize_optional_field::<Option<u64>>(
@@ -254,6 +259,7 @@ mod tests {
assert!(serialized.contains("ignored_lints"));
assert!(serialized.contains("lint_config"));
assert!(serialized.contains("integrations"));
+ assert!(serialized.contains("onboarding_completed"));
assert!(serialized.contains("debounce_ms"));
assert!(serialized.contains("auto_update"));
assert!(serialized.contains("last_update_check"));
@@ -273,6 +279,10 @@ mod tests {
assert_eq!(deserialized.dialect, config.dialect);
assert_eq!(deserialized.lint_config, config.lint_config);
assert_eq!(deserialized.integrations, config.integrations);
+ assert_eq!(
+ deserialized.onboarding_completed,
+ config.onboarding_completed
+ );
assert_eq!(deserialized.debounce_ms, config.debounce_ms);
assert_eq!(deserialized.auto_update, config.auto_update);
assert_eq!(deserialized.last_update_check, config.last_update_check);
diff --git a/harper-desktop/src-tauri/src/lib.rs b/harper-desktop/src-tauri/src/lib.rs
index ed76125dd..7bb6ddc06 100644
--- a/harper-desktop/src-tauri/src/lib.rs
+++ b/harper-desktop/src-tauri/src/lib.rs
@@ -296,6 +296,7 @@ pub fn run_highlighter(has_parent: bool) {
ignored_lints: IgnoredLints::new(),
lint_config,
integrations: Vec::new(),
+ onboarding_completed: false,
debounce_ms: *dictionary_debounce_ms.borrow(),
auto_update: true,
last_update_check: None,
@@ -377,6 +378,7 @@ fn fetch_highlighter_config(
ignored_lints,
lint_config,
integrations,
+ onboarding_completed: false,
debounce_ms,
auto_update: true,
last_update_check: None,
diff --git a/harper-desktop/src/lib/client.ts b/harper-desktop/src/lib/client.ts
index fc10bd119..4df61c0eb 100644
--- a/harper-desktop/src/lib/client.ts
+++ b/harper-desktop/src/lib/client.ts
@@ -100,6 +100,14 @@ export class Client {
await invoke('set_last_update_check', { lastUpdateCheck });
}
+ static async getOnboardingCompleted(): Promise<boolean> {
+ return await invoke<boolean>('get_onboarding_completed');
+ }
+
+ static async setOnboardingCompleted(onboardingCompleted: boolean): Promise<void> {
+ await invoke('set_onboarding_completed', { onboardingCompleted });
+ }
+
static async getLaunchAtStartup(): Promise<boolean> {
return await isEnabled();
}
diff --git a/harper-desktop/src/lib/settings/SettingsApp.svelte b/harper-desktop/src/lib/settings/SettingsApp.svelte
index 847e1f24d..f1e42c7da 100644
--- a/harper-desktop/src/lib/settings/SettingsApp.svelte
+++ b/harper-desktop/src/lib/settings/SettingsApp.svelte
@@ -1,4 +1,6 @@
<script lang="ts">
+import { onMount } from 'svelte';
+import { Client } from '$lib/client';
import SettingsSidebar from './SettingsSidebar.svelte';
import './settings.css';
import AboutPage from './pages/AboutPage.svelte';
@@ -14,6 +16,7 @@ import type { SectionId } from './settings-data';
let active: SectionId = 'getting-started';
let contentEl: HTMLElement;
+let isLoadingOnboarding = true;
const titleMap: Record<SectionId, string> = {
'getting-started': 'Getting Started',
@@ -27,6 +30,20 @@ const titleMap: Record<SectionId, string> = {
about: 'About',
};
+onMount(() => {
+ void loadInitialSection();
+});
+
+async function loadInitialSection() {
+ try {
+ active = (await Client.getOnboardingCompleted()) ? 'general' : 'getting-started';
+ } catch (error) {
+ console.error('Unable to load onboarding state.', error);
+ } finally {
+ isLoadingOnboarding = false;
+ }
+}
+
$: title = titleMap[active];
$: if (contentEl && active) {
@@ -35,10 +52,14 @@ $: if (contentEl && active) {
</script>
<div class="settings-shell">
- <SettingsSidebar bind:active />
+ {#if !isLoadingOnboarding}
+ <SettingsSidebar bind:active />
+ {/if}
- <main bind:this={contentEl} class="content" aria-label={title}>
- {#if active === "getting-started"}
+ <main bind:this={contentEl} class="content" aria-label={isLoadingOnboarding ? "Settings" : title}>
+ {#if isLoadingOnboarding}
+ <p>Loading settings...</p>
+ {:else if active === "getting-started"}
<GettingStartedPage navigateToSection={(section) => (active = section)} />
{:else if active === "general"}
<GeneralPage />
diff --git a/harper-desktop/src/lib/settings/pages/GettingStartedPage.svelte b/harper-desktop/src/lib/settings/pages/GettingStartedPage.svelte
index 826e5a7ee..71f8b45bb 100644
--- a/harper-desktop/src/lib/settings/pages/GettingStartedPage.svelte
+++ b/harper-desktop/src/lib/settings/pages/GettingStartedPage.svelte
@@ -2,7 +2,7 @@
import { onMount } from 'svelte';
import { type AccessibilityPermissionStatus, Client, type Integration } from '$lib/client';
import AppIcon from '../components/AppIcon.svelte';
-import { createInitialSettingsState, type SectionId, type SettingsState } from '../settings-data';
+import type { SectionId } from '../settings-data';
type SetupStep = {
id: 'accessibility' | 'integration' | 'test-drive';
@@ -19,7 +19,6 @@ type SetupStep = {
export let navigateToSection: (section: SectionId) => void;
-let state: SettingsState = createInitialSettingsState();
let accessibilityStatus: AccessibilityPermissionStatus | null = null;
let accessibilityError = '';
let isCheckingAccessibility = true;
@@ -31,12 +30,13 @@ let isLoadingIntegrations = true;
let isEnablingTextEdit = false;
let isLaunchingTextEdit = false;
let testDriveError = '';
+let isCompletingOnboarding = false;
+let onboardingError = '';
$: textEditIntegration = integrations.find((item) => item.bundle_id === 'com.apple.TextEdit');
$: isTextEditEnabled = textEditIntegration?.enabled === true;
$: setupSteps = buildSetupSteps(
- state,
accessibilityStatus,
isCheckingAccessibility,
isRequestingAccessibility,
@@ -44,19 +44,20 @@ $: setupSteps = buildSetupSteps(
isTextEditEnabled,
isLoadingIntegrations,
isEnablingTextEdit,
+ isLaunchingTextEdit,
);
-$: setupCompletedCount = setupSteps.filter((step) => step.done).length;
-$: setupAllDone = setupSteps.every((step) => step.done);
+$: requiredSetupSteps = setupSteps.filter((step) => step.required);
+$: setupCompletedCount = requiredSetupSteps.filter((step) => step.done).length;
+$: setupAllDone =
+ !isCheckingAccessibility &&
+ !isLoadingIntegrations &&
+ requiredSetupSteps.every((step) => step.done);
onMount(() => {
void checkAccessibilityPermission();
void loadIntegrations();
});
-function updateSetup(patch: Partial<SettingsState['setup']>) {
- state = { ...state, setup: { ...state.setup, ...patch } };
-}
-
async function loadIntegrations() {
isLoadingIntegrations = true;
integrationsError = '';
@@ -89,12 +90,6 @@ async function enableTextEditForSetup() {
{ bundle_id: 'com.apple.TextEdit', enabled: true, display_name: 'TextEdit' },
];
}
-
- state = {
- ...state,
- integrations: { ...state.integrations, textedit: true },
- setup: { ...state.setup, integration: 'selected' },
- };
} catch (error) {
integrationsError = `Unable to enable TextEdit: ${error}`;
} finally {
@@ -108,7 +103,6 @@ async function launchTextEditForTestDrive() {
try {
await Client.launchApp('com.apple.TextEdit');
- updateSetup({ testDrive: 'completed' });
} catch (error) {
testDriveError = `Unable to launch TextEdit: ${error}`;
} finally {
@@ -116,6 +110,20 @@ async function launchTextEditForTestDrive() {
}
}
+async function completeOnboarding() {
+ isCompletingOnboarding = true;
+ onboardingError = '';
+
+ try {
+ await Client.setOnboardingCompleted(true);
+ navigateToSection('general');
+ } catch (error) {
+ onboardingError = `Unable to complete onboarding: ${error}`;
+ } finally {
+ isCompletingOnboarding = false;
+ }
+}
+
async function checkAccessibilityPermission() {
isCheckingAccessibility = true;
accessibilityError = '';
@@ -198,7 +206,6 @@ function accessibilityActionLabel(
}
function buildSetupSteps(
- currentState: SettingsState,
currentAccessibilityStatus: AccessibilityPermissionStatus | null,
currentIsCheckingAccessibility: boolean,
currentIsRequestingAccessibility: boolean,
@@ -206,10 +213,11 @@ function buildSetupSteps(
currentIsTextEditEnabled: boolean,
currentIsLoadingIntegrations: boolean,
currentIsEnablingTextEdit: boolean,
+ currentIsLaunchingTextEdit: boolean,
): SetupStep[] {
const accessibilityDone = currentAccessibilityStatus === 'Granted';
+ const accessibilityReady = accessibilityDone || currentAccessibilityStatus === 'Unsupported';
const integrationDone = currentIsTextEditEnabled;
- const testDriveDone = currentState.setup.testDrive === 'completed';
const accessibilityActionDisabled =
currentIsCheckingAccessibility ||
currentIsRequestingAccessibility ||
@@ -221,7 +229,7 @@ function buildSetupSteps(
id: 'accessibility',
title: 'Grant Accessibility permission',
desc: accessibilityDescription(currentAccessibilityStatus),
- required: true,
+ required: currentAccessibilityStatus !== 'Unsupported',
done: accessibilityDone,
locked: false,
actionLabel: accessibilityActionLabel(
@@ -230,7 +238,7 @@ function buildSetupSteps(
currentIsRequestingAccessibility,
currentHasRequestedAccessibility,
),
- actionVariant: accessibilityDone ? 'default' : 'primary',
+ actionVariant: accessibilityReady ? 'default' : 'primary',
action: requestAccessibilityPermission,
actionDisabled: accessibilityActionDisabled,
},
@@ -240,7 +248,7 @@ function buildSetupSteps(
desc: 'Start with TextEdit, then add more apps from Integrations when you are ready.',
required: true,
done: integrationDone,
- locked: !accessibilityDone,
+ locked: !accessibilityReady,
actionLabel: integrationDone ? 'Manage' : 'Browse apps',
actionVariant: 'default',
action: () => navigateToSection('integrations'),
@@ -251,16 +259,12 @@ function buildSetupSteps(
title: 'Take a test drive',
desc: 'Open TextEdit, type "its not alot of fun", and watch Harper underline the mistakes.',
required: false,
- done: testDriveDone,
- locked: !accessibilityDone || !integrationDone,
- actionLabel: isLaunchingTextEdit
- ? 'Launching...'
- : testDriveDone
- ? 'Run again'
- : 'Launch TextEdit',
- actionVariant: testDriveDone ? 'default' : 'primary',
+ done: false,
+ locked: !accessibilityReady || !integrationDone,
+ actionLabel: currentIsLaunchingTextEdit ? 'Launching...' : 'Launch TextEdit',
+ actionVariant: 'primary',
action: launchTextEditForTestDrive,
- actionDisabled: isLaunchingTextEdit,
+ actionDisabled: currentIsLaunchingTextEdit,
},
];
}
@@ -278,9 +282,12 @@ function buildSetupSteps(
Harper is ready to check writing in the apps you choose. You can revisit any section
from the sidebar.
</p>
+ {#if onboardingError}
+ <p>{onboardingError}</p>
+ {/if}
</div>
- <button class="button" type="button" on:click={() => updateSetup({ testDrive: "not_started" })}>
- Walk through again
+ <button class="button" type="button" disabled={isCompletingOnboarding} on:click={completeOnboarding}>
+ {isCompletingOnboarding ? "Continuing..." : "Continue"}
</button>
</div>
{:else}
@@ -307,9 +314,9 @@ function buildSetupSteps(
<h1>Let's get Harper up and running.</h1>
<div class="progress-row">
<div class="progress-track">
- <div class="progress-fill" style={`width: ${(setupCompletedCount / setupSteps.length) * 100}%`}></div>
+ <div class="progress-fill" style={`width: ${(setupCompletedCount / requiredSetupSteps.length) * 100}%`}></div>
</div>
- <span>{setupCompletedCount} of {setupSteps.length}</span>
+ <span>{setupCompletedCount} of {requiredSetupSteps.length}</span>
</div>
</div>
{/if}