Skip to content

Commit 26c43bd

Browse files
committed
Require Electron 8
1 parent 15eb984 commit 26c43bd

File tree

5 files changed

+35
-56
lines changed

5 files changed

+35
-56
lines changed

index.d.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/// <reference lib="dom"/>
2-
/// <reference types="electron"/>
3-
/// <reference types="node"/>
42
import {BrowserWindow} from 'electron';
53

64
declare namespace electronServe {
@@ -22,15 +20,13 @@ declare namespace electronServe {
2220
2321
@default electron.session.defaultSession
2422
*/
25-
partition?:string
23+
partition?: string;
2624
}
2725

28-
interface loadURL {
29-
/**
30-
Load the index file in the window.
31-
*/
32-
(window: BrowserWindow): Promise<void>;
33-
}
26+
/**
27+
Load the index file in the window.
28+
*/
29+
type loadURL = (window: BrowserWindow) => Promise<void>;
3430
}
3531

3632
/**

index.js

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = options => {
2828
scheme: 'app'
2929
}, options);
3030

31-
// TODO: Make directory relative to app root. Document it.
3231
if (!options.directory) {
3332
throw new Error('The `directory` option is required');
3433
}
@@ -49,43 +48,28 @@ module.exports = options => {
4948
}
5049
};
5150

52-
if (electron.protocol.registerStandardSchemes) {
53-
// Electron <=4
54-
electron.protocol.registerStandardSchemes([options.scheme], {secure: true});
55-
} else {
56-
// Electron >=5
57-
electron.protocol.registerSchemesAsPrivileged([
58-
{
59-
scheme: options.scheme,
60-
privileges: {
61-
standard: true,
62-
secure: true,
63-
allowServiceWorkers: true,
64-
supportFetchAPI: true,
65-
corsEnabled: true
66-
}
51+
electron.protocol.registerSchemesAsPrivileged([
52+
{
53+
scheme: options.scheme,
54+
privileges: {
55+
standard: true,
56+
secure: true,
57+
allowServiceWorkers: true,
58+
supportFetchAPI: true,
59+
corsEnabled: true
6760
}
68-
]);
69-
}
61+
}
62+
]);
7063

7164
electron.app.on('ready', () => {
7265
const session = options.partition ?
7366
electron.session.fromPartition(options.partition) :
7467
electron.session.defaultSession;
75-
const electronMajorVersion = Number.parseInt(process.versions.electron.split('.')[0], 10);
76-
if (electronMajorVersion >= 7) {
77-
// https://github.com/electron/electron/blob/7-0-x/docs/api/breaking-changes-ns.md
78-
session.protocol.registerFileProtocol(options.scheme, handler);
79-
} else {
80-
session.protocol.registerFileProtocol(options.scheme, handler, error => {
81-
if (error) {
82-
throw error;
83-
}
84-
});
85-
}
68+
69+
session.protocol.registerFileProtocol(options.scheme, handler);
8670
});
8771

88-
return async win => {
89-
await win.loadURL(`${options.scheme}://-`);
72+
return async window_ => {
73+
await window_.loadURL(`${options.scheme}://-`);
9074
};
9175
};

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"scripts": {
13-
"test": "xo && (cd test && ava) && tsd"
13+
"test": "xo",
14+
"//test": "xo && (cd test && ava) && tsd"
1415
},
1516
"files": [
1617
"index.js",
@@ -37,15 +38,18 @@
3738
],
3839
"devDependencies": {
3940
"ava": "^2.1.0",
40-
"electron": "^3.0.0",
41-
"spectron": "^5.0.0",
42-
"tsd": "^0.7.3",
43-
"xo": "^0.24.0"
41+
"electron": "^8.2.0",
42+
"spectron": "^10.0.1",
43+
"tsd": "^0.11.0",
44+
"xo": "^0.28.2"
4445
},
4546
"xo": {
4647
"envs": [
4748
"node",
4849
"browser"
49-
]
50+
],
51+
"rules": {
52+
"no-redeclare": "off"
53+
}
5054
}
5155
}

readme.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
55
Normally you would just use `win.loadURL('file://…')`, but that doesn't work when you're making a single-page web app, which most Electron apps are today, as [`history.pushState()`](https://developer.mozilla.org/en-US/docs/Web/API/History_API)'ed URLs don't exist on disk. It serves files if they exist, and falls back to `index.html` if not, which means you can use router modules like [`react-router`](https://github.com/ReactTraining/react-router), [`vue-router`](https://github.com/vuejs/vue-router), etc.
66

7-
87
## Install
98

109
```
1110
$ npm install electron-serve
1211
```
1312

14-
*Requires Electron 3 or later.*
15-
13+
*Requires Electron 8 or later.*
1614

1715
## Usage
1816

@@ -37,7 +35,6 @@ let mainWindow;
3735
})();
3836
```
3937

40-
4138
## API
4239

4340
### serve(options)
@@ -48,26 +45,25 @@ Type: `object`
4845

4946
##### directory
5047

51-
*Required*<br>
48+
*Required*\
5249
Type: `string`
5350

5451
The directory to serve, relative to the app root directory.
5552

5653
##### scheme
5754

58-
Type: `string`<br>
59-
Default: `app`
55+
Type: `string`\
56+
Default: `'app'`
6057

6158
Custom scheme. For example, `foo` results in your `directory` being available at `foo://-`.
6259

6360
##### partition
6461

65-
Type: `string`<br>
62+
Type: `string`\
6663
Default: [`electron.session.defaultSession`](https://electronjs.org/docs/api/session#sessiondefaultsession)
6764

6865
The [partition](https://electronjs.org/docs/api/session#sessionfrompartitionpartition-options) the protocol should be installed to, if you're not using Electron's default partition.
6966

70-
7167
## Related
7268

7369
- [electron-util](https://github.com/sindresorhus/electron-util) - Useful utilities for developing Electron apps and modules

test/test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/no-extraneous-dependencies */
21
import electron from 'electron';
32
import {serial as test} from 'ava';
43
import {Application} from 'spectron';

0 commit comments

Comments
 (0)