Skip to content

Commit b6fd4fe

Browse files
committed
💄 Update default_app to ES6 conventions
Add space before object literal method
1 parent c18880b commit b6fd4fe

File tree

3 files changed

+31
-39
lines changed

3 files changed

+31
-39
lines changed

default_app/default_app.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
const electron = require('electron')
2-
const app = electron.app
3-
const BrowserWindow = electron.BrowserWindow
1+
const {app, BrowserWindow} = require('electron')
42

53
var mainWindow = null
64

75
// Quit when all windows are closed.
8-
app.on('window-all-closed', function () {
6+
app.on('window-all-closed', () => {
97
app.quit()
108
})
119

12-
exports.load = function (appUrl) {
13-
app.on('ready', function () {
10+
exports.load = (appUrl) => {
11+
app.on('ready', () => {
1412
mainWindow = new BrowserWindow({
1513
width: 800,
1614
height: 600,

default_app/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@
113113
</head>
114114
<body>
115115
<script>
116-
const electron = require('electron');
117-
const remote = electron.remote;
118-
const shell = electron.shell;
116+
const {remote, shell} = require('electron');
119117

120118
var execPath = remote.process.execPath;
121119
var command = execPath + ' path-to-your-app';

default_app/main.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
const electron = require('electron')
2-
const app = electron.app
3-
const dialog = electron.dialog
4-
const shell = electron.shell
5-
const Menu = electron.Menu
1+
const {app, dialog, shell, Menu} = require('electron')
62

73
const fs = require('fs')
84
const path = require('path')
95
const repl = require('repl')
106
const url = require('url')
117

128
// Parse command line options.
13-
var argv = process.argv.slice(1)
14-
var option = { file: null, help: null, version: null, webdriver: null, modules: [] }
15-
for (var i = 0; i < argv.length; i++) {
9+
const argv = process.argv.slice(1)
10+
const option = { file: null, help: null, version: null, webdriver: null, modules: [] }
11+
for (let i = 0; i < argv.length; i++) {
1612
if (argv[i] === '--version' || argv[i] === '-v') {
1713
option.version = true
1814
break
@@ -38,17 +34,17 @@ for (var i = 0; i < argv.length; i++) {
3834
}
3935

4036
// Quit when all windows are closed and no other one is listening to this.
41-
app.on('window-all-closed', function () {
37+
app.on('window-all-closed', () => {
4238
if (app.listeners('window-all-closed').length === 1 && !option.interactive) {
4339
app.quit()
4440
}
4541
})
4642

4743
// Create default menu.
48-
app.once('ready', function () {
44+
app.once('ready', () => {
4945
if (Menu.getApplicationMenu()) return
5046

51-
var template = [
47+
const template = [
5248
{
5349
label: 'Edit',
5450
submenu: [
@@ -93,25 +89,25 @@ app.once('ready', function () {
9389
{
9490
label: 'Reload',
9591
accelerator: 'CmdOrCtrl+R',
96-
click: function (item, focusedWindow) {
92+
click (item, focusedWindow) {
9793
if (focusedWindow) focusedWindow.reload()
9894
}
9995
},
10096
{
10197
label: 'Toggle Full Screen',
102-
accelerator: (function () {
98+
accelerator: (() => {
10399
return (process.platform === 'darwin') ? 'Ctrl+Command+F' : 'F11'
104100
})(),
105-
click: function (item, focusedWindow) {
101+
click (item, focusedWindow) {
106102
if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
107103
}
108104
},
109105
{
110106
label: 'Toggle Developer Tools',
111-
accelerator: (function () {
107+
accelerator: (() => {
112108
return (process.platform === 'darwin') ? 'Alt+Command+I' : 'Ctrl+Shift+I'
113109
})(),
114-
click: function (item, focusedWindow) {
110+
click (item, focusedWindow) {
115111
if (focusedWindow) focusedWindow.toggleDevTools()
116112
}
117113
}
@@ -139,27 +135,27 @@ app.once('ready', function () {
139135
submenu: [
140136
{
141137
label: 'Learn More',
142-
click: function () {
138+
click () {
143139
shell.openExternal('http://electron.atom.io')
144140
}
145141
},
146142
{
147143
label: 'Documentation',
148-
click: function () {
144+
click () {
149145
shell.openExternal(
150146
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme`
151147
)
152148
}
153149
},
154150
{
155151
label: 'Community Discussions',
156-
click: function () {
152+
click () {
157153
shell.openExternal('https://discuss.atom.io/c/electron')
158154
}
159155
},
160156
{
161157
label: 'Search Issues',
162-
click: function () {
158+
click () {
163159
shell.openExternal('https://github.com/electron/electron/issues')
164160
}
165161
}
@@ -206,7 +202,7 @@ app.once('ready', function () {
206202
{
207203
label: 'Quit',
208204
accelerator: 'Command+Q',
209-
click: function () { app.quit() }
205+
click () { app.quit() }
210206
}
211207
]
212208
})
@@ -221,7 +217,7 @@ app.once('ready', function () {
221217
)
222218
}
223219

224-
var menu = Menu.buildFromTemplate(template)
220+
const menu = Menu.buildFromTemplate(template)
225221
Menu.setApplicationMenu(menu)
226222
})
227223

@@ -236,9 +232,9 @@ function loadApplicationPackage (packagePath) {
236232
try {
237233
// Override app name and version.
238234
packagePath = path.resolve(packagePath)
239-
var packageJsonPath = path.join(packagePath, 'package.json')
235+
const packageJsonPath = path.join(packagePath, 'package.json')
240236
if (fs.existsSync(packageJsonPath)) {
241-
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
237+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
242238
if (packageJson.version) app.setVersion(packageJson.version)
243239

244240
if (packageJson.productName) {
@@ -277,17 +273,17 @@ function loadApplicationByUrl (appUrl) {
277273
}
278274

279275
function startRepl () {
280-
repl.start('> ').on('exit', function () {
276+
repl.start('> ').on('exit', () => {
281277
process.exit(0)
282278
})
283279
}
284280

285281
// Start the specified app if there is one specified in command line, otherwise
286282
// start the default app.
287283
if (option.file && !option.webdriver) {
288-
var file = option.file
289-
var protocol = url.parse(file).protocol
290-
var extension = path.extname(file)
284+
const file = option.file
285+
const protocol = url.parse(file).protocol
286+
const extension = path.extname(file)
291287
if (protocol === 'http:' || protocol === 'https:' || protocol === 'file:') {
292288
loadApplicationByUrl(file)
293289
} else if (extension === '.html' || extension === '.htm') {
@@ -299,7 +295,7 @@ if (option.file && !option.webdriver) {
299295
console.log('v' + process.versions.electron)
300296
process.exit(0)
301297
} else if (option.help) {
302-
var helpMessage = `Electron v${process.versions.electron} - Cross Platform Desktop Application Shell
298+
const helpMessage = `Electron v${process.versions.electron} - Cross Platform Desktop Application Shell
303299
304300
Usage: electron [options] [path]
305301
@@ -322,6 +318,6 @@ if (option.file && !option.webdriver) {
322318
} else if (option.interactive) {
323319
startRepl()
324320
} else {
325-
var indexPath = path.join(__dirname, '/index.html')
321+
const indexPath = path.join(__dirname, '/index.html')
326322
loadApplicationByUrl(`file://${indexPath}`)
327323
}

0 commit comments

Comments
 (0)