diff --git a/cptr/frontend/src/lib/components/Sidebar.svelte b/cptr/frontend/src/lib/components/Sidebar.svelte index 90aee35..d850169 100644 --- a/cptr/frontend/src/lib/components/Sidebar.svelte +++ b/cptr/frontend/src/lib/components/Sidebar.svelte @@ -18,6 +18,7 @@ import DirectoryPicker from './DirectoryPicker.svelte'; import DropdownMenu from './DropdownMenu.svelte'; import SettingsModal from './SettingsModal.svelte'; + import SystemInfoModal from './SystemInfoModal.svelte'; import { tooltip } from '$lib/tooltip'; import { session, clearSession } from '$lib/session'; @@ -34,6 +35,7 @@ let showPicker = $state(false); let showMenu = $state(false); let showSettings = $state(false); + let showSystemInfo = $state(false); let settingsTab = $state('general'); let wsMenuPath = $state(null); let wsMenuAnchor = $state(null); @@ -214,6 +216,11 @@ showSettings = true; } + function openSystemInfo() { + showMenu = false; + showSystemInfo = true; + } + function logout() { clearSession(); } @@ -503,6 +510,11 @@ shortcut: formatChord($keybindings.openSettings), onclick: openSettings }, + { + label: 'System info', + icon: 'info', + onclick: openSystemInfo + }, { divider: true, label: '', onclick: () => {} }, { label: $t('sidebar.logOut'), icon: 'log-out', onclick: logout } ]} @@ -538,6 +550,10 @@ /> {/if} +{#if showSystemInfo} + (showSystemInfo = false)} /> +{/if} + diff --git a/cptr/frontend/src/routes/+page.svelte b/cptr/frontend/src/routes/+page.svelte index d2cb08a..41837ee 100644 --- a/cptr/frontend/src/routes/+page.svelte +++ b/cptr/frontend/src/routes/+page.svelte @@ -20,12 +20,13 @@ showSearch, pwaPreferences } from '$lib/stores'; - import type { Tab, EditorGroup } from '$lib/stores'; + import type { Tab, EditorGroup, WorkspaceState } from '$lib/stores'; import { t } from '$lib/i18n'; import { get } from 'svelte/store'; - import { getWelcome } from '$lib/apis/state'; + import { getWelcome, getWorkspaceState } from '$lib/apis/state'; import { createSession } from '$lib/apis/terminal'; import { createEntry, writeFile, uploadFiles as uploadFilesApi } from '$lib/apis/files'; + import { getChats, type ChatInfo } from '$lib/apis/chat'; import { deleteSharePayload, getSharePayload } from '$lib/intents/payloadStore'; import type { LaunchIntent, ShareBehavior, SharePayload } from '$lib/intents/types'; import FileBrowser from '$lib/components/FileBrowser.svelte'; @@ -38,7 +39,7 @@ import GroupTabBar from '$lib/components/GroupTabBar.svelte'; import Icon from '$lib/components/Icon.svelte'; import WorkspacePicker from '$lib/components/WorkspacePicker.svelte'; - import SystemInfo from '$lib/components/SystemInfo.svelte'; + import WorkspaceResumeSheet from '$lib/components/WorkspaceResumeSheet.svelte'; import Spinner from '$lib/components/common/Spinner.svelte'; import { isSupportedWorkspacePath } from '$lib/utils/paths'; @@ -46,6 +47,7 @@ let pendingIntent = $state(null); let folderPickerIntent = $state(null); let folderPickerWorkspace = $state(null); + let dismissedResumePath = $state(null); const INTENT_URL_KEYS = [ 'intent', 'chatId', @@ -392,6 +394,21 @@ recent: { name: string; path: string }[]; } | null>(null); + type WorkspaceResume = { + path: string; + tabs: Tab[]; + terminalCount: number; + previewPorts: number[]; + chatCount: number; + fileCount: number; + recentChats: ChatInfo[]; + activeChatCount: number; + activeLabels: string[]; + }; + + let workspaceResumes = $state>(new Map()); + let resumeLoadSeq = 0; + // Fetch welcome data whenever no workspace is active $effect(() => { if (!$currentWorkspace) { @@ -403,6 +420,74 @@ } }); + $effect(() => { + if ($currentWorkspace || !welcomeData) return; + const paths = [ + ...(welcomeData.recent ?? []).map((item) => item.path), + ...(welcomeData.suggestions ?? []).map((item) => item.path) + ] + .filter((path, index, all) => path && all.indexOf(path) === index) + .slice(0, 8); + loadWorkspaceResumes(paths); + }); + + async function loadWorkspaceResumes(paths: string[]) { + const seq = ++resumeLoadSeq; + if (!paths.length) { + workspaceResumes = new Map(); + return; + } + const entries = await Promise.all( + paths.map(async (path) => { + try { + const [state, chatsData] = await Promise.all([ + getWorkspaceState(path).catch(() => null), + getChats(path, 3, 0, 'updated_at', 'desc').catch(() => null) + ]); + if (!state) return null; + return [ + path, + buildWorkspaceResume(path, state as unknown as WorkspaceState, chatsData?.chats ?? []) + ] as const; + } catch { + return null; + } + }) + ); + if (seq !== resumeLoadSeq) return; + workspaceResumes = new Map( + entries.filter((entry): entry is [string, WorkspaceResume] => !!entry) + ); + } + + function buildWorkspaceResume( + path: string, + state: WorkspaceState, + recentChats: ChatInfo[] + ): WorkspaceResume { + const tabs = (state.groups ?? []).flatMap((group) => group.tabs ?? []); + const previewPorts = tabs + .filter((tab) => tab.type === 'preview' && tab.port) + .map((tab) => tab.port!) + .filter((port, index, all) => all.indexOf(port) === index); + const activeLabels = tabs + .filter((tab) => !tab.permanent && ['terminal', 'chat', 'preview', 'file'].includes(tab.type)) + .slice(0, 3) + .map((tab) => tab.label); + + return { + path, + tabs, + terminalCount: tabs.filter((tab) => tab.type === 'terminal').length, + previewPorts, + chatCount: tabs.filter((tab) => tab.type === 'chat').length, + fileCount: tabs.filter((tab) => tab.type === 'file').length, + recentChats, + activeChatCount: recentChats.filter((chat) => chat.is_active).length, + activeLabels + }; + } + // Lazy-init terminal sessions for any group's active tab let initingTerminal = $state(false); $effect(() => { @@ -454,6 +539,28 @@ return path; } + function resumeSignals(resume: WorkspaceResume | undefined): string[] { + if (!resume) return []; + const signals: string[] = []; + if (resume.terminalCount) signals.push(`${resume.terminalCount} term`); + if (resume.previewPorts.length) + signals.push(resume.previewPorts.map((port) => `:${port}`).join(', ')); + if (resume.fileCount) + signals.push(`${resume.fileCount} file${resume.fileCount === 1 ? '' : 's'}`); + if (resume.chatCount || resume.activeChatCount) { + signals.push( + resume.activeChatCount ? `${resume.activeChatCount} active` : `${resume.chatCount} chat` + ); + } + return signals; + } + + function workspaceItems() { + const recent = welcomeData?.recent ?? []; + if (recent.length) return recent.slice(0, 6); + return (welcomeData?.suggestions ?? []).slice(0, 6); + } + // ── Draggable divider ────────────────────────────────────────── let isDragging = $state(false); @@ -495,6 +602,10 @@ return () => window.removeEventListener('resize', onResize); }); + $effect(() => { + if (!$currentWorkspace) dismissedResumePath = null; + }); + const allGroups = $derived($currentWorkspace?.groups ?? []); const splitDirection = $derived($currentWorkspace?.splitDirection ?? 'horizontal'); const splitRatio = $derived($currentWorkspace?.splitRatio ?? 0.5); @@ -579,40 +690,31 @@ {#if !$currentWorkspace} -
+
- -
+

cptr

{#if $appVersion} {/if}
{#if welcomeData?.hostname} -

+

{welcomeData.hostname}

{/if}
- - {#if welcomeData?.system} -
- -
- {/if} - -
-

{$t('home.start')}

+

{$t('home.start')}

- - {#if welcomeData?.recent?.length} + {#if workspaceItems().length}
-

{$t('home.recent')}

+

+ {welcomeData?.recent?.length ? $t('home.recent') : $t('home.folders')} +

- {#each welcomeData.recent.slice(0, 5) as item} + {#each workspaceItems() as item} + {@const resume = workspaceResumes.get(item.path)} + {@const signals = resumeSignals(resume)} {/each}
+ {:else} +
+

{$t('home.recent')}

+ +
{/if} - - {#if welcomeData?.suggestions?.length} + {#if welcomeData?.suggestions?.length && welcomeData?.recent?.length}
-

{$t('home.folders')}

+

{$t('home.folders')}

{#each welcomeData.suggestions.slice(0, 5) as item} {/each}
@@ -767,6 +919,10 @@
{/if}
+ + {#if dismissedResumePath !== $currentWorkspace.path} + (dismissedResumePath = $currentWorkspace?.path ?? null)} /> + {/if} {/if} {#if pendingIntent}