Files
paseo/packages/app/src/utils/sidebar-project-row-model.ts
T
800bd2bef1 feat: add host-local custom project icons (#2335)
* feat(projects): add local icons and colors

* refactor(projects): simplify appearance handling

* fix(projects): serialize appearance saves

* test(app): update project appearance expectations

* test: fix project appearance CI expectations

* refactor(projects): organize appearance code

* fix(server): adopt main's reconcile model in project appearance updates

* fix(projects): preserve host-local appearance targets

* fix(desktop): restore Linux development startup

Ubuntu can block Electron's unprivileged user-namespace fallback while the npm-installed sandbox helper is not SUID. Disable the Chromium process sandbox only in the Linux development runner so packaged desktop policy remains unchanged.

* feat(projects): add custom project icons

Keep URL acquisition in the client so the host daemon only validates uploaded bytes. Project name and icon changes share one adaptive edit sheet.

* refactor(settings): scope projects by host

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
2026-08-01 01:34:42 +08:00

119 lines
3.6 KiB
TypeScript

import type { SidebarProjectEntry } from "@/hooks/use-sidebar-workspaces-list";
export interface SidebarProjectHostTarget {
serverId: string;
projectId: string;
iconWorkingDir: string;
customIconRevision?: string | null;
}
export type SidebarProjectTrailingAction =
| { kind: "new_workspace"; target: SidebarProjectHostTarget }
| { kind: "none" };
export interface SidebarProjectSectionRowModel {
kind: "project_section";
chevron: "expand" | "collapse";
trailingAction: SidebarProjectTrailingAction;
}
export type SidebarProjectRowModel = SidebarProjectSectionRowModel;
const EMPTY_MULTIPLICITY_MAP: ReadonlyMap<string, boolean> = new Map();
function hostTarget(input: {
serverId: string;
projectId: string;
iconWorkingDir: string;
customIconRevision?: string | null;
}): SidebarProjectHostTarget | null {
const iconWorkingDir = input.iconWorkingDir.trim();
if (!input.serverId || !iconWorkingDir) {
return null;
}
return {
serverId: input.serverId,
projectId: input.projectId,
iconWorkingDir,
customIconRevision: input.customIconRevision,
};
}
export function resolveSidebarProjectIconTarget(
project: SidebarProjectEntry,
): SidebarProjectHostTarget | null {
for (const host of project.hosts) {
const target = hostTarget(host);
if (target) {
return target;
}
}
return null;
}
export interface SidebarProjectIconTarget extends SidebarProjectHostTarget {
projectViewKey: string;
}
export function resolveSidebarProjectIconTargets(
projects: readonly SidebarProjectEntry[],
): SidebarProjectIconTarget[] {
return projects.flatMap((project) => {
const target = resolveSidebarProjectIconTarget(project);
return target ? [{ projectViewKey: project.viewKey, ...target }] : [];
});
}
export function resolveSidebarProjectLocalPath(
project: SidebarProjectEntry,
localServerId: string | null,
): string {
if (!localServerId) return "";
return project.hosts.find((host) => host.serverId === localServerId)?.iconWorkingDir.trim() ?? "";
}
// A project can host a brand-new workspace on a host when that host can create a
// git worktree (git projects) OR the host supports running multiple independent
// workspaces per directory (`workspaceMultiplicity`), which is what lets non-git
// directories add a second workspace. Mirrors the gate used by the global "New
// workspace" affordances (use-global-new-workspace-action.ts and left-sidebar's
// SidebarNewWorkspaceHeaderRow): `canCreateWorktree || supportsMultiplicity`.
function resolveNewWorkspaceTarget(
project: SidebarProjectEntry,
supportsMultiplicityByServerId: ReadonlyMap<string, boolean>,
): SidebarProjectHostTarget | null {
for (const host of project.hosts) {
if (
host.worktreeSupport === "unsupported" &&
!supportsMultiplicityByServerId.get(host.serverId)
) {
continue;
}
const target = hostTarget(host);
if (target) return target;
}
return null;
}
function projectTrailingAction(
project: SidebarProjectEntry,
supportsMultiplicityByServerId: ReadonlyMap<string, boolean>,
): SidebarProjectTrailingAction {
const target = resolveNewWorkspaceTarget(project, supportsMultiplicityByServerId);
return target ? { kind: "new_workspace", target } : { kind: "none" };
}
export function buildSidebarProjectRowModel(input: {
project: SidebarProjectEntry;
collapsed: boolean;
supportsMultiplicityByServerId?: ReadonlyMap<string, boolean>;
}): SidebarProjectRowModel {
return {
kind: "project_section",
chevron: input.collapsed ? "expand" : "collapse",
trailingAction: projectTrailingAction(
input.project,
input.supportsMultiplicityByServerId ?? EMPTY_MULTIPLICITY_MAP,
),
};
}