Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/apps/desktop/src/api/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ pub struct ResetAssistantWorkspaceRequest {
pub workspace_id: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RemoveRecentWorkspaceRequest {
pub workspace_id: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReorderOpenedWorkspacesRequest {
Expand Down Expand Up @@ -1240,6 +1246,18 @@ pub async fn get_recent_workspaces(
.collect())
}

#[tauri::command]
pub async fn remove_recent_workspace(
state: State<'_, AppState>,
request: RemoveRecentWorkspaceRequest,
) -> Result<(), String> {
state
.workspace_service
.remove_workspace_from_recent(&request.workspace_id)
.await
.map_err(|e| format!("Failed to remove workspace from recent: {}", e))
}

#[tauri::command]
pub async fn cleanup_invalid_workspaces(
state: State<'_, AppState>,
Expand Down
1 change: 1 addition & 0 deletions src/apps/desktop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ pub async fn run() {
subscribe_config_updates,
get_model_configs,
get_recent_workspaces,
remove_recent_workspace,
cleanup_invalid_workspaces,
get_opened_workspaces,
open_workspace,
Expand Down
10 changes: 10 additions & 0 deletions src/apps/server/src/rpc_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ pub async fn dispatch(
let list = state.workspace_service.get_recent_workspaces().await;
Ok(serde_json::to_value(&list).unwrap_or_default())
}
"remove_recent_workspace" => {
let request = extract_request(&params)?;
let workspace_id = get_string(request, "workspaceId")?;
state
.workspace_service
.remove_workspace_from_recent(&workspace_id)
.await
.map_err(|e| anyhow!("{}", e))?;
Ok(serde_json::Value::Null)
}
"get_opened_workspaces" => {
let list = state.workspace_service.get_opened_workspaces().await;
Ok(serde_json::to_value(&list).unwrap_or_default())
Expand Down
16 changes: 16 additions & 0 deletions src/crates/core/src/service/workspace/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,22 @@ impl WorkspaceManager {
.collect();
}

/// Removes a workspace id from recent lists only (does not unregister the workspace).
pub fn remove_from_recent_workspaces_only(&mut self, workspace_id: &str) -> bool {
let mut changed = false;
let before = self.recent_workspaces.len();
self.recent_workspaces.retain(|id| id != workspace_id);
if self.recent_workspaces.len() != before {
changed = true;
}
let before_a = self.recent_assistant_workspaces.len();
self.recent_assistant_workspaces.retain(|id| id != workspace_id);
if self.recent_assistant_workspaces.len() != before_a {
changed = true;
}
changed
}

/// Returns a reference to the recent-workspaces list.
pub fn get_recent_workspaces(&self) -> &Vec<String> {
&self.recent_workspaces
Expand Down
12 changes: 12 additions & 0 deletions src/crates/core/src/service/workspace/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,18 @@ impl WorkspaceService {
recent_workspaces
}

/// Drops a workspace from recent lists only (workspace record and open state unchanged).
pub async fn remove_workspace_from_recent(&self, workspace_id: &str) -> BitFunResult<()> {
let changed = {
let mut manager = self.manager.write().await;
manager.remove_from_recent_workspaces_only(workspace_id)
};
if changed {
self.save_workspace_data().await?;
}
Ok(())
}

/// Searches workspaces.
pub async fn search_workspaces(&self, query: &str) -> Vec<WorkspaceSummary> {
let manager = self.manager.read().await;
Expand Down
124 changes: 108 additions & 16 deletions src/web-ui/src/app/scenes/welcome/WelcomeScene.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,55 @@
gap: 1px;
}

&__recent-row {
display: flex;
align-items: stretch;
border-radius: $size-radius-sm;
overflow: hidden;
transition: background $motion-fast $easing-standard;

&:hover {
background: var(--element-bg-soft);

.welcome-scene__recent-item {
color: var(--color-text-primary);

svg { color: var(--color-text-secondary); }
}

.welcome-scene__recent-time-btn__label {
opacity: 0;
}

.welcome-scene__recent-time-btn__icon {
opacity: 1;
color: var(--color-text-secondary);
}
}

&:hover .welcome-scene__recent-time-btn:hover {
background: var(--element-bg-muted);

.welcome-scene__recent-time-btn__icon svg {
transform: scale(1.12);
}
}
}

&__recent-item {
display: flex;
align-items: center;
gap: $size-gap-2;
flex: 1;
min-width: 0;
padding: $size-gap-1 + 2px $size-gap-2;
border: none;
border-radius: $size-radius-sm;
background: transparent;
color: var(--color-text-secondary);
font-size: $font-size-base;
cursor: pointer;
text-align: left;
transition: background $motion-fast $easing-standard,
color $motion-fast $easing-standard;

&:hover {
background: var(--element-bg-soft);
color: var(--color-text-primary);

svg { color: var(--color-text-secondary); }
}
transition: color $motion-fast $easing-standard;

svg {
flex-shrink: 0;
Expand All @@ -153,6 +181,67 @@
}
}

&__recent-time-btn {
position: relative;
flex-shrink: 0;
align-self: stretch;
min-width: 5.25rem;
margin: 0;
padding: 0 $size-gap-2 0 $size-gap-1;
border: none;
background: transparent;
color: var(--color-text-muted);
font-size: $font-size-sm;
cursor: pointer;
transition: color $motion-fast $easing-standard,
background $motion-fast $easing-standard;

&__label {
display: flex;
align-items: center;
justify-content: flex-end;
min-height: 100%;
padding-right: 1px;
transition: opacity $motion-fast $easing-standard;
}

&__icon {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: flex-end;
padding-right: $size-gap-2;
opacity: 0;
color: var(--color-text-muted);
pointer-events: none;
transition: opacity $motion-fast $easing-standard,
color $motion-fast $easing-standard;

svg {
display: block;
transform-origin: center right;
transition: transform $motion-fast $easing-standard;
}
}

&:focus-visible {
color: var(--color-text-primary);
outline: 2px solid var(--focus-ring-color, var(--color-accent));
outline-offset: -2px;
z-index: 1;
}

&:focus-visible &__label {
opacity: 0;
}

&:focus-visible &__icon {
opacity: 1;
color: var(--color-text-secondary);
}
}

&__recent-name {
flex: 1;
display: inline-flex;
Expand Down Expand Up @@ -180,12 +269,6 @@
font-size: $font-size-sm;
}

&__recent-time {
flex-shrink: 0;
font-size: $font-size-sm;
color: var(--color-text-muted);
}

&__no-recent {
font-size: $font-size-xs;
color: var(--color-text-muted);
Expand Down Expand Up @@ -221,8 +304,17 @@
animation: none;

&__recent-item,
&__recent-time-btn,
&__link-btn {
transition: none;
}

&__recent-time-btn__icon svg {
transition: none;
}
}

.welcome-scene__recent-row:hover .welcome-scene__recent-time-btn:hover .welcome-scene__recent-time-btn__icon svg {
transform: none;
}
}
60 changes: 42 additions & 18 deletions src/web-ui/src/app/scenes/welcome/WelcomeScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React, { useState, useCallback, useMemo } from 'react';
import {
FolderOpen, Clock, FolderPlus,
FolderOpen, Clock, FolderPlus, Trash2,
} from 'lucide-react';
import { useWorkspaceContext } from '@/infrastructure/contexts/WorkspaceContext';
import { useSceneStore } from '@/app/stores/sceneStore';
Expand All @@ -26,7 +26,7 @@ const WelcomeScene: React.FC = () => {
const { t } = useI18n('common');
const {
hasWorkspace, currentWorkspace, recentWorkspaces,
openWorkspace, switchWorkspace,
openWorkspace, switchWorkspace, removeWorkspaceFromRecent,
} = useWorkspaceContext();
const openScene = useSceneStore(s => s.openScene);
const [isSelecting, setIsSelecting] = useState(false);
Expand Down Expand Up @@ -85,6 +85,14 @@ const WelcomeScene: React.FC = () => {
}
}, [switchWorkspace, openScene]);

const handleRemoveFromRecent = useCallback(async (workspaceId: string) => {
try {
await removeWorkspaceFromRecent(workspaceId);
} catch (e) {
log.error('Failed to remove workspace from recent', e);
}
}, [removeWorkspaceFromRecent]);

const formatDate = useCallback((dateString: string) => {
try {
const date = new Date(dateString);
Expand Down Expand Up @@ -137,26 +145,42 @@ const WelcomeScene: React.FC = () => {
{displayRecentWorkspaces.map(ws => {
const { hostPrefix, folderLabel, tooltip } = getRecentWorkspaceLineParts(ws);
return (
<Tooltip key={ws.id} content={tooltip} placement="right" followCursor>
<div key={ws.id} className="welcome-scene__recent-row">
<Tooltip content={tooltip} placement="right" followCursor>
<button
type="button"
className="welcome-scene__recent-item"
onClick={() => { void handleSwitchWorkspace(ws); }}
>
<FolderOpen size={13} />
<span className="welcome-scene__recent-name">
{hostPrefix ? (
<>
<span className="welcome-scene__recent-host">{hostPrefix}</span>
<span className="welcome-scene__recent-host-sep" aria-hidden>
{' · '}
</span>
</>
) : null}
{folderLabel}
</span>
</button>
</Tooltip>
<button
className="welcome-scene__recent-item"
onClick={() => { void handleSwitchWorkspace(ws); }}
type="button"
className="welcome-scene__recent-time-btn"
title={t('welcomeScene.removeFromRecent')}
aria-label={t('welcomeScene.removeFromRecent')}
onClick={() => { void handleRemoveFromRecent(ws.id); }}
>
<FolderOpen size={13} />
<span className="welcome-scene__recent-name">
{hostPrefix ? (
<>
<span className="welcome-scene__recent-host">{hostPrefix}</span>
<span className="welcome-scene__recent-host-sep" aria-hidden>
{' · '}
</span>
</>
) : null}
{folderLabel}
<span className="welcome-scene__recent-time-btn__label">
{formatDate(ws.lastAccessed)}
</span>
<span className="welcome-scene__recent-time-btn__icon" aria-hidden>
<Trash2 size={15} strokeWidth={2} />
</span>
<span className="welcome-scene__recent-time">{formatDate(ws.lastAccessed)}</span>
</button>
</Tooltip>
</div>
);
})}
</div>
Expand Down
10 changes: 10 additions & 0 deletions src/web-ui/src/infrastructure/api/service-api/GlobalAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ export class GlobalAPI {
}
}

async removeRecentWorkspace(workspaceId: string): Promise<void> {
try {
await api.invoke('remove_recent_workspace', {
request: { workspaceId },
});
} catch (error) {
throw createTauriCommandError('remove_recent_workspace', error, { workspaceId });
}
}

async cleanupInvalidWorkspaces(): Promise<number> {
try {
return await api.invoke('cleanup_invalid_workspaces');
Expand Down
Loading
Loading