//主进程 const {app,BrowserWindow,ipcMain} = require('electron') //引入定义electron,且调用模块 //ipcMain为调用通信模块(主进程) const path = require('path') //引入定义path const fs = require('fs') const filePath = 'F:/' //定义一个函数(写入文件) function wirteFile (_,data){ fs.writeFileSync(filePath,data) //定义函数名为res,写入对应文件,data为写入内容 } //定义一个新函数(创建窗口) function createWindow(){ const win = new BrowserWindow({ width:1150, height:750, autoHideMenuBar:true, //自动隐藏菜单栏 webPreferences:{ preload:path.resolve(__dirname,'./preload.js'), devTools:false }, //绑定中间人:预加载进程 frame: false, }) win.loadFile('./pages/index.html') //加载窗口文件 ipcMain.on('close-main-window', () => { win.close(); }); ipcMain.on('toggle-full-screen', () => { if (win.isFullScreen()) { win.setFullScreen(false); } else { win.setFullScreen(true); } }); ipcMain.on('minimize-window', ()=>{ win.minimize(); }) } function createTodolist(){ const win = new BrowserWindow({ width:1150, height:750, autoHideMenuBar:false, webPreferences:{ preload:path.resolve(__dirname,'./preload.js') }, //绑定中间人:预加载进程 frame: true }) win.loadURL('https://www.dida365.com/webapp/#q/today/tasks') //加载窗口URL }; function createAddnewDiary(){ const newAdd = new BrowserWindow({ width:950, height:850, autoHideMenuBar:true, webPreferences:{ preload:path.resolve(__dirname,'./preload.js') }, //绑定中间人:预加载进程 frame: true, icon:'./head.ico', }) newAdd.loadFile('./pages/diary/new-diary.html') //加载窗口文件 } function createClassimg(){ const newAdd = new BrowserWindow({ width:1200, height:880, autoHideMenuBar:true, webPreferences:{ preload:path.resolve(__dirname,'./preload.js') }, //绑定中间人:预加载进程 frame: true, icon:'./head.ico', }) newAdd.loadFile('./pages/classimg.html') //加载窗口文件 } ipcMain.on('open-class-img', ()=>{ createClassimg() console.log('Classimg has opened.') }) ipcMain.on('new-diary', ()=>{ createAddnewDiary() console.log('AddnewDiary is running.') }) ipcMain.on('open-todolist',()=>{ createTodolist() console.log('Todolist is running.') }) app.on('ready',()=>{ createWindow() console.log('App is Running.') }) app.on('window-all-closed', () => { if(process.platform !=='darwin') app.quit() })