node-ddk 文件协议
https://blog.csdn.net/eli960/article/details/146207062
也可以下载demo直接演示
http://linuxmail.cn/go#node-ddk
安全
考虑到安全, 本系统禁止使用 file:///
在主窗口, 自定义文件协议,可以多个
import main, { NODEDDK } from "node-ddk/main"
main.protocol.registerFileProtocol({
protocol: "myfile",
realpath: async (options: NODEDDK.FileProtocolRealpathOptions) => {
// 根据options 返回 实际的文件路径
return "/opt/data/image/789.png"
}
})
在渲染进程, 可以这么访问
<img src="myile://xxx/linuxmail.cn/vvv/123.some.png">
用操作系统默认程序打开文件
import renderer, { NODEDDK } from "node-ddk/renderer"
// 用浏览器打开网址
renderer.shell.openUrl({ url: "https://www.baidu.com/" })
// 用默认程序打开系统文件
renderer.shell.openLocalFile({ path: "/etc/resolv.conf" })
是否应该打开这些网址和本地文件, 可以由界面端控制.
也可以调用主进程限制逻辑. 默认拒绝全部操作
// 检查需要用浏览器打开的地址, 默认拒绝
main.shell.registerOpenUrlChecker(async (attrs: NODEDDK.OpenUrlOptions) => {
let url = attrs.url
if (url.indexOf("qiandu.com") > -1) {
return false
}
return true
})
// 检查需要用本地程序打开的文件, 默认拒绝
main.shell.registerOpenLocalFileChecker(async (attrs: NODEDDK.OpenLocalFileOptions) => {
let path = attrs.path
if (path.endsWith(".exe")) {
return false
}
return true
})