fix(gallery): 删除后不残留「图片已丢失」格子(deleteOutputs 返回 Promise + 插件本地先摘除)v3.25.55

- deleteOutputs 返回 Promise(删除+refreshOutputs 完成才 resolve)
- capability.remove 等删除完成再返回
- gallery 1.2.1:先本地摘除重排,250ms 后重拉校正
- 回归测试增加删除场景
This commit is contained in:
qiqi committed 2026-11-20 12:15:02 +08:00
1 parent 5c378c3d73
commit d5449e8b71
10 files changed
+54 -15

No files matched your search

+10
View File
@@ -14,6 +14,16 @@
> 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。
> 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。
## v3.25.55(2026-11-20)修:删除图片后残留「图片已丢失」格子
- 症状:图库删图后,被删位置仍渲染一格「图片已丢失」,不会自动补齐。
- 原因:`deleteOutputs` 是 fire-and-forget,`ctx.gallery.remove` 立刻返回 ok,插件随即重拉到的还是**旧列表**(宿主 state 尚未刷新),旧条目取不到缩略图 ⇒ 显示丢失格。
- 修复:
- `deleteOutputs` 返回 Promise(删除 + `refreshOutputs` 完成后才 resolve);
- `ctx.gallery.remove` 等它完成再返回 `{ok, removed}`;
- gallery 插件 1.2.1:删除后**先本地摘掉**这些条目并重排(立刻补齐),250ms 后再向宿主重拉校正。
- 回归:`tests/plugin-gallery-render-test.js` 增加「删除后只剩 1 张、无丢失格」断言。
## v3.25.54(2026-11-20)图库:缩略图失败重试 + 下载失败可重试
- 宿主 `ctx.gallery.download`:每张最多尝试 3 次(间隔 300/700/1100ms),返回 `{ok, count, failed[]}`;
+1 -1
View File
@@ -8039,7 +8039,7 @@ const tbCenterSeed = (type, refs) => {
return { ok: failed.length === 0, count: n, failed: failed }
},
insert: async (names, o) => ({ ok: true, inserted: await insertOutputsToCanvas((outputs || []).filter((f) => names.indexOf(f.name) >= 0), (o && o.insertK) || '1k') }),
remove: (names) => { deleteOutputs(names); return { ok: true } },
remove: async (names) => { const n = await deleteOutputs(names); return { ok: n > 0, removed: n } },
})
const dockPanels = {
groups: { title: '节点组', icon: 'group', node: dockGroupsEl },
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "image-workbench-web",
"private": true,
"version": "3.25.54",
"version": "3.25.55",
"description": "Browser-based node canvas image workbench",
"scripts": {
"build": "node scripts/build.js && node scripts/copy-plugins.js",
+3 -3
View File
@@ -19,9 +19,9 @@
},
{
"id": "gallery",
"file": "plugin-gallery.a88dbe92b7ad.js",
"version": "1.2.0",
"integrity": "sha256-qI2+kretsEF6Pdn2FVFpb6v4/yIHzmSc7yyNxfJ61/s="
"file": "plugin-gallery.e9559022aeb3.js",
"version": "1.2.1",
"integrity": "sha256-6VWQIq6zXcayLwbA6OVXNxKCMeVdfjeTk1RdFK3UtII="
},
{
"id": "image-annotate",
@@ -95,7 +95,18 @@
actions.appendChild(btn('删除', '删除选中的图片(不可恢复)', function () {
var C = global.IWBUIConfirm
var ask = C && C.askOrNative ? C.askOrNative('删除选中的 ' + n + ' 张图片?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除选中的 ' + n + ' 张图片?'))
ask.then(function (ok) { if (!ok) return; return ctx.gallery.remove(pickedNames()) }).then(function () { picked = {}; load() }).catch(function () {})
var names = pickedNames()
ask.then(function (ok) {
if (!ok) return
// 先本地摘掉,避免删除后还渲染一格「图片已丢失」;随后再向宿主重拉(等它删完+刷新)
items = items.filter(function (x) { return names.indexOf(x.name) < 0 })
total = Math.max(0, total - names.length)
picked = {}
render()
return Promise.resolve(ctx.gallery.remove(names)).then(function () {
setTimeout(load, 250)
})
}).catch(function () {})
}, true, true))
function field (key, options, label) {
@@ -260,7 +271,7 @@
global.IWBPluginHost.register({
id: 'gallery',
name: '图库',
version: '1.2.0',
version: '1.2.1',
apiVersion: 1,
capabilities: ['panels', 'gallery'],
data: { schemaVersion: 1, maxBytes: 65536 },
+1 -1
View File
@@ -1983,7 +1983,7 @@ dependencies = [
[[package]]
name = "image-workbench"
version = "3.25.54"
version = "3.25.55"
dependencies = [
"arboard",
"base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "image-workbench"
version = "3.25.54"
version = "3.25.55"
description = "无限画布 · 生图工作台桌面版"
authors = ["malongan"]
license = ""
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "image-workbench",
"version": "3.25.54",
"version": "3.25.55",
"identifier": "com.malongan.imageworkbench",
"build": {
"frontendDist": "../dist",
+5 -3
View File
@@ -2043,11 +2043,13 @@
}
const deleteOutputs = (names) => {
const list = Array.isArray(names) ? names : []
if (!list.length) return
api('outputs', { action: 'delete', names: list }).then(() => {
if (!list.length) return Promise.resolve(0)
// v3.25.55:返回 Promise(调用方可等删除+刷新完成再重拉列表,避免 UI 里残留「图片已丢失」格子)
return api('outputs', { action: 'delete', names: list }).then(() => {
refreshOutputs()
setNotice({ type: 'ok', text: '已删除 ' + list.length + ' 张图片' })
}).catch(() => setNotice({ type: 'err', text: '删除失败' }))
return list.length
}).catch(() => { setNotice({ type: 'err', text: '删除失败' }); return 0 })
}
const loadDemo = () => {
CanvasStore.replace([
+18 -2
View File
@@ -37,11 +37,12 @@ window.confirm = () => true
assert.ok(manifest.capabilities.indexOf('gallery') >= 0, '应声明 gallery 能力')
const calls = { list: 0, thumb: 0 }
let current = [{ name: 'a.png', w: 200, h: 300 }, { name: 'b.png', w: 200, h: 120 }]
const ctx = {
ui: { registerPanel (p) { mounted = p.mount } },
data: { read: async () => ({ cfg: { tile: 130 } }), patch: async () => true },
gallery: {
list: async () => { calls.list++; return { items: [{ name: 'a.png', w: 200, h: 300 }, { name: 'b.png', w: 200, h: 120 }], total: 2 } },
list: async () => { calls.list++; return { items: current.slice(), total: current.length } },
thumb: async (n) => { calls.thumb++; return 'data:image/svg+xml;utf8,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="2" height="3"/>') },
preview: () => {}, download: async () => ({ ok: true }), insert: async () => ({ ok: true }), remove: async () => ({ ok: true }),
},
@@ -63,5 +64,20 @@ window.confirm = () => true
assert.ok(imgs.every((i) => String(i.getAttribute('src')).indexOf('data:image/svg') === 0), 'img.src 应来自 thumb()')
assert.strictEqual(missing.length, 0, '不应出现「图片已丢失」:' + missing.join(','))
console.log('plugin-gallery checks passed(异步缩略图 / 2 张图渲染 / 无丢失)')
// 删除后不得残留「图片已丢失」格子:本地先摘除 + 宿主删除完成后重拉
let removedNames = null
ctx.gallery.remove = async (names) => { removedNames = names.slice(); current = current.filter((x) => names.indexOf(x.name) < 0); return { ok: true, removed: names.length } }
// 选中第一张(点击 img),再点顶部「删除」
imgs[0].dispatchEvent(new window.MouseEvent('click', { bubbles: true }))
const delBtn = Array.from(node.querySelectorAll('.iwb-gal-actions button')).find((b) => b.textContent === '删除')
assert.ok(delBtn, '应有删除按钮')
delBtn.dispatchEvent(new window.MouseEvent('click', { bubbles: true }))
for (let i = 0; i < 30; i++) await new Promise((r) => setTimeout(r, 20))
assert.deepStrictEqual(removedNames, ['a.png'], '删除应把选中的名字交给宿主')
const left = node.querySelectorAll('.iwb-history-item img').length
assert.strictEqual(left, 1, '删除后应只剩 1 张,实际 ' + left)
const missingAfter = Array.from(node.querySelectorAll('.iwb-history-missing')).map((x) => x.textContent).filter((t) => t !== '加载中…')
assert.strictEqual(missingAfter.length, 0, '删除后不应出现「图片已丢失」:' + missingAfter.join(','))
console.log('plugin-gallery checks passed(异步缩略图 / 渲染 / 删除后不残留丢失格)')
})().catch((e) => { console.error(e); process.exit(1) })