Show the engine setup until the browser engine is installed

A browser tab shows the download size, Download the engine, Install from
file, and Open in default browser until the engine can start. It shows
progress, Cancel, the cause of a failure, and Retry, and then opens the
page. Settings -> Browser shows the engine state and Remove engine. Web
links open in the system browser until the engine is installed. Open
link in app browser always opens a browser tab.
This commit is contained in:
Knotty Wyvern
2026-10-29 01:18:21 -07:00
parent 6004e126f7
commit c06d48f250
19 changed files with 425 additions and 107 deletions
+14 -5
View File
@@ -1,21 +1,30 @@
<script lang="ts">
import { t } from "$lib/i18n";
import { onMount } from 'svelte';
import Icon from '$lib/ui/Icon.svelte';
import IconButton from '$lib/ui/IconButton.svelte';
import { state as browserState, request } from './client';
import { engine, engineReady } from './engine';
let { open }: { open: (profileId: string, url: string) => Promise<void> } = $props();
let error = $state('');
onMount(() => { void request('state').catch(reason => error = String(reason)); });
// The bookmarks live in the engine. A missing engine is not started here.
const installed = $derived(engineReady($engine));
let loaded = false;
$effect(() => {
if (!installed) { loaded = false; return; }
if (loaded) return;
loaded = true;
void request('state').catch(reason => error = String(reason));
});
</script>
<div class="bookmarks">
{#if error}<p role="alert">{error}</p>{/if}
{#each $browserState?.bookmarks || [] as item (item.id)}
{#if !installed}<p class="note">{$t("Install the browser engine to see the browser bookmarks.")}</p>{/if}
{#if error}<p class="error" role="alert">{error}</p>{/if}
{#each installed ? $browserState?.bookmarks || [] : [] as item (item.id)}
<div class="row"><button class="link" title={item.url} onclick={() => void open(item.profileId, item.url)}><Icon icon="globe" /><span>{item.title}</span></button><IconButton icon="close" label={`Remove ${item.title}`} onclick={() => void request('removeBookmark', { id: item.id })} /></div>
{/each}
</div>
<style>
.bookmarks{color:var(--rs-text);font-family:var(--rs-font-ui)}.row{display:flex;align-items:center;padding:0 5px;border-radius:var(--rs-control-radius)}.row:hover{background:var(--rs-bg-active)}
.link{display:flex;align-items:center;gap:8px;flex:1;min-width:0;padding:7px 5px;border:0;border-radius:var(--rs-control-radius);color:inherit;background:transparent;text-align:left;cursor:pointer}
span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.link:focus-visible{outline:2px solid var(--rs-focus)}p{color:var(--rs-error);padding:8px;font-size:12px}
span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.link:focus-visible{outline:2px solid var(--rs-focus)}p{padding:8px;font-size:12px}.error{color:var(--rs-error)}.note{margin:0;color:var(--rs-text-dim)}
</style>
+2 -1
View File
@@ -9,6 +9,7 @@
import { showActionMenu } from '$lib/ui/managedActionMenu';
import { WheelQueue } from './inputQueue';
import { TabSession, type TabStatus } from './tabSession';
import { engine } from './engine';
import { AutoScroll } from './autoScroll';
let { initial, onSessionChange, newTab }: { initial: { tabId?: string; profileId?: string; url?: string }; onSessionChange: (value: TabStatus) => void; newTab: (profileId: string, url?: string) => Promise<void> } = $props();
let status = $state<TabStatus>({ tabId: '', phase: 'connecting', message: $t('Opening browser…') });
@@ -269,7 +270,7 @@
<details class="diagnostics"><summary>{$t("Browser error details")}</summary><dl>
<dt>{$t("Operation")}</dt><dd>{status.detail.operation}</dd><dt>{$t("Reason")}</dt><dd>{status.detail.reason}</dd>
<dt>{$t("Tab")}</dt><dd>{status.detail.tabId || $t('Not created')}</dd><dt>{$t("Time")}</dt><dd>{status.detail.time}</dd>
<dt>{$t("Browser")}</dt><dd>{$t("Included with RuneStone")}</dd>
<dt>{$t("Engine")}</dt><dd>{$engine?.version ?? ''}</dd>
</dl></details>
{/if}
{#if openingError || $pageErrors[tabId]}<p class="error" role="alert">{openingError || $pageErrors[tabId]}</p>{/if}
+17
View File
@@ -0,0 +1,17 @@
<script lang="ts">
import type { ComponentProps } from "svelte";
import Browser from "./Browser.svelte";
import EngineSetup from "./EngineSetup.svelte";
import { engine, engineReady } from "./engine";
// A browser tab shows the engine setup until the engine can start. Then it opens the page.
let props: ComponentProps<typeof Browser> = $props();
let browser = $state<ReturnType<typeof Browser>>();
export async function find() { await browser?.find(); }
export function detach() { browser?.detach(); }
export async function action(command: string, args: Record<string, unknown> = {}) { await browser?.action(command, args); }
</script>
{#if engineReady($engine)}
<Browser bind:this={browser} {...props} />
{:else}
<EngineSetup variant="tab" url={props.initial.url} />
{/if}
+78
View File
@@ -0,0 +1,78 @@
<script lang="ts">
import { t } from "$lib/i18n";
import { confirm } from "@tauri-apps/plugin-dialog";
import { openUrl } from "@tauri-apps/plugin-opener";
import Icon from "$lib/ui/Icon.svelte";
import { engine, installEngine, installEngineFile, cancelEngine, removeEngine, megabytes } from "./engine";
// `tab` fills a browser tab while the engine is missing. `settings` is the Engine section of Settings → Browser.
let { variant, url = "" }: { variant: "tab" | "settings"; url?: string } = $props();
let failure = $state("");
const status = $derived($engine);
const phase = $derived(status?.state ?? "missing");
const busy = $derived(phase === "downloading" || phase === "installing");
const error = $derived(failure || status?.error || "");
const web = $derived(variant === "tab" && /^https?:\/\//i.test(url));
async function run(action: () => Promise<unknown>) {
failure = "";
try { await action(); } catch (reason) { failure = String(reason); }
}
async function remove() {
const accepted = await confirm($t("Remove the browser engine? Open browser tabs close. Your profiles, bookmarks, and history stay."), { title: $t("Remove browser engine"), kind: "warning", okLabel: $t("Remove"), cancelLabel: $t("Cancel") });
if (accepted) await run(removeEngine);
}
</script>
<section class="engine {variant}" aria-labelledby={`engine-${variant}`} data-engine-state={phase}>
{#if variant === "tab"}<span class="mark"><Icon icon="globe" /></span>{/if}
<h3 id={`engine-${variant}`}>{$t("Browser engine")}</h3>
{#if phase === "installed"}
<p>{$t("Version {version} is installed.", { version: status?.version ?? "" })}</p>
{:else if phase === "development"}
<p>{$t("This development build uses the engine in src-tauri/browser-engine.")}</p>
{:else if phase === "unavailable"}
<p>{$t("No browser engine is available for this platform yet.")}</p>
{:else if phase === "downloading"}
<p role="status">{$t("Downloading the browser engine: {received} of {total}.", { received: megabytes(status?.received ?? 0), total: megabytes(status?.bytes ?? 0) })}</p>
<progress max={status?.bytes || 1} value={status?.received ?? 0} aria-label={$t("Download progress")}></progress>
{:else if phase === "installing"}
<p role="status">{$t("Installing the browser engine…")}</p>
<progress aria-label={$t("Installation progress")}></progress>
{:else if phase === "update"}
<p>{$t("This RuneStone version needs browser engine {version}. The download is {size}.", { version: status?.version ?? "", size: megabytes(status?.bytes ?? 0) })}</p>
{:else}
<p>{$t("The built-in browser needs its engine. The engine is a separate download of {size}.", { size: megabytes(status?.bytes ?? 0) })}</p>
{/if}
{#if error && !busy}<p class="error" role="alert"><Icon icon="alert" /><span>{$t("The browser engine could not be installed: {reason}", { reason: error })}</span></p>{/if}
<div class="actions">
{#if busy}
<button type="button" disabled={phase === "installing"} onclick={() => void run(cancelEngine)}><Icon icon="close" />{$t("Cancel")}</button>
{:else if phase === "missing" || phase === "update"}
<button type="button" class="primary" onclick={() => void run(installEngine)}><Icon icon={error ? "refresh" : "download"} />{error ? $t("Retry") : phase === "update" ? $t("Update the engine") : $t("Download the engine")}</button>
<button type="button" onclick={() => void run(installEngineFile)}><Icon icon="folder-open" />{$t("Install from file…")}</button>
{:else if phase === "installed" && variant === "settings"}
<button type="button" class="danger" onclick={() => void remove()}><Icon icon="trash" />{$t("Remove engine")}</button>
{/if}
{#if web}<button type="button" onclick={() => void run(() => openUrl(url))}><Icon icon="globe" />{$t("Open in default browser")}</button>{/if}
</div>
</section>
<style>
.engine { color: var(--rs-text); font-family: var(--rs-font-ui); }
.engine.tab { box-sizing: border-box; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 100%; min-height: 200px; padding: 24px 16px; text-align: center; background: var(--rs-bg); }
.engine.settings { padding: var(--rs-settings-row-padding); background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
.mark { display: grid; place-items: center; width: 48px; height: 48px; color: var(--rs-accent); }
.mark :global(svg) { width: 40px; height: 40px; }
h3 { margin: 0 0 4px; font-size: 14px; font-weight: 500; color: var(--rs-text-strong); }
.tab h3 { font-size: var(--rs-settings-heading-size); }
p { margin: 4px 0; max-width: 60ch; color: var(--rs-text); font-size: var(--rs-settings-description-size); line-height: 1.6; }
.error { display: flex; align-items: flex-start; gap: 6px; color: var(--rs-error); text-align: left; }
.error :global(svg) { flex: none; width: 16px; height: 16px; margin-top: 2px; }
.error span { overflow-wrap: anywhere; }
progress { width: min(320px, 100%); height: 8px; accent-color: var(--rs-accent); }
.actions { display: flex; flex-wrap: wrap; justify-content: inherit; gap: 8px; margin-top: 8px; }
.tab .actions { justify-content: center; }
button { display: inline-flex; align-items: center; gap: 7px; min-height: var(--rs-settings-control-height); padding: 4px 10px; border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg-elevated); color: var(--rs-text); font: inherit; cursor: pointer; }
button:hover:not(:disabled) { background: var(--rs-bg-active); }
button:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: 1px; }
button:disabled { color: var(--rs-text-dim); cursor: default; }
button.primary, button.primary:hover { border-color: var(--rs-accent); background: var(--rs-accent); color: var(--rs-on-accent); }
button.danger { border-color: var(--rs-error); color: var(--rs-error); }
</style>
+103 -88
View File
@@ -1,88 +1,103 @@
<script lang="ts">
import { t } from "$lib/i18n";
import { onMount, onDestroy } from 'svelte';
import Icon from '$lib/ui/Icon.svelte';
import { showActionMenu } from '$lib/ui/managedActionMenu';
import WebData from './WebData.svelte';
import { state as browserState, request } from './client';
let selected = $state('user'), name = $state(''), message = $state('');
let search = $state('duckduckgo'), adblock = $state(true), internalLinks = $state(true), rules = $state('');
let homepage = $state(''), filterLists = $state(''), ready = $state(false), busy = $state(false);
const engines = [{ id: 'duckduckgo', name: 'DuckDuckGo' }, { id: 'google', name: 'Google' }, { id: 'bing', name: 'Bing' }];
let closePicker = () => {};
onDestroy(() => closePicker());
function picker(event: MouseEvent, profile = false) {
closePicker();
const anchor = event.currentTarget as HTMLButtonElement;
const bounds = anchor.getBoundingClientRect();
closePicker = showActionMenu({ x: bounds.left, y: bounds.bottom + 4, label: profile ? $t('Profile') : $t('Search engine'),
parent: anchor.closest('dialog') ?? undefined,
items: (profile ? $browserState?.profiles || [] : engines).map(choice => ({ label: choice.name,
radio: true, checked: choice.id === (profile ? selected : search),
run: () => { if (profile) selected = choice.id; else { search = choice.id; void save(); } } })) }).close;
}
onMount(() => { void request('state').then(value => {
selected = value.profiles[0].id; search = value.settings.search; adblock = value.settings.adblock;
internalLinks = value.settings.linkDestination === 'internal'; rules = value.settings.personalRules;
homepage = value.settings.homepage || ''; filterLists = (value.settings.filterLists || []).join('\n'); ready = true;
}).catch(error => message = String(error)); });
async function act(command: string, args: Record<string, unknown>) {
try { const next = await request(command, args); message = $t('Changes saved.'); return next; } catch (error) { message = String(error); return null; }
}
async function create(duplicate: boolean) {
if (!name.trim()) { message = $t('Enter a profile name.'); return; }
const result = await act(duplicate ? 'duplicateProfile' : 'createProfile', duplicate ? { profileId: selected, name } : { name });
if (result) { selected = result.profiles.at(-1)!.id; name = ''; }
}
// Settings apply at once: a switch or a choice on change, a text field when it loses focus.
// A change during a save starts one more save after it.
let pending = false;
async function save() {
if (!ready) return;
if (busy) { pending = true; return; }
busy = true; message = $t('Saving browser settings…');
try {
await act('settings', { search, adblock, linkDestination: internalLinks ? 'internal' : 'external', personalRules: rules,
homepage, filterLists: filterLists.split(/\r?\n/).map(value => value.trim()).filter(Boolean) });
} finally { busy = false; }
if (pending) { pending = false; void save(); }
}
</script>
<div class="settings">
<h2>{$t("Browser")}</h2><p>{$t("Choose how you browse within RuneStone.")}</p>
<h3>{$t("General")}</h3>
<fieldset disabled={!ready} onchange={() => void save()}>
<div class="card">
<label class="row"><span>{$t("Open web links in RuneStone")}<small>{$t("Turn this off to use your system browser.")}</small></span><input class="rs-switch" type="checkbox" role="switch" aria-label={$t("Open web links in RuneStone")} bind:checked={internalLinks}></label>
<label class="row"><span>{$t("Homepage")}<small>{$t("The page to open in each new browser tab. Leave blank for an empty page.")}</small></span><input class="address" type="url" aria-label={$t("Homepage")} placeholder="https://example.com" maxlength="8192" bind:value={homepage}></label>
<div class="row"><span>{$t("Search engine")}</span><button type="button" class="picker" aria-label={$t("Search engine")} aria-haspopup="menu" onclick={event => picker(event)}>{engines.find(engine => engine.id === search)?.name ?? 'DuckDuckGo'}<Icon icon="chevron-down" /></button></div>
<label class="row"><span>{$t("Block ads and trackers")}<small>{$t("Apply the filter lists and personal rules to all browser tabs.")}</small></span><input class="rs-switch" type="checkbox" role="switch" aria-label={$t("Block ads and trackers")} bind:checked={adblock}></label>
<label class="row list-row"><span>{$t("Ad blocking lists")}<small>{$t("One HTTPS filter list URL per line, up to eight lists. New lists download when you leave the field.")}</small></span><textarea aria-label={$t("Ad blocking lists")} rows="4" maxlength="66000" placeholder="https://easylist.to/easylist/easylist.txt" bind:value={filterLists}></textarea></label>
</div>
<label class="rules">{$t("Personal filter rules")}<small>{$t("Use one rule per line. Block a domain with ||ads.example.com^, allow it with @@||ads.example.com^, or hide an element with example.com##.advertisement. Save to apply the rules.")}</small><textarea rows="4" maxlength="100000" placeholder={'! Block an advertising domain\n||ads.example.com^\n! Hide an element on one site\nexample.com##.advertisement'} bind:value={rules}></textarea></label>
</fieldset>
<h3>{$t("Profiles")}</h3><p>{$t("New profiles start blank. Duplicate a profile to copy its stored browsing data and bookmarks.")}</p>
<div class="card profiles">
<div class="profile-choice"><span>{$t("Profile")}</span><button type="button" class="picker" aria-label={$t("Profile")} aria-haspopup="menu" disabled={!ready} onclick={event => picker(event, true)}>{$browserState?.profiles.find(profile => profile.id === selected)?.name ?? $t('Profile')}<Icon icon="chevron-down" /></button></div>
<label>{$t("New profile name")}<input bind:value={name} maxlength="60" placeholder={$t("Profile name")}></label>
<div class="actions"><button onclick={() => void create(false)}><Icon icon="plus" />{$t("New blank profile")}</button><button onclick={() => void create(true)}><Icon icon="duplicate" />{$t("Duplicate profile")}</button></div>
<p class="note">{$t("Duplication briefly restarts browser tabs. The copies remain separate. Agent permissions are not copied.")}</p>
</div>
<h3>{$t("Web data")}</h3><p>{$t("Clear data for the selected profile. Its browser tabs will close. Bookmarks remain.")}</p>
<div class="actions"><button onclick={() => void act('clearData', { profileId: selected, kind: 'cache' })}>{$t("Clear cache")}</button><button onclick={() => void act('clearData', { profileId: selected, kind: 'cookies' })}>{$t("Clear cookies")}</button><button onclick={() => void act('clearData', { profileId: selected, kind: 'history' })}>{$t("Clear history")}</button></div>
<p role="status">{message}</p>
{#if ready}<WebData profileId={selected} />{/if}
</div>
<style>
.settings{color:var(--rs-text);font-family:var(--rs-font-ui)}h2{margin:0;font-size:var(--rs-settings-heading-size);font-weight:500;color:var(--rs-text-strong)}h3{margin:var(--rs-settings-section-gap) 0 var(--rs-settings-gap);font-size:14px;font-weight:500}
p{color:var(--rs-text-dim);font-size:var(--rs-settings-description-size);line-height:1.6}.card{padding:0 var(--rs-settings-row-padding);background:var(--rs-bg-elevated);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius)}
.row{display:flex;justify-content:space-between;align-items:center;gap:var(--rs-settings-gap);padding:var(--rs-settings-row-padding) 0}.row+.row{border-top:1px solid var(--rs-border)}
input:not(.rs-switch),textarea,button{border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg);color:var(--rs-text);font:inherit;box-sizing:border-box;min-height:var(--rs-settings-control-height);padding:4px 8px}
button{display:inline-flex;align-items:center;gap:7px;background:var(--rs-bg-elevated);cursor:pointer}button:hover{background:var(--rs-bg-active)}button:focus-visible,input:focus-visible,textarea:focus-visible{outline:2px solid var(--rs-focus);outline-offset:1px}
.picker{justify-content:space-between;min-width:140px;max-width:100%;overflow-wrap:anywhere;text-align:left}
.rules{display:flex;flex-direction:column;gap:7px;margin:16px 0}.profiles{padding-top:16px;padding-bottom:8px}.profiles label,.profile-choice{display:flex;flex-direction:column;gap:7px;margin-bottom:14px}
.actions{display:flex;flex-wrap:wrap;gap:8px}.note{margin-bottom:0}
fieldset{border:0;margin:0;padding:0;min-width:0}small{display:block;color:var(--rs-text-dim);font-size:var(--rs-settings-description-size);line-height:1.5;margin-top:5px}
.row>span{flex:1}.address,.list-row textarea{width:260px;max-width:48%;box-sizing:border-box}.list-row{align-items:flex-start}textarea{resize:vertical}␍
@media(max-width:600px){.row{flex-wrap:wrap}.address,.list-row textarea{width:100%;max-width:100%}}
</style>
<script lang="ts">
import { t } from "$lib/i18n";
import { onDestroy } from 'svelte';
import Icon from '$lib/ui/Icon.svelte';
import { showActionMenu } from '$lib/ui/managedActionMenu';
import WebData from './WebData.svelte';
import EngineSetup from './EngineSetup.svelte';
import { state as browserState, request } from './client';
import { engine, engineReady } from './engine';
let selected = $state('user'), name = $state(''), message = $state('');
let search = $state('duckduckgo'), adblock = $state(true), internalLinks = $state(true), rules = $state('');
let homepage = $state(''), filterLists = $state(''), ready = $state(false), busy = $state(false);
const engines = [{ id: 'duckduckgo', name: 'DuckDuckGo' }, { id: 'google', name: 'Google' }, { id: 'bing', name: 'Bing' }];
let closePicker = () => {};
onDestroy(() => closePicker());
function picker(event: MouseEvent, profile = false) {
closePicker();
const anchor = event.currentTarget as HTMLButtonElement;
const bounds = anchor.getBoundingClientRect();
closePicker = showActionMenu({ x: bounds.left, y: bounds.bottom + 4, label: profile ? $t('Profile') : $t('Search engine'),
parent: anchor.closest('dialog') ?? undefined,
items: (profile ? $browserState?.profiles || [] : engines).map(choice => ({ label: choice.name,
radio: true, checked: choice.id === (profile ? selected : search),
run: () => { if (profile) selected = choice.id; else { search = choice.id; void save(); } } })) }).close;
}
// The browser settings live in the engine, so they load when the engine can start.
const installed = $derived(engineReady($engine));
let loading = false;
$effect(() => {
if (!installed) { ready = false; loading = false; return; }
if (loading) return;
loading = true;
void request('state').then(value => {
selected = value.profiles[0].id; search = value.settings.search; adblock = value.settings.adblock;
internalLinks = value.settings.linkDestination === 'internal'; rules = value.settings.personalRules;
homepage = value.settings.homepage || ''; filterLists = (value.settings.filterLists || []).join('\n'); ready = true;
}).catch(error => message = String(error));
});
async function act(command: string, args: Record<string, unknown>) {
try { const next = await request(command, args); message = $t('Changes saved.'); return next; } catch (error) { message = String(error); return null; }
}
async function create(duplicate: boolean) {
if (!name.trim()) { message = $t('Enter a profile name.'); return; }
const result = await act(duplicate ? 'duplicateProfile' : 'createProfile', duplicate ? { profileId: selected, name } : { name });
if (result) { selected = result.profiles.at(-1)!.id; name = ''; }
}
// Settings apply at once: a switch or a choice on change, a text field when it loses focus.
// A change during a save starts one more save after it.
let pending = false;
async function save() {
if (!ready) return;
if (busy) { pending = true; return; }
busy = true; message = $t('Saving browser settings…');
try {
await act('settings', { search, adblock, linkDestination: internalLinks ? 'internal' : 'external', personalRules: rules,
homepage, filterLists: filterLists.split(/\r?\n/).map(value => value.trim()).filter(Boolean) });
} finally { busy = false; }
if (pending) { pending = false; void save(); }
}
</script>
<div class="settings">
<h2>{$t("Browser")}</h2><p>{$t("Choose how you browse within RuneStone.")}</p>
<EngineSetup variant="settings" />
{#if !installed}
<p class="note">{$t("The other browser settings show after the engine is installed.")}</p>
{:else}
<h3>{$t("General")}</h3>
<fieldset disabled={!ready} onchange={() => void save()}>
<div class="card">
<label class="row"><span>{$t("Open web links in RuneStone")}<small>{$t("Turn this off to use your system browser.")}</small></span><input class="rs-switch" type="checkbox" role="switch" aria-label={$t("Open web links in RuneStone")} bind:checked={internalLinks}></label>
<label class="row"><span>{$t("Homepage")}<small>{$t("The page to open in each new browser tab. Leave blank for an empty page.")}</small></span><input class="address" type="url" aria-label={$t("Homepage")} placeholder="https://example.com" maxlength="8192" bind:value={homepage}></label>
<div class="row"><span>{$t("Search engine")}</span><button type="button" class="picker" aria-label={$t("Search engine")} aria-haspopup="menu" onclick={event => picker(event)}>{engines.find(engine => engine.id === search)?.name ?? 'DuckDuckGo'}<Icon icon="chevron-down" /></button></div>
<label class="row"><span>{$t("Block ads and trackers")}<small>{$t("Apply the filter lists and personal rules to all browser tabs.")}</small></span><input class="rs-switch" type="checkbox" role="switch" aria-label={$t("Block ads and trackers")} bind:checked={adblock}></label>
<label class="row list-row"><span>{$t("Ad blocking lists")}<small>{$t("One HTTPS filter list URL per line, up to eight lists. New lists download when you leave the field.")}</small></span><textarea aria-label={$t("Ad blocking lists")} rows="4" maxlength="66000" placeholder="https://easylist.to/easylist/easylist.txt" bind:value={filterLists}></textarea></label>
</div>
<label class="rules">{$t("Personal filter rules")}<small>{$t("Use one rule per line. Block a domain with ||ads.example.com^, allow it with @@||ads.example.com^, or hide an element with example.com##.advertisement. Save to apply the rules.")}</small><textarea rows="4" maxlength="100000" placeholder={'! Block an advertising domain\n||ads.example.com^\n! Hide an element on one site\nexample.com##.advertisement'} bind:value={rules}></textarea></label>
</fieldset>
<h3>{$t("Profiles")}</h3><p>{$t("New profiles start blank. Duplicate a profile to copy its stored browsing data and bookmarks.")}</p>
<div class="card profiles">
<div class="profile-choice"><span>{$t("Profile")}</span><button type="button" class="picker" aria-label={$t("Profile")} aria-haspopup="menu" disabled={!ready} onclick={event => picker(event, true)}>{$browserState?.profiles.find(profile => profile.id === selected)?.name ?? $t('Profile')}<Icon icon="chevron-down" /></button></div>
<label>{$t("New profile name")}<input bind:value={name} maxlength="60" placeholder={$t("Profile name")}></label>
<div class="actions"><button onclick={() => void create(false)}><Icon icon="plus" />{$t("New blank profile")}</button><button onclick={() => void create(true)}><Icon icon="duplicate" />{$t("Duplicate profile")}</button></div>
<p class="note">{$t("Duplication briefly restarts browser tabs. The copies remain separate. Agent permissions are not copied.")}</p>
</div>
<h3>{$t("Web data")}</h3><p>{$t("Clear data for the selected profile. Its browser tabs will close. Bookmarks remain.")}</p>
<div class="actions"><button onclick={() => void act('clearData', { profileId: selected, kind: 'cache' })}>{$t("Clear cache")}</button><button onclick={() => void act('clearData', { profileId: selected, kind: 'cookies' })}>{$t("Clear cookies")}</button><button onclick={() => void act('clearData', { profileId: selected, kind: 'history' })}>{$t("Clear history")}</button></div>
<p role="status">{message}</p>
{#if ready}<WebData profileId={selected} />{/if}
{/if}
</div>
<style>
.settings{color:var(--rs-text);font-family:var(--rs-font-ui)}h2{margin:0;font-size:var(--rs-settings-heading-size);font-weight:500;color:var(--rs-text-strong)}h3{margin:var(--rs-settings-section-gap) 0 var(--rs-settings-gap);font-size:14px;font-weight:500}
p{color:var(--rs-text-dim);font-size:var(--rs-settings-description-size);line-height:1.6}.card{padding:0 var(--rs-settings-row-padding);background:var(--rs-bg-elevated);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius)}
.row{display:flex;justify-content:space-between;align-items:center;gap:var(--rs-settings-gap);padding:var(--rs-settings-row-padding) 0}.row+.row{border-top:1px solid var(--rs-border)}
input:not(.rs-switch),textarea,button{border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg);color:var(--rs-text);font:inherit;box-sizing:border-box;min-height:var(--rs-settings-control-height);padding:4px 8px}
button{display:inline-flex;align-items:center;gap:7px;background:var(--rs-bg-elevated);cursor:pointer}button:hover{background:var(--rs-bg-active)}button:focus-visible,input:focus-visible,textarea:focus-visible{outline:2px solid var(--rs-focus);outline-offset:1px}
.picker{justify-content:space-between;min-width:140px;max-width:100%;overflow-wrap:anywhere;text-align:left}
.rules{display:flex;flex-direction:column;gap:7px;margin:16px 0}.profiles{padding-top:16px;padding-bottom:8px}.profiles label,.profile-choice{display:flex;flex-direction:column;gap:7px;margin-bottom:14px}
.actions{display:flex;flex-wrap:wrap;gap:8px}.note{margin-bottom:0}
fieldset{border:0;margin:0;padding:0;min-width:0}small{display:block;color:var(--rs-text-dim);font-size:var(--rs-settings-description-size);line-height:1.5;margin-top:5px}
.row>span{flex:1}.address,.list-row textarea{width:260px;max-width:48%;box-sizing:border-box}.list-row{align-items:flex-start}textarea{resize:vertical}
@media(max-width:600px){.row{flex-wrap:wrap}.address,.list-row textarea{width:100%;max-width:100%}}
</style>
+28
View File
@@ -0,0 +1,28 @@
import { invoke } from '@tauri-apps/api/core';
import { listen } from '@tauri-apps/api/event';
import { writable } from 'svelte/store';
import { tr } from '../i18n/index.ts';
/** The engine states of `browser_engine_status`. See src-tauri/src/browser_engine.rs. */
export type EngineStatus = {
state: 'installed' | 'missing' | 'update' | 'downloading' | 'installing' | 'unavailable' | 'development';
version: string; bytes: number; received: number; error: string | null;
};
export const engine = writable<EngineStatus | null>(null);
/** True when the engine can start: the pinned version is installed, or a development engine is staged. */
export const engineReady = (status: EngineStatus | null) => status?.state === 'installed' || status?.state === 'development';
const update = (status: EngineStatus) => { engine.set(status); return status; };
/** Follow the engine status in this window. A failed status request reports the engine as unavailable. */
export async function watchEngine(signal: AbortSignal) {
const off = await listen<EngineStatus>('browser-engine', ({ payload }) => { if (!signal.aborted) engine.set(payload); });
try { update(await invoke<EngineStatus>('browser_engine_status')); }
catch (error) { update({ state: 'unavailable', version: '', bytes: 0, received: 0, error: String(error) }); }
return () => { off(); engine.set(null); };
}
export const installEngine = () => invoke<EngineStatus>('browser_engine_install').then(update);
export const installEngineFile = () => invoke<EngineStatus>('browser_engine_install_file').then(update);
export const cancelEngine = () => invoke<EngineStatus>('browser_engine_cancel').then(update);
export const removeEngine = () => invoke<EngineStatus>('browser_engine_remove').then(update);
/** A download size in megabytes, such as "161 MB". */
export const megabytes = (bytes: number) => tr('{size} MB', { size: Math.max(bytes ? 1 : 0, Math.round(bytes / 1_000_000)) });
+8 -3
View File
@@ -4,16 +4,18 @@ import { mount, unmount } from 'svelte';
import { get } from 'svelte/store';
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
import type { PluginApi, PluginViewOpenOptions } from '$lib/plugins/sdk';
import Browser from './Browser.svelte';
import BrowserTab from './BrowserTab.svelte';
import Settings from './Settings.svelte';
import Bookmarks from './Bookmarks.svelte';
import { connect, request, state } from './client';
import { engine, engineReady, watchEngine } from './engine';
import type { TabStatus } from './tabSession';
type BrowserControl = { find(): Promise<void>; detach(): void; action(command: string, args?: Record<string, unknown>): Promise<void> };
type SavedView = { view: string; profileId?: string; url?: string; runtimeId: string; status?: TabStatus; control?: BrowserControl };
export async function activate(api: PluginApi) {
const offEngine = await watchEngine(api.signal); api.onDispose(offEngine);
const dispose = await connect(api.signal); api.onDispose(dispose);
const owners = new Map<string, SavedView>();
const offMove = await getCurrentWebviewWindow().listen<{ tabId: string }>('browser-tab-moved', ({ payload }) => {
@@ -72,7 +74,7 @@ export async function activate(api: PluginApi) {
];
}, mount: container => {
let runtimeId = '';
const instance = mount(Browser, { target: container, props: {
const instance = mount(BrowserTab, { target: container, props: {
initial: { tabId, profileId: saved.profileId, url: saved.url },
onSessionChange: value => {
saved.status = value;
@@ -97,10 +99,13 @@ export async function activate(api: PluginApi) {
}
api.registerCommand({ id: 'new-tab', title: 'New browser tab', category: 'open', icon: 'globe', run: () => open() });
api.contribute('browser', {
newTab: () => open(),
// A new tab shows the engine setup when the engine is missing.
newTab: url => open(undefined, url),
mountSettings: container => retain(mount(Settings, { target: container })),
mountBookmarks: container => retain(mount(Bookmarks, { target: container, props: { open } })),
// A web link never starts a download. Without an engine, the link opens in the system browser.
open: async url => {
if (!engineReady(get(engine))) return false;
const value = await request('state');
if (value.settings.linkDestination === 'external') return false;
await open(undefined, url); return true;