Compare commits

..
3 Commits
Author SHA1 Message Date
lofyer c294b68e96 feat: 分类计数改为括号样式并发布 v2.1.3
构建与发布 / 单测与集成测试 (push) Waiting to run
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
构建与发布 / 发布 GitHub Release (push) Blocked by required conditions
2026-08-06 18:37:50 +08:00
lofyer d6078098d6 feat: 分类显示书籍数量并发布 v2.1.2
构建与发布 / 单测与集成测试 (push) Waiting to run
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
构建与发布 / 发布 GitHub Release (push) Blocked by required conditions
2026-08-06 18:27:47 +08:00
lofyer eaf9939436 feat: 缺失文件扫描支持清理并发布 v2.1.1
构建与发布 / 发布 GitHub Release (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
构建与发布 / 单测与集成测试 (push) Waiting to run
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
2026-08-06 17:57:45 +08:00
16 changed files with 334 additions and 22 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ DRM 保护的 MOBI/AZW/AZW3、KFX、Topaz 以及损坏或不兼容的文件不
2. 双击目录中的 `PeopleLib.exe`
3. 保留整个程序目录,不要只移动 exe。用户数据默认保存在程序同级的 `data/`
当前版本为 **2.1.0**。可在「设置」中手动检查更新,也可启用启动时自动检查。检测到新版本后,应用会打开对应的 GitHub Release 下载页,更新前请退出旧版本并覆盖程序文件,`data/` 目录无需替换。
当前版本为 **2.1.3**。可在「设置」中手动检查更新,也可启用启动时自动检查。检测到新版本后,应用会打开对应的 GitHub Release 下载页,更新前请退出旧版本并覆盖程序文件,`data/` 目录无需替换。
## 开发
+7
View File
@@ -506,6 +506,13 @@ ipcMain.handle('library:scan', () => wrap(() => {
for (const job of coverGenerator.ensureAll()) job.catch(() => {});
return r;
}));
ipcMain.handle('library:removeMissing', () => wrap(async () => {
const ids = library.list()
.filter((item) => item.missing)
.map((item) => String(item.id));
for (const id of ids) await requestReaderPurge(id);
return library.removeMissing();
}));
// 本地书库
ipcMain.handle('library:list', () => wrap(() => library.list().map((item) => ({
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "peoplelib",
"version": "2.1.0",
"version": "2.1.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "peoplelib",
"version": "2.1.0",
"version": "2.1.3",
"license": "MIT",
"dependencies": {
"foliate-js": "1.0.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "peoplelib",
"version": "2.1.0",
"version": "2.1.3",
"description": "多源开放文献、电子书与本地书库客户端",
"main": "main.js",
"author": "peoplelib",
+1
View File
@@ -73,6 +73,7 @@ contextBridge.exposeInMainWorld('api', {
ipcRenderer.invoke('library:importLocal', selectionId, options)
),
scan: () => ipcRenderer.invoke('library:scan'),
removeMissing: () => ipcRenderer.invoke('library:removeMissing'),
onChanged: (cb) => {
const h = () => cb();
ipcRenderer.on('library:changed', h);
@@ -357,6 +357,66 @@ app.whenReady().then(async () => {
.every((title) => allTitles.includes(title))
&& (await js("document.getElementById('libStatus').textContent")) === '共 3 条'
);
const rescanMissingFile = path.join(TMP, 'rescan-missing.txt');
fs.writeFileSync(rescanMissingFile, 'rescan missing fixture');
const rescanMissingShelf = library.addShelf({ name: 'Rescan Missing Shelf' });
const rescanMissingBook = library.add({
title: 'Rescan Missing Book',
shelfId: rescanMissingShelf.id,
tags: ['Rescan Missing Tag'],
files: [{ path: rescanMissingFile, name: 'rescan-missing.txt', format: 'TXT' }]
});
await pollJs(
'缺失扫描夹具显示在书库',
`!!document.querySelector('#libGrid .card[data-id="${rescanMissingBook.id}"]')`
);
fs.unlinkSync(rescanMissingFile);
await js("document.getElementById('rescanBtn').click()");
await waitForModal('发现文件缺失');
check(
'重新扫描报告缺失数量并说明保留阅读资料',
await js(`(() => {
const text = document.getElementById('modalBody').textContent;
return text.includes('1 条书库内容的文件均已缺失')
&& text.includes('对应分类和标签也会一并清理')
&& text.includes('笔记、书签、进度和标注会保留');
})()`)
);
await js("document.getElementById('modalCancel').click()");
await pollJs(
'取消缺失清理后恢复扫描按钮',
"!document.getElementById('rescanBtn').disabled",
5000
);
check(
'取消清理保留缺失书库条目',
!!library.get(rescanMissingBook.id)
&& library.get(rescanMissingBook.id).missing
&& library.listShelves().some((shelf) => shelf.id === rescanMissingShelf.id)
&& library.listTags().some((tag) => tag.name === 'Rescan Missing Tag')
);
await js("document.getElementById('rescanBtn').click()");
await waitForModal('发现文件缺失');
await submitModal();
await poll(
'确认后清理缺失书库条目',
() => Promise.resolve(!library.get(rescanMissingBook.id))
);
await pollJs(
'缺失条目清理后书库恢复',
`!document.querySelector('#libGrid .card[data-id="${rescanMissingBook.id}"]')
&& document.querySelectorAll('#libGrid .card').length === 3`
);
check(
'缺失清理移除对应空分类和标签且不影响其余内容',
library.list().length === 3
&& library.list().every((item) => item.id !== rescanMissingBook.id)
&& !library.listShelves().some((shelf) => shelf.id === rescanMissingShelf.id)
&& !library.listTags().some((tag) => tag.name === 'Rescan Missing Tag')
);
await js(`(() => {
document.getElementById('librarySearchInput').value = 'Rsrch';
document.getElementById('librarySearchBtn').click();
@@ -509,6 +569,30 @@ app.whenReady().then(async () => {
);
readerWindow.destroy();
await wait(200);
check(
'分类侧栏显示全部、未分类和各书架的真实书籍数量',
await js(`(() => {
const all = document.querySelector('#libraryTab .library-filter[data-shelf=""]');
const uncategorized = document.querySelector(
'#libraryTab .library-filter[data-shelf="__uncategorized__"]'
);
const shelves = Array.from(document.querySelectorAll('#libraryShelfList .library-filter'));
const research = shelves.find((button) => button.textContent.includes('研究书架'));
const review = shelves.find((button) => button.textContent.includes('待复核书架'));
const actionButtons = Array.from(
document.querySelectorAll('.library-shelf-actions .notes-icon-btn')
);
return all.textContent.trim() === '全部书籍(3'
&& uncategorized.textContent.trim() === '未分类(1'
&& research.textContent.trim() === '研究书架(1'
&& review.textContent.trim() === '待复核书架(1'
&& actionButtons.every((button) => {
const style = getComputedStyle(button);
return style.backgroundColor === 'rgba(0, 0, 0, 0)'
&& style.borderTopColor === 'rgba(0, 0, 0, 0)';
});
})()`)
);
check(
'标签侧栏显示真实聚合计数',
await js(`(() => {
@@ -572,7 +656,7 @@ app.whenReady().then(async () => {
await js(`(() => {
const button = Array.from(document.querySelectorAll('#libraryShelfList .library-filter'))
.find((candidate) => candidate.textContent.trim() === '研究书架');
.find((candidate) => candidate.firstElementChild.textContent.trim() === '研究书架');
button.click();
})()`);
await pollJs(
@@ -621,7 +705,7 @@ app.whenReady().then(async () => {
!!uiShelf
&& await js(`(() => {
const button = Array.from(document.querySelectorAll('#libraryShelfList .library-filter'))
.find((candidate) => candidate.textContent.trim() === '界面书架');
.find((candidate) => candidate.firstElementChild.textContent.trim() === '界面书架');
return !!button && button.classList.contains('active')
&& document.getElementById('libStatus').textContent === '显示 0 条,共 3 条';
})()`)
@@ -723,7 +807,7 @@ app.whenReady().then(async () => {
await js(`(() => {
const button = Array.from(document.querySelectorAll('#libraryShelfList .library-filter'))
.find((candidate) => candidate.textContent.trim() === '界面书架已重命名');
.find((candidate) => candidate.firstElementChild.textContent.trim() === '界面书架已重命名');
button.click();
})()`);
await pollJs(
@@ -799,7 +883,7 @@ app.whenReady().then(async () => {
// 否则批量操作会误伤用户看不到的书
await js(`(() => {
const button = Array.from(document.querySelectorAll('#libraryShelfList .library-filter'))
.find((candidate) => candidate.textContent.trim() === '研究书架');
.find((candidate) => candidate.firstElementChild.textContent.trim() === '研究书架');
button.click();
})()`);
await pollJs(
+55
View File
@@ -335,6 +335,61 @@ test('批量移除只写一次索引,可选删除库内文件', () => {
assert.deepStrictEqual(store.removeMany(['missing'], false), { removed: 0 });
});
test('清理缺失条目时一并清理对应的空书架和标签', () => {
const root = freshRoot('remove-missing');
const emptyShelf = store.addShelf({ name: '仅缺失书籍分类' });
const sharedShelf = store.addShelf({ name: '仍在使用分类' });
const unrelatedShelf = store.addShelf({ name: '无关空分类' });
store.addTag({ name: '仅缺失书籍标签' });
store.addTag({ name: '仍在使用标签' });
store.addTag({ name: '无关空标签' });
const missingA = store.add({
title: '缺失 A',
shelfId: emptyShelf.id,
tags: ['仅缺失书籍标签', '仍在使用标签'],
files: [{ path: path.join(root, 'missing-a.pdf') }]
});
const missingB = store.add({
title: '缺失 B',
shelfId: sharedShelf.id,
tags: ['仍在使用标签'],
files: [{ path: path.join(root, 'missing-b.pdf') }]
});
const existingPath = path.join(root, 'existing.pdf');
fs.writeFileSync(existingPath, '%PDF-1.4\n');
const existing = store.add({
title: '仍存在',
shelfId: sharedShelf.id,
tags: ['仍在使用标签'],
files: [{ path: existingPath }]
});
const noFiles = store.add({ title: '无文件元数据', files: [] });
assert.deepStrictEqual(store.removeMissing(), {
removed: 2,
shelvesRemoved: 1,
tagsRemoved: 1
});
assert.strictEqual(store.get(missingA.id), null);
assert.strictEqual(store.get(missingB.id), null);
assert.ok(store.get(existing.id));
assert.ok(store.get(noFiles.id), '没有文件的元数据条目不应按文件缺失清理');
assert.deepStrictEqual(
store.listShelves().map((shelf) => shelf.name).sort(),
[sharedShelf.name, unrelatedShelf.name].sort()
);
assert.deepStrictEqual(
store.listTags().map((tag) => tag.name).sort(),
['仍在使用标签', '无关空标签'].sort()
);
assert.deepStrictEqual(store.removeMissing(), {
removed: 0,
shelvesRemoved: 0,
tagsRemoved: 0
});
});
test('explicit tag creation enforces the existing catalog limit', () => {
const root = freshRoot('limit');
const now = Date.now();
+13 -1
View File
@@ -73,7 +73,7 @@ test('下载校验协议,拒绝 file:// 等非 http(s)', () => {
test('下载请求使用可识别且带项目地址的 User-Agent', () => {
assert.match(mainSrc, /UA:\s*DL_UA[\s\S]+require\('\.\/src\/sources\/http'\)/);
const httpSrc = fs.readFileSync(path.join(__dirname, '..', 'sources', 'http.js'), 'utf8');
assert.match(httpSrc, /PeopleLib\/2\.1\.0 \(\+https:\/\/github\.com\/lofyer\/peoplelib\)/);
assert.match(httpSrc, /PeopleLib\/2\.1\.3 \(\+https:\/\/github\.com\/lofyer\/peoplelib\)/);
});
test('移除书籍默认保留阅读资料,仅显式勾选时清理', () => {
@@ -108,6 +108,18 @@ test('批量整理与移除走单次索引提交,不按条目循环 IPC', () =
'渲染层不应再逐条发 IPC');
});
test('重新扫描清理缺失条目前在主进程重新核对磁盘状态', () => {
const start = mainSrc.indexOf("ipcMain.handle('library:removeMissing'");
assert.ok(start > 0, '缺少文件缺失清理通道');
const end = mainSrc.indexOf('ipcMain.handle(', start + 20);
const segment = mainSrc.slice(start, end < 0 ? undefined : end);
assert.match(segment, /wrap\(async \(\) =>/);
assert.match(segment, /library\.list\(\)[\s\S]*\.filter\(\(item\) => item\.missing\)/);
assert.match(segment, /await requestReaderPurge\(id\)/);
assert.match(segment, /library\.removeMissing\(\)/);
assert.doesNotMatch(segment, /readerStore\.forget|annotations\.forget|aiSessions\.forget/);
});
test('孤立阅读资料只报告不自动删除,清理需分别勾选', () => {
const start = mainSrc.indexOf("ipcMain.handle('reader:orphanReport'");
assert.ok(start > 0, '缺少孤立资料对账通道');
+1 -1
View File
@@ -455,7 +455,7 @@ test('wikisource: 搜索使用整数偏移并携带可识别 User-Agent', async
assert.strictEqual(result.items[0].subtitle, '中文');
assert.strictEqual(result.maxPage, 500, 'MediaWiki 搜索最多允许偏移到 10000 条');
assert.ok(request.url.includes('sroffset=20'), request.url);
assert.match(request.options.headers['User-Agent'], /PeopleLib\/2\.1\.0/);
assert.match(request.options.headers['User-Agent'], /PeopleLib\/2\.1\.3/);
});
test('wikisource: 浏览按 continuation 令牌翻页', async () => {
+19
View File
@@ -613,6 +613,25 @@ test('书架 CRUD 强制唯一非空名称并返回深拷贝', () => {
assert.throws(() => store.updateShelf(other.id, { name: ' 文学 ' }), /已存在/);
});
test('书架列表返回每个分类当前包含的书籍数量', () => {
freshRoot('shelf-counts');
const research = store.addShelf('研究');
const archive = store.addShelf('归档');
const first = store.add({ title: 'A', shelfId: research.id });
store.add({ title: 'B', shelfId: research.id });
store.add({ title: '未分类' });
assert.deepStrictEqual(
store.listShelves().map((shelf) => [shelf.name, shelf.count]),
[['研究', 2], ['归档', 0]]
);
store.update(first.id, { shelfId: archive.id });
assert.deepStrictEqual(
store.listShelves().map((shelf) => [shelf.name, shelf.count]),
[['研究', 1], ['归档', 1]]
);
});
test('删除书架只清空条目 shelfId 且组织变更触发通知', () => {
freshRoot('shelf-remove');
let changes = 0;
+37
View File
@@ -165,6 +165,23 @@ test('书库页提供可管理标签目录和整理多选下拉', () => {
assert.doesNotMatch(library, /id="libraryBookTags" type="text"/);
});
test('全部书籍、未分类和每个书架都以内联括号显示实时数量', () => {
const html = fs.readFileSync(path.join(__dirname, '..', 'ui', 'index.html'), 'utf8');
const library = fs.readFileSync(libFile, 'utf8');
assert.match(
html,
/data-shelf="">[\s\S]*全部书籍[\s\S]*class="library-filter-count">0<\/span>/
);
assert.match(
html,
/data-shelf="__uncategorized__">[\s\S]*未分类[\s\S]*class="library-filter-count">0<\/span>/
);
assert.match(library, /items\.filter\(\(item\) => !item\.shelfId\)\.length/);
assert.match(library, /count\.textContent = `\$\{value\}`/);
assert.match(library, /count\.textContent = `\$\{shelf\.count \|\| 0\}`/);
assert.match(library, /filter\.append\(name, count\)/);
});
test('下载区接入全局任务中心且完成按钮使用高对比绿色底色', () => {
const html = fs.readFileSync(path.join(__dirname, '..', 'ui', 'index.html'), 'utf8');
const browse = fs.readFileSync(path.join(__dirname, '..', 'ui', 'views', 'browse.js'), 'utf8');
@@ -602,6 +619,15 @@ test('侧栏行内操作不占据布局,选中高亮与静态筛选项等宽',
assert.match(actionsRule[1], /position:\s*absolute/);
assert.doesNotMatch(css, /\.library-shelf-actions\s*\{\s*display:\s*flex;\s*flex:\s*none/);
assert.match(css, /\.library-shelf-row \.library-filter,\s*\n\.library-tag-row \.library-filter\s*\{[^}]*padding-right:\s*48px/);
// 分类数量紧跟名称显示为「分类(数量)」,不再像标签数量那样浮到右侧
assert.match(css, /#libraryTab \.library-filter\[data-shelf\] \.library-filter-count,\s*\n\.library-shelf-row \.library-filter-count\s*\{\s*float:\s*none/);
const actionButtons = css.match(
/\.library-shelf-actions \.notes-icon-btn,\s*\n\.library-tag-actions \.notes-icon-btn\s*\{([^}]*)\}/
);
assert.ok(actionButtons, '缺少侧栏操作按钮样式');
assert.match(actionButtons[1], /background:\s*transparent/);
assert.match(actionButtons[1], /border-color:\s*transparent/);
assert.match(css, /\.library-shelf-actions \.notes-icon-btn:hover,[\s\S]*?background:\s*transparent;[\s\S]*?border-color:\s*transparent/);
// 书架与标签共用同一个列表容器类,行间距不会一边有一边没有
assert.match(css, /\.library-filter-list\s*\{[^}]*gap:\s*1px/);
assert.match(html, /id="libraryShelfList" class="library-filter-list"/);
@@ -645,6 +671,17 @@ test('书库多选提供全选、批量整理与批量移除', () => {
assert.match(library, /window\.api\.library\.updateMany\(patches\)/);
});
test('重新扫描发现文件缺失后提示清理书库条目', () => {
const library = fs.readFileSync(libFile, 'utf8');
const preload = fs.readFileSync(path.join(__dirname, '..', '..', 'preload.js'), 'utf8');
assert.match(library, /const missing = Math\.max\(0, Number\(\(r\.data \|\| \{\}\)\.missing\)/);
assert.match(library, /confirmModal\(\s*'发现文件缺失'/);
assert.match(library, /对应分类和标签也会一并清理/);
assert.match(library, /笔记、书签、进度和标注会保留/);
assert.match(library, /window\.api\.library\.removeMissing\(\)/);
assert.match(preload, /removeMissing: \(\) => ipcRenderer\.invoke\('library:removeMissing'\)/);
});
test('卡片定位上下文不随多选状态消失', () => {
const css = fs.readFileSync(path.join(__dirname, '..', 'ui', 'style.css'), 'utf8');
// 退出多选是同步移除 class,重绘要等 IPC;若定位上下文只在 select-mode 下建立,
+39 -2
View File
@@ -494,7 +494,12 @@ function findBySource(sourceId, sourcePostId) {
function listShelves() {
load();
return shelves.map((shelf) => ({ ...shelf }));
const counts = new Map();
for (const item of items) {
if (!item.shelfId) continue;
counts.set(item.shelfId, (counts.get(item.shelfId) || 0) + 1);
}
return shelves.map((shelf) => ({ ...shelf, count: counts.get(shelf.id) || 0 }));
}
function listTags() {
@@ -978,6 +983,38 @@ function removeMany(ids, deleteFiles) {
return { removed: doomed.length };
}
function removeMissing() {
load();
const doomed = items.filter((item) => {
const files = item.files || [];
return files.length > 0 && files.every((file) => !fs.existsSync(toAbsolute(file.path)));
});
if (!doomed.length) return { removed: 0, shelvesRemoved: 0, tagsRemoved: 0 };
const ids = new Set(doomed.map((item) => item.id));
const candidateShelves = new Set(doomed.map((item) => item.shelfId).filter(Boolean));
const candidateTags = new Set(doomed.flatMap((item) => normalizeTags(item.tags).map(tagKey)));
const nextItems = items.filter((item) => !ids.has(item.id));
const usedShelves = new Set(nextItems.map((item) => item.shelfId).filter(Boolean));
const usedTags = new Set(nextItems.flatMap((item) => normalizeTags(item.tags).map(tagKey)));
const nextShelves = shelves.filter((shelf) => (
!candidateShelves.has(shelf.id) || usedShelves.has(shelf.id)
));
const nextTags = tags.filter((tag) => (
!candidateTags.has(tagKey(tag.name)) || usedTags.has(tagKey(tag.name))
));
const shelvesRemoved = shelves.length - nextShelves.length;
const tagsRemoved = tags.length - nextTags.length;
commit(nextItems, true, nextShelves, nextTags);
for (const item of doomed) removeCoverFile(item.id);
return {
removed: doomed.length,
shelvesRemoved,
tagsRemoved
};
}
function remove(id, deleteFiles) {
load();
const it = items.find((x) => x.id === id);
@@ -1311,7 +1348,7 @@ function importLegacy(legacyDir) {
module.exports = {
init, getRoot, filesDir, allocFilePath, sanitize,
list, get, findBySource, listShelves, listTags,
add, importLocal, update, updateMany, remove, removeMany, attachFile,
add, importLocal, update, updateMany, remove, removeMany, removeMissing, attachFile,
addShelf, updateShelf, removeShelf,
addTag, updateTag, removeTag,
scan, migrateTo, finalizeMigration, rollbackMigration, importLegacy,
+1 -1
View File
@@ -1,4 +1,4 @@
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36 PeopleLib/2.1.0 (+https://github.com/lofyer/peoplelib)';
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36 PeopleLib/2.1.3 (+https://github.com/lofyer/peoplelib)';
const { fetch: undiciFetch, ProxyAgent } = require('undici');
// 代理配置:默认直连(空字符串)。一旦设置,所有 HTTP 请求统一走该代理。
+6 -2
View File
@@ -69,8 +69,12 @@
<button id="addShelfBtn" class="notes-icon-btn" title="新建书架" aria-label="新建书架">+</button>
</div>
<div class="library-filter-list">
<button class="library-filter active" data-shelf="">全部书籍</button>
<button class="library-filter" data-shelf="__uncategorized__">未分类</button>
<button class="library-filter active" data-shelf="">
<span>全部书籍</span><span class="library-filter-count">0</span>
</button>
<button class="library-filter" data-shelf="__uncategorized__">
<span>未分类</span><span class="library-filter-count">0</span>
</button>
<div id="libraryShelfList" class="library-filter-list"></div>
</div>
<div class="library-sidebar-section">
+14 -1
View File
@@ -727,8 +727,21 @@ body {
.library-tag-row:hover .library-tag-actions,
.library-tag-row:focus-within .library-tag-actions { opacity: 1; pointer-events: auto; }
.library-shelf-actions .notes-icon-btn,
.library-tag-actions .notes-icon-btn { width: 22px; height: 22px; font-size: 12px; }
.library-tag-actions .notes-icon-btn {
width: 22px;
height: 22px;
background: transparent;
border-color: transparent;
font-size: 12px;
}
.library-shelf-actions .notes-icon-btn:hover,
.library-tag-actions .notes-icon-btn:hover {
background: transparent;
border-color: transparent;
}
.library-filter-count { float: right; color: var(--text-dim); }
#libraryTab .library-filter[data-shelf] .library-filter-count,
.library-shelf-row .library-filter-count { float: none; }
.library-content { min-width: 0; }
.library-search {
display: flex;
+49 -6
View File
@@ -84,9 +84,39 @@ const Library = (() => {
btn.disabled = true;
btn.textContent = '扫描中...';
const r = await window.api.library.scan();
btn.textContent = r.ok && r.data && r.data.added ? `新增 ${r.data.added} 本 ✓` : '已是最新 ✓';
if (!r || !r.ok) {
btn.textContent = '扫描失败';
await confirmModal('扫描失败', (r && r.error) || '未知错误');
setTimeout(() => { btn.textContent = '重新扫描'; btn.disabled = false; }, 2000);
return;
}
btn.textContent = r.data && r.data.added ? `新增 ${r.data.added} 本 ✓` : '已是最新 ✓';
dirty = true;
await refresh(true);
const missing = Math.max(0, Number((r.data || {}).missing) || 0);
if (missing) {
const clean = await confirmModal(
'发现文件缺失',
`扫描发现 ${missing} 条书库内容的文件均已缺失,是否从书库中清理这些条目?不再被其他书籍使用的对应分类和标签也会一并清理;笔记、书签、进度和标注会保留。`
);
if (clean) {
const removed = await window.api.library.removeMissing();
if (!removed || !removed.ok) {
await confirmModal('清理失败', (removed && removed.error) || '未知错误');
} else {
const count = Math.max(0, Number((removed.data || {}).removed) || 0);
const shelvesRemoved = Math.max(0, Number((removed.data || {}).shelvesRemoved) || 0);
const tagsRemoved = Math.max(0, Number((removed.data || {}).tagsRemoved) || 0);
const extras = [
shelvesRemoved ? `${shelvesRemoved} 个分类` : '',
tagsRemoved ? `${tagsRemoved} 个标签` : ''
].filter(Boolean);
btn.textContent = `已清理 ${count}${extras.length ? `${extras.join('、')}` : ''}`;
dirty = true;
await refresh(true);
}
}
}
setTimeout(() => { btn.textContent = '重新扫描'; btn.disabled = false; }, 2000);
}
@@ -342,10 +372,10 @@ const Library = (() => {
if (selectedShelf && selectedShelf !== '__uncategorized__'
&& !shelves.some((shelf) => shelf.id === selectedShelf)) selectedShelf = '';
if (selectedTag && !libraryTags.some((tag) => tag.name === selectedTag)) selectedTag = '';
renderOrganizationSidebar();
const allItems = res.data.slice();
renderOrganizationSidebar(allItems);
const noteCounts = noteCountsOf(noteCountResult);
const annotationCounts = noteCountsOf(annotationCountResult);
const allItems = res.data.slice();
const scopedItems = allItems.filter((item) => {
if (selectedShelf === '__uncategorized__' && item.shelfId) return false;
if (selectedShelf && selectedShelf !== '__uncategorized__' && item.shelfId !== selectedShelf) return false;
@@ -394,12 +424,20 @@ const Library = (() => {
refresh(true);
}
function renderOrganizationSidebar() {
function renderOrganizationSidebar(items) {
document.querySelectorAll('#libraryTab .library-filter[data-shelf]').forEach((button) => {
const shelfId = button.dataset.shelf || '';
button.classList.toggle(
'active',
!selectedTag && (button.dataset.shelf || '') === selectedShelf
!selectedTag && shelfId === selectedShelf
);
const count = button.querySelector('.library-filter-count');
if (count) {
const value = shelfId === '__uncategorized__'
? items.filter((item) => !item.shelfId).length
: items.length;
count.textContent = `${value}`;
}
});
const shelfList = $('libraryShelfList');
shelfList.textContent = '';
@@ -410,8 +448,13 @@ const Library = (() => {
filter.type = 'button';
filter.className = 'library-filter';
filter.classList.toggle('active', !selectedTag && selectedShelf === shelf.id);
filter.textContent = shelf.name;
filter.title = shelf.name;
const name = document.createElement('span');
name.textContent = shelf.name;
const count = document.createElement('span');
count.className = 'library-filter-count';
count.textContent = `${shelf.count || 0}`;
filter.append(name, count);
filter.onclick = () => selectShelf(shelf.id);
const actions = document.createElement('div');