Skip to content

Commit 1c34f3f

Browse files
committed
feat(generator): add support for electron v6
1 parent 55ed677 commit 1c34f3f

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

Diff for: __tests__/generator.spec.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ beforeEach(() => {
3333
// Reset mock status
3434
jest.clearAllMocks()
3535
})
36+
const runGenerator = () =>
37+
generator(mockApi, { electronBuilder: { electronVersion: '^5.0.0' } })
3638

3739
describe('.gitignore', () => {
3840
test('extends gitignore if it exists', () => {
3941
// Mock existence of .gitignore
4042
fs.existsSync = jest.fn(path => path === 'apiResolve_./.gitignore')
4143
// Run the generator with mock api
42-
generator(mockApi)
44+
runGenerator()
4345
// Run the onCreateComplete callback
4446
completionCb()
4547
// New .gitignore should have been written
@@ -53,7 +55,7 @@ describe('.gitignore', () => {
5355
// Mock lack of .gitignore
5456
fs.existsSync = jest.fn(path => !(path === 'apiResolve_./.gitignore'))
5557
// Run the generator with mock api
56-
generator(mockApi)
58+
runGenerator()
5759
// Run the onCreateComplete callback
5860
completionCb()
5961
// New .gitignore should not have been read from or written
@@ -88,7 +90,7 @@ describe('.gitignore', () => {
8890
// Mock existence of .gitignore
8991
fs.existsSync = jest.fn(path => path === 'apiResolve_./.gitignore')
9092
// Run the generator with mock api
91-
generator(mockApi)
93+
runGenerator()
9294
// Run the onCreateComplete callback
9395
completionCb()
9496
// New .gitignore should not have been written
@@ -113,7 +115,7 @@ describe('background.js', () => {
113115
)
114116
// Mock existence of background file
115117
fs.existsSync.mockImplementation(path => path === `apiResolve_./${file}`)
116-
generator(mockApi)
118+
runGenerator()
117119
completionCb()
118120
expect(mockApi.render).not.toBeCalled()
119121
}
@@ -141,7 +143,7 @@ describe('background.js', () => {
141143
// return mock content
142144
return background
143145
})
144-
generator(mockApi)
146+
runGenerator()
145147
completionCb()
146148
expect(fs.writeFileSync).toBeCalledWith(
147149
'apiResolve_./src/background.ts',
@@ -152,7 +154,7 @@ describe('background.js', () => {
152154

153155
describe.each(['postinstall', 'postuninstall'])('package.json (%s)', script => {
154156
test(`Adds electron-builder install-app-deps to ${script}`, () => {
155-
generator(mockApi)
157+
runGenerator()
156158
completionCb()
157159
expect(pkg.scripts[script]).toBe('electron-builder install-app-deps')
158160
})
@@ -169,7 +171,7 @@ describe.each(['postinstall', 'postuninstall'])('package.json (%s)', script => {
169171
return 'existing_content'
170172
})
171173

172-
generator(mockApi)
174+
runGenerator()
173175
completionCb()
174176

175177
expect(pkg.scripts[script]).toBe(
@@ -193,7 +195,7 @@ describe.each(['postinstall', 'postuninstall'])('package.json (%s)', script => {
193195
return 'existing_content'
194196
})
195197

196-
generator(mockApi)
198+
runGenerator()
197199
completionCb()
198200

199201
expect(pkg.scripts[script]).toBe(

Diff for: generator/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs')
22
const semver = require('semver')
3+
const { warn } = require('@vue/cli-shared-utils')
34

45
module.exports = (api, options = {}) => {
56
if (!options.electronBuilder) options.electronBuilder = {}
@@ -11,14 +12,25 @@ module.exports = (api, options = {}) => {
1112
fs.existsSync(api.resolve(`./src/background.ts`)) ||
1213
fs.existsSync(api.resolve(`./src/background.js`))
1314

15+
const devtoolsExtensionsBroken = semver.gte(
16+
(electronVersion || pkg.devDependencies.electron).replace('^', ''),
17+
'6.0.0'
18+
)
19+
if (devtoolsExtensionsBroken) {
20+
warn('Devtools extensions are broken in Electron 6.0.0 and greater')
21+
warn(
22+
'Vue Devtools have been disabled, see the comments in your background file for more info'
23+
)
24+
}
1425
if (!hasBackground) {
1526
// If user does not have a background file it should be created
1627
api.render('./templates/base', {
1728
// Scheme registration changed in Electron 5.0.0
1829
newSchemeRegistrationFunction: semver.gte(
1930
(electronVersion || pkg.devDependencies.electron).replace('^', ''),
2031
'5.0.0'
21-
)
32+
),
33+
devtoolsExtensionsBroken
2234
})
2335
}
2436
// Add tests

Diff for: generator/templates/base/src/background.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,22 @@ app.on('activate', () => {
5959
app.on('ready', async () => {
6060
if (isDevelopment && !process.env.IS_TEST) {
6161
// Install Vue Devtools
62-
try {
63-
await installVueDevtools()
64-
} catch (e) {
65-
console.error('Vue Devtools failed to install:', e.toString())
66-
}
62+
<% if (devtoolsExtensionsBroken) { %>// Devtools extensions are broken in Electron 6.0.0 and greater
63+
// See https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/378 for more info
64+
// Electron will not launch with Devtools extensions installed on Windows 10 with dark mode
65+
// If you are not using Windows 10 dark mode, you may uncomment these lines
66+
// In addition, if the linked issue is closed, you can upgrade electron and uncomment these lines
67+
// try {
68+
// await installVueDevtools()
69+
// } catch (e) {
70+
// console.error('Vue Devtools failed to install:', e.toString())
71+
// }
72+
<% } else { %>try {
73+
await installVueDevtools()
74+
} catch (e) {
75+
console.error('Vue Devtools failed to install:', e.toString())
76+
}
77+
<% } %>
6778
}
6879
createWindow()
6980
})

Diff for: prompts.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@ module.exports = [
55
name: 'electronBuilder.electronVersion',
66
type: 'list',
77
message: 'Choose Electron Version',
8-
default: '^5.0.0',
8+
default: '^6.0.0',
99
choices: [
10-
{
11-
name: '^3.0.0',
12-
value: '^3.0.0',
13-
short: '^3.0.0'
14-
},
1510
{
1611
name: '^4.0.0',
1712
value: '^4.0.0',
@@ -21,6 +16,11 @@ module.exports = [
2116
name: '^5.0.0',
2217
value: '^5.0.0',
2318
short: '^5.0.0'
19+
},
20+
{
21+
name: '^6.0.0',
22+
value: '^6.0.0',
23+
short: '^6.0.0'
2424
}
2525
],
2626
when: () => {

0 commit comments

Comments
 (0)