const path = require('path') const { app, BrowserWindow, ipcMain, dialog, globalShortcut } = require('electron') const WinState = require('electron-win-state').default // 主进程 const createWindow = () => { const winState = new WinState({ defaultWidth: 800, defaultHeight: 600 // other winState options, see below }) const win = new BrowserWindow({ ...winState.winOptions, backgroundColor: '#6435c9', webPreferences: { // dirname当前入口文件的绝对物理路径+相对路径 preload: path.resolve(__dirname, './preload.js') } }) const wc = win.webContents //全部加载完毕 wc.on('did-finish-load', () => { console.log('Conent fully loaded') }) //dom加载完毕 wc.on('dom-ready', () => { console.log('DOM Ready') }) //鼠标右键,保存图片 wc.on('context-menu', (e, params) => { // console.log(params) //------------------------------------------------------- // dialog // .showOpenDialog({ // buttonLabel: '选择', // defaultPath: app.getPath('desktop'), // properties: [ // 'multiSelections', // 'createDirectory', // 'openFile', // 'openDirectory' // ] // }) // .then((result) => { // // console.log(result.filepaths) // console.log(result) // }) //------------------------------------------------------- // dialog.showSaveDialog({}).then((result) => { // console.log(result.filePath) // }) //------------------------------------------------------- const answers = ['Yes', 'No', 'Maybe'] dialog .showMessageBox({ title: 'Message Box', //标题 message: 'Please select an option', //解析作用 detail: 'Message details.', buttons: answers }) .then(({ response }) => { console.log(`User selected: ${answers[response]}`) })
//------------------------------------------------------- // wc.executeJavaScript(`alert('${params.selectionText}')`) }) wc.openDevTools() win.loadFile('./index.html') winState.manage(win) // globalShortcut.register('G', () => { // console.log('user') // }) //-------------------------------- globalShortcut.register('CommandOrControl+Y', () => { console.log('user') globalShortcut.unregister('CommandOrControl+Y') }) }
|