This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1261 from beakerbrowser/external-dat-process
Move dat into a 'daemon' process
- Loading branch information
Showing
14 changed files
with
156 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {app, BrowserWindow} from 'electron' | ||
|
||
// globals | ||
// = | ||
|
||
var hiddenWindows = {} | ||
|
||
// exported api | ||
// = | ||
|
||
export async function spawn (id, modulePath) { | ||
var fullModulePath = require.resolve(modulePath) | ||
var win = new BrowserWindow({show: false}) | ||
// win.webContents.toggleDevTools() | ||
console.log('[', id, '] Starting...') | ||
win.loadURL(`beaker-hidden-window://loader/?module=${encodeURIComponent(fullModulePath)}&userDataPath=${encodeURIComponent(app.getPath('userData'))}`) | ||
win.webContents.on('console-message', (e, level, msg) => { | ||
console.log('[', id, ']', msg) | ||
}) | ||
await new Promise((resolve, reject) => { | ||
win.webContents.on('did-finish-load', resolve) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}) | ||
hiddenWindows[id] = win | ||
return win | ||
} | ||
|
||
export function close (id) { | ||
hiddenWindows[id].close() | ||
delete hiddenWindows[id] | ||
} | ||
|
||
export async function exec (id, script) { | ||
return hiddenWindows[id].executeJavaScript(script) | ||
} | ||
|
||
export async function send (id, ...args) { | ||
return hiddenWindows[id].webContents.send(...args) | ||
} |
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,10 @@ | ||
import {protocol} from 'electron' | ||
import path from 'path' | ||
|
||
export function setup () { | ||
protocol.registerFileProtocol('beaker-hidden-window', (request, cb) => { | ||
cb({path: path.join(__dirname, 'hidden-window.html')}) | ||
}, e => { | ||
if (e) { console.error('Failed to register beaker-hidden-window protocol', e) } | ||
}) | ||
} |
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,8 @@ | ||
const {join} = require('path') | ||
const rpcAPI = require('pauls-electron-rpc') | ||
const beakerCoreDatDaemon = require('@beaker/core/dat/daemon') | ||
|
||
beakerCoreDatDaemon.setup({ | ||
rpcAPI, | ||
logfilePath: join(window.userDataPath, 'dat.log') | ||
}) |
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,30 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'"> | ||
</head> | ||
<body> | ||
<h1>Hidden Window</h1> | ||
<script> | ||
// patch console methods to properly give us full content to stdout | ||
function patchConsole (name) { | ||
var org = console[name] | ||
console[name] = (...args) => { | ||
org(args.map(v => { | ||
if (typeof v === 'string') return v | ||
return JSON.stringify(v) | ||
}).join(' ')) | ||
} | ||
} | ||
patchConsole('log') | ||
patchConsole('debug') | ||
patchConsole('warn') | ||
patchConsole('error') | ||
|
||
// load module | ||
var url = new URL(window.location) | ||
console.log('Loading: ' + url.searchParams.get('module')) | ||
window.userDataPath = url.searchParams.get('userDataPath') | ||
require(url.searchParams.get('module')) | ||
</script> | ||
</body> | ||
</html> |
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
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
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
Neat!