Skip to content

Commit 94e10b5

Browse files
committed
fix(generator/background): inconsistant variable names
1 parent 90dac25 commit 94e10b5

File tree

2 files changed

+26
-41
lines changed

2 files changed

+26
-41
lines changed

__tests__/checkLogs.helper.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,13 @@ module.exports = async ({ client, projectPath, projectName, mode }) => {
8686
})
8787

8888
await client.getMainProcessLogs().then(logs => {
89-
logs.forEach(log => {
90-
// Make sure there are no fatal errors
91-
expect(log.level).not.toBe('SEVERE')
92-
})
9389
let appStatic = logs
9490
// Find __static log
9591
.find(m => m.indexOf('__static=') !== -1)
9692
// Get just the value
9793
.split('=')[1]
9894
// Remove any quotes
99-
appStatic = appStatic.replace('"', '')
95+
appStatic = appStatic.replace('"', '').split(',')[0]
10096
// __static should point to public folder or packaged asar
10197
expect(path.normalize(appStatic)).toBe(
10298
isBuild ? outputPath : projectPath('public')
@@ -110,7 +106,7 @@ module.exports = async ({ client, projectPath, projectName, mode }) => {
110106
// Parse modulePaths array
111107
modulePaths = modulePaths.split(',')
112108
// Normalize paths
113-
modulePaths = modulePaths.map(p => path.normalize(p))
109+
modulePaths = modulePaths.map(p => path.normalize(p.replace('"', '')))
114110
// module.paths should include path to project's node_modules unless in build
115111
if (isBuild) {
116112
expect(modulePaths).not.toContain(
@@ -128,7 +124,7 @@ module.exports = async ({ client, projectPath, projectName, mode }) => {
128124
// Get just the value
129125
.split('=')[1]
130126
// Remove any quotes
131-
mockExternalPath = mockExternalPath.replace('"', '')
127+
mockExternalPath = mockExternalPath.replace('"', '').split(',')[0]
132128
// mockExternal should be externalized (can't check in build because of NamedModulePlugin)
133129
if (!isBuild) {
134130
expect(mockExternalPath).toBe('mockExternal')

generator/template/src/background.js

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict'
22

33
import { app, protocol, BrowserWindow } from 'electron'
4-
import * as path from 'path'
5-
import { format as formatUrl } from 'url'
64
import {
75
createProtocol,
86
installVueDevtools
@@ -13,64 +11,55 @@ if (isDevelopment) {
1311
require('module').globalPaths.push(process.env.NODE_MODULES_PATH)
1412
}
1513

16-
// global reference to mainWindow (necessary to prevent window from being garbage collected)
17-
let mainWindow
14+
// Keep a global reference of the window object, if you don't, the window will
15+
// be closed automatically when the JavaScript object is garbage collected.
16+
let win
1817

1918
// Standard scheme must be registered before the app is ready
2019
protocol.registerStandardSchemes(['app'], { secure: true })
21-
function createMainWindow () {
22-
const window = new BrowserWindow()
20+
function createWindow () {
21+
// Create the browser window.
22+
win = new BrowserWindow({ width: 800, height: 600 })
2323

2424
if (isDevelopment) {
2525
// Load the url of the dev server if in development mode
26-
window.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
27-
if (!process.env.IS_TEST) window.webContents.openDevTools()
26+
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
27+
if (!process.env.IS_TEST) win.webContents.openDevTools()
2828
} else {
2929
createProtocol('app')
30-
// Load the index.html when not in development
31-
window.loadURL(
32-
formatUrl({
33-
pathname: path.join(__dirname, 'index.html'),
34-
protocol: 'file',
35-
slashes: true
36-
})
37-
)
30+
// Load the index.html when not in development
31+
win.loadFile('index.html')
3832
}
3933

40-
window.on('closed', () => {
41-
mainWindow = null
34+
win.on('closed', () => {
35+
win = null
4236
})
43-
44-
window.webContents.on('devtools-opened', () => {
45-
window.focus()
46-
setImmediate(() => {
47-
window.focus()
48-
})
49-
})
50-
51-
return window
5237
}
5338

54-
// quit application when all windows are closed
39+
// Quit when all windows are closed.
5540
app.on('window-all-closed', () => {
56-
// on macOS it is common for applications to stay open until the user explicitly quits
41+
// On macOS it is common for applications and their menu bar
42+
// to stay active until the user quits explicitly with Cmd + Q
5743
if (process.platform !== 'darwin') {
5844
app.quit()
5945
}
6046
})
6147

6248
app.on('activate', () => {
63-
// on macOS it is common to re-create a window even after all windows have been closed
64-
if (mainWindow === null) {
65-
mainWindow = createMainWindow()
49+
// On macOS it's common to re-create a window in the app when the
50+
// dock icon is clicked and there are no other windows open.
51+
if (win === null) {
52+
createWindow()
6653
}
6754
})
6855

69-
// create main BrowserWindow when electron is ready
56+
// This method will be called when Electron has finished
57+
// initialization and is ready to create browser windows.
58+
// Some APIs can only be used after this event occurs.
7059
app.on('ready', async () => {
7160
if (isDevelopment && !process.env.IS_TEST) {
7261
// Install Vue Devtools
7362
await installVueDevtools()
7463
}
75-
mainWindow = createMainWindow()
64+
createWindow()
7665
})

0 commit comments

Comments
 (0)