- Background replaces the Background Slideshow plugin and the background image of Appearance. It shows a folder as a slideshow, or one image. - It is on by default. Its module loads at launch only when a folder or an image is chosen. - Rust keeps the one folder in background-folder.json. The interface never sends a path. Eight background_* commands replace the six deprecated backgrounds_* commands. - The first start moves the slideshow folder and settings, and keeps the saved image as the image source. - One blur worker with a cache, fewer folder reads, and a decode before each fade. The hub writes only the changed properties. - Remove the deprecated folder methods of api.backgrounds. set, get, and subscribe stay for the Project Management plugin. - Show the view buttons in the workbench test without text, after UI-056. - Update the tests, the measurement tool, the docs, and UI-057.
127 lines
7.0 KiB
Svelte
127 lines
7.0 KiB
Svelte
<script lang="ts">
|
|
import { t } from "$lib/i18n";
|
|
import { keys } from "$lib/ui/shortcuts";
|
|
import { tick, untrack } from "svelte";
|
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
|
import { pluginHost } from "$lib/plugins/registry";
|
|
import { browserModule, pluginEditors, pluginView, pluginSplits, externalErrors, pluginServiceError, selectPluginEditor, closePluginEditor, pinPluginEditor, pluginTabActions, pluginTabDragData, dropPluginTab, findPluginEditor } from "$lib/plugins/external";
|
|
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
|
|
import { containsPane, paneBounds } from "$lib/workspace/splitLayout";
|
|
import { tabsToClose, type TabCloseScope } from "$lib/workspace/tabActions";
|
|
import type { WorkbenchTab } from "$lib/workspace/workbenchTabs";
|
|
import TabBar from "./TabBar.svelte";
|
|
import IconButton from "$lib/ui/IconButton.svelte";
|
|
import WindowControls from "$lib/ui/WindowControls.svelte";
|
|
|
|
let error = $state("");
|
|
let opening = $state(false);
|
|
let hadTabs = false;
|
|
const browser = $derived.by(() => { void $pluginHost; return pluginHost.get("browser"); });
|
|
const tabs = $derived<WorkbenchTab[]>($pluginEditors.map(view => ({
|
|
id: view.key, relPath: view.key, name: view.title, title: view.title,
|
|
pinned: !!view.pinned, draggable: view.draggable, icon: "globe", iconImage: view.iconImage, panelId: `plugin-editor-${view.key}`,
|
|
})));
|
|
const active = $derived($pluginView?.key ?? null);
|
|
const split = $derived($pluginSplits.find(tree => active && containsPane(tree, active)));
|
|
const bounds = $derived(split ? paneBounds(split) : active ? paneBounds(active) : {});
|
|
const message = $derived(error || $externalErrors[browserModule] || $pluginServiceError);
|
|
|
|
$effect(() => {
|
|
if (tabs.length) hadTabs = true;
|
|
else if (hadTabs) void tick().then(() => {
|
|
if (!untrack(() => $pluginEditors.length)) void getCurrentWindow().destroy().catch(reason => error = String(reason));
|
|
});
|
|
});
|
|
|
|
function select(path: string) {
|
|
const view = $pluginEditors.find(view => view.key === path);
|
|
if (view) selectPluginEditor(view);
|
|
}
|
|
function move(path: string, index: number) {
|
|
pluginEditors.update(views => {
|
|
const from = views.findIndex(view => view.key === path);
|
|
if (from < 0) return views;
|
|
const ordered = [...views], [view] = ordered.splice(from, 1);
|
|
ordered.splice(Math.max(0, Math.min(index, ordered.length)), 0, view);
|
|
return ordered;
|
|
});
|
|
}
|
|
function close(path: string, scope: TabCloseScope = "one") {
|
|
for (const tab of tabsToClose(tabs, path, scope)) closePluginEditor(tab.id);
|
|
}
|
|
function actions(tab: WorkbenchTab) {
|
|
const view = $pluginEditors.find(view => view.key === tab.id);
|
|
return view ? pluginTabActions(view) : [];
|
|
}
|
|
function dragData(tab: WorkbenchTab) {
|
|
const view = $pluginEditors.find(view => view.key === tab.id);
|
|
return view ? pluginTabDragData(view) : undefined;
|
|
}
|
|
async function receive(data: string, index: number) {
|
|
try { await dropPluginTab(data); if ($pluginView) move($pluginView.key, index); error = ""; }
|
|
catch (reason) { error = String(reason); }
|
|
}
|
|
async function newTab() {
|
|
if (opening || !browser?.newTab) return;
|
|
opening = true;
|
|
try { await browser.newTab(); error = ""; } catch (reason) { error = String(reason); }
|
|
finally { opening = false; }
|
|
}
|
|
function keydown(event: KeyboardEvent) {
|
|
if (event.defaultPrevented || !(event.ctrlKey || event.metaKey) || event.shiftKey || event.altKey) return;
|
|
if (event.target instanceof Element && event.target.closest("dialog, [role=menu]")) return;
|
|
if (event.key.toLowerCase() === "t") { event.preventDefault(); void newTab(); }
|
|
if (event.key.toLowerCase() === "w" && active) { event.preventDefault(); close(active); }
|
|
if (event.key.toLowerCase() === "f" && $pluginView && findPluginEditor($pluginView)) event.preventDefault();
|
|
}
|
|
</script>
|
|
|
|
<svelte:window onkeydown={keydown} />
|
|
<div class="browser-window" role="application" aria-label={$t("RuneStone browser")}>
|
|
<header class="header" data-tauri-drag-region>
|
|
<TabBar {tabs} activePath={active} onSelect={select} onClose={close} onCloseTabs={close}
|
|
onMove={move} onPin={pinPluginEditor} fileActions={() => []} tabActions={actions}
|
|
tabDragData={dragData} onDropTab={(data, index) => void receive(data, index)} />
|
|
<IconButton icon="plus" label={$t("New browser tab ({shortcut})", { shortcut: keys("Mod+T") })} disabled={!browser?.newTab || opening} onclick={() => void newTab()} />
|
|
<div class="window-drag-space" data-tauri-drag-region></div>
|
|
<WindowControls onError={message => error = message} />
|
|
</header>
|
|
{#if message}<p class="error" role="alert">{message}</p>{/if}
|
|
<main class="pages">
|
|
<!-- A blank browser tab shows the background of the Background feature (src/lib/theme/background.css). -->
|
|
<div class="workarea-background" aria-hidden="true"></div>
|
|
{#each $pluginEditors as view (view.key)}
|
|
{@const position = bounds[view.key]}
|
|
<!-- svelte-ignore a11y_no_static_element_interactions (Input selects its browser pane.) -->
|
|
<div class="pane" class:inactive={!position} class:split={!!split} class:focused={active === view.key}
|
|
style:left={`${position?.left ?? 0}%`} style:top={`${position?.top ?? 0}%`}
|
|
style:width={`${position?.width ?? 100}%`} style:height={`${position?.height ?? 100}%`}
|
|
onfocusin={() => { if (active !== view.key) select(view.key); }}
|
|
onpointerdown={() => { if (active !== view.key) select(view.key); }}>
|
|
{#if split && position}
|
|
<TabBar tabs={tabs.filter(tab => tab.id === view.key)} activePath={active}
|
|
onSelect={select} onClose={close} onCloseTabs={close} onMove={move} onPin={pinPluginEditor}
|
|
fileActions={() => []} tabActions={actions} tabDragData={dragData} onDropTab={(data, index) => void receive(data, index)} />
|
|
{/if}
|
|
<PluginEditor {view} />
|
|
</div>
|
|
{/each}
|
|
{#if !tabs.length}<p class="placeholder">{browser ? "Open a browser tab with the + button." : "Loading browser…"}</p>{/if}
|
|
</main>
|
|
</div>
|
|
|
|
<style>
|
|
.browser-window { height: 100vh; display: flex; flex-direction: column; background: var(--rs-bg); }
|
|
.header { display: flex; align-items: center; height: 36px; flex-shrink: 0; padding-left: var(--rs-titlebar-inset-start); background: var(--rs-bg-elevated); border-bottom: 1px solid var(--rs-border); }
|
|
.header :global(.tabs) { flex: 0 1 auto; min-width: 80px; height: 100%; border-bottom: 0; }
|
|
.window-drag-space { flex: 1; min-width: 120px; align-self: stretch; }
|
|
.pages { position: relative; flex: 1; min-height: 0; overflow: hidden; }
|
|
.workarea-background { position: absolute; inset: 0; }
|
|
.pane { position: absolute; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
|
|
.pane.inactive { display: none; }
|
|
.pane.split { border: 1px solid var(--rs-border); }
|
|
.pane.split.focused { border-color: var(--rs-accent); }
|
|
.placeholder { padding: 24px; color: var(--rs-text-dim); }
|
|
.error { margin: 0; padding: 8px; color: var(--rs-error); }
|
|
</style>
|