Skip to content
Merged
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
21 changes: 17 additions & 4 deletions src-tauri/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,24 @@ pub fn parse_callback(target: &str, expected_state: &str) -> Option<Callback> {
}
}

/// The page the browser shows after it hands the sign-in back to the app.
/// `box-sizing` matters: `min-height: 100vh` plus body padding overflowed by
/// the padding and put a scrollbar on a page with one sentence on it.
fn callback_page(heading: &str, body: &str) -> String {
let ok = heading.starts_with("You're");
let failed = heading.contains("didn't");
// A check for success, a dash for cancelled, an exclamation for a failure.
let (icon, tone) = if ok {
("<path d=\"M5 12.5l4.5 4.5L19 7.5\"/>", "ok")
} else if failed {
("<path d=\"M12 6.5v7\"/><path d=\"M12 17.5h.01\"/>", "bad")
} else {
("<path d=\"M7 12h10\"/>", "")
};
format!(
r#"<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="color-scheme" content="dark light"><title>Stroke</title>
<style>body{{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;font:15px/1.5 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;background:#0b0b0c;color:#ededee;padding:16px}}main{{max-width:380px}}h1{{font-size:19px;font-weight:600;margin:0 0 6px}}p{{margin:0;color:#a1a1a8}}@media (prefers-color-scheme: light){{body{{background:#f6f6f7;color:#18181b}}p{{color:#5b5b63}}}}</style></head>
<body><main><h1>{heading}</h1><p>{body}</p></main></body></html>"#
r#"<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="color-scheme" content="dark light"><title>{heading} · Stroke</title>
<style>*,*::before,*::after{{box-sizing:border-box}}html,body{{height:100%}}body{{margin:0;display:grid;place-items:center;padding:24px;font:15px/1.55 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;background:#0b0b0c;color:#ededee;-webkit-font-smoothing:antialiased;overflow:hidden}}main{{width:100%;max-width:360px;display:flex;flex-direction:column;align-items:center;text-align:center}}.mark{{width:44px;height:44px;border-radius:50%;display:grid;place-items:center;background:#1a1a1d;box-shadow:inset 0 0 0 1px #2a2a2e,inset 0 1px 0 rgb(255 255 255/.06);color:#a1a1a8}}.mark.ok{{color:#4ade80;background:#0f1f15;box-shadow:inset 0 0 0 1px #1d3b26}}.mark.bad{{color:#f87171;background:#221212;box-shadow:inset 0 0 0 1px #3d1d1d}}svg{{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round}}h1{{font-size:20px;font-weight:600;letter-spacing:-.01em;margin:18px 0 6px}}p{{margin:0;color:#a1a1a8;text-wrap:pretty}}small{{margin-top:28px;font-size:12px;color:#6b6b73}}@media (prefers-color-scheme: light){{body{{background:#f6f6f7;color:#18181b}}p{{color:#5b5b63}}small{{color:#8b8b93}}.mark{{background:#fff;box-shadow:inset 0 0 0 1px #e4e4e7;color:#5b5b63}}.mark.ok{{background:#ecfdf3;box-shadow:inset 0 0 0 1px #bbf7d0;color:#16a34a}}.mark.bad{{background:#fef2f2;box-shadow:inset 0 0 0 1px #fecaca;color:#dc2626}}}}</style></head>
<body><main><span class="mark {tone}" aria-hidden="true"><svg viewBox="0 0 24 24">{icon}</svg></span><h1>{heading}</h1><p>{body}</p><small>Stroke</small></main></body></html>"#
)
}

Expand Down Expand Up @@ -655,7 +668,7 @@ pub async fn wait_for_callback(listener: TcpListener, expected_state: &str) -> R
Some(Callback::Code(code)) => {
respond(&mut stream, "200 OK", &callback_page(
"You're signed in",
"You can close this tab and return to Stroke.",
"Head back to Stroke. You can close this tab.",
)).await;
return Ok(code);
}
Expand Down
51 changes: 24 additions & 27 deletions src/lib/components/AccountSignInButtons.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script>
// "Continue with GitHub / Google", the waiting state with Cancel, and the
// error state. Shared by the new-install screen and the account card.
// One "Sign in" button, the waiting state with Cancel, and the error state.
// Shared by the new-install screen, the trial screen and the account card.
// The provider (GitHub, Google) is picked on stroke.click's sign-in page:
// choosing it here as well asked the same question twice.
import { signInState, signIn, cancelSignIn } from '$lib/stores/account.js'
import { Button } from '$lib/components/ui/button/index.js'
import AuthProviderIcon from './AuthProviderIcon.svelte'
import Icon from './Icon.svelte'
import LoaderCircle from '@lucide/svelte/icons/loader-circle'
import CircleAlert from '@lucide/svelte/icons/circle-alert'
import Copy from '@lucide/svelte/icons/copy'
Expand All @@ -24,11 +26,8 @@
$effect(() => {
if (!waiting) pasting = false
})
const providerName = $derived($signInState.provider === 'google' ? 'Google' : $signInState.provider === 'github' ? 'GitHub' : 'your account')

/** @param {'github' | 'google'} p */
async function go(p) {
if (await signIn(p)) onsignedin()
async function go() {
if (await signIn(null)) onsignedin()
}

async function copyLink() {
Expand All @@ -45,7 +44,7 @@
<div class="flex flex-col items-center gap-2 text-center" role="status" aria-live="polite">
<div class="flex items-center gap-2 text-ui-sm text-foreground">
<LoaderCircle class="size-4 shrink-0 animate-spin text-muted-foreground" />
Waiting for {providerName}…
Waiting for your browser…
</div>
<p class="text-ui-xs text-muted-foreground text-pretty">Finish signing in in your browser, then come back here.</p>
<div class="mt-2 flex flex-wrap items-center justify-center gap-x-1 gap-y-1 text-ui-xs">
Expand All @@ -68,24 +67,22 @@
{/if}
</div>
{:else}
<Button
variant="secondary"
size={size === 'lg' ? 'lg' : 'sm'}
class={cn('w-full gap-2.5 font-medium', size === 'lg' && 'text-ui-sm')}
onclick={() => void go('github')}
>
<AuthProviderIcon name="github" class="size-4 shrink-0" />
Continue with GitHub
</Button>
<Button
variant="secondary"
size={size === 'lg' ? 'lg' : 'sm'}
class={cn('w-full gap-2.5 font-medium', size === 'lg' && 'text-ui-sm')}
onclick={() => void go('google')}
>
<AuthProviderIcon name="google" class="size-4 shrink-0" />
Continue with Google
</Button>
{#if size === 'lg'}
<button
type="button"
class="keycap-btn inline-flex h-10 w-full items-center justify-center gap-2 rounded-md px-4 text-ui-sm font-medium"
onclick={() => void go()}
>
Sign in
<Icon name="external-link" class="size-3.5 shrink-0 text-muted-foreground" />
</button>
{:else}
<Button variant="secondary" size="sm" class="w-full gap-2 font-medium" onclick={() => void go()}>
Sign in
<Icon name="external-link" class="size-3.5 shrink-0 text-muted-foreground" />
</Button>
{/if}
<p class="text-center text-ui-2xs text-muted-foreground">Opens stroke.click in your browser.</p>
{#if $signInState.phase === 'error'}
<p class="flex items-start gap-1.5 text-left text-ui-xs leading-relaxed text-destructive" role="alert">
<CircleAlert class="mt-0.5 size-3.5 shrink-0" />
Expand Down
13 changes: 12 additions & 1 deletion src/lib/components/LicenseGate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { isBlocked, refreshLicenseStatus, runLicenseCheck } from '$lib/stores/license.js'
import TrialExpiredScreen from './TrialExpiredScreen.svelte'
import SignInScreen from './SignInScreen.svelte'
import { needsOnboarding, startAccountSync } from '$lib/stores/account.js'
import { needsOnboarding, startAccountSync, account } from '$lib/stores/account.js'

let { children } = $props()

Expand All @@ -21,6 +21,17 @@

let onboardingDone = $state(false)

// Signing out goes back to the sign-in screen. `onboardingDone` stayed true
// from the sign-in earlier in the session, so the gate skipped it and fell
// through to the trial check: a signed-out user whose device trial had run
// out saw "Your trial has ended" instead of "Sign in".
let wasSignedIn = false
$effect(() => {
const signedIn = !!$account?.signed_in
if (wasSignedIn && !signedIn) onboardingDone = false
wasSignedIn = signedIn
})

// Dev-only: Alt+Shift+O previews the first-run tour even on the sign-in
// screen, where the app shell (and its own Alt+Shift+O) is not mounted.
let tourPreview = $state(false)
Expand Down
29 changes: 18 additions & 11 deletions src/lib/components/TrialExpiredScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,16 @@
<LoaderCircle class="size-3.5 shrink-0 animate-spin" /> Loading
</div>
{:else if $isSignedIn}
<Button size="lg" class="w-full" onclick={() => void openStore()}>
Get Stroke Pro <Icon name="external-link" class="size-3.5 shrink-0" />
</Button>
<Button variant="secondary" class="w-full" disabled={checking} onclick={() => void checkAgain()}>
<button type="button" class="keycap-btn inline-flex h-10 w-full items-center justify-center gap-2 rounded-md px-4 text-ui-sm font-medium" onclick={() => void openStore()}>
Get Stroke Pro <Icon name="external-link" class="size-3.5 shrink-0 text-muted-foreground" />
</button>
<button type="button" class="inline-flex h-8 w-full items-center justify-center gap-1.5 rounded-md text-ui-xs text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none" disabled={checking} aria-busy={checking} onclick={() => void checkAgain()}>
{#if checking}<LoaderCircle class="size-3.5 shrink-0 animate-spin" /> Checking{:else}<RefreshCw class="size-3.5 shrink-0" /> I bought it, check again{/if}
</Button>
</button>
{:else}
<!-- One way in: an account that has Pro. Buying is a quiet link
below, beside the key, not a second big button. -->
<AccountSignInButtons size="lg" />
<Button variant="secondary" class="w-full" onclick={() => void openStore()}>
Get Stroke Pro <Icon name="external-link" class="size-3.5 shrink-0" />
</Button>
{/if}
</div>

Expand All @@ -174,9 +173,17 @@
<ArrowLeft class="size-3.5 shrink-0" /> Back
</button>
{:else}
<button type="button" onclick={() => (mode = 'key')} class="mt-4 inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-ui-xs text-muted-foreground transition-[color,scale] duration-[120ms] hover:text-foreground active:scale-[0.97]">
<KeyRound class="size-3.5 shrink-0" /> Use a license key
</button>
<div class={cn('mt-4 flex items-center justify-center gap-1 text-ui-xs text-muted-foreground', waiting && 'pointer-events-none opacity-0')}>
{#if !$isSignedIn}
<button type="button" onclick={() => void openStore()} class="inline-flex h-7 items-center gap-1.5 rounded-md px-2 transition-[color,scale] duration-[120ms] hover:text-foreground active:scale-[0.97]">
Get Stroke Pro <Icon name="external-link" class="size-3 shrink-0" />
</button>
<span aria-hidden="true">·</span>
{/if}
<button type="button" onclick={() => (mode = 'key')} class="inline-flex h-7 items-center gap-1.5 rounded-md px-2 transition-[color,scale] duration-[120ms] hover:text-foreground active:scale-[0.97]">
<KeyRound class="size-3.5 shrink-0" /> Use a license key
</button>
</div>
{/if}
{/if}

Expand Down
Loading