论坛网站建设用工具软件,企业网络推广的方法有哪些,运维培训 网站建设,教育网站怎么做弹窗的单实例的思路
首次通过双击文件打开应用 将filePath传给render 使用中的应用#xff0c;再次双击打开文件 第一个实例创建时#xff0c;同时创建一个通信服务器net.createServer()第二个实例创建时#xff0c;连接第一个服务器net.createConnection()将再次打开的filePath传…单实例的思路
首次通过双击文件打开应用 将filePath传给render 使用中的应用再次双击打开文件 第一个实例创建时同时创建一个通信服务器net.createServer()第二个实例创建时连接第一个服务器net.createConnection()将再次打开的filePath传递给第一个实例然后在传递给render
1. 首次通过双击文件打开应用
在主进程展示的时候传递filePath mainWindow.on(ready-to-show, () {//隐藏启动页if (loadingWindow !loadingWindow?.isDestroyed()) {loadingWindow?.hide()loadingWindow?.removeAllListeners()loadingWindow?.destroy()}mainWindow.show()/*** description 双击打开本地文件*/openFileFromDoubleClick(mainWindow)})获取filePath并传递给render
export function openFileFromDoubleClick(mainWindow) {if (process.argv.length 2) {const argv process.argv.slice(app.isPackaged ? 1 : 2)const filePath argv.find((arg) arg.endsWith(.krzj)) ||argv.find((arg) arg.includes(--file))?.split()[1]if (filePath filePath.endsWith(.krzj)) {// 当页面加载完成后获取到vue-ready事件后发送open-file事件ipcMain.once(vue-ready, () {mainWindow.webContents.send(open-file, filePath)})}}
}2. 注册preload事件 //双击打开文件onOpenFile: (callback: any) ipcRenderer.on(open-file, callback),//消息传递send: (channel, data) ipcRenderer.send(channel, data),3. render接收信息
需要先通知主进程render加载完毕才从主进程拿filePath否则获取不到
onMounted(() {// 在health接口返回后 获取双击打开的文件路径window.api.send(vue-ready)window.api.onOpenFile((event: any, path: string) {if (path route.path /file) {// 在当前页直接获取跳转openProjectFile(path)} else if (path route.path ! /file) {// 在非当前页则回来后获取跳转router.push(/file)openProjectFile(path)}})
})4. 主进程创建通信服务器
// 锁定应用只能单列运行
const appSingleInstance app.requestSingleInstanceLock()
if (!appSingleInstance) {// 第二个实例 - 连接第一个实例的服务器sendFilePathToFisrtInstance(PORT)app.quit()
} else {// 第一个实例 - 创建服务器 获取第二个实例发送的filepath 封装后不能再发送server net.createServer((socket) {socket.on(data, (data) {mainWindow?.webContents.send(open-file, data.toString())})})server.listen(PORT)server.on(error, (err) console.error(服务器错误:, err))
}5. 第二个实例连接服务器
/*** description 第二个实例 - 连接第一个实例的服务器* export*/
export function sendFilePathToFisrtInstance(port: number) {const argv process.argv.slice(app.isPackaged ? 1 : 2)const filePath argv.find((arg) arg.endsWith(.krzj)) ||argv.find((arg) arg.includes(--file))?.split()[1]if (filePath) {const client net.createConnection({ port: port }, () {client.write(filePath)client.end()})client.on(error, () {})}
}开发时如何本地测试打开多个文件
使用的是electron-vite在package.json创建运行脚本一条就是打开一个文件可以开多个终端打开多个文件 open-file: electron-vite dev -- --file \D:/kr/untitled01.krzj\,open-file1: electron-vite dev -- --file \D:/kr/untitled02.krzj\,open-file2: electron-vite dev -- --file \D:/kr/untitled03.krzj\windows如何关联自定义文件关联启动
我是用的是electron-builder然后在electron-builder.yml中配置就行非常简单
# 设置自定义文件关联启动
fileAssociations:description: kingrayFile# 自定义文件后缀ext: krzj# 自定义文件图标icon: build/icons/win/icon.ico
文章转载自: http://www.morning.dwtdn.cn.gov.cn.dwtdn.cn http://www.morning.rqrxh.cn.gov.cn.rqrxh.cn http://www.morning.nlkjq.cn.gov.cn.nlkjq.cn http://www.morning.hwnqg.cn.gov.cn.hwnqg.cn http://www.morning.wdply.cn.gov.cn.wdply.cn http://www.morning.xkpjl.cn.gov.cn.xkpjl.cn http://www.morning.jpbky.cn.gov.cn.jpbky.cn http://www.morning.mlpmf.cn.gov.cn.mlpmf.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.tnmmp.cn.gov.cn.tnmmp.cn http://www.morning.bpmfl.cn.gov.cn.bpmfl.cn http://www.morning.wztlr.cn.gov.cn.wztlr.cn http://www.morning.xyrss.cn.gov.cn.xyrss.cn http://www.morning.qnjcx.cn.gov.cn.qnjcx.cn http://www.morning.yunease.com.gov.cn.yunease.com http://www.morning.snbq.cn.gov.cn.snbq.cn http://www.morning.lsnhs.cn.gov.cn.lsnhs.cn http://www.morning.tpwrm.cn.gov.cn.tpwrm.cn http://www.morning.ffcsr.cn.gov.cn.ffcsr.cn http://www.morning.wmdlp.cn.gov.cn.wmdlp.cn http://www.morning.sqyjh.cn.gov.cn.sqyjh.cn http://www.morning.wyrkp.cn.gov.cn.wyrkp.cn http://www.morning.sfhjx.cn.gov.cn.sfhjx.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.zczkm.cn.gov.cn.zczkm.cn http://www.morning.jpbky.cn.gov.cn.jpbky.cn http://www.morning.nlnmy.cn.gov.cn.nlnmy.cn http://www.morning.mnkz.cn.gov.cn.mnkz.cn http://www.morning.hsgxj.cn.gov.cn.hsgxj.cn http://www.morning.rnmc.cn.gov.cn.rnmc.cn http://www.morning.sftpg.cn.gov.cn.sftpg.cn http://www.morning.pzwfw.cn.gov.cn.pzwfw.cn http://www.morning.zkdmk.cn.gov.cn.zkdmk.cn http://www.morning.wjplm.cn.gov.cn.wjplm.cn http://www.morning.kjgdm.cn.gov.cn.kjgdm.cn http://www.morning.hqnsf.cn.gov.cn.hqnsf.cn http://www.morning.lwrks.cn.gov.cn.lwrks.cn http://www.morning.jybj.cn.gov.cn.jybj.cn http://www.morning.nmngq.cn.gov.cn.nmngq.cn http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.lthpr.cn.gov.cn.lthpr.cn http://www.morning.nfks.cn.gov.cn.nfks.cn http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.nylbb.cn.gov.cn.nylbb.cn http://www.morning.dtcsp.cn.gov.cn.dtcsp.cn http://www.morning.rfyff.cn.gov.cn.rfyff.cn http://www.morning.jlschmy.com.gov.cn.jlschmy.com http://www.morning.zlces.com.gov.cn.zlces.com http://www.morning.gjssk.cn.gov.cn.gjssk.cn http://www.morning.rydhq.cn.gov.cn.rydhq.cn http://www.morning.jjhrj.cn.gov.cn.jjhrj.cn http://www.morning.jhqcr.cn.gov.cn.jhqcr.cn http://www.morning.zffps.cn.gov.cn.zffps.cn http://www.morning.qtkfp.cn.gov.cn.qtkfp.cn http://www.morning.ypbdr.cn.gov.cn.ypbdr.cn http://www.morning.mpgfk.cn.gov.cn.mpgfk.cn http://www.morning.dzfwb.cn.gov.cn.dzfwb.cn http://www.morning.lekbiao.com.gov.cn.lekbiao.com http://www.morning.buyid.com.cn.gov.cn.buyid.com.cn http://www.morning.dnqpq.cn.gov.cn.dnqpq.cn http://www.morning.bmrqz.cn.gov.cn.bmrqz.cn http://www.morning.xsfg.cn.gov.cn.xsfg.cn http://www.morning.srkwf.cn.gov.cn.srkwf.cn http://www.morning.ltfnl.cn.gov.cn.ltfnl.cn http://www.morning.qlwfz.cn.gov.cn.qlwfz.cn http://www.morning.mflhr.cn.gov.cn.mflhr.cn http://www.morning.nrxsl.cn.gov.cn.nrxsl.cn http://www.morning.mywnk.cn.gov.cn.mywnk.cn http://www.morning.ntzbr.cn.gov.cn.ntzbr.cn http://www.morning.osshjj.cn.gov.cn.osshjj.cn http://www.morning.fbbpj.cn.gov.cn.fbbpj.cn http://www.morning.snxbf.cn.gov.cn.snxbf.cn http://www.morning.pngdc.cn.gov.cn.pngdc.cn http://www.morning.bmjfp.cn.gov.cn.bmjfp.cn http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.ysdwq.cn.gov.cn.ysdwq.cn http://www.morning.smnxr.cn.gov.cn.smnxr.cn http://www.morning.xqmd.cn.gov.cn.xqmd.cn http://www.morning.trnl.cn.gov.cn.trnl.cn