Cleanup init.js

This commit is contained in:
Cheng Zhao 2016-08-02 17:45:46 +09:00
parent 8f62e79243
commit 892026458d

View file

@ -65,7 +65,7 @@ process.on('uncaughtException', function (error) {
}) })
// Emit 'exit' event on quit. // Emit 'exit' event on quit.
var app = require('electron').app const {app} = require('electron')
app.on('quit', function (event, exitCode) { app.on('quit', function (event, exitCode) {
process.emit('exit', exitCode) process.emit('exit', exitCode)
@ -86,15 +86,12 @@ if (process.platform === 'win32') {
// form `com.squirrel.PACKAGE-NAME.OUREXE`. We need to call // form `com.squirrel.PACKAGE-NAME.OUREXE`. We need to call
// app.setAppUserModelId with a matching identifier so that renderer processes // app.setAppUserModelId with a matching identifier so that renderer processes
// will inherit this value. // will inherit this value.
var updateDotExe = path.join( const updateDotExe = path.join(path.dirname(process.execPath), '..', 'update.exe')
path.dirname(process.execPath),
'..',
'update.exe')
if (fs.statSyncNoException(updateDotExe)) { if (fs.existsSync(updateDotExe)) {
var packageDir = path.dirname(path.resolve(updateDotExe)) const packageDir = path.dirname(path.resolve(updateDotExe))
var packageName = path.basename(packageDir).replace(/\s/g, '') const packageName = path.basename(packageDir).replace(/\s/g, '')
var exeName = path.basename(process.execPath).replace(/\.exe$/i, '').replace(/\s/g, '') const exeName = path.basename(process.execPath).replace(/\.exe$/i, '').replace(/\s/g, '')
app.setAppUserModelId(`com.squirrel.${packageName}.${exeName}`) app.setAppUserModelId(`com.squirrel.${packageName}.${exeName}`)
} }
@ -108,15 +105,13 @@ require('./rpc-server')
// Load the guest view manager. // Load the guest view manager.
require('./guest-view-manager') require('./guest-view-manager')
require('./guest-window-manager') require('./guest-window-manager')
// Now we try to load app's package.json. // Now we try to load app's package.json.
var packageJson = null let packagePath = null
var searchPaths = ['app', 'app.asar', 'default_app.asar'] let packageJson = null
var i, len, packagePath const searchPaths = ['app', 'app.asar', 'default_app.asar']
for (i = 0, len = searchPaths.length; i < len; i++) { for (packagePath of searchPaths) {
packagePath = searchPaths[i]
try { try {
packagePath = path.join(process.resourcesPath, packagePath) packagePath = path.join(process.resourcesPath, packagePath)
packageJson = require(path.join(packagePath, 'package.json')) packageJson = require(path.join(packagePath, 'package.json'))
@ -157,14 +152,9 @@ if (packageJson.v8Flags != null) {
v8.setFlagsFromString(packageJson.v8Flags) v8.setFlagsFromString(packageJson.v8Flags)
} }
// Chrome 42 disables NPAPI plugins by default, reenable them here
app.commandLine.appendSwitch('enable-npapi')
// Set the user path according to application's name. // Set the user path according to application's name.
app.setPath('userData', path.join(app.getPath('appData'), app.getName())) app.setPath('userData', path.join(app.getPath('appData'), app.getName()))
app.setPath('userCache', path.join(app.getPath('cache'), app.getName())) app.setPath('userCache', path.join(app.getPath('cache'), app.getName()))
app.setAppPath(packagePath) app.setAppPath(packagePath)
// Load the chrome extension support. // Load the chrome extension support.
@ -177,7 +167,7 @@ require('./desktop-capturer')
require('./api/protocol') require('./api/protocol')
// Set main startup script of the app. // Set main startup script of the app.
var mainStartupScript = packageJson.main || 'index.js' const mainStartupScript = packageJson.main || 'index.js'
// Finally load app's main.js and transfer control to C++. // Finally load app's main.js and transfer control to C++.
Module._load(path.join(packagePath, mainStartupScript), Module, true) Module._load(path.join(packagePath, mainStartupScript), Module, true)