RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user