用于mock后端接口,不用连接任何外部网,无需安装任何其他依赖,双击exe文件即可开始使用!
ApiFox需要登录,而登录就需要外网,而本人所处环境,外网访问受限
coder_pan
https://gitee.com/free_pan/electron-easy-mock
src/preload/index.js
import { contextBridge, ipcRenderer } from 'electron'
// 通过contextBridge.exposeInMainWorld向浏览器中注册对象,js通过调用该对象中的方法间接向主进程发送事件
contextBridge.exposeInMainWorld('electron', {
restart:()=>{
// 向主进程发送事件
ipcRenderer.invoke('restart')
},
sendMsg: (msg: string): Promise<string> => ipcRenderer.invoke('msg', msg),
onReplyMsg: (cb: (msg: string) => any) =>
ipcRenderer.on('reply-msg', (e, msg: string) => {
cb(msg)
}),
})
// window.electron 是自行注册的通信桥对象
const { restart } = window.electron
// 调用通信桥对象中的方法,由桥方法向electron主进程发送事件
restart()
import { app, ipcMain } from 'electron'
const win = new BrowserWindow({
width: 1024,
height: 768,
autoHideMenuBar: true,
webPreferences: {
contextIsolation: true,
preload: join(__dirname, '../preload/index.js'),
},
})
ipcMain.handle('restart', () => {
// 调用relaunch方法不会真正重启(但必须调用,相当于告诉exit方法,我这次不是直接退出,而是要重启)
app.relaunch()
// 调用exit,才会退出然后重启(如果不调用relaunch方法,直接就是exit,那么就只是退出,而不是重启)
app.exit()
})
electron builder打包时,出现errorOut=ERROR: Cannot create symbolic link
doubleshot: 用于整合 vite 与 electron的插件
windows下,electron安装better-sqlite3并编译
Electron 中安装Better-sqlite3遇到的问题总结
By default, it writes logs to the following locations:
on Linux: ~/.config/{app name}/logs/main.log
on macOS: ~/Library/Logs/{app name}/main.log
on Windows: %USERPROFILE%\AppData\Roaming\{app name}\logs\main.log
import log from 'electron-log/main'
// Optional, initialize the logger for any renderer process
log.initialize()
log.info('Log from the main process')
import log from 'electron-log/renderer'
log.info('Log from the renderer process')
只会打包dependencies
中的依赖,所以非必要以来请放到devDependencies
中
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。