diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d827cc..9e633e1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ All notable changes to Kromacut are documented in this file. - **Open in Slicer (desktop)** - The 3D download menu in the desktop app adds **Open in Slicer**, which builds the same 3MF as **Download 3MF** and opens it with the system's default `.3mf` app without a Save As dialog. Set your slicer as that default app to open models straight in it. The model is written to a new file in Kromacut's cache folder, so a slicer that still has an earlier copy open is never overwritten, and copies older than a day are removed on the next handoff. Failures to write or dispatch the file, including a missing default app, show a localized error that points to **Download 3MF**. Native dispatch runs off the UI thread and reports OS launch errors without waiting for the slicer to close. The browser version is unchanged. Updated the localized export guides; added native tests for file naming, collisions, invalid data, cache cleanup, and launcher failures, and a browser regression for the desktop handoff. - **Choose the slicer for Open in Slicer (desktop, #152)** - **Open in Slicer** now asks which app opens the model before building it. The chooser lists **System default** (the system's `.3mf` app, as before) plus Bambu Studio, Orca Slicer, PrusaSlicer, and UltiMaker Cura when they are installed in their usual locations: `/Applications` or `~/Applications` on macOS; Program Files or `%LOCALAPPDATA%\Programs` on Windows, including the newest versioned Cura folder (a saved older Cura stays usable after a newer version is installed next to it, #200); and `PATH` commands or Flatpak installs on Linux. **Browse** picks any other app with the native file dialog; only app bundles, `.exe` files, or executables are accepted, and Kromacut remembers picked apps in its config folder, up to 16, always keeping the saved slicer among them so later Browse picks cannot push it out. Models are only ever launched with a detected slicer or a picked app, never with a program named by the web view. **Always use this slicer** saves the choice under `kromacut:desktop-slicer`, so later clicks open the model straight away and the menu names the slicer; **Choose Slicer** in the same menu changes or forgets it. Closing a chooser opened from the menu returns keyboard focus to the download button, because the menu item that opened it is gone (#185). A saved slicer that was moved or uninstalled is forgotten and the chooser explains why. Flatpak slicers receive the model through Flatpak file forwarding, so their sandbox can read it. Launch failures keep the existing localized error. The chooser and menu are localized into all 12 languages, and the export guides describe the choice. Added native tests for per-platform detection, newest-version selection, a saved older Cura staying launchable after an upgrade, launchable-app validation, the detected-or-picked launch rule, picked-app storage that keeps the saved slicer, launch commands, and slicer path decoding; unit tests for the saved preference; and browser regressions for choosing, remembering, changing, browsing (including which saved slicer Browse keeps), forgetting, a missing saved slicer, and focus after closing a chooser opened from the menu. - **Change or forget the saved slicer from Settings (desktop, #173)** - The desktop Settings dialog gains an **Open in Slicer** row that shows the saved choice (**Ask every time**, **System default**, or the slicer's name and path) and works without an image or model. **Change** opens the slicer chooser, whose confirm button then reads **Save**: it saves the selected slicer, including one picked with **Browse**, without exporting or opening anything; the **Always use this slicer** switch is hidden there because the choice is always saved. **Forget** clears the saved choice so the next Open in Slicer asks again. Closing the chooser opened from Settings returns keyboard focus to the Settings button. Settings and the 3D download menu share one preference, so a change in either shows up in the other straight away. The new strings, the updated remember hint, and the export guides' Open in Slicer paragraph are localized into all 12 languages. Added browser regressions for the browser build without the row, saving a detected, browsed, or system-default slicer from Settings without exporting, including with a model built, keeping the saved slicer launchable while browsing, focus after closing the chooser, cancelling, forgetting, and the download menu following a choice made or forgotten in Settings. -- **Saved slicer survives a slow check (desktop, #186)** - When **Open in Slicer** is still checking the saved slicer while a new one is saved or forgotten in Settings, the late check result is ignored. It no longer clears the newly saved slicer or opens the model in the replaced one. A rebuild that finishes during the check is exported with its own head count, pause schedule, and layer heights, instead of the settings of the build shown when **Open in Slicer** was clicked. Added unit regressions that hold the slicer lookup until after Settings saves a new slicer or a new build finishes. +- **Saved slicer survives a slow check (desktop, #186)** - When **Open in Slicer** is still checking the saved slicer while a new one is saved or forgotten in Settings, the late check result is ignored. It no longer clears the newly saved slicer or opens the model in the replaced one. A rebuild that finishes during the check is exported with its own head count, pause schedule, and layer heights, instead of the settings of the build shown when **Open in Slicer** was clicked. A slicer chooser opened during the check, for example from **Settings → Change**, is also left alone: the late result no longer turns that chooser's **Save** into **Open**, opens the model over it, or forgets the saved slicer. Added unit regressions that hold the slicer lookup until after Settings saves or forgets a slicer, a chooser opens or closes, or a new build finishes, and browser regressions for a found, missing, or failed check that finishes while the Settings chooser is open. - **Pull request CI and `test:e2e:all`** - Pull requests into `develop` and `main`, and pushes to them, now run lint, the build, unit tests, the desktop app's Rust tests (`cargo test` on Linux, macOS, and Windows), and every Playwright e2e suite in parallel jobs, with cached npm packages, Chromium, and cargo builds. The other Linux jobs run on Ubuntu 24.04 rather than `ubuntu-latest` (Ubuntu 26.04), where Playwright cannot install Chromium, and the Chromium cache is keyed by runner image. One `CI passed` check summarizes the result. Fork pull requests get a read-only token and no secrets. `npm run test:e2e:all` runs the same suites locally one after another: the `@smoke` tests, then the docs, landing, privacy, terms, 404, i18n, and i18n build suites, each on a fresh server. It fails if any suite fails, if a Playwright config isn't in the suite list, or if a test isn't run by any suite; the long `@full` export matrix stays on demand. Area specs now refuse to run under the wrong Playwright config and name the script to use. Palette Proof, the Settings legal links, and the adaptive Stack Matrix round trip were not in any suite and now run with `@smoke`. - **Cats Exact benchmark reproducibility** - Audited the stale replay fingerprint against historical prediction changes while preserving captured observations and artifact hashes. Calibrated benchmarks capture provenance before optimization, pin archived source and provenance to one resolved commit, and save full results before golden assertions. CLI validation rejects invalid case/head/grouping selections and report paths that alias saved inputs, and checks replay results against preparation checksums; cached preparation requires an uncached Exact result and rejects mismatched physical/separation settings, repeat budgets, profiles, palettes, and model contexts. Fresh-stack multi-head measurements support warmed repeated samples, deterministic result checks, and separate fitting, optimization, analysis, and build-validation timing. The cats fixtures record the profile hash of the committed LF file instead of its Windows CRLF form, and `.kfil` and performance fixture JSON files are checked out byte-for-byte on every platform, so the immutability check passes on macOS and Linux; cached multi-head preparation still accepts results captured from CRLF checkouts of the same profile. - **Multi-head printing guide** - New in-app documentation page explaining Multi-head printing: prerequisites, how layers become color runs and windows, the Head Schedule, the combination search space, Color grouping, and what Fast, Balanced, and Thorough search depth change, with four explanatory diagrams. The guide, navigation metadata, and diagrams are available in all 12 languages, with measured translated labels and reciprocal Auto-paint links. Covers routed preview colors, 3MF head assignments and M600 checkpoints, single-head fallback, and cancellation when the image changes. Regression checks require matching guide metadata and complete diagram catalogs and label bounds; browser coverage loads the guide and all four illustrations in every language. diff --git a/src/hooks/useSlicerChoice.ts b/src/hooks/useSlicerChoice.ts index f6d68ec4..ca88625e 100644 --- a/src/hooks/useSlicerChoice.ts +++ b/src/hooks/useSlicerChoice.ts @@ -28,6 +28,14 @@ export function useSlicerChoice(openInSlicer: (slicer: SlicerApp | null) => Prom // with the current mesh, not the settings captured when Open in Slicer was clicked. const openInSlicerRef = useRef(openInSlicer); openInSlicerRef.current = openInSlicer; + // The Open in Slicer click whose saved-slicer check may still act. Showing any chooser + // clears it, so a late check result never replaces or launches over that chooser. + const pendingOpenRef = useRef(null); + + const showChooser = useCallback((request: SlicerChooserRequest) => { + pendingOpenRef.current = null; + setChooser(request); + }, []); const updatePreference = useCallback((next: SlicerPreference | null) => { saveSlicerPreference(next); @@ -39,34 +47,40 @@ export function useSlicerChoice(openInSlicer: (slicer: SlicerApp | null) => Prom const preference = preferenceRef.current; if (preference?.kind === 'system') return openInSlicer(null); if (preference?.kind === 'app') { + const request = {}; + pendingOpenRef.current = request; + // Changed in Settings, a chooser shown, or another click during the check: the + // newer action wins, so do nothing. + const superseded = () => + preferenceRef.current !== preference || pendingOpenRef.current !== request; let found: SlicerApp | null; try { found = await findSlicerApp(preference.app.path); } catch (err) { - if (preferenceRef.current !== preference) return; + if (superseded()) return; console.warn('Checking the saved slicer failed', err); - setChooser({ missingSlicerName: null, saveOnly: false }); + showChooser({ missingSlicerName: null, saveOnly: false }); return; } - // Changed in Settings during the check: the newer choice wins, so do nothing. - if (preferenceRef.current !== preference) return; + if (superseded()) return; + pendingOpenRef.current = null; if (found) return openInSlicerRef.current(found); // The slicer was moved or uninstalled: forget it and ask again. updatePreference(null); - setChooser({ missingSlicerName: preference.app.name, saveOnly: false }); + showChooser({ missingSlicerName: preference.app.name, saveOnly: false }); return; } - setChooser({ missingSlicerName: null, saveOnly: false }); - }, [openInSlicer, updatePreference]); + showChooser({ missingSlicerName: null, saveOnly: false }); + }, [openInSlicer, showChooser, updatePreference]); const onChooseSlicer = useCallback( - () => setChooser({ missingSlicerName: null, saveOnly: false }), - [] + () => showChooser({ missingSlicerName: null, saveOnly: false }), + [showChooser] ); const onChangeSavedSlicer = useCallback( - () => setChooser({ missingSlicerName: null, saveOnly: true }), - [] + () => showChooser({ missingSlicerName: null, saveOnly: true }), + [showChooser] ); const onForgetSlicer = useCallback(() => updatePreference(null), [updatePreference]); diff --git a/tests/e2e/open-in-slicer.spec.ts b/tests/e2e/open-in-slicer.spec.ts index bd175d6a..decbf881 100644 --- a/tests/e2e/open-in-slicer.spec.ts +++ b/tests/e2e/open-in-slicer.spec.ts @@ -15,6 +15,8 @@ type SlicerTestWindow = Window & { pickRequests: PickRequest[]; }; __KROMACUT_E2E: { buildHistory: unknown[] }; + /** When set, `find_slicer_app` waits for it; `true` makes the check fail. */ + slicerCheck?: { held: Promise; release(fail: boolean): void }; }; const SLICER_FAILED = 'Could not open the 3MF in your slicer. Use Download 3MF to save it instead.'; @@ -178,9 +180,16 @@ async function setUpChooser( }); desktop.handle('list_slicer_apps', () => host.slicerTest.installed); desktop.handle('find_slicer_app', ({ path }: { path: string }) => { - const { installed, picked } = host.slicerTest; - const known = typeof picked === 'object' ? [...installed, picked] : installed; - return known.find((app) => app.path === path) ?? null; + const find = () => { + const { installed, picked } = host.slicerTest; + const known = typeof picked === 'object' ? [...installed, picked] : installed; + return known.find((app) => app.path === path) ?? null; + }; + if (!host.slicerCheck) return find(); + return host.slicerCheck.held.then((fail) => { + if (fail) throw new Error('Mock check failure'); + return find(); + }); }); desktop.handle('pick_slicer_app', (request: PickRequest) => { host.slicerTest.pickRequests.push(request); @@ -354,6 +363,57 @@ test('@smoke desktop Open in Slicer asks again when the saved slicer is gone', a expect(errors).toEqual([]); }); +for (const result of ['found', 'missing', 'failed'] as const) { + test(`@smoke a ${result} saved-slicer check finishing late keeps the Settings chooser`, async ({ + page, + }) => { + const errors: string[] = []; + page.on('pageerror', (error) => errors.push(error.message)); + // Bambu Studio is saved; it is still installed only when the check finds it. + const installed = result === 'found' ? [BAMBU, ORCA] : [ORCA]; + const slicers = await setUpChooser(page, installed, { kind: 'app', app: BAMBU }); + const chooser = page.getByTestId('slicer-chooser'); + await page.evaluate(() => { + const host = window as unknown as SlicerTestWindow; + let release!: (fail: boolean) => void; + const held = new Promise((resolve) => (release = resolve)); + host.slicerCheck = { held, release }; + }); + + // Open in Slicer starts the slow check, then Settings opens the chooser to change it. + await slicers.openMenu(); + await page.getByTestId('open-3mf-in-slicer').click(); + await expect.poll(() => fakeDesktopCalls(page)).toContain('find_slicer_app'); + await page.getByRole('button', { name: 'Open settings' }).click(); + await page.getByTestId('settings-slicer-change').click(); + await expect(page.getByTestId('slicer-save')).toBeVisible(); + + await page.evaluate(async (fail) => { + const check = (window as unknown as SlicerTestWindow).slicerCheck!; + check.release(fail); + await check.held; + // Let the check result reach React and render. + await new Promise((resolve) => setTimeout(resolve, 100)); + }, result === 'failed'); + + // The late result neither replaced the chooser nor opened the model. + await expect(page.getByTestId('slicer-save')).toHaveText('Save'); + await expect(page.getByTestId('slicer-open')).toHaveCount(0); + await expect(page.getByTestId('slicer-remember')).toHaveCount(0); + await expect(chooser).not.toContainText('could not be found'); + expect(await slicers.savedPreference()).toEqual({ kind: 'app', app: BAMBU }); + expect((await slicers.state()).headers).toHaveLength(0); + + // Saving still only remembers the choice. + await chooser.getByText(ORCA.name, { exact: true }).click(); + await page.getByTestId('slicer-save').click(); + await expect(chooser).toHaveCount(0); + expect(await slicers.savedPreference()).toEqual({ kind: 'app', app: ORCA }); + expect(await fakeDesktopCalls(page)).not.toContain('open_model_in_slicer'); + expect(errors).toEqual([]); + }); +} + test('@smoke closing the chooser from the download menu returns focus to the menu button', async ({ page, }) => { diff --git a/tests/useSlicerChoice.test.ts b/tests/useSlicerChoice.test.ts index 2b7cf2da..03a297be 100644 --- a/tests/useSlicerChoice.test.ts +++ b/tests/useSlicerChoice.test.ts @@ -32,15 +32,19 @@ const bambu: SlicerApp = { name: 'Bambu Studio', path: '/Applications/BambuStudi const orca: SlicerApp = { name: 'Orca Slicer', path: '/Applications/OrcaSlicer.app' }; /** - * Saves `bambu` and holds `find_slicer_app` until `release` is called. `restore` puts the - * original `window` back. + * Saves `bambu` and holds `find_slicer_app` until `release` or `fail` is called. `restore` puts + * the original `window` back. */ function holdSavedSlicerLookup() { globalThis.localStorage.clear(); saveSlicerPreference({ kind: 'app', app: bambu }); let release!: (app: SlicerApp | null) => void; - const lookup = new Promise((resolve) => (release = resolve)); + let fail!: (err: Error) => void; + const lookup = new Promise((resolve, reject) => { + release = resolve; + fail = reject; + }); const windowDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'window'); Object.defineProperty(globalThis, 'window', { configurable: true, @@ -57,22 +61,30 @@ function holdSavedSlicerLookup() { if (windowDescriptor) Object.defineProperty(globalThis, 'window', windowDescriptor); else Reflect.deleteProperty(globalThis, 'window'); }; - return { release, restore }; + return { release, fail, restore }; } +type SlicerChoice = ReturnType; + /** - * Saves `bambu`, then clicks Open in Slicer while `find_slicer_app` is held, saves `orca` from - * Settings, and only then lets the lookup resolve to `found`. + * Saves `bambu`, then clicks Open in Slicer while `find_slicer_app` is held, runs `meanwhile`, + * and only then lets the lookup resolve to `found` (or fail with it, for an `Error`). */ -async function saveDuringSlowCheck(found: SlicerApp | null) { +async function duringSlowCheck( + found: SlicerApp | null | Error, + meanwhile: (choice: SlicerChoice) => void +) { const { useSlicerChoice } = await loadViteModule( '/src/hooks/useSlicerChoice.ts' ); - const { release, restore } = holdSavedSlicerLookup(); + const { release, fail, restore } = holdSavedSlicerLookup(); const opened: (SlicerApp | null)[] = []; + const warn = console.warn; + const warnings: unknown[][] = []; + console.warn = (...args: unknown[]) => warnings.push(args); try { - let choice!: ReturnType; + let choice!: SlicerChoice; function Probe() { choice = useSlicerChoice(async (slicer) => { opened.push(slicer); @@ -82,16 +94,24 @@ async function saveDuringSlowCheck(found: SlicerApp | null) { renderToStaticMarkup(createElement(Probe)); const open = choice.onOpenInSlicer(); - choice.onChangeSavedSlicer(); - choice.onChooserConfirm(orca, true); - release(found); + meanwhile(choice); + if (found instanceof Error) fail(found); + else release(found); await open; } finally { + console.warn = warn; restore(); } - return opened; + return { opened, warnings }; } +/** Saves `orca` from Settings during the check. */ +const saveDuringSlowCheck = (found: SlicerApp | null) => + duringSlowCheck(found, (choice) => { + choice.onChangeSavedSlicer(); + choice.onChooserConfirm(orca, true); + }).then(({ opened }) => opened); + test('a missing saved slicer found late does not forget the slicer saved in Settings', async () => { await saveDuringSlowCheck(null); assert.deepEqual(loadSlicerPreference(), { kind: 'app', app: orca }); @@ -136,3 +156,43 @@ test('a saved slicer found late exports with the build that finished during the } assert.deepEqual(exported, [{ build: 2, slicer: bambu }]); }); + +test('a saved slicer found late does not open the model over the Settings chooser', async () => { + const { opened } = await duringSlowCheck(bambu, (choice) => choice.onChangeSavedSlicer()); + assert.deepEqual(opened, []); + assert.deepEqual(loadSlicerPreference(), { kind: 'app', app: bambu }); +}); + +test('a missing saved slicer found late leaves the Settings chooser and the slicer alone', async () => { + const { opened } = await duringSlowCheck(null, (choice) => choice.onChangeSavedSlicer()); + assert.deepEqual(opened, []); + assert.deepEqual(loadSlicerPreference(), { kind: 'app', app: bambu }); +}); + +test('a failed saved-slicer check ignores a chooser opened meanwhile', async () => { + const { opened, warnings } = await duringSlowCheck(new Error('lookup failed'), (choice) => + choice.onChangeSavedSlicer() + ); + assert.deepEqual(opened, []); + assert.deepEqual(warnings, [], 'the late failure must not show its own chooser'); + assert.deepEqual(loadSlicerPreference(), { kind: 'app', app: bambu }); +}); + +test('a saved slicer found late does not open the model after a chooser was closed', async () => { + const { opened } = await duringSlowCheck(bambu, (choice) => { + choice.onChangeSavedSlicer(); + choice.onChooserCancel(); + }); + assert.deepEqual(opened, []); +}); + +test('a saved slicer found without interruption still opens the model', async () => { + const { opened } = await duringSlowCheck(bambu, () => {}); + assert.deepEqual(opened, [bambu]); +}); + +test('a saved slicer found late does not open the model after Settings forgot it', async () => { + const { opened } = await duringSlowCheck(bambu, (choice) => choice.onForgetSlicer()); + assert.deepEqual(opened, []); + assert.equal(loadSlicerPreference(), null); +});