https://github.com/tableflip/electron-window.ipfs
Test repo to see if we can add `window.ipfs` to a web page bundled in electron
https://github.com/tableflip/electron-window.ipfs
Last synced: about 1 year ago
JSON representation
Test repo to see if we can add `window.ipfs` to a web page bundled in electron
- Host: GitHub
- URL: https://github.com/tableflip/electron-window.ipfs
- Owner: tableflip
- License: cc0-1.0
- Created: 2018-03-21T16:46:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-21T16:58:15.000Z (over 8 years ago)
- Last Synced: 2025-02-15T12:46:52.489Z (over 1 year ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# electron-window.ipfs
> This is a test repo to see if we can add `window.ipfs` to a web page bundled in electron.
In this repo we're using the [``](https://electronjs.org/docs/api/webview-tag) tag in the renderer process to load up a web app from a URL.
```html
```
The web app makes use of `window.ipfs` if it is available.
The [`preload`](https://electronjs.org/docs/api/webview-tag#preload) attribute allows us to run a script on the `` page before other scripts run. We use `preload` to create the `window.ipfs` object that the app can use.
**webview.js**
```js
const { ipcRenderer } = require('electron')
const { createProxyClient } = require('ipfs-postmsg-proxy')
window.ipfs = createProxyClient({
postMessage: data => ipcRenderer.send('ipfs-postmsg-proxy:message', data),
addListener: (_, handler) => ipcRenderer.on('ipfs-postmsg-proxy:message', handler),
removeListener: (_, handler) => ipcRenderer.removeListener('ipfs-postmsg-proxy:message', handler),
getMessageData: (_, data) => data
})
```
The `window.ipfs` object is a proxy that uses IPC messaging to communicate with the IPFS node running in the main process. We're using [`ipfs-postmsg-proxy`](https://github.com/tableflip/ipfs-postmsg-proxy) for this.