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
16 changes: 10 additions & 6 deletions src-tauri/src/cloudflare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,16 @@ pub async fn cloudflare_start_oauth(app: tauri::AppHandle) -> Result<CfOAuthStat

crate::providers::open_sign_in_page(&app, &auth_url);

let code = tokio::time::timeout(
std::time::Duration::from_secs(AUTH_TIMEOUT_SECS),
crate::providers::await_oauth_callback(listener, &state, "code", "Cloudflare"),
)
.await
.map_err(|_| "Authorization timed out - please try again.".to_string())??;
// Cancel (provider_cancel_oauth) drops the wait and frees the port, the
// same as for the other providers.
let cancelled = crate::providers::oauth_cancel().notified();
let code = tokio::select! {
r = tokio::time::timeout(
std::time::Duration::from_secs(AUTH_TIMEOUT_SECS),
crate::providers::await_oauth_callback(listener, &state, "code", "Cloudflare"),
) => r.map_err(|_| "Authorization timed out - please try again.".to_string())??,
_ = cancelled => return Err("cancelled".to_string()),
};

let token = exchange_code(&code, &verifier, &redirect_uri).await?;

Expand Down
9 changes: 8 additions & 1 deletion src-tauri/src/db/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ pub(crate) fn client_dir_candidates(explicit: &str) -> Vec<PathBuf> {
let mut parents: Vec<PathBuf> = Vec::new();
if let Some(home) = dirs_home() {
parents.push(home.clone());
parents.push(home.join("Downloads"));
// Not on macOS: Downloads is a protected folder there, and listing it
// (even just to look for an `instantclient_*`) makes macOS ask whether
// Stroke may read your Downloads, at launch, for a client most people
// never use. Unzipped there, it is found once its path is set in the
// connection or STROKE_ORACLE_CLIENT_DIR.
if !cfg!(target_os = "macos") {
parents.push(home.join("Downloads"));
}
parents.push(home.join("oracle"));
}
if cfg!(target_os = "windows") {
Expand Down
8 changes: 7 additions & 1 deletion src-tauri/src/db/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,13 @@ fn install_dirs() -> Vec<PathBuf> {
// and SQLcl unzipped next to it.
out.extend(super::oracle::client_dir_candidates(""));
if let Some(home) = home_dir() {
for parent in [home.clone(), home.join("Downloads"), home.join("oracle")] {
// Downloads only off macOS: touching it there raises the "would like
// to access files in your Downloads folder" prompt (see oracle.rs).
let mut parents = vec![home.clone(), home.join("oracle")];
if !cfg!(target_os = "macos") {
parents.push(home.join("Downloads"));
}
for parent in parents {
out.push(parent.join("sqlcl").join("bin"));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const TOKEN_PROXY: &str = "https://stroke.click/api/oauth/token";
// drops the callback listener future, which frees the localhost port instead of
// holding it until the 5-minute timeout.
static OAUTH_CANCEL: OnceLock<tokio::sync::Notify> = OnceLock::new();
fn oauth_cancel() -> &'static tokio::sync::Notify {
pub(crate) fn oauth_cancel() -> &'static tokio::sync::Notify {
OAUTH_CANCEL.get_or_init(tokio::sync::Notify::new)
}

Expand Down
9 changes: 7 additions & 2 deletions src/lib/components/AiChat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@
} = $props();

/** A statement that changes the schema, so the sidebar must reload. @param {string} sql */
const isDdl = (sql) => /^\s*(?:--[^\n]*\n\s*)*(create|alter|drop|rename|truncate|comment\s+on)\b/i.test(sql ?? "") || /;\s*(create|alter|drop|rename|truncate)\b/i.test(sql ?? "");
// A statement that changes the catalog, wherever it sits in the batch: at the
// start, after a `;`, or after a `--` or `/* */` comment (an agent often opens
// with `SET search_path ...;` or a comment line before its CREATE VIEW).
const isDdl = (sql) => /(?:^|;|\*\/|\n)\s*(?:--[^\n]*\n\s*)*(create|alter|drop|rename|truncate|comment\s+on)\b/i.test(sql ?? "");

$effect(() => {
if (isActive) {
Expand Down Expand Up @@ -2886,7 +2889,9 @@
: s,
),
}));
if (t.name === "execute_sql" && !res.is_error && isDdl(t.detail)) onschemadirty();
// An empty detail means the result beat the call's full input here: the
// SQL is unknown, so the sidebar re-reads rather than miss a CREATE VIEW.
if (t.name === "execute_sql" && !res.is_error && (!t.detail || isDdl(t.detail))) onschemadirty();
const parsed = t.name === "execute_sql" && !res.is_error ? parseSqlResult(out) : null;
// Rows still get their table; a failure is already shown in the fold.
if (parsed && parsed.total > 0) {
Expand Down
20 changes: 13 additions & 7 deletions src/lib/components/CellEditorPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
import X from '@lucide/svelte/icons/x'
import { cn } from '$lib/utils.js'
import { toast } from '$lib/components/ui/sonner/toast.svelte.js'
import Kbd from './Kbd.svelte'
import { detectOs } from '$lib/platform.js'
/** The stage shortcut as one glyph run: ⌘↵ on a Mac, Ctrl↵ elsewhere. */
const modEnter = detectOs() === 'macos' ? '⌘↵' : 'Ctrl ↵'

let {
open = $bindable(false),
Expand Down Expand Up @@ -677,16 +679,20 @@
>
<Undo2 class="size-3.5 shrink-0" />
</button>
<button
type="button"
class="ms-2 inline-flex h-7 items-center gap-2 rounded-lg bg-primary ps-2.5 pe-1.5 text-ui-xs font-medium text-primary-foreground transition-[background-color,opacity,scale] hover:bg-primary/90 active:scale-[0.97] disabled:bg-muted disabled:text-muted-foreground disabled:active:scale-100"
<!-- The shared button (same corner, height and focus ring as every
other primary action), with the shortcut as a quiet glyph after the
label. Two boxed key chips inside a filled button read as a second
set of buttons. -->
<Button
size="sm"
class="ms-2 gap-1.5"
disabled={!dirty}
onclick={apply}
title="Stage this value with your other pending edits"
title="Stage this value with your other pending edits ({modEnter})"
>
Stage change
<Kbd combo="Mod+Enter" class="opacity-80" />
</button>
<span class="font-mono text-ui-2xs opacity-60" aria-hidden="true">{modEnter}</span>
</Button>
{/if}
<button
type="button"
Expand Down
61 changes: 40 additions & 21 deletions src/lib/components/CloudflareLogin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { Button } from '$lib/components/ui/button/index.js'
import ConfirmDialog from './ConfirmDialog.svelte'
import { cfStartOAuth, cfOAuthStatus, cfLogout, cfGetValidToken } from '$lib/cloudflare.js'
import { providerCancelOAuth } from '$lib/providers.js'
import { readProviderList, writeProviderList, clearProviderLists } from '$lib/provider-list-cache.js'
import { cloudflareListAccounts, cloudflareListD1Databases, cloudflareCreateD1Database } from '$lib/api.js'
import { cn } from '$lib/utils.js'
Expand Down Expand Up @@ -182,7 +183,11 @@
} catch { /* clipboard blocked */ }
}

/** Set by Cancel, so the wait's own error on the way out is not shown as a failure. */
let cancelled = false

async function startAuth() {
cancelled = false
phase = 'authorizing'
errorMsg = ''
authUrl = ''
Expand All @@ -200,14 +205,23 @@
phase = 'fetching'
await loadAccounts()
} catch (e) {
phase = 'error'
errorMsg = String(e)
// Cancel lands here too: back to the start, not an error.
if (cancelled || /cancel/i.test(String(e))) { phase = 'idle'; errorMsg = '' }
else { phase = 'error'; errorMsg = String(e) }
} finally {
unlisten?.()
authUrl = ''
}
}

/** Stop waiting on the browser: frees the callback port and goes back to Sign in. */
async function cancelAuth() {
cancelled = true
try { await providerCancelOAuth() } catch { /* the wait ends on its own */ }
phase = 'idle'
errorMsg = ''
}

/**
* A failure while refreshing a cached view keeps that view: a network blip
* shouldn't swap a usable list for an error card. An ended session still
Expand Down Expand Up @@ -365,9 +379,9 @@
<ProviderAuthPanel
title="Sign in with Cloudflare"
subtitle="Opens your browser to authorize. Stroke gets a scoped token for D1 - your Cloudflare password never passes through it."
hint="Same PKCE flow as Wrangler"
hint="Cloudflare's own sign-in, the one Wrangler uses"
>
{#snippet mark()}<DbIcon id="d1" class="size-4 shrink-0" />{/snippet}
{#snippet mark()}<DbIcon id="d1" class="size-5 shrink-0" />{/snippet}
{#snippet action()}
<Button class="group" onclick={startAuth}>
Sign in
Expand All @@ -380,23 +394,28 @@
<ProviderAuthPanel
tone="busy"
progress
title="Waiting for Cloudflare…"
subtitle="Finish authorizing in the browser tab, then come back here."
hint="Times out in 5 min"
title="Waiting for Cloudflare"
subtitle="Approve Stroke in the Cloudflare tab in your browser. This page carries on by itself."
timeout={300}
>
{#snippet mark()}<DbIcon id="d1" class="size-4 shrink-0" />{/snippet}
{#snippet mark()}<DbIcon id="d1" class="size-5 shrink-0" />{/snippet}
{#snippet action()}
<Button variant="ghost" size="sm" onclick={cancelAuth}>Cancel</Button>
{/snippet}
{#snippet footer()}
{#if authUrl}
<span class="me-1">Browser didn't open?</span>
<Button variant="ghost" size="xs" onclick={reopenAuthPage}>Open again</Button>
<Button variant="ghost" size="xs" onclick={copyAuthLink}>
{#if linkCopied}<Check class="size-3 shrink-0 text-success" aria-hidden="true" /> Copied{:else}Copy link{/if}
</Button>
<span class="sr-only" role="status">{linkCopied ? 'Link copied' : ''}</span>
{:else}
<Loader2 class="size-3 shrink-0 animate-spin" aria-hidden="true" />
<span class="ms-1">Opening your browser</span>
{/if}
{/snippet}
</ProviderAuthPanel>
{#if authUrl}
<!-- Same recovery row as the other providers' waiting panel. -->
<div class="flex flex-wrap items-center gap-x-1 gap-y-1 ps-11 text-ui-2xs text-muted-foreground">
<span class="me-1">Browser didn't open?</span>
<Button variant="ghost" size="xs" onclick={reopenAuthPage}>Open again</Button>
<Button variant="ghost" size="xs" onclick={copyAuthLink}>
{#if linkCopied}<Check class="size-3 shrink-0 text-success" aria-hidden="true" /> Copied{:else}Copy link{/if}
</Button>
<span class="sr-only" role="status">{linkCopied ? 'Link copied' : ''}</span>
</div>
{/if}

{:else if phase === 'fetching'}
<ProviderAuthPanel
Expand All @@ -406,7 +425,7 @@
subtitle="Loading your Cloudflare accounts…"
hint={email}
>
{#snippet mark()}<Check class="size-4 shrink-0 text-success" />{/snippet}
{#snippet mark()}<Check class="size-5 shrink-0 text-success" />{/snippet}
</ProviderAuthPanel>

{:else if phase === 'error'}
Expand All @@ -420,7 +439,7 @@
subtitle={shownError.detail}
hint={signedIn ? email : 'Nothing was saved'}
>
{#snippet mark()}<AlertTriangle class="size-4 shrink-0 text-destructive" />{/snippet}
{#snippet mark()}<AlertTriangle class="size-5 shrink-0 text-destructive" />{/snippet}
{#snippet action()}
<div class="flex shrink-0 items-center gap-2">
<Button variant="outline" class="group" onclick={() => (signedIn ? loadAccounts() : startAuth())}>
Expand Down
25 changes: 13 additions & 12 deletions src/lib/components/ConnectionModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3616,11 +3616,11 @@
</div>
</ScrollArea>
{:else}
<div class="flex h-full items-center justify-center pb-8">
<p class="text-ui-2xs text-muted-foreground">
No saved connections
</p>
</div>
<!-- At the top, where the first saved one will appear, not
floating halfway down an empty rail. -->
<p class="px-3 pt-1 text-ui-xs text-muted-foreground">
Saved connections show up here.
</p>
{/if}
</div>
<!-- Drag the rail wider when connection names are long. -->
Expand Down Expand Up @@ -3705,7 +3705,7 @@
<!-- The same top inset on both steps, so going from the list to the
form doesn't nudge the page up (it was pt-4, then pt-2). -->
<div
class="w-full max-w-6xl shrink-0 px-10 pt-3"
class="mx-auto w-full max-w-6xl shrink-0 px-10 pt-3"
>
{#if step === "pick"}
<!-- pe-6 keeps the rescan button clear of the dialog's own close
Expand Down Expand Up @@ -3897,12 +3897,13 @@
auto-fill grid with 200px of air between them, and "New
connection" put its chevron 1800px from its own label. One
42rem column, one leading edge. -->
<!-- Left-aligned, not centred: the rail is on the left and the
header sits above this, so a column centred in the panel
starts somewhere neither of them does. One leading edge. -->
<!-- Centred in the panel, like the header and footer (all three
mx-auto at the same width, so they keep one leading edge).
Pinned left, a wide window left a third of the panel empty
on the right. -->
<!-- Full width: the grids below are four columns, so a wide window
buys wider tiles and fewer truncated names, not empty margin. -->
<div class="@container flex w-full max-w-6xl flex-col gap-7 px-10 py-6">
<div class="@container mx-auto flex w-full max-w-6xl flex-col gap-7 px-10 py-6">
<!-- ── Paste a connection string ─────────────────────────
The fastest path there is, and the one a developer already
has in a clipboard from their provider dashboard or a
Expand Down Expand Up @@ -4197,7 +4198,7 @@
same layout roomier - and the panel already runs the header,
the footer and the URL bar edge to edge, so a capped form in
the middle of them was the odd one out. -->
<div class="flex w-full max-w-6xl items-start gap-10 px-10 py-6">
<div class="mx-auto flex w-full max-w-6xl items-start gap-10 px-10 py-6">
<!-- Enter connects, from any field - filling a form and having to go
find the button is the one interaction nobody expects here. The
paste bar's own Enter handler runs first and marks the event
Expand Down Expand Up @@ -5304,7 +5305,7 @@
px-10, padding inside the width): with the padding outside, the
bar ran 80px past the tiles, plain to see once the rail is
collapsed and the window is wide. -->
<div class="flex min-h-8 w-full max-w-6xl flex-col justify-center px-10">
<div class="mx-auto flex min-h-8 w-full max-w-6xl flex-col justify-center px-10">
<!-- The alert itself is a toast (see failWith). What stays here is the
one-line record of it, so the driver's own words are still
readable after the toast has gone - without a panel that shoves
Expand Down
23 changes: 23 additions & 0 deletions src/lib/components/DisconnectDialog.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
<script>
import ConfirmDialog from './ConfirmDialog.svelte'
import { Button } from '$lib/components/ui/button/index.js'

let {
open = $bindable(false),
connectionName = '',
/** Labs: the other databases still open, by name. Disconnecting this one moves to one of them. */
others = /** @type {string[]} */ ([]),
ondisconnect = () => {},
/** Close every open database at once. */
ondisconnectall = () => {},
} = $props()

const question = $derived(
connectionName ? `Disconnect from ${connectionName}?` : 'Disconnect from the current database?',
)
// With others open, Disconnect lands on the next one, so getting out of all
// of them used to mean answering this same question once per database.
const note = $derived(
others.length === 1 ? `${others[0]} stays open, and Stroke moves to it.`
: others.length > 1 ? `${others.length} other databases stay open, and Stroke moves to ${others.at(-1)}.`
: '',
)
</script>

{#snippet allRow()}
<div class="flex items-center justify-between gap-3 px-5 py-3">
<p class="text-ui-xs text-muted-foreground">Done with all of them?</p>
<Button variant="outline" size="sm" onclick={() => { open = false; ondisconnectall() }}>
Disconnect all
</Button>
</div>
{/snippet}

<ConfirmDialog
bind:open
icon="unplug"
title="Disconnect"
description={question}
{note}
confirmLabel="Disconnect"
confirmIcon="unplug"
variant="destructive"
confirmOnEnter
onconfirm={ondisconnect}
extra={others.length ? allRow : undefined}
/>
Loading
Loading