cc-haha/desktop/electron/ipc/channels.ts
程序员阿江(Relakkes) fc9f5d554e feat(desktop): let a nine-row action sheet become a pet instead of demanding an exact atlas
Importing an animated pet required a file that was exactly 1536x2288, laid
out as 88 seamless cells, with the last two rows holding sixteen distinct
gaze angles. No image model emits that. Whatever a user got back from Jimeng
or ChatGPT was some fixed size like 1024x1536, so the path ended at "the
animation atlas must be exactly 1536x2288 pixels" every time. The third card
was worse: "AI-generate full animation" was hardcoded `disabled`, so the one
entry point named after what people actually wanted to do was dead.

The fix was already in the tree. `scripts/assemble-generated-pet-atlas.py`
landed in the same commit as the four built-in pets, which is to say the
built-ins were produced this way — it takes an action sheet at any size,
slices it on an 8x9 grid, fits each cell to 192x208, mirrors the run row to
make run-left, and reuses rows to reach eleven. That capability was never
wired to anything a user could reach.

`petAtlasNormalize.ts` reimplements it on a canvas in the renderer, so an
author draws nine rows and the app derives the rest. Verified against the
reference assembler by reversing dada-code's atlas into a nine-row sheet and
re-normalizing it: every difference lands on semi-transparent antialiased
edges (2314 pixels, max channel delta 14/255) and opaque regions are
identical. That residue is canvas premultiplied-alpha round-tripping, not a
slicing bug.

Three contract details worth stating. Row frame counts are now derived from
`PET_ANIMATION_DEFINITIONS` rather than typed out a fourth time; they come
out equal to the assembler's `(6,8,8,4,5,8,6,6,6,8,8)`. A sheet already at
1536x2288 passes through byte-for-byte instead of being resliced, because
resampling finished artwork buys nothing. And since the validator never
inspects the alpha channel, a flattened white background used to import
happily and render as a rectangle on the desktop — the renderer now rejects
sheets whose atlas is under 5% transparent (the built-ins sit near 78%) with
a message that names the actual problem.

The copy stops describing the implementation. "Animate one image" and
"Import professional animation atlas / exact 1536x2288 v2 PNG" become "use a
picture you already have" and "I already have an action sheet"; the dead AI
card becomes a three-step walkthrough carrying a copyable prompt, a labelled
8x9 reference grid that can be saved locally, and the checks that catch the
common failures. Reference images are generated by a script rather than hand-
placed, in both languages. All five locales move together.

Caught while reviewing the real dialog in Electron: after finishing the
walkthrough the form heading fell through to the atlas branch and announced
"I already have an action sheet" to someone who had just been walked through
drawing one. Covered by a test now.

Not done: docs/images/desktop_ui/15_pet_create_methods.png still shows the
old dialog and needs a fresh capture from a running app to match the styling
of the shots around it.
2026-07-27 07:20:09 +08:00

88 lines
4.1 KiB
TypeScript

export const ELECTRON_IPC_CHANNELS = {
appGetVersion: 'desktop:app:get-version',
runtimeGetServerUrl: 'desktop:runtime:get-server-url',
runtimeGetLocalAccessToken: 'desktop:runtime:get-local-access-token',
runtimeGetPetAccessToken: 'desktop:runtime:get-pet-access-token',
commandInvoke: 'desktop:command:invoke',
clipboardReadText: 'desktop:clipboard:read-text',
clipboardWriteText: 'desktop:clipboard:write-text',
shellOpen: 'desktop:shell:open',
shellOpenPath: 'desktop:shell:open-path',
traceOpenWindow: 'desktop:trace:open-window',
petsList: 'desktop:pets:list',
petsCreateFromImage: 'desktop:pets:create-from-image',
petsCreateFromAtlas: 'desktop:pets:create-from-atlas',
petsPickSourceSheet: 'desktop:pets:pick-source-sheet',
petsCreateFromAtlasBytes: 'desktop:pets:create-from-atlas-bytes',
petsOpenFolder: 'desktop:pets:open-folder',
petsShow: 'desktop:pets:show',
petsHide: 'desktop:pets:hide',
petsShowContextMenu: 'desktop:pets:show-context-menu',
petsDragWindow: 'desktop:pets:drag-window',
petsSetIgnoreMouseEvents: 'desktop:pets:set-ignore-mouse-events',
petsSetInteractiveRegions: 'desktop:pets:set-interactive-regions',
petsFocusMainWindow: 'desktop:pets:focus-main-window',
petsFocusSession: 'desktop:pets:focus-session',
dialogOpen: 'desktop:dialog:open',
dialogSave: 'desktop:dialog:save',
updateCheck: 'desktop:update:check',
updateDownload: 'desktop:update:download',
updateInstall: 'desktop:update:install',
updatePrepareInstall: 'desktop:update:prepare-install',
updateCancelInstall: 'desktop:update:cancel-install',
updateRelaunch: 'desktop:update:relaunch',
notificationPermissionState: 'desktop:notification:permission-state',
notificationRequestPermission: 'desktop:notification:request-permission',
notificationSend: 'desktop:notification:send',
notificationActionAck: 'desktop:notification:action-ack',
windowMinimize: 'desktop:window:minimize',
windowToggleMaximize: 'desktop:window:toggle-maximize',
windowClose: 'desktop:window:close',
windowStartDragging: 'desktop:window:start-dragging',
windowRequestAttention: 'desktop:window:request-attention',
windowFocus: 'desktop:window:focus',
windowIsMaximized: 'desktop:window:is-maximized',
terminalSpawn: 'desktop:terminal:spawn',
terminalWrite: 'desktop:terminal:write',
terminalResize: 'desktop:terminal:resize',
terminalKill: 'desktop:terminal:kill',
terminalGetBashPath: 'desktop:terminal:get-bash-path',
terminalSetBashPath: 'desktop:terminal:set-bash-path',
previewOpen: 'desktop:preview:open',
previewNavigate: 'desktop:preview:navigate',
previewSetBounds: 'desktop:preview:set-bounds',
previewSetVisible: 'desktop:preview:set-visible',
previewSetZoom: 'desktop:preview:set-zoom',
previewClose: 'desktop:preview:close',
previewMessage: 'desktop:preview:message',
appModeGet: 'desktop:app-mode:get',
appModeSet: 'desktop:app-mode:set',
appModePrepareRestart: 'desktop:app-mode:prepare-restart',
appModeRestart: 'desktop:app-mode:restart',
adaptersRestartSidecar: 'desktop:adapters:restart-sidecar',
zoomSet: 'desktop:zoom:set',
appearanceSetApplied: 'desktop:appearance:set-applied',
} as const
export const ELECTRON_EVENT_CHANNELS = {
event: 'desktop:event',
webviewDragDrop: 'desktop:webview:drag-drop',
notificationAction: 'desktop:notification:action',
updateDownloadEvent: 'desktop:update:download-event',
windowResized: 'desktop:window:resized',
nativeMenuNavigate: 'desktop:window:native-menu-navigate',
terminalOutput: 'desktop:terminal:output',
terminalExit: 'desktop:terminal:exit',
previewEvent: 'desktop:preview:event',
petNavigateSession: 'desktop:pets:navigate-session',
petVisibilityChanged: 'desktop:pets:visibility-changed',
} as const
export const ELECTRON_INTERNAL_CHANNELS = {
previewMessageFromView: 'desktop:preview:message-from-view',
} as const
export type ElectronIpcChannel = typeof ELECTRON_IPC_CHANNELS[keyof typeof ELECTRON_IPC_CHANNELS]
export type ElectronEventChannel = typeof ELECTRON_EVENT_CHANNELS[keyof typeof ELECTRON_EVENT_CHANNELS]
export type ElectronInternalChannel = typeof ELECTRON_INTERNAL_CHANNELS[keyof typeof ELECTRON_INTERNAL_CHANNELS]