fix(ui): one window, one way back, and a sidebar that stops mid-plan
Four things from the first real click-through of the installed build. **Two "Back to packages" buttons after a successful run.** `PdSummarySheet` renders `plan.done` from its `onDone`, and the panel rendered a second one beneath it. The panel's is now shown only when there is no sheet — a run that failed before producing an `ExecutionSummary` has an error row and nothing else, and without a button that phase is a dead end. Worth naming *why* no test caught it: `PdSummarySheet` has its own tests and `PdPlanPanel` had none, so the two had never been rendered together. `PdPlanPanel.test.tsx` now does exactly that, and it was checked against the bug — reverting just the panel change makes it fail with "expected 2 to have length 1". Adding it exposed a second gap: `ipcMock` had no `reportBugUrl`, which `PdErrorRow` asks for on mount, so any screen containing an error was untestable. **No single instance.** Five launches gave five windows — which is five `AppState`s over one machine: five `Sessions` slots, each certain it owned the mutation in flight, and five `PD-RES-003` guards that cannot see each other. `tauri-plugin-single-instance` is registered **first**, before any plugin that could take a lock, and the handler unminimizes before focusing: focusing a minimized window leaves it minimized, and the user's second launch appears to do nothing. Added without the `deep-link` feature `cargo add` selects by default — PipDock registers no deep links, and it pulls three crates into the audit surface for nothing. **The sidebar is disabled while a plan owns the content area.** Navigating away left the plan parked in Rust with nothing on screen driving it, and the next Update answered `PD-RES-003` about a plan the user could no longer see. `App.tsx` already refuses `Ctrl+1..8` while the guard dialog is open; this is that rule applied to the panel and to the mouse. **The window is bounded and cannot be maximized.** `maxWidth`/`maxHeight` at 1600×1100 with `maximizable: false` and `fullscreen: false`. The layout is a fixed sidebar plus one scrolling column; stretched across a 4K panel it is a column of text with a metre of empty surface. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b4ab2d94ce
commit
2abfef6a7c
9 files changed
+132
-4
No files matched your search
Generated
+17
@@ -3179,6 +3179,7 @@ dependencies = [
|
||||
"tauri-plugin-clipboard-manager",
|
||||
"tauri-plugin-dialog",
|
||||
"tauri-plugin-opener",
|
||||
"tauri-plugin-single-instance",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
@@ -4693,6 +4694,22 @@ dependencies = [
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-single-instance"
|
||||
version = "2.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3214becf9ef5783c0ae99a3bb25adf5353a7a16ebf53e74b909e29205735c6c"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"thiserror 2.0.19",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"windows-sys 0.60.2",
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "2.11.3"
|
||||
|
||||
@@ -34,6 +34,10 @@ tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||
# `plan_cancel` trips the same `CancellationToken` the core threads through `exec`.
|
||||
tokio-util = "0.7"
|
||||
tracing = "0.1"
|
||||
# One window, always. Launching PipDock again focuses the window that exists rather than opening
|
||||
# a second one — two of them would be two `Sessions` slots over one set of environments, each
|
||||
# certain it owned the mutation in flight.
|
||||
tauri-plugin-single-instance = "2.4.3"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -36,6 +36,21 @@ pub fn run() {
|
||||
use tauri::Manager as _;
|
||||
|
||||
tauri::Builder::default()
|
||||
// **First, before every other plugin.** The single-instance handler has to be registered
|
||||
// before anything that could take a lock or open the store, because a second launch runs
|
||||
// this far and then hands off — and the reason it must hand off at all is that two windows
|
||||
// would be two `AppState`s over one machine: two `Sessions` slots, each certain it owned
|
||||
// the mutation in flight, and two `PD-RES-003` guards that cannot see each other.
|
||||
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
|
||||
// Focus the window that already exists. Restoring first matters: a minimized window
|
||||
// that is only focused stays minimized, and the user sees their second launch do
|
||||
// nothing at all.
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.unminimize();
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}))
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
|
||||
@@ -17,7 +17,11 @@
|
||||
"height": 760,
|
||||
"minWidth": 900,
|
||||
"minHeight": 560,
|
||||
"maxWidth": 1600,
|
||||
"maxHeight": 1100,
|
||||
"resizable": true,
|
||||
"maximizable": false,
|
||||
"fullscreen": false,
|
||||
"theme": "Dark"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { NAV_KEYS, type NavKey } from '@/components/nav'
|
||||
import { useEnvStore, useUiStore } from '@/stores'
|
||||
import { PANEL_PHASES, useEnvStore, usePlanStore, useUiStore } from '@/stores'
|
||||
|
||||
/** Tabs whose screens land in a later milestone. Kept in place, not hidden. */
|
||||
const NOT_YET: readonly NavKey[] = ['security']
|
||||
@@ -12,6 +12,12 @@ const NOT_YET: readonly NavKey[] = ['security']
|
||||
* `Ctrl+1..8` maps to `NAV_KEYS` positionally, which is why that order is load-bearing. Tabs
|
||||
* without a screen yet stay in place and stay focusable rather than being hidden: hiding them
|
||||
* would renumber every shortcut after them, and the user would relearn the map twice.
|
||||
*
|
||||
* **Every tab is disabled while a plan owns the content area.** `PdPlanPanel` replaces `<main>`
|
||||
* for the whole of a preview, an execution and its summary; navigating away left the plan parked
|
||||
* in Rust with nothing on screen driving it, and the user's next Update answered `PD-RES-003`
|
||||
* about a plan they could no longer see. `App.tsx` already refuses `Ctrl+1..8` while the guard
|
||||
* dialog is open, for the same reason — this is that rule applied to the panel and to the mouse.
|
||||
*/
|
||||
export function PdSidebar() {
|
||||
const { t } = useTranslation()
|
||||
@@ -19,6 +25,8 @@ export function PdSidebar() {
|
||||
const setNav = useUiStore((s) => s.setNav)
|
||||
// UI-SPEC §3's layout sketch shows `Updates (7)`. A primitive, so this selector is stable.
|
||||
const updatesCount = useEnvStore((s) => s.updatesCount)
|
||||
// A boolean rather than the phase, so an unrelated phase change does not re-render the sidebar.
|
||||
const planBusy = usePlanStore((s) => PANEL_PHASES.has(s.phase))
|
||||
|
||||
return (
|
||||
<nav aria-label={t('app.name')} className="w-48 shrink-0 border-r border-border p-2">
|
||||
@@ -30,12 +38,15 @@ export function PdSidebar() {
|
||||
<button
|
||||
type="button"
|
||||
aria-current={active ? 'page' : undefined}
|
||||
disabled={planBusy}
|
||||
onClick={() => {
|
||||
setNav(key)
|
||||
}}
|
||||
className={`flex w-full items-center justify-between rounded-pd px-3 py-1.5 text-left ${
|
||||
active ? 'bg-surface-2 text-accent' : 'text-text-dim hover:bg-surface-2'
|
||||
} ${NOT_YET.includes(key) ? 'opacity-60' : ''}`}
|
||||
} ${NOT_YET.includes(key) ? 'opacity-60' : ''} ${
|
||||
planBusy ? 'cursor-not-allowed opacity-40' : ''
|
||||
}`}
|
||||
>
|
||||
<span>
|
||||
{t(`nav.${key}`)}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* `PdPlanPanel`'s summary phase — the one screen no other test renders together with its child.
|
||||
*
|
||||
* `PdSummarySheet` has its own tests and the panel had none, so the two were never on screen at
|
||||
* the same time in a test. That is exactly where the bug lived: both rendered `plan.done`, and a
|
||||
* successful run showed *Back to packages* twice, one under the other. Reported from the
|
||||
* installed build.
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { PdPlanPanel } from '@/screens/PdPlanPanel'
|
||||
import type { ExecutionSummary } from '@/ipc'
|
||||
import { usePlanStore } from '@/stores/plan'
|
||||
import { resetStore } from '@/test/stores'
|
||||
import summaryFixture from '@/test/fixtures/execution_summary.json'
|
||||
|
||||
vi.mock('@/ipc', async () => {
|
||||
const { ipcMock } = await import('@/test/ipc')
|
||||
return ipcMock()
|
||||
})
|
||||
|
||||
const SUMMARY = summaryFixture as ExecutionSummary
|
||||
|
||||
const OUTCOME = {
|
||||
summary: SUMMARY,
|
||||
snapshot: {
|
||||
id: '2026-08-13T10-00-00Z',
|
||||
createdAt: '2026-08-13T10:00:00Z',
|
||||
engine: 'pip' as const,
|
||||
trigger: { plan: { planId: SUMMARY.planId } },
|
||||
packageCount: 6,
|
||||
envHash: 'aaa',
|
||||
interpreter: 'C:\\venv\\Scripts\\python.exe',
|
||||
pythonVersion: '3.12.4',
|
||||
},
|
||||
}
|
||||
|
||||
describe('the summary phase', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
resetStore(usePlanStore)
|
||||
})
|
||||
|
||||
it('offers exactly one way back after a successful run', () => {
|
||||
usePlanStore.setState({ phase: 'summary', outcome: OUTCOME, kind: 'update' })
|
||||
render(<PdPlanPanel onFinished={vi.fn()} />)
|
||||
|
||||
// One, not two. The sheet renders it; the panel must not render a second beneath.
|
||||
expect(screen.getAllByText('Back to packages')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('still offers a way back when the run failed before producing a summary', () => {
|
||||
// No `ExecutionSummary` means no sheet, so without the panel's own button this phase would
|
||||
// be a dead end — the error is on screen and nothing dismisses it.
|
||||
usePlanStore.setState({
|
||||
phase: 'summary',
|
||||
outcome: null,
|
||||
error: { code: 'PD-SNP-001', message: 'snapshot failed' },
|
||||
})
|
||||
render(<PdPlanPanel onFinished={vi.fn()} />)
|
||||
|
||||
expect(screen.getAllByText('Back to packages')).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
@@ -103,7 +103,13 @@ export function PdPlanPanel({ onFinished }: PdPlanPanelProps) {
|
||||
: {})}
|
||||
/>
|
||||
)}
|
||||
{outcome === null && error === null ? null : (
|
||||
{/* **Only when `PdSummarySheet` is not on screen.** The sheet renders its own
|
||||
`plan.done` from `onDone`, so a successful run showed the same button twice, one
|
||||
under the other. Reported from the installed build — the summary is the one screen
|
||||
no component test renders together with its panel. The button still has to exist
|
||||
here, because a run that failed before producing an `ExecutionSummary` has an error
|
||||
row and no sheet, and would otherwise be a dead end. */}
|
||||
{outcome === null && error !== null ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
@@ -114,7 +120,7 @@ export function PdPlanPanel({ onFinished }: PdPlanPanelProps) {
|
||||
>
|
||||
{t('plan.done')}
|
||||
</button>
|
||||
)}
|
||||
) : null}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -575,6 +575,7 @@ export const useUiStore = create<UiState>((set) => ({
|
||||
// event subscription. Re-exported so `@/stores` stays the single import site.
|
||||
export {
|
||||
CONSOLE_LIMIT,
|
||||
PANEL_PHASES,
|
||||
apply,
|
||||
usePlanStore,
|
||||
type ConsoleLine,
|
||||
|
||||
@@ -48,6 +48,7 @@ export interface IpcMock {
|
||||
healthSaveReport: ReturnType<typeof vi.fn>
|
||||
healthFix: ReturnType<typeof vi.fn>
|
||||
healthDirty: ReturnType<typeof vi.fn>
|
||||
reportBugUrl: ReturnType<typeof vi.fn>
|
||||
isPdError: (value: unknown) => boolean
|
||||
}
|
||||
|
||||
@@ -84,6 +85,9 @@ export function ipcMock(): IpcMock {
|
||||
healthSaveReport: vi.fn().mockResolvedValue([]),
|
||||
healthFix: vi.fn(),
|
||||
healthDirty: vi.fn().mockResolvedValue(null),
|
||||
// `PdErrorRow` asks for this on mount, so any test that renders a screen containing an error
|
||||
// needs it — a gap that only appears once a *screen* is under test rather than the row alone.
|
||||
reportBugUrl: vi.fn().mockResolvedValue('https://github.com/poli0981/pipdock/issues/new'),
|
||||
// Real, not a spy: the stores decide whether a rejection carries a catalog code by asking it,
|
||||
// and a stub that always answered one way would make every error test agree with itself.
|
||||
isPdError: (value: unknown): boolean =>
|
||||
|
||||
Reference in new issue
Block a user