💄 Update default_app to ES6 conventions
Add space before object literal method
This commit is contained in:
parent
c18880bd77
commit
b6fd4fed38
3 changed files with 31 additions and 39 deletions
|
@ -1,16 +1,14 @@
|
||||||
const electron = require('electron')
|
const {app, BrowserWindow} = require('electron')
|
||||||
const app = electron.app
|
|
||||||
const BrowserWindow = electron.BrowserWindow
|
|
||||||
|
|
||||||
var mainWindow = null
|
var mainWindow = null
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', () => {
|
||||||
app.quit()
|
app.quit()
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.load = function (appUrl) {
|
exports.load = (appUrl) => {
|
||||||
app.on('ready', function () {
|
app.on('ready', () => {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600,
|
height: 600,
|
||||||
|
|
|
@ -113,9 +113,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
const electron = require('electron');
|
const {remote, shell} = require('electron');
|
||||||
const remote = electron.remote;
|
|
||||||
const shell = electron.shell;
|
|
||||||
|
|
||||||
var execPath = remote.process.execPath;
|
var execPath = remote.process.execPath;
|
||||||
var command = execPath + ' path-to-your-app';
|
var command = execPath + ' path-to-your-app';
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
const electron = require('electron')
|
const {app, dialog, shell, Menu} = require('electron')
|
||||||
const app = electron.app
|
|
||||||
const dialog = electron.dialog
|
|
||||||
const shell = electron.shell
|
|
||||||
const Menu = electron.Menu
|
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
@ -10,9 +6,9 @@ const repl = require('repl')
|
||||||
const url = require('url')
|
const url = require('url')
|
||||||
|
|
||||||
// Parse command line options.
|
// Parse command line options.
|
||||||
var argv = process.argv.slice(1)
|
const argv = process.argv.slice(1)
|
||||||
var option = { file: null, help: null, version: null, webdriver: null, modules: [] }
|
const option = { file: null, help: null, version: null, webdriver: null, modules: [] }
|
||||||
for (var i = 0; i < argv.length; i++) {
|
for (let i = 0; i < argv.length; i++) {
|
||||||
if (argv[i] === '--version' || argv[i] === '-v') {
|
if (argv[i] === '--version' || argv[i] === '-v') {
|
||||||
option.version = true
|
option.version = true
|
||||||
break
|
break
|
||||||
|
@ -38,17 +34,17 @@ for (var i = 0; i < argv.length; i++) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit when all windows are closed and no other one is listening to this.
|
// Quit when all windows are closed and no other one is listening to this.
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', () => {
|
||||||
if (app.listeners('window-all-closed').length === 1 && !option.interactive) {
|
if (app.listeners('window-all-closed').length === 1 && !option.interactive) {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create default menu.
|
// Create default menu.
|
||||||
app.once('ready', function () {
|
app.once('ready', () => {
|
||||||
if (Menu.getApplicationMenu()) return
|
if (Menu.getApplicationMenu()) return
|
||||||
|
|
||||||
var template = [
|
const template = [
|
||||||
{
|
{
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -93,25 +89,25 @@ app.once('ready', function () {
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
click: function (item, focusedWindow) {
|
click (item, focusedWindow) {
|
||||||
if (focusedWindow) focusedWindow.reload()
|
if (focusedWindow) focusedWindow.reload()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Full Screen',
|
label: 'Toggle Full Screen',
|
||||||
accelerator: (function () {
|
accelerator: (() => {
|
||||||
return (process.platform === 'darwin') ? 'Ctrl+Command+F' : 'F11'
|
return (process.platform === 'darwin') ? 'Ctrl+Command+F' : 'F11'
|
||||||
})(),
|
})(),
|
||||||
click: function (item, focusedWindow) {
|
click (item, focusedWindow) {
|
||||||
if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Toggle Developer Tools',
|
||||||
accelerator: (function () {
|
accelerator: (() => {
|
||||||
return (process.platform === 'darwin') ? 'Alt+Command+I' : 'Ctrl+Shift+I'
|
return (process.platform === 'darwin') ? 'Alt+Command+I' : 'Ctrl+Shift+I'
|
||||||
})(),
|
})(),
|
||||||
click: function (item, focusedWindow) {
|
click (item, focusedWindow) {
|
||||||
if (focusedWindow) focusedWindow.toggleDevTools()
|
if (focusedWindow) focusedWindow.toggleDevTools()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,13 +135,13 @@ app.once('ready', function () {
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'Learn More',
|
label: 'Learn More',
|
||||||
click: function () {
|
click () {
|
||||||
shell.openExternal('http://electron.atom.io')
|
shell.openExternal('http://electron.atom.io')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Documentation',
|
label: 'Documentation',
|
||||||
click: function () {
|
click () {
|
||||||
shell.openExternal(
|
shell.openExternal(
|
||||||
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme`
|
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme`
|
||||||
)
|
)
|
||||||
|
@ -153,13 +149,13 @@ app.once('ready', function () {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Community Discussions',
|
label: 'Community Discussions',
|
||||||
click: function () {
|
click () {
|
||||||
shell.openExternal('https://discuss.atom.io/c/electron')
|
shell.openExternal('https://discuss.atom.io/c/electron')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Search Issues',
|
label: 'Search Issues',
|
||||||
click: function () {
|
click () {
|
||||||
shell.openExternal('https://github.com/electron/electron/issues')
|
shell.openExternal('https://github.com/electron/electron/issues')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,7 +202,7 @@ app.once('ready', function () {
|
||||||
{
|
{
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
accelerator: 'Command+Q',
|
accelerator: 'Command+Q',
|
||||||
click: function () { app.quit() }
|
click () { app.quit() }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
@ -221,7 +217,7 @@ app.once('ready', function () {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var menu = Menu.buildFromTemplate(template)
|
const menu = Menu.buildFromTemplate(template)
|
||||||
Menu.setApplicationMenu(menu)
|
Menu.setApplicationMenu(menu)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -236,9 +232,9 @@ function loadApplicationPackage (packagePath) {
|
||||||
try {
|
try {
|
||||||
// Override app name and version.
|
// Override app name and version.
|
||||||
packagePath = path.resolve(packagePath)
|
packagePath = path.resolve(packagePath)
|
||||||
var packageJsonPath = path.join(packagePath, 'package.json')
|
const packageJsonPath = path.join(packagePath, 'package.json')
|
||||||
if (fs.existsSync(packageJsonPath)) {
|
if (fs.existsSync(packageJsonPath)) {
|
||||||
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
|
||||||
if (packageJson.version) app.setVersion(packageJson.version)
|
if (packageJson.version) app.setVersion(packageJson.version)
|
||||||
|
|
||||||
if (packageJson.productName) {
|
if (packageJson.productName) {
|
||||||
|
@ -277,7 +273,7 @@ function loadApplicationByUrl (appUrl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function startRepl () {
|
function startRepl () {
|
||||||
repl.start('> ').on('exit', function () {
|
repl.start('> ').on('exit', () => {
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -285,9 +281,9 @@ function startRepl () {
|
||||||
// Start the specified app if there is one specified in command line, otherwise
|
// Start the specified app if there is one specified in command line, otherwise
|
||||||
// start the default app.
|
// start the default app.
|
||||||
if (option.file && !option.webdriver) {
|
if (option.file && !option.webdriver) {
|
||||||
var file = option.file
|
const file = option.file
|
||||||
var protocol = url.parse(file).protocol
|
const protocol = url.parse(file).protocol
|
||||||
var extension = path.extname(file)
|
const extension = path.extname(file)
|
||||||
if (protocol === 'http:' || protocol === 'https:' || protocol === 'file:') {
|
if (protocol === 'http:' || protocol === 'https:' || protocol === 'file:') {
|
||||||
loadApplicationByUrl(file)
|
loadApplicationByUrl(file)
|
||||||
} else if (extension === '.html' || extension === '.htm') {
|
} else if (extension === '.html' || extension === '.htm') {
|
||||||
|
@ -299,7 +295,7 @@ if (option.file && !option.webdriver) {
|
||||||
console.log('v' + process.versions.electron)
|
console.log('v' + process.versions.electron)
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
} else if (option.help) {
|
} else if (option.help) {
|
||||||
var helpMessage = `Electron v${process.versions.electron} - Cross Platform Desktop Application Shell
|
const helpMessage = `Electron v${process.versions.electron} - Cross Platform Desktop Application Shell
|
||||||
|
|
||||||
Usage: electron [options] [path]
|
Usage: electron [options] [path]
|
||||||
|
|
||||||
|
@ -322,6 +318,6 @@ if (option.file && !option.webdriver) {
|
||||||
} else if (option.interactive) {
|
} else if (option.interactive) {
|
||||||
startRepl()
|
startRepl()
|
||||||
} else {
|
} else {
|
||||||
var indexPath = path.join(__dirname, '/index.html')
|
const indexPath = path.join(__dirname, '/index.html')
|
||||||
loadApplicationByUrl(`file://${indexPath}`)
|
loadApplicationByUrl(`file://${indexPath}`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue