-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use contextBridge in favour of requiring nodeIntegration (#300)
* feat: use contextBridge in favour of requiring nodeIntegration Due to security concerns related to usage of nodeIntegration flag, according to best electron practices, renderer functions should be exposed with contextBridge. This PR does exactly that. It also changes a bit API to accomodate for this feature * feat: fixing issues with test enviroment * fix: add missing preventDoubleInitialization() check * change the scope of the contextBridge bindings to only expose high level API
- Loading branch information
1 parent
2d05fa7
commit 83146af
Showing
33 changed files
with
305 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Include me in your preload script! | ||
require('electron-redux/preload') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"internal": true, | ||
"main": "../lib/main.js", | ||
"module": "../es/main.js", | ||
"types": "../types/main.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"internal": true, | ||
"main": "../lib/preload.js", | ||
"module": "../es/preload.js", | ||
"types": "../types/preload.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"internal": true, | ||
"main": "../lib/renderer.js", | ||
"module": "../es/renderer.js", | ||
"types": "../types/renderer.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
|
||
import { StoreEnhancer } from 'redux' | ||
import { forwardAction } from './forwardAction' | ||
import { forwardAction, ProcessForwarder } from './utils/forwardAction' | ||
import { StateSyncOptions } from './options/StateSyncOptions' | ||
import { stateSyncEnhancer } from './stateSyncEnhancer' | ||
import { StateSyncEnhancer } from './utils/types' | ||
|
||
const forwardActionEnhancer = (options?: StateSyncOptions): StoreEnhancer => (createStore) => ( | ||
reducer, | ||
preloadedState | ||
) => { | ||
const forwardActionEnhancer = ( | ||
processForwarder: ProcessForwarder, | ||
options?: StateSyncOptions | ||
): StoreEnhancer => (createStore) => (reducer, preloadedState) => { | ||
const store = createStore(reducer, preloadedState) | ||
|
||
return forwardAction(store, options) | ||
return forwardAction(store, processForwarder, options) | ||
} | ||
|
||
const extensionCompose = (options: StateSyncOptions) => ( | ||
...funcs: StoreEnhancer[] | ||
): StoreEnhancer => { | ||
const extensionCompose = ( | ||
stateSyncEnhancer: StateSyncEnhancer, | ||
processForwarder: ProcessForwarder, | ||
options: StateSyncOptions | ||
) => (...funcs: StoreEnhancer[]): StoreEnhancer => { | ||
return (createStore) => { | ||
return [ | ||
stateSyncEnhancer({ ...options, preventActionReplay: true }), | ||
...funcs, | ||
forwardActionEnhancer(options), | ||
forwardActionEnhancer(processForwarder, options), | ||
].reduceRight((composed, f) => f(composed), createStore) | ||
} | ||
} | ||
|
||
export function composeWithStateSync( | ||
options: StateSyncOptions | ||
): (...funcs: Function[]) => StoreEnhancer | ||
export function composeWithStateSync(...funcs: StoreEnhancer[]): StoreEnhancer | ||
export function composeWithStateSync( | ||
firstFuncOrOpts: StoreEnhancer | StateSyncOptions, | ||
...funcs: StoreEnhancer[] | ||
): StoreEnhancer | ((...funcs: StoreEnhancer[]) => StoreEnhancer) { | ||
if (arguments.length === 0) { | ||
return stateSyncEnhancer() | ||
} | ||
if (arguments.length === 1 && typeof firstFuncOrOpts === 'object') { | ||
return extensionCompose(firstFuncOrOpts) | ||
export function createComposer( | ||
stateSyncEnhancer: StateSyncEnhancer, | ||
processForwarder: ProcessForwarder | ||
) { | ||
return function composeWithStateSync( | ||
firstFuncOrOpts: StoreEnhancer | StateSyncOptions, | ||
...funcs: Array<StoreEnhancer> | ||
): StoreEnhancer { | ||
if (arguments.length === 0) { | ||
return stateSyncEnhancer({}) | ||
} | ||
if (arguments.length === 1 && typeof firstFuncOrOpts === 'object') { | ||
return extensionCompose(stateSyncEnhancer, processForwarder, firstFuncOrOpts)() | ||
} | ||
return extensionCompose( | ||
stateSyncEnhancer, | ||
processForwarder, | ||
{} | ||
)(firstFuncOrOpts as StoreEnhancer, ...funcs) | ||
} | ||
return extensionCompose({})(firstFuncOrOpts as StoreEnhancer, ...funcs) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
import { mainStateSyncEnhancer } from './mainStateSyncEnhancer' | ||
import { stopForwarding } from './utils' | ||
import { rendererStateSyncEnhancer } from './rendererStateSyncEnhancer' | ||
import { stateSyncEnhancer } from './stateSyncEnhancer' | ||
import { composeWithStateSync } from './composeWithStateSync' | ||
import { stopForwarding } from './utils/actions' | ||
|
||
export { | ||
mainStateSyncEnhancer, | ||
rendererStateSyncEnhancer, | ||
stopForwarding, | ||
stateSyncEnhancer, | ||
composeWithStateSync, | ||
} | ||
export { stopForwarding } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { webContents } from 'electron' | ||
import { IPCEvents } from 'src/constants' | ||
import { MainStateSyncEnhancerOptions } from 'src/options/MainStateSyncEnhancerOptions' | ||
import { validateAction } from 'src/utils' | ||
|
||
export const forwardActionToRenderers = <A>( | ||
action: A, | ||
options: MainStateSyncEnhancerOptions = {} | ||
): void => { | ||
if (validateAction(action, options.denyList)) { | ||
webContents.getAllWebContents().forEach((contents) => { | ||
// Ignore chromium devtools | ||
if (contents.getURL().startsWith('devtools://')) return | ||
contents.send(IPCEvents.ACTION, action) | ||
}) | ||
} | ||
} |
Oops, something went wrong.