CyberExam2-front/main.js
2024-12-03 01:03:00 +08:00

55 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const {app, BrowserWindow, ipcMain} = require('electron')
const path = require('path')
const fs = require('fs')
function writeFile(event, data){
console.log(data)
fs.writeFileSync('E:/hello.txt', data)
}
function readFile(){
const res = fs.readFileSync('E:/hello.txt').toString()
console.log('###', res)
return res
}
//创建窗口函数
function createWindow(){
//创建窗口
const win = new BrowserWindow({
//指定窗口大小
width: 1200,
height: 900,
//指定窗口位置
// x: 0, y: 0,
// alwaysOnTop: true,
//加载窗口选项
webPreferences:{
//预加载进程必须传入绝对路径所以使用path.resolve
preload:path.resolve(__dirname, './preload.js')
},
//隐藏菜单栏
autoHideMenuBar: true
})
ipcMain.on('file-save', writeFile)
ipcMain.handle('file-read', readFile)
//加载主页面
win.loadFile('./pages/index.html')
}
//启动调用
app.on('ready', ()=>{
createWindow()
//针对mac用户的无窗口时继续运行点击图标创建窗口有
app.on('activate', ()=>{
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
console.log('启动完毕')
})
//对于非mac用户无窗口时立即退出程序。
app.on('window-all-closed', ()=>{
if (process.platform !== 'darwin') app.quit()
})