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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user