Files
peoplelib/preload.js
T
lofyerandfactory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> b8c8d24107 feat: 完善本地书库与发布更新流程
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-07-28 21:55:16 +08:00

54 lines
2.7 KiB
JavaScript

const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('api', {
sources: {
list: () => ipcRenderer.invoke('sources:list'),
browse: (sourceId, page) => ipcRenderer.invoke('source:list', sourceId, page),
search: (sourceId, keyword, page) => ipcRenderer.invoke('source:search', sourceId, keyword, page),
detail: (sourceId, postId) => ipcRenderer.invoke('source:detail', sourceId, postId),
download: (sourceId, postId) => ipcRenderer.invoke('source:download', sourceId, postId)
},
library: {
list: () => ipcRenderer.invoke('library:list'),
get: (id) => ipcRenderer.invoke('library:get', id),
findBySource: (sourceId, postId) => ipcRenderer.invoke('library:findBySource', sourceId, postId),
add: (item) => ipcRenderer.invoke('library:add', item),
update: (id, patch) => ipcRenderer.invoke('library:update', id, patch),
remove: (id, deleteFiles) => ipcRenderer.invoke('library:remove', id, deleteFiles),
getDir: () => ipcRenderer.invoke('library:getDir'),
pickDir: () => ipcRenderer.invoke('library:pickDir'),
setDir: (dir, migrate) => ipcRenderer.invoke('library:setDir', dir, migrate),
scan: () => ipcRenderer.invoke('library:scan'),
onChanged: (cb) => ipcRenderer.on('library:changed', () => cb())
},
settings: {
get: (key, def) => ipcRenderer.invoke('settings:get', key, def),
set: (key, value) => ipcRenderer.invoke('settings:set', key, value)
},
downloadFile: (url, suggestName, entryId, extraHeaders, meta) => ipcRenderer.invoke('download:file', url, suggestName, entryId, extraHeaders, meta),
zlib: {
hasCreds: () => ipcRenderer.invoke('zlib:hasCreds'),
login: (email, password) => ipcRenderer.invoke('zlib:login', email, password),
logout: () => ipcRenderer.invoke('zlib:logout')
},
semanticScholar: {
keyStatus: () => ipcRenderer.invoke('semanticScholar:keyStatus'),
setKey: (key) => ipcRenderer.invoke('semanticScholar:setKey', key),
clearKey: () => ipcRenderer.invoke('semanticScholar:clearKey')
},
proxy: {
get: () => ipcRenderer.invoke('proxy:get'),
set: (url) => ipcRenderer.invoke('proxy:set', url)
},
pickFile: () => ipcRenderer.invoke('dialog:pickFile'),
openPath: (p) => ipcRenderer.invoke('shell:openPath', p),
showItem: (p) => ipcRenderer.invoke('shell:showItem', p),
openExternal: (url) => ipcRenderer.invoke('shell:openExternal', url),
copy: (text) => ipcRenderer.invoke('copy', text),
getVersion: () => ipcRenderer.invoke('app:version'),
checkUpdate: () => ipcRenderer.invoke('app:checkUpdate'),
minimize: () => ipcRenderer.send('win:minimize'),
maximize: () => ipcRenderer.send('win:maximize'),
close: () => ipcRenderer.send('win:close')
});