分离主进程与渲染进程的功能,禁用remote模块
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
const { app } = require('electron')
|
||||
const { name: defaultName } = require('../../../package.json')
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
const { mainHandle } = require('../../common/ipc')
|
||||
|
||||
mainHandle('clearCache', async(event, options) => {
|
||||
if (!global.mainWindow) throw new Error('mainwindow is undefined')
|
||||
return global.mainWindow.webContents.session.clearCache()
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
const { mainHandle } = require('../../common/ipc')
|
||||
|
||||
mainHandle('getCacheSize', async(event, options) => {
|
||||
if (!global.mainWindow) throw new Error('mainwindow is undefined')
|
||||
return global.mainWindow.webContents.session.getCacheSize()
|
||||
})
|
||||
|
||||
@@ -4,3 +4,8 @@ require('./request')
|
||||
require('./progressBar')
|
||||
require('./trafficLight')
|
||||
require('./musicMeta')
|
||||
require('./selectDir')
|
||||
require('./setWindowSize')
|
||||
require('./showSaveDialog')
|
||||
require('./clearCache')
|
||||
require('./getCacheSize')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
const { setMeta } = require('../utils/musicMeta')
|
||||
|
||||
mainOn('setMusicMeta', (event, { filePath, meta }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
|
||||
mainOn('progress', (event, params) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const request = require('request')
|
||||
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
const tasks = []
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
|
||||
mainOn('restartWindow', (event, name) => {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
const { mainHandle } = require('../../common/ipc')
|
||||
const { dialog } = require('electron')
|
||||
|
||||
mainHandle('selectDir', async(event, options) => {
|
||||
if (!global.mainWindow) throw new Error('mainwindow is undefined')
|
||||
return dialog.showOpenDialog(global.mainWindow, options)
|
||||
})
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { dialog } = require('electron')
|
||||
|
||||
module.exports = win => {
|
||||
mainOn('selectPath', (event, params) => {
|
||||
let path = dialog.showOpenDialog(win, params.options)
|
||||
if (path === undefined) return
|
||||
event.sender.send(params.eventName, path)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
mainOn('setWindowSize', (event, options) => {
|
||||
if (!global.mainWindow) return
|
||||
global.mainWindow.setBounds(options)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
const { mainHandle } = require('../../common/ipc')
|
||||
const { dialog } = require('electron')
|
||||
|
||||
mainHandle('showSaveDialog', async(event, options) => {
|
||||
if (!global.mainWindow) throw new Error('mainwindow is undefined')
|
||||
return dialog.showSaveDialog(global.mainWindow, options)
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// const { app } = require('electron')
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
|
||||
mainOn('min', event => {
|
||||
@@ -7,11 +7,11 @@ mainOn('min', event => {
|
||||
global.mainWindow.minimize()
|
||||
}
|
||||
})
|
||||
// mainOn('max', event => {
|
||||
// if (global.mainWindow) {
|
||||
// global.mainWindow.maximize()
|
||||
// }
|
||||
// })
|
||||
mainOn('max', event => {
|
||||
if (global.mainWindow) {
|
||||
global.mainWindow.maximize()
|
||||
}
|
||||
})
|
||||
mainOn('close', event => {
|
||||
if (global.mainWindow) {
|
||||
// global.mainWindowdow.destroy()
|
||||
|
||||
@@ -50,6 +50,7 @@ function createWindow() {
|
||||
width: windowSizeInfo.width,
|
||||
frame: false,
|
||||
transparent: !isLinux,
|
||||
enableRemoteModule: false,
|
||||
// icon: path.join(global.__static, isWin ? 'icons/256x256.ico' : 'icons/512x512.png'),
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { log } = require('../../common/utils')
|
||||
const { autoUpdater } = require('electron-updater')
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
autoUpdater.logger = log
|
||||
// autoUpdater.autoDownload = false
|
||||
@@ -21,7 +21,7 @@ log.info('App starting...')
|
||||
|
||||
function sendStatusToWindow(text) {
|
||||
log.info(text)
|
||||
// global.mainWindow.webContents.send('message', text)
|
||||
// ipcMain.send('message', text)
|
||||
}
|
||||
|
||||
|
||||
@@ -90,16 +90,20 @@ module.exports = isFirstCheckedUpdate => {
|
||||
sendStatusToWindow('Update not available.')
|
||||
handleSendEvent({ type: 'update-not-available' })
|
||||
})
|
||||
autoUpdater.on('error', () => {
|
||||
autoUpdater.on('error', err => {
|
||||
sendStatusToWindow('Error in auto-updater.')
|
||||
handleSendEvent({ type: 'update-error' })
|
||||
handleSendEvent({ type: 'update-error', info: err })
|
||||
})
|
||||
autoUpdater.on('download-progress', progressObj => {
|
||||
sendStatusToWindow('Download progress...')
|
||||
let log_message = 'Download speed: ' + progressObj.bytesPerSecond
|
||||
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'
|
||||
log_message = log_message + ' (' + progressObj.transferred + '/' + progressObj.total + ')'
|
||||
sendStatusToWindow(log_message)
|
||||
handleSendEvent({ type: 'download-progress', info: progressObj })
|
||||
})
|
||||
autoUpdater.on('update-downloaded', info => {
|
||||
sendStatusToWindow('Update downloaded.')
|
||||
handleSendEvent({ type: 'update-downloaded' })
|
||||
handleSendEvent({ type: 'update-downloaded', info })
|
||||
})
|
||||
mainOn('quit-update', () => {
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user