Skip to content

Commit c6e8c2a

Browse files
authored
Merge pull request #165 from johnb8/electron-plugin
Electron package
2 parents 1792d22 + 7dc0548 commit c6e8c2a

28 files changed

+616
-8
lines changed

.github/workflows/linux.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
node-version: ${{ matrix.node-version }}
2222
- uses: bahmutov/npm-install@v1
2323

24+
- run: yarn playwright install-deps chromium
2425
- run: yarn build
25-
- run: yarn test --testTimeout 20000
26+
- run: xvfb-run yarn test --testTimeout 20000
2627
env: { CI: 1 }
2728

.github/workflows/macos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
node-version: ${{ matrix.node-version }}
2222
- uses: bahmutov/npm-install@v1
2323

24+
- run: yarn playwright install-deps chromium
2425
- run: yarn build
2526
- run: yarn test --testTimeout 20000
2627
env: { CI: 1 }

.github/workflows/main.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
# for branches, we only need to check Linux + Node LTS
1010
# note that we do linting here, but not on Windows / MacOS (no need to)
1111
linux-and-lts:
12-
runs-on: ubuntu-latest
12+
runs-on: ${{ matrix.os }}
1313

1414
strategy:
1515
matrix:
@@ -22,12 +22,17 @@ jobs:
2222
with:
2323
node-version: ${{ matrix.node-version }}
2424
- uses: bahmutov/npm-install@v1
25+
- run: yarn playwright install-deps chromium
2526
- run: yarn build
2627
- run: yarn build:es
2728
- run: yarn build:all
2829
- run: yarn lint
30+
- run: xvfb-run yarn test --coverage --testTimeout 20000
31+
env: { CI: 1 }
32+
if: matrix.os == 'ubuntu-latest'
2933
- run: yarn test --coverage --testTimeout 20000
3034
env: { CI: 1 }
35+
if: matrix.os != 'ubuntu-latest'
3136

3237
# sanity check that the rollup plugin made a file without needing to loadConfig
3338
- run: yarn --cwd ./examples/rollup-project start
@@ -62,5 +67,6 @@ jobs:
6267
./app-config-webpack/coverage/coverage-final.json,
6368
./app-config-rollup/coverage/coverage-final.json,
6469
./app-config-vite/coverage/coverage-final.json,
70+
./app-config-electron/coverage/coverage-final.json,
6571
fail_ci_if_error: true
6672
verbose: true

.github/workflows/publishing.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ jobs:
3434
token: ${{ secrets.NPM_TOKEN }}
3535
access: public
3636
package: ./app-config-cypress/package.json
37+
- name: app-config-electron
38+
uses: JS-DevTools/npm-publish@v1
39+
with:
40+
token: ${{ secrets.NPM_TOKEN }}
41+
access: public
42+
package: ./app-config-electron/package.json
3743
- name: app-config-default-extensions
3844
uses: JS-DevTools/npm-publish@v1
3945
with:

.github/workflows/windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
node-version: ${{ matrix.node-version }}
2222
- uses: bahmutov/npm-install@v1
2323

24+
- run: yarn playwright install-deps chromium
2425
- run: yarn build
2526
- run: yarn test --testTimeout 20000
2627
env: { CI: 1 }

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ node_modules/
22

33
# app-config files, when developing
44
.app-config.*
5+
# keep example files though
6+
!examples/**/.app-config.*
57

68
# common build sites
79
dist/

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ If you are adding anything new or changing behavior, please add applicable tests
5353
- `@app-config/webpack`: webpack plugin
5454
- `@app-config/rollup`: rollup plugin
5555
- `@app-config/vite`: vite plugin
56+
- `@app-config/electron`: injects config into Electron renderer processes
5657
- `@app-config/main`: main config singleton and loading logic
5758
- `@lcdev/app-config`: alias for `@app-config/main`
5859
- `@lcdev/app-config-webpack-plugin`: alias for `@app-config/webpack`

app-config-electron/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@lcdev/eslint-config/cwd')(__dirname);

app-config-electron/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# App Config Electron
2+
3+
Easily inject `app-config` values into Electron renderer processes. An example project is provided [here.](https://github.com/launchcodedev/app-config/tree/master/examples/electron-project)
4+
5+
## Usage
6+
7+
### 1. Install App Config and the Electron Package
8+
9+
```shell
10+
yarn add @app-config/main @app-config/electron
11+
```
12+
13+
Or, if you use NPM.
14+
15+
```shell
16+
npm i @app-config/main @app-config/electron
17+
```
18+
19+
### 2. Load your config with any options you need in the main Electron process before creating any windows
20+
```typescript
21+
app.whenReady().then(() => {
22+
loadConfig().then(() => {
23+
const mainWindow = new BrowserWindow();
24+
25+
mainWindow.loadFile('./index.html')
26+
});
27+
});
28+
```
29+
30+
### 3. Insert the App Config preload script into your `BrowserWindow` `webPreferences`
31+
32+
Pass your config and optionally any other `BrowserWindow` `webPreferences` you need to `addAppConfigPreload`.
33+
```typescript
34+
app.whenReady().then(() => {
35+
loadConfig().then(() => {
36+
const mainWindow = new BrowserWindow({
37+
webPreferences: addAppConfigPreload(config),
38+
});
39+
40+
mainWindow.loadFile('./index.html')
41+
});
42+
});
43+
```
44+
45+
### 4. Your App Config values are now available!
46+
47+
They can be found in `window._appConfig` or in `config` if using `@app-config/main` in your web page (when using `@app-config/webpack` with `headerInjection` or `@app-config/vite` with `readGlobal`). It's also available in `config` in the main Electron process.
48+
49+
Your app will need to be restarted to reflect any configuration changes.
50+
51+
Setting `contextIsolation` to `true` in the `browserOptions` of your `BrowserWindow` settings is required for this package to work. We set this for you, but if your app requres `contextIsolation` to be `false` using this package will break your app.

app-config-electron/package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "@app-config/electron",
3+
"description": "Exposes app-config values to Electron render processes",
4+
"version": "2.6.0",
5+
"license": "MPL-2.0",
6+
"author": {
7+
"name": "Launchcode",
8+
"email": "[email protected]",
9+
"url": "https://lc.dev"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/launchcodedev/app-config.git"
14+
},
15+
"main": "dist/index.js",
16+
"module": "dist/es/index.js",
17+
"types": "dist/index.d.ts",
18+
"files": [
19+
"/dist",
20+
"!**/*.tsbuildinfo",
21+
"!**/*.test.*"
22+
],
23+
"scripts": {
24+
"build": "tsc -b",
25+
"build:es": "tsc -b tsconfig.es.json",
26+
"clean": "rm -rf dist *.tsbuildinfo",
27+
"lint": "eslint src",
28+
"fix": "eslint --fix src",
29+
"test": "jest",
30+
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
31+
},
32+
"dependencies": {
33+
"@app-config/main": "^2.6.0",
34+
"@app-config/logging": "^2.6.0"
35+
},
36+
"peerDependencies": {
37+
"electron": "13 || 12 || 11 || 10"
38+
},
39+
"devDependencies": {},
40+
"prettier": "@lcdev/prettier",
41+
"jest": {
42+
"preset": "@lcdev/jest"
43+
}
44+
}

0 commit comments

Comments
 (0)