From 892026458d7f8c6bfc8e507a16cbee39dc70bb3e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 2 Aug 2016 17:45:46 +0900 Subject: [PATCH] Cleanup init.js --- lib/browser/init.js | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/lib/browser/init.js b/lib/browser/init.js index 88377a6..f7619fd 100644 --- a/lib/browser/init.js +++ b/lib/browser/init.js @@ -65,7 +65,7 @@ process.on('uncaughtException', function (error) { }) // Emit 'exit' event on quit. -var app = require('electron').app +const {app} = require('electron') app.on('quit', function (event, exitCode) { process.emit('exit', exitCode) @@ -86,15 +86,12 @@ if (process.platform === 'win32') { // form `com.squirrel.PACKAGE-NAME.OUREXE`. We need to call // app.setAppUserModelId with a matching identifier so that renderer processes // will inherit this value. - var updateDotExe = path.join( - path.dirname(process.execPath), - '..', - 'update.exe') + const updateDotExe = path.join(path.dirname(process.execPath), '..', 'update.exe') - if (fs.statSyncNoException(updateDotExe)) { - var packageDir = path.dirname(path.resolve(updateDotExe)) - var packageName = path.basename(packageDir).replace(/\s/g, '') - var exeName = path.basename(process.execPath).replace(/\.exe$/i, '').replace(/\s/g, '') + if (fs.existsSync(updateDotExe)) { + const packageDir = path.dirname(path.resolve(updateDotExe)) + const packageName = path.basename(packageDir).replace(/\s/g, '') + const exeName = path.basename(process.execPath).replace(/\.exe$/i, '').replace(/\s/g, '') app.setAppUserModelId(`com.squirrel.${packageName}.${exeName}`) } @@ -108,15 +105,13 @@ require('./rpc-server') // Load the guest view manager. require('./guest-view-manager') - require('./guest-window-manager') // Now we try to load app's package.json. -var packageJson = null -var searchPaths = ['app', 'app.asar', 'default_app.asar'] -var i, len, packagePath -for (i = 0, len = searchPaths.length; i < len; i++) { - packagePath = searchPaths[i] +let packagePath = null +let packageJson = null +const searchPaths = ['app', 'app.asar', 'default_app.asar'] +for (packagePath of searchPaths) { try { packagePath = path.join(process.resourcesPath, packagePath) packageJson = require(path.join(packagePath, 'package.json')) @@ -157,14 +152,9 @@ if (packageJson.v8Flags != null) { 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. app.setPath('userData', path.join(app.getPath('appData'), app.getName())) - app.setPath('userCache', path.join(app.getPath('cache'), app.getName())) - app.setAppPath(packagePath) // Load the chrome extension support. @@ -177,7 +167,7 @@ require('./desktop-capturer') require('./api/protocol') // 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++. Module._load(path.join(packagePath, mainStartupScript), Module, true) -- 2.7.4