From c06d48f250e873ca34b77b1183d1c6d5267c9179 Mon Sep 17 00:00:00 2001 From: Knotty Wyvern Date: Thu, 29 Oct 2026 01:18:21 -0700 Subject: [PATCH] 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. --- docs/design-decisions.md | 15 ++ docs/plugin-development.md | 2 +- docs/user-guide.md | 11 +- packages/plugin-sdk/src/contributions.ts | 4 +- src/lib/browser/Bookmarks.svelte | 19 ++- src/lib/browser/Browser.svelte | 3 +- src/lib/browser/BrowserTab.svelte | 17 ++ src/lib/browser/EngineSetup.svelte | 78 +++++++++ src/lib/browser/Settings.svelte | 191 ++++++++++++---------- src/lib/browser/engine.ts | 28 ++++ src/lib/browser/index.ts | 11 +- src/lib/i18n/messages.ts | 22 ++- src/lib/layout/Workbench.svelte | 3 +- src/lib/ui/Icon.svelte | 2 + src/lib/ui/IconButton.svelte | 3 +- tests/smoke/_harness/index.mjs | 5 +- tests/smoke/browser/engine.smoke.mjs | 112 +++++++++++++ tests/smoke/editor/interactions.smoke.mjs | 3 +- tests/smoke/links/linkMenus.smoke.mjs | 3 +- 19 files changed, 425 insertions(+), 107 deletions(-) create mode 100644 src/lib/browser/BrowserTab.svelte create mode 100644 src/lib/browser/EngineSetup.svelte create mode 100644 src/lib/browser/engine.ts create mode 100644 tests/smoke/browser/engine.smoke.mjs diff --git a/docs/design-decisions.md b/docs/design-decisions.md index 57d0b6f..648b145 100644 --- a/docs/design-decisions.md +++ b/docs/design-decisions.md @@ -997,3 +997,18 @@ Native shell, background image, and desktop acceptance remain open. - Evidence: `tests/smoke/layout/plainFixes.smoke.mjs` and `tests/unit/layout/settings.spec.ts`. - Replaces / replaced by: The OK and Cancel close prompt, and `white-space: pre-line` for every Read paragraph. - Limits: The word count splits on spaces and counts each Han, Hiragana, and Katakana character as one word. The close prompt uses the native dialog, which browser checks mock. The table control area keeps its 26-pixel padding, because the drag handles need it. The drag handles still show only on hover: showing every row and column handle on focus was too busy. The line break setting applies to Read. The table preview and cell editors of Write keep each line break, because their editing depends on it. + +### UI-054 — The browser engine as a separate download + +- Type: Rule change +- Date: 2026-10-29 +- Status: Implemented for user review +- Decision source: The owner decision "Built-in browser: optional download, installed on first use" of 2026-10-27, and Phase 6 decisions 4 and 5 of 2026-10-29. +- Previous rule: Each installer included the browser engine. A browser tab, Settings → Browser, and the browser bookmarks started the engine as soon as they opened. A web link opened in the app browser when **Open web links in RuneStone** was on. "Open link in app browser" failed when that setting was off. +- New rule: Until the engine is installed, a browser tab shows the engine setup: the download size, **Download the engine** as the primary action, **Install from file…**, and **Open in default browser** when the tab has a web address. A download shows its progress and Cancel. A failure shows its cause in the error color and **Retry**. When the engine is installed, the same tab opens its page. Settings → Browser starts with a **Browser engine** section: the state, the version, and **Remove engine** in the error color with a confirmation. The other browser settings and the browser bookmarks show after the engine is installed. Web links in documents open in the system browser until the engine is installed. "Open link in app browser" always opens an app browser tab, with the engine setup if necessary. +- Reason: A large download needs the user's consent and a clear size. A link must never wait for a download that the user did not start. The explicit command must do what its label says. +- Scope: Browser tabs, browser windows, Settings → Browser, the browser bookmarks, and web links in documents. +- Shared implementation: `src/lib/browser/engine.ts`, `EngineSetup.svelte`, `BrowserTab.svelte`, and `src-tauri/src/browser_engine.rs`. +- Evidence: `tests/smoke/browser/engine.smoke.mjs`, with screenshots of each state in both themes and a 360-pixel Settings window. +- Replaces / replaced by: The bundled engine. +- Limits: The download does not resume. A failed download starts again from zero. The engine installs for the current Windows account only. Browser checks mock the native download. diff --git a/docs/plugin-development.md b/docs/plugin-development.md index f7367f2..7d1dd7d 100644 --- a/docs/plugin-development.md +++ b/docs/plugin-development.md @@ -388,7 +388,7 @@ Only one enabled plugin can own each key. The host removes contributions before | --- | --- | --- | | `terminal` | Mounts terminal controls in a host element. Returns update, command, and dispose functions. | Terminal plugin | | `git` | Supplies line blame for the editor. | Git plugin | -| `browser` | The built-in browser. | RuneStone | +| `browser` | The built-in browser. `newTab(url?)` opens a browser tab. `open(url)` returns false when the system browser must open a web link, for example before the engine is installed. | RuneStone | A terminal contribution must stop its controls and native sessions before its cleanup finishes. diff --git a/docs/user-guide.md b/docs/user-guide.md index a063795..eb3af8b 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -207,12 +207,19 @@ Reopen a document to update its editor tooltips after a language change. ## Use the built-in browser -RuneStone includes a Chromium-based browser. It needs no plugin. +RuneStone includes a Chromium-based browser. It needs no plugin, but its engine is a separate download of about 160 MB. 1. Select the globe button in the left ribbon to open a **New browser tab**. -2. Type an address or a search. +2. The first time, select **Download the engine**. RuneStone downloads the engine, makes sure that it is complete, and opens the page. +3. Type an address or a search. + +Without internet access, select **Install from file…** and choose the engine ZIP for your RuneStone version. +If a download fails, the tab shows the cause. Select **Retry** to start the download again. +Until the engine is installed, web links in your documents open in your system browser. +After a RuneStone update that needs a new engine, a browser tab offers **Update the engine**. Use **Settings → Browser** to set the homepage and search engine, manage profiles, block ads, and clear cookies, cache, or history. +**Settings → Browser → Browser engine** shows the installed version. **Remove engine** frees the disk space. Your profiles, bookmarks, and history stay. Each profile keeps its own cookies and bookmarks. Web bookmarks show in the Bookmarks pane. To open web links from your documents in your system browser instead, turn off **Open web links in RuneStone**. diff --git a/packages/plugin-sdk/src/contributions.ts b/packages/plugin-sdk/src/contributions.ts index b60b2ed..3c868c3 100644 --- a/packages/plugin-sdk/src/contributions.ts +++ b/packages/plugin-sdk/src/contributions.ts @@ -16,9 +16,11 @@ export interface TerminalMount { export interface Contributions { git: { blame(path: string, line: number): Promise }; browser: { - newTab?(): Promise; + /** Opens a browser tab, with `url` when it is given. */ + newTab?(url?: string): Promise; mountSettings(container: HTMLElement): Dispose | Promise; mountBookmarks(container: HTMLElement): Dispose | Promise; + /** Opens a web link from a document. False means that the system browser opens it. */ open(url: string): Promise; }; terminal: { diff --git a/src/lib/browser/Bookmarks.svelte b/src/lib/browser/Bookmarks.svelte index c36feea..eef9d21 100644 --- a/src/lib/browser/Bookmarks.svelte +++ b/src/lib/browser/Bookmarks.svelte @@ -1,21 +1,30 @@
- {#if error}

{error}

{/if} - {#each $browserState?.bookmarks || [] as item (item.id)} + {#if !installed}

{$t("Install the browser engine to see the browser bookmarks.")}

{/if} + {#if error}{/if} + {#each installed ? $browserState?.bookmarks || [] : [] as item (item.id)}
void request('removeBookmark', { id: item.id })} />
{/each}
diff --git a/src/lib/browser/Browser.svelte b/src/lib/browser/Browser.svelte index 2a864e1..23ff217 100644 --- a/src/lib/browser/Browser.svelte +++ b/src/lib/browser/Browser.svelte @@ -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 } = $props(); let status = $state({ tabId: '', phase: 'connecting', message: $t('Opening browser…') }); @@ -269,7 +270,7 @@
{$t("Browser error details")}
{$t("Operation")}
{status.detail.operation}
{$t("Reason")}
{status.detail.reason}
{$t("Tab")}
{status.detail.tabId || $t('Not created')}
{$t("Time")}
{status.detail.time}
-
{$t("Browser")}
{$t("Included with RuneStone")}
+
{$t("Engine")}
{$engine?.version ?? ''}
{/if} {#if openingError || $pageErrors[tabId]}{/if} diff --git a/src/lib/browser/BrowserTab.svelte b/src/lib/browser/BrowserTab.svelte new file mode 100644 index 0000000..dd09472 --- /dev/null +++ b/src/lib/browser/BrowserTab.svelte @@ -0,0 +1,17 @@ + +{#if engineReady($engine)} + +{:else} + +{/if} diff --git a/src/lib/browser/EngineSetup.svelte b/src/lib/browser/EngineSetup.svelte new file mode 100644 index 0000000..d6d41bf --- /dev/null +++ b/src/lib/browser/EngineSetup.svelte @@ -0,0 +1,78 @@ + +
+ {#if variant === "tab"}{/if} +

{$t("Browser engine")}

+ {#if phase === "installed"} +

{$t("Version {version} is installed.", { version: status?.version ?? "" })}

+ {:else if phase === "development"} +

{$t("This development build uses the engine in src-tauri/browser-engine.")}

+ {:else if phase === "unavailable"} +

{$t("No browser engine is available for this platform yet.")}

+ {:else if phase === "downloading"} +

{$t("Downloading the browser engine: {received} of {total}.", { received: megabytes(status?.received ?? 0), total: megabytes(status?.bytes ?? 0) })}

+ + {:else if phase === "installing"} +

{$t("Installing the browser engine…")}

+ + {:else if phase === "update"} +

{$t("This RuneStone version needs browser engine {version}. The download is {size}.", { version: status?.version ?? "", size: megabytes(status?.bytes ?? 0) })}

+ {:else} +

{$t("The built-in browser needs its engine. The engine is a separate download of {size}.", { size: megabytes(status?.bytes ?? 0) })}

+ {/if} + {#if error && !busy}{/if} +
+ {#if busy} + + {:else if phase === "missing" || phase === "update"} + + + {:else if phase === "installed" && variant === "settings"} + + {/if} + {#if web}{/if} +
+
+ diff --git a/src/lib/browser/Settings.svelte b/src/lib/browser/Settings.svelte index def1d65..874442a 100644 --- a/src/lib/browser/Settings.svelte +++ b/src/lib/browser/Settings.svelte @@ -1,88 +1,103 @@ - -
-

{$t("Browser")}

{$t("Choose how you browse within RuneStone.")}

-

{$t("General")}

-
void save()}> -
- - -
{$t("Search engine")}
- - -
- -
-

{$t("Profiles")}

{$t("New profiles start blank. Duplicate a profile to copy its stored browsing data and bookmarks.")}

-
-
{$t("Profile")}
- -
-

{$t("Duplication briefly restarts browser tabs. The copies remain separate. Agent permissions are not copied.")}

-
-

{$t("Web data")}

{$t("Clear data for the selected profile. Its browser tabs will close. Bookmarks remain.")}

-
-

{message}

- {#if ready}{/if} -
- + +
+

{$t("Browser")}

{$t("Choose how you browse within RuneStone.")}

+ + {#if !installed} +

{$t("The other browser settings show after the engine is installed.")}

+ {:else} +

{$t("General")}

+
void save()}> +
+ + +
{$t("Search engine")}
+ + +
+ +
+

{$t("Profiles")}

{$t("New profiles start blank. Duplicate a profile to copy its stored browsing data and bookmarks.")}

+
+
{$t("Profile")}
+ +
+

{$t("Duplication briefly restarts browser tabs. The copies remain separate. Agent permissions are not copied.")}

+
+

{$t("Web data")}

{$t("Clear data for the selected profile. Its browser tabs will close. Bookmarks remain.")}

+
+

{message}

+ {#if ready}{/if} + {/if} +
+ diff --git a/src/lib/browser/engine.ts b/src/lib/browser/engine.ts new file mode 100644 index 0000000..f562dd7 --- /dev/null +++ b/src/lib/browser/engine.ts @@ -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(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('browser-engine', ({ payload }) => { if (!signal.aborted) engine.set(payload); }); + try { update(await invoke('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('browser_engine_install').then(update); +export const installEngineFile = () => invoke('browser_engine_install_file').then(update); +export const cancelEngine = () => invoke('browser_engine_cancel').then(update); +export const removeEngine = () => invoke('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)) }); diff --git a/src/lib/browser/index.ts b/src/lib/browser/index.ts index f2329e1..182b8d1 100644 --- a/src/lib/browser/index.ts +++ b/src/lib/browser/index.ts @@ -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; detach(): void; action(command: string, args?: Record): Promise }; 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(); 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; diff --git a/src/lib/i18n/messages.ts b/src/lib/i18n/messages.ts index 06788ef..de04c5f 100644 --- a/src/lib/i18n/messages.ts +++ b/src/lib/i18n/messages.ts @@ -3309,7 +3309,6 @@ export const messageRows: [string, string, string, string][] = [ ["Enter a relative workspace path without reserved characters.", "Saisissez un chemin relatif dans l’espace de travail, sans caractères réservés.", "予約文字を含まないワークスペースの相対パスを入力してください。", "请输入不含保留字符的工作区相对路径。"], ["Open a workspace before renaming a document.", "Ouvrez un espace de travail avant de renommer un document.", "ドキュメント名を変更する前にワークスペースを開いてください。", "重命名文档前,请先打开工作区。"], ["The workspace changed. Reopen the document.", "L’espace de travail a changé. Rouvrez le document.", "ワークスペースが変更されました。ドキュメントを開き直してください。", "工作区已更改。请重新打开文档。"], - ["Could not open the app browser.", "Impossible d’ouvrir le navigateur de l’application.", "アプリのブラウザーを開けませんでした。", "无法打开应用内浏览器。"], ["Could not add the word to the dictionary.", "Impossible d’ajouter le mot au dictionnaire.", "単語を辞書に追加できませんでした。", "无法将该词添加到词典。"], ["Copied workspace paths", "Chemins dans l’espace de travail copiés", "ワークスペースのパスをコピーしました", "已复制工作区路径"], ["Copied system paths", "Chemins système copiés", "システムのパスをコピーしました", "已复制系统路径"], @@ -3423,6 +3422,27 @@ export const messageRows: [string, string, string, string][] = [ ["Install, keep disabled", "Installer, laisser désactivé", "インストールして無効のままにする", "安装,保持停用"], ["Keep line breaks", "Conserver les sauts de ligne", "改行を保持", "保留换行"], ["Show each line break of the source in Read. When this is off, Read joins the lines of a paragraph, as CommonMark does.", "Afficher chaque saut de ligne de la source en lecture. Désactivé, la lecture joint les lignes d’un paragraphe, comme CommonMark.", "閲覧でソースの各改行を表示します。オフにすると、CommonMark と同様に段落内の行を連結します。", "在阅读中显示源文本的每个换行。关闭后,阅读会像 CommonMark 一样合并段落中的各行。"], + ["{size} MB", "{size} Mo", "{size} MB", "{size} MB"], + ["Browser engine", "Moteur du navigateur", "ブラウザーエンジン", "浏览器引擎"], + ["Version {version} is installed.", "La version {version} est installée.", "バージョン {version} がインストールされています。", "已安装版本 {version}。"], + ["This development build uses the engine in src-tauri/browser-engine.", "Cette version de développement utilise le moteur de src-tauri/browser-engine.", "この開発ビルドは src-tauri/browser-engine のエンジンを使用します。", "此开发版本使用 src-tauri/browser-engine 中的引擎。"], + ["No browser engine is available for this platform yet.", "Aucun moteur de navigateur n’est encore disponible pour cette plateforme.", "このプラットフォーム向けのブラウザーエンジンはまだありません。", "此平台尚无可用的浏览器引擎。"], + ["Downloading the browser engine: {received} of {total}.", "Téléchargement du moteur du navigateur : {received} sur {total}.", "ブラウザーエンジンをダウンロードしています: {received} / {total}。", "正在下载浏览器引擎:{received} / {total}。"], + ["Download progress", "Progression du téléchargement", "ダウンロードの進行状況", "下载进度"], + ["Installing the browser engine…", "Installation du moteur du navigateur…", "ブラウザーエンジンをインストールしています…", "正在安装浏览器引擎…"], + ["Installation progress", "Progression de l’installation", "インストールの進行状況", "安装进度"], + ["This RuneStone version needs browser engine {version}. The download is {size}.", "Cette version de RuneStone nécessite le moteur de navigateur {version}. Le téléchargement fait {size}.", "この RuneStone のバージョンにはブラウザーエンジン {version} が必要です。ダウンロードサイズは {size} です。", "此版本的 RuneStone 需要浏览器引擎 {version}。下载大小为 {size}。"], + ["The built-in browser needs its engine. The engine is a separate download of {size}.", "Le navigateur intégré a besoin de son moteur. Le moteur est un téléchargement séparé de {size}.", "内蔵ブラウザーにはエンジンが必要です。エンジンは {size} の別ダウンロードです。", "内置浏览器需要其引擎。引擎需单独下载,大小为 {size}。"], + ["The browser engine could not be installed: {reason}", "Impossible d’installer le moteur du navigateur : {reason}", "ブラウザーエンジンをインストールできませんでした: {reason}", "无法安装浏览器引擎:{reason}"], + ["Update the engine", "Mettre à jour le moteur", "エンジンを更新", "更新引擎"], + ["Download the engine", "Télécharger le moteur", "エンジンをダウンロード", "下载引擎"], + ["Install from file…", "Installer depuis un fichier…", "ファイルからインストール…", "从文件安装…"], + ["Remove engine", "Supprimer le moteur", "エンジンを削除", "移除引擎"], + ["Remove the browser engine? Open browser tabs close. Your profiles, bookmarks, and history stay.", "Supprimer le moteur du navigateur ? Les onglets de navigateur ouverts se ferment. Vos profils, signets et historique restent.", "ブラウザーエンジンを削除しますか?開いているブラウザータブは閉じます。プロファイル、ブックマーク、履歴は残ります。", "要移除浏览器引擎吗?打开的浏览器标签页将关闭。您的配置文件、书签和历史记录将保留。"], + ["Remove browser engine", "Supprimer le moteur du navigateur", "ブラウザーエンジンを削除", "移除浏览器引擎"], + ["Install the browser engine to see the browser bookmarks.", "Installez le moteur du navigateur pour voir les signets du navigateur.", "ブラウザーのブックマークを表示するには、ブラウザーエンジンをインストールしてください。", "安装浏览器引擎后即可查看浏览器书签。"], + ["The other browser settings show after the engine is installed.", "Les autres paramètres du navigateur s’affichent une fois le moteur installé.", "その他のブラウザー設定は、エンジンのインストール後に表示されます。", "安装引擎后将显示其他浏览器设置。"], + ["Engine", "Moteur", "エンジン", "引擎"], ]; export const catalogs: Record, Record> = { fr: Object.fromEntries(messageRows.map(row => [row[0], row[1]])), diff --git a/src/lib/layout/Workbench.svelte b/src/lib/layout/Workbench.svelte index c156d5b..9c57522 100644 --- a/src/lib/layout/Workbench.svelte +++ b/src/lib/layout/Workbench.svelte @@ -1376,7 +1376,8 @@ onRenameTitle={renameNoteTitle} tableActions={(pane) => ({ onSearch: searchSelection, onExtract: (markdown, label, valid) => extractSelection(markdown, label, valid, pane.buffer) })} linkActions={(pane) => ({ - browser: browserContribution ? async target => { if (!await browserContribution?.open(target)) throw new Error($t("Could not open the app browser.")); } : undefined, + // "Open link in app browser" always opens a browser tab. Without an engine, the tab shows the engine setup. + browser: browserContribution?.newTab ? async target => { await browserContribution?.newTab?.(target); } : undefined, defaultBrowser: target => openUrl(target), workspaceItems: link => workspaceLinkItems(link, pane.buffer?.relPath ?? "", pane.id), })} diff --git a/src/lib/ui/Icon.svelte b/src/lib/ui/Icon.svelte index 8ee8cde..7fa2ab7 100644 --- a/src/lib/ui/Icon.svelte +++ b/src/lib/ui/Icon.svelte @@ -142,6 +142,8 @@ {:else if icon === "plus"} + {:else if icon === "download"} + {/if}