dsh-sidebar-open-with-app
Đã xác minhdsh-sidebar-open-with-app · v0.2.0 · MIT · Giao diện web
DSH web 插件:为 better-sidebar 的 Office 预览(.docx/.xlsx/.pptx)加「用系统默认程序打开」按钮,并内置 pdf.js 为 PDF 提供内嵌预览。宿主侧注册 /sidebar-open-with-app/open 路由。
Cài đặt
dsh plugin add dsh-sidebar-open-with-app Xác nhận layer đã áp bằng dsh --profile default --dump-config — xem hướng dẫn cài plugin.
Mã nguồn
Phát hành lên npm mà không có repository công khai. Hãy kiểm tra nội dung package trước khi cài.
Thẻ
Tác giả
Readme
dsh-sidebar-open-with-app
DSH web 插件:为 better-sidebar 的文件预览增强——
.docx/.xlsx/.pptx:顶部加「用系统默认程序打开」按钮(点击用本机默认程序如 WPS 打开),并把预览委托给 Office 预览插件。.pdf:用 pdf.js 内嵌渲染(分页浏览),顶部同样有「用系统默认程序打开」按钮。
原理
- 宿主侧:注册一个受信任围栏(loopback + 同源)保护的
/sidebar-open-with-app/open路由,用系统命令(macOSopen/ Windowsstart/ Linuxxdg-open)打开传入的绝对路径。 - 客户端侧:通过公开 API
ctx.betterSidebar.registerFileViewer注册 4 个 viewer(priority 10):open-with-app:docx/xlsx/pptx:顶部按钮 + 把预览委托给 Office 预览插件(@huanlin/dsh-plugin-better-sidebar-plugin-office)的同扩展名 viewer;open-with-app:pdf:pdf.js(打进本插件 bundle)内嵌渲染。DSH 桌面应用(Electron)没开原生 PDF 查看器(webPreferences.plugins未设),所以 iframe 无法渲染 PDF,这里改用 pdf.js 的 canvas 渲染,绕开该限制。
这样既保留了内嵌预览,又提供「用系统默认程序打开」,且不修改 dsh-better-sidebar 的 node_modules —— dsh plugin update 不会抹掉它。
依赖
dsh-better-sidebar >= 0.6.0(提供ctx.betterSidebar服务)。- 可选:
@huanlin/dsh-plugin-better-sidebar-plugin-office(提供 docx/xlsx/pptx 内嵌预览;不装则只显示打开按钮 + 提示)。 pdfjs-dist(打进 bundle,运行时无需额外安装)。
安装
从 npm 安装(推荐):
dsh plugin --profile desktop add dsh-sidebar-open-with-app
dsh plugin add 会自动写入 profile 依赖并追加 cordis 插入条目,无需手动改配置。装完完全退出并重启 DSH Desktop 应用。
本地开发(link:,改代码即生效):
cd ~/.dsh/profiles/desktop
pnpm add "link:<本仓库本地路径>"
# 并在 ~/.dsh/profiles/desktop/cordis.patch.yml 手动追加:
# - insert:
# - id: dsh-sidebar-open-with-app
# name: 'dsh-sidebar-open-with-app'
构建
客户端 bundle 由 tsdown 打包(把 pdf.js 内联进 lib/client.js):
pnpm install
pnpm build
与 better-sidebar 的差异
- 该插件不提供右键菜单「用系统默认程序打开」——那是 better-sidebar 的内部 UI,没有公开钩子。改为预览页顶部按钮。
- PDF 预览不依赖 Electron 原生查看器,走 pdf.js。