mirror of
https://github.com/open-webui/computer.git
synced 2026-11-25 14:57:45 -05:00
refac
This commit is contained in:
1 parent
9c47e65420
commit
650fb254a2
3 files changed
+63
-24
No files matched your search
@@ -310,9 +310,12 @@
|
||||
function resize(debounce = false) {
|
||||
if (!container || !ready) return;
|
||||
const rect = container.getBoundingClientRect();
|
||||
const width = Math.round(rect.width);
|
||||
const height = Math.round(rect.height);
|
||||
if (width <= 0 || height <= 0) return;
|
||||
viewport = {
|
||||
width: Math.max(320, Math.min(1920, Math.round(rect.width))),
|
||||
height: Math.max(240, Math.min(1080, Math.round(rect.height)))
|
||||
width,
|
||||
height
|
||||
};
|
||||
if (viewportTimer) clearTimeout(viewportTimer);
|
||||
if (debounce || (mobile && document.activeElement === keyboardAntenna)) {
|
||||
|
||||
@@ -113,6 +113,7 @@ export interface UserPreferences {
|
||||
pwa?: PwaPreferences;
|
||||
textScale?: number | null;
|
||||
widescreenMode?: boolean;
|
||||
homeGroup?: EditorGroup;
|
||||
}
|
||||
|
||||
// ── ID generation ───────────────────────────────────────────────
|
||||
@@ -254,6 +255,11 @@ function normalizeLayout(
|
||||
|
||||
/** The workspace currently displayed in THIS browser tab. Null = welcome page. */
|
||||
export const currentWorkspace = writable<WorkspaceState | null>(null);
|
||||
export const homeGroup = writable<EditorGroup>({
|
||||
id: 'home',
|
||||
tabs: [{ id: 'home', type: 'home', label: 'Home', permanent: true }],
|
||||
activeTabId: 'home'
|
||||
});
|
||||
|
||||
/** List of all workspace summaries for the sidebar. */
|
||||
export const workspaceList = writable<{ path: string; name: string }[]>([]);
|
||||
@@ -408,7 +414,8 @@ function persistPreferences(): void {
|
||||
showUpdateToast: get(showUpdateToastPref),
|
||||
pwa: get(pwaPreferences),
|
||||
textScale: get(textScale) ?? undefined,
|
||||
widescreenMode: get(widescreenMode)
|
||||
widescreenMode: get(widescreenMode),
|
||||
homeGroup: get(homeGroup)
|
||||
};
|
||||
savePreferences(prefs as unknown as Record<string, unknown>).catch(() => {});
|
||||
}, 300);
|
||||
@@ -421,6 +428,9 @@ function subscribeForPersistence() {
|
||||
currentWorkspace.subscribe(() => {
|
||||
if (get(stateLoaded)) persistWorkspace();
|
||||
});
|
||||
homeGroup.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
theme.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
@@ -507,6 +517,36 @@ export async function loadPreferences(): Promise<void> {
|
||||
: null
|
||||
);
|
||||
if (prefs.widescreenMode !== undefined) widescreenMode.set(prefs.widescreenMode as boolean);
|
||||
const savedHomeGroup = prefs.homeGroup as EditorGroup | undefined;
|
||||
if (savedHomeGroup && Array.isArray(savedHomeGroup.tabs)) {
|
||||
const [terminalIds, browserIds] = await Promise.all([
|
||||
listSessions().catch(() => []),
|
||||
listBrowserSessions().catch(() => [])
|
||||
]);
|
||||
const aliveTerminals = new Set(terminalIds);
|
||||
const aliveBrowsers = new Set(browserIds);
|
||||
const tabs = savedHomeGroup.tabs.filter(
|
||||
(tab) =>
|
||||
tab.type !== 'terminal' ||
|
||||
(tab.sessionId !== undefined && aliveTerminals.has(tab.sessionId))
|
||||
);
|
||||
const liveTabs = tabs.filter(
|
||||
(tab) =>
|
||||
tab.type !== 'browser' ||
|
||||
(tab.browserSessionId !== undefined && aliveBrowsers.has(tab.browserSessionId))
|
||||
);
|
||||
if (!liveTabs.some((tab) => tab.type === 'home')) {
|
||||
liveTabs.unshift({ id: 'home', type: 'home', label: 'Home', permanent: true });
|
||||
}
|
||||
homeGroup.set({
|
||||
...savedHomeGroup,
|
||||
id: 'home',
|
||||
tabs: liveTabs,
|
||||
activeTabId: liveTabs.some((tab) => tab.id === savedHomeGroup.activeTabId)
|
||||
? savedHomeGroup.activeTabId
|
||||
: 'home'
|
||||
});
|
||||
}
|
||||
const pwaPrefs = prefs.pwa;
|
||||
if (pwaPrefs)
|
||||
pwaPreferences.set({
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
appVersion,
|
||||
showChangelog,
|
||||
showSearch,
|
||||
pwaPreferences
|
||||
pwaPreferences,
|
||||
homeGroup
|
||||
} from '$lib/stores';
|
||||
import type { Tab, EditorGroup, EditorLayout, SplitDirection, WorkspaceState } from '$lib/stores';
|
||||
import { chatEnabled } from '$lib/stores/chat';
|
||||
@@ -48,22 +49,17 @@
|
||||
let pendingIntent = $state<LaunchIntent | null>(null);
|
||||
let folderPickerIntent = $state<LaunchIntent | null>(null);
|
||||
let folderPickerWorkspace = $state<string | null>(null);
|
||||
let homeGroup = $state<EditorGroup>({
|
||||
id: 'home',
|
||||
tabs: [{ id: 'home', type: 'home', label: 'Home', permanent: true }],
|
||||
activeTabId: 'home'
|
||||
});
|
||||
const activeHomeTab = $derived(
|
||||
homeGroup.tabs.find((tab) => tab.id === homeGroup.activeTabId) ?? homeGroup.tabs[0]
|
||||
$homeGroup.tabs.find((tab) => tab.id === $homeGroup.activeTabId) ?? $homeGroup.tabs[0]
|
||||
);
|
||||
|
||||
function updateHomeTabs(update: (tabs: Tab[]) => { tabs: Tab[]; activeTabId: string }) {
|
||||
const next = update(homeGroup.tabs);
|
||||
homeGroup = { ...homeGroup, ...next };
|
||||
const next = update($homeGroup.tabs);
|
||||
homeGroup.set({ ...$homeGroup, ...next });
|
||||
}
|
||||
|
||||
function openHomeChat(chatId?: string) {
|
||||
const existing = homeGroup.tabs.find(
|
||||
const existing = $homeGroup.tabs.find(
|
||||
(tab) =>
|
||||
tab.type === 'chat' &&
|
||||
(chatId
|
||||
@@ -71,7 +67,7 @@
|
||||
: tab.path?.startsWith('new-') || tab.path?.startsWith('pending-'))
|
||||
);
|
||||
if (existing) {
|
||||
homeGroup = { ...homeGroup, activeTabId: existing.id };
|
||||
homeGroup.set({ ...$homeGroup, activeTabId: existing.id });
|
||||
return;
|
||||
}
|
||||
const tab: Tab = {
|
||||
@@ -115,30 +111,30 @@
|
||||
}
|
||||
|
||||
function closeHomeTab(tabId: string) {
|
||||
const index = homeGroup.tabs.findIndex((tab) => tab.id === tabId);
|
||||
const tab = homeGroup.tabs[index];
|
||||
const index = $homeGroup.tabs.findIndex((tab) => tab.id === tabId);
|
||||
const tab = $homeGroup.tabs[index];
|
||||
if (!tab || tab.permanent) return;
|
||||
if (tab.type === 'terminal' && tab.sessionId) deleteSession(tab.sessionId);
|
||||
if (tab.type === 'browser' && tab.browserSessionId) deleteBrowserSession(tab.browserSessionId);
|
||||
const tabs = homeGroup.tabs.filter((item) => item.id !== tabId);
|
||||
const tabs = $homeGroup.tabs.filter((item) => item.id !== tabId);
|
||||
const activeTabId =
|
||||
homeGroup.activeTabId === tabId
|
||||
$homeGroup.activeTabId === tabId
|
||||
? (tabs[Math.max(0, index - 1)]?.id ?? 'home')
|
||||
: homeGroup.activeTabId;
|
||||
homeGroup = { ...homeGroup, tabs, activeTabId };
|
||||
: $homeGroup.activeTabId;
|
||||
homeGroup.set({ ...$homeGroup, tabs, activeTabId });
|
||||
}
|
||||
|
||||
function updateHomeChatTab(tabId: string, chatId: string, label: string) {
|
||||
updateHomeTabs((tabs) => ({
|
||||
tabs: tabs.map((tab) => (tab.id === tabId ? { ...tab, path: chatId, label } : tab)),
|
||||
activeTabId: homeGroup.activeTabId
|
||||
activeTabId: $homeGroup.activeTabId
|
||||
}));
|
||||
}
|
||||
|
||||
function updateHomeBrowserTab(tabId: string, label: string) {
|
||||
updateHomeTabs((tabs) => ({
|
||||
tabs: tabs.map((tab) => (tab.id === tabId ? { ...tab, label } : tab)),
|
||||
activeTabId: homeGroup.activeTabId
|
||||
activeTabId: $homeGroup.activeTabId
|
||||
}));
|
||||
}
|
||||
const INTENT_URL_KEYS = [
|
||||
@@ -898,10 +894,10 @@
|
||||
{#if !$currentWorkspace}
|
||||
<div class="flex h-full flex-col">
|
||||
<GroupTabBar
|
||||
group={homeGroup}
|
||||
group={$homeGroup}
|
||||
home
|
||||
isPrimary
|
||||
onHomeSelect={(tabId) => (homeGroup = { ...homeGroup, activeTabId: tabId })}
|
||||
onHomeSelect={(tabId) => homeGroup.set({ ...$homeGroup, activeTabId: tabId })}
|
||||
onHomeClose={closeHomeTab}
|
||||
onHomeNewChat={openHomeChat}
|
||||
onHomeNewTerminal={openHomeTerminal}
|
||||
|
||||
Reference in new issue
Block a user