11const fs = require ( 'fs' )
2+ const semver = require ( 'semver' )
23
34module . exports = ( api , options = { } ) => {
45 if ( ! options . electronBuilder ) options . electronBuilder = { }
6+ const electronVersion = options . electronBuilder . electronVersion
7+ let pkg = fs . readFileSync ( api . resolve ( './package.json' ) , 'utf8' )
8+ pkg = JSON . parse ( pkg )
59 const usesTS = api . hasPlugin ( 'typescript' )
610 const hasBackground =
711 fs . existsSync ( api . resolve ( `./src/background.ts` ) ) ||
812 fs . existsSync ( api . resolve ( `./src/background.js` ) )
13+
914 if ( ! hasBackground ) {
1015 // If user does not have a background file it should be created
11- api . render ( './templates/base' )
16+ api . render ( './templates/base' , {
17+ // Scheme registration changed in Electron 5.0.0
18+ newSchemeRegistrationFunction : semver . gte (
19+ ( electronVersion || pkg . devDependencies . electron ) . replace ( '^' , '' ) ,
20+ '5.0.0'
21+ )
22+ } )
1223 }
1324 // Add tests
1425 let testFramework
@@ -44,7 +55,10 @@ module.exports = (api, options = {}) => {
4455 / p r o c e s s \. e n v \. W E B P A C K _ D E V _ S E R V E R _ U R L \s * ?\) $ / m,
4556 'process.env.WEBPACK_DEV_SERVER_URL as string)'
4657 )
47- background = background . replace ( / l e t w i n \s * ?$ / m, 'let win: BrowserWindow | null' )
58+ background = background . replace (
59+ / l e t w i n \s * ?$ / m,
60+ 'let win: BrowserWindow | null'
61+ )
4862 fs . writeFileSync ( api . resolve ( './src/background.ts' ) , background )
4963 if ( api . hasPlugin ( 'router' ) ) {
5064 console . log ( '\n' )
@@ -60,8 +74,6 @@ module.exports = (api, options = {}) => {
6074 'electron:build' : 'vue-cli-service electron:build' ,
6175 'electron:serve' : 'vue-cli-service electron:serve'
6276 }
63- let pkg = fs . readFileSync ( api . resolve ( './package.json' ) , 'utf8' )
64- pkg = JSON . parse ( pkg )
6577 const addScript = ( name , command ) => {
6678 // Add on to existing script if it exists
6779 if ( pkg . scripts && pkg . scripts [ name ] ) {
@@ -81,9 +93,9 @@ module.exports = (api, options = {}) => {
8193 addScript ( 'postinstall' , 'electron-builder install-app-deps' )
8294 addScript ( 'postuninstall' , 'electron-builder install-app-deps' )
8395 const devDependencies = { }
84- if ( options . electronBuilder . electronVersion ) {
96+ if ( electronVersion ) {
8597 // Use provided electron version
86- devDependencies . electron = options . electronBuilder . electronVersion
98+ devDependencies . electron = electronVersion
8799 }
88100 const dependencies = { }
89101 if ( testFramework === 'mocha' ) {
0 commit comments