Browse Source

fix: 🐛 修复electron使用loadFile方式加载项目时未记住用户登录信息的问题

main
yonghang 1 year ago
parent
commit
620de73aa8
  1. 15
      main.js

15
main.js

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow ,dialog} = require('electron')
const { app, BrowserWindow ,dialog, globalShortcut} = require('electron')
const { execSync } = require('child_process');
const path = require('node:path')
@ -22,6 +22,7 @@ function createWindow () {
//mainWindow.loadFile('index.html')
// window.isElectron = true;
mainWindow.loadFile('./dist/index.html')
// mainWindow.loadURL('http://localhost:8888/')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
@ -47,6 +48,16 @@ function createWindow () {
mainWindow.on('closed', () => {
app.quit() // 关闭应用程序
})
// 注册快捷键
// mainWindow.on('focus', () => {
// globalShortcut.register('CommandOrControl+Alt+F', function () {
// mainWindow && mainWindow.webContents.toggleDevTools()
// })
// })
// mainWindow.on('blur', () => {
// globalShortcut.unregisterAll() // 注销键盘事件
// })
}
/**
@ -54,7 +65,7 @@ function createWindow () {
 */
function clearCache(mainWindow) {
// 在窗口即将关闭时清除 localStorage 和 sessionStorage
mainWindow.webContents.executeJavaScript('localStorage.clear();')
mainWindow.webContents.executeJavaScript('localStorage.removeItem("Admin-Token");')
mainWindow.webContents.executeJavaScript('sessionStorage.clear();')
}
// This method will be called when Electron has finished

Loading…
Cancel
Save