Created
February 5, 2022 18:59
-
-
Save Sveagruva/04d02de3a61c8561e37566d355cc8876 to your computer and use it in GitHub Desktop.
stream content asynchronously in your electron app without http server. stream html as you build it.
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
const electron = require('electron'); | |
const PassThrough = require('stream').PassThrough; | |
// why. idk | |
electron.app.whenReady().then(() => { | |
electron.protocol.interceptStreamProtocol('file', async (req, callback) => { | |
const stream = new PassThrough(); | |
callback({ | |
data: stream | |
}); | |
for (let i = 0; i < 100; i++) { | |
await wait(100); | |
stream.push('hi\n'); | |
} | |
stream.push(null); | |
}); | |
const window = new electron.BrowserWindow(); | |
window.webContents.openDevTools(); | |
window.loadFile("index.html"); | |
}); | |
const wait = async (ms) => new Promise(r => setTimeout(() => r(), ms)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment