@scrypted/server 0.115.35 → 0.115.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/postinstall CHANGED
@@ -4,5 +4,3 @@
4
4
  if (!process.env.SCRYPTED_PYTHON_PATH) {
5
5
  require('./packaged-python').installScryptedServerRequirements();
6
6
  }
7
-
8
- require('./electron-get').installElectron();
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBuiltinRuntimeHosts = getBuiltinRuntimeHosts;
4
4
  const custom_worker_1 = require("./custom-worker");
5
- const electron_worker_1 = require("./electron-worker");
6
5
  const node_fork_worker_1 = require("./node-fork-worker");
7
6
  const python_worker_1 = require("./python-worker");
8
7
  function getBuiltinRuntimeHosts() {
@@ -10,12 +9,6 @@ function getBuiltinRuntimeHosts() {
10
9
  pluginHosts.set('custom', (_, pluginId, options, runtime) => new custom_worker_1.CustomRuntimeWorker(pluginId, options, runtime));
11
10
  pluginHosts.set('python', (_, pluginId, options) => new python_worker_1.PythonRuntimeWorker(pluginId, options));
12
11
  pluginHosts.set('node', (mainFilename, pluginId, options) => new node_fork_worker_1.NodeForkWorker(mainFilename, pluginId, options));
13
- // safe
14
- pluginHosts.set('electron', (mainFilename, pluginId, options, runtime) => new electron_worker_1.ElectronForkWorker(mainFilename, pluginId, options, runtime, 'default'));
15
- // mostly safe
16
- pluginHosts.set('electron-webgl', (mainFilename, pluginId, options, runtime) => new electron_worker_1.ElectronForkWorker(mainFilename, pluginId, options, runtime, 'webgl'));
17
- // there be dragons
18
- pluginHosts.set('electron-webgpu', (mainFilename, pluginId, options, runtime) => new electron_worker_1.ElectronForkWorker(mainFilename, pluginId, options, runtime, 'webgpu'));
19
12
  return pluginHosts;
20
13
  }
21
14
  //# sourceMappingURL=runtime-host.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-host.js","sourceRoot":"","sources":["../../../src/plugin/runtime/runtime-host.ts"],"names":[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AAC,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE7J,OAAO,WAAW,CAAC;AACvB,CAAC"}
1
+ {"version":3,"file":"runtime-host.js","sourceRoot":"","sources":["../../../src/plugin/runtime/runtime-host.ts"],"names":[],"mappings":";;AAQA,wDAQC;AAfD,mDAAsD;AACtD,yDAAoD;AACpD,mDAAsD;AAKtD,SAAgB,sBAAsB;IAClC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEnD,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,mCAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAClH,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,mCAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAChG,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,iCAAc,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAElH,OAAO,WAAW,CAAC;AACvB,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@scrypted/server",
3
- "version": "0.115.35",
3
+ "version": "0.115.37",
4
4
  "description": "",
5
5
  "dependencies": {
6
- "@electron/get": "^3.1.0",
7
6
  "@mapbox/node-pre-gyp": "^1.0.11",
8
7
  "@scrypted/ffmpeg-static": "^6.1.0-build1",
9
8
  "@scrypted/node-pty": "^1.0.18",
10
- "@scrypted/types": "^0.3.51",
9
+ "@scrypted/types": "^0.3.53",
11
10
  "adm-zip": "^0.5.15",
12
11
  "body-parser": "^1.20.2",
13
12
  "cookie-parser": "^1.4.6",
@@ -29,7 +28,7 @@
29
28
  "sharp": "^0.33.5",
30
29
  "source-map-support": "^0.5.21",
31
30
  "tar": "^7.4.3",
32
- "tslib": "^2.6.3",
31
+ "tslib": "^2.7.0",
33
32
  "typescript": "^5.5.4",
34
33
  "whatwg-mimetype": "^4.0.0",
35
34
  "ws": "^8.18.0"
@@ -41,14 +40,13 @@
41
40
  "@types/follow-redirects": "^1.14.4",
42
41
  "@types/http-auth": "^4.1.4",
43
42
  "@types/lodash": "^4.17.7",
44
- "@types/node": "^22.4.2",
43
+ "@types/node": "^22.5.0",
45
44
  "@types/node-dijkstra": "^2.5.6",
46
45
  "@types/node-forge": "^1.3.11",
47
46
  "@types/semver": "^7.5.8",
48
47
  "@types/source-map-support": "^0.5.10",
49
48
  "@types/whatwg-mimetype": "^3.0.2",
50
- "@types/ws": "^8.5.12",
51
- "electron": "^31.4.0"
49
+ "@types/ws": "^8.5.12"
52
50
  },
53
51
  "bin": {
54
52
  "scrypted-serve": "bin/scrypted-serve"
@@ -1,6 +1,5 @@
1
1
  import type { ScryptedRuntime } from "../../runtime";
2
2
  import { CustomRuntimeWorker } from "./custom-worker";
3
- import { ElectronForkWorker } from "./electron-worker";
4
3
  import { NodeForkWorker } from "./node-fork-worker";
5
4
  import { PythonRuntimeWorker } from "./python-worker";
6
5
  import type { RuntimeWorker, RuntimeWorkerOptions } from "./runtime-worker";
@@ -14,12 +13,5 @@ export function getBuiltinRuntimeHosts() {
14
13
  pluginHosts.set('python', (_, pluginId, options) => new PythonRuntimeWorker(pluginId, options));
15
14
  pluginHosts.set('node', (mainFilename, pluginId, options) => new NodeForkWorker(mainFilename, pluginId, options));
16
15
 
17
- // safe
18
- pluginHosts.set('electron', (mainFilename, pluginId, options, runtime) => new ElectronForkWorker(mainFilename, pluginId, options, runtime, 'default'));
19
- // mostly safe
20
- pluginHosts.set('electron-webgl', (mainFilename, pluginId, options, runtime) => new ElectronForkWorker(mainFilename, pluginId, options, runtime, 'webgl'));
21
- // there be dragons
22
- pluginHosts.set('electron-webgpu', (mainFilename, pluginId, options, runtime) => new ElectronForkWorker(mainFilename, pluginId, options, runtime, 'webgpu'));
23
-
24
16
  return pluginHosts;
25
17
  }
@@ -1,3 +0,0 @@
1
- export declare declare const version: string;
2
- export declare async function installElectron(): Promise<void>;
3
- export declare const electronBin: string;
@@ -1,49 +0,0 @@
1
- const path = require('path');
2
- const extract = require('extract-zip');
3
- const { download } = require('@electron/get');
4
- const fs = require('fs');
5
-
6
- const version = '31.4.0';
7
- const binDir = path.join(__dirname, '..', 'electron', 'bin');
8
- const versionedBinDir = path.join(binDir, process.platform, version);
9
- const tmpDir = path.join(versionedBinDir, 'tmp');
10
- const targetDir = path.join(versionedBinDir, 'target');
11
-
12
- let electronBin;
13
- switch (process.platform) {
14
- case 'mas':
15
- case 'darwin':
16
- electronBin = 'Electron.app/Contents/MacOS/Electron';
17
- break;
18
- case 'freebsd':
19
- case 'openbsd':
20
- case 'linux':
21
- electronBin = 'electron';
22
- break;
23
- case 'win32':
24
- electronBin = 'electron.exe';
25
- break;
26
- default:
27
- console.warn('Electron builds are not available on platform: ' + process.platform);
28
- }
29
-
30
- module.exports.version = version;
31
- module.exports.electronBin = electronBin ? path.join(targetDir, electronBin) : undefined;
32
-
33
- function extractFile(zipPath) {
34
- return extract(zipPath, { dir: tmpDir });
35
- }
36
-
37
- module.exports.installElectron = function installElectron() {
38
- return download(version).then(async zipPath => {
39
- console.log('electron zip', zipPath);
40
- if (fs.existsSync(targetDir)) {
41
- console.log('electron already downloaded', targetDir);
42
- return;
43
- }
44
- fs.rmSync(binDir, { recursive: true, force: true });
45
- await extractFile(zipPath);
46
- fs.renameSync(tmpDir, targetDir);
47
- console.log('electron downloaded', targetDir);
48
- });
49
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const plugin_remote_worker_1 = require("../../plugin-remote-worker");
4
- const electron_1 = require("electron");
5
- // import { bufferWrapUint8Array } from "./buffer-wrap";
6
- // import { setNpmExecFunctionElectron } from "./set-npm-exec";
7
- const stream_1 = require("stream");
8
- const console_1 = require("console");
9
- const plugin_console_1 = require("../../plugin-console");
10
- // setNpmExecFunctionElectron();
11
- electron_1.ipcRenderer.on('scrypted-init', (e, initMessage) => {
12
- const { pluginId, options } = initMessage;
13
- for (const [k, v] of Object.entries(options.env || {})) {
14
- process.env[k] = v?.toString();
15
- }
16
- const originalConsole = console;
17
- const stdout = new stream_1.PassThrough();
18
- const stderr = new stream_1.PassThrough();
19
- (0, plugin_console_1.pipeWorkerConsole)({ stdout, stderr }, originalConsole);
20
- stdout.on('data', d => {
21
- electron_1.ipcRenderer.send('scrypted-stdout', d);
22
- });
23
- stderr.on('data', d => {
24
- electron_1.ipcRenderer.send('scrypted-stderr', d);
25
- });
26
- const pluginConsole = new console_1.Console(stdout, stderr);
27
- globalThis.foo = 3;
28
- global.console = pluginConsole;
29
- global.ss = originalConsole;
30
- const peer = (0, plugin_remote_worker_1.startPluginRemote)('', pluginId, (message, reject, serializationContext) => {
31
- try {
32
- electron_1.ipcRenderer.send('scrypted', message);
33
- }
34
- catch (e) {
35
- reject?.(e);
36
- }
37
- }, {
38
- sourceURL(filename) {
39
- return `scrypted-electron://${filename}`;
40
- }
41
- });
42
- // const evalLocal = peer.evalLocal.bind(peer);
43
- // peer.evalLocal = (script, filename, params) => {
44
- // // at some point vscode or chromes source map pathing got confused by
45
- // // file paths and no longer mapped them. by using a custom protocol,
46
- // // the source map paths get properly resolved.
47
- // return evalLocal(script, `scrypted-electron://${filename}`, params);
48
- // }
49
- peer.transportSafeArgumentTypes.add(Buffer.name);
50
- peer.transportSafeArgumentTypes.add(Uint8Array.name);
51
- // const deserialize = peer.deserialize;
52
- // peer.deserialize = (value, deserializationContext) => {
53
- // const ret = deserialize.call(peer, value, deserializationContext);
54
- // if (ret instanceof Uint8Array)
55
- // return bufferWrapUint8Array(ret);
56
- // return ret;
57
- // }
58
- electron_1.ipcRenderer.on('scrypted', (_, data) => {
59
- peer.handleMessage(data);
60
- });
61
- });
62
- //# sourceMappingURL=electron-plugin-preload.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"electron-plugin-preload.js","sourceRoot":"","sources":["../../../../src/plugin/runtime/electron/electron-plugin-preload.ts"],"names":[],"mappings":";;AAAA,qEAA+D;AAC/D,uCAAuC;AACvC,wDAAwD;AACxD,+DAA+D;AAC/D,mCAAqC;AACrC,qCAAkC;AAElC,yDAAyD;AAEzD,gCAAgC;AAEhC,sBAAW,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,WAAgE,EAAE,EAAE;IACpG,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC;IAE1C,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,eAAe,GAAG,OAAO,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,oBAAW,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,oBAAW,EAAE,CAAC;IACjC,IAAA,kCAAiB,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC;IACvD,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;QAClB,sBAAW,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;QAClB,sBAAW,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,IAAI,iBAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,UAAkB,CAAC,GAAG,GAAG,CAAC,CAAC;IAC5B,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;IAC9B,MAAc,CAAC,EAAE,GAAG,eAAe,CAAC;IAErC,MAAM,IAAI,GAAG,IAAA,wCAAiB,EAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,EAAE;QACnF,IAAI,CAAC;YACD,sBAAW,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACP,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACL,CAAC,EAAE;QACC,SAAS,CAAC,QAAQ;YACd,OAAO,uBAAuB,QAAQ,EAAE,CAAC;QAC7C,CAAC;KACJ,CAAC,CAAC;IAEH,+CAA+C;IAC/C,mDAAmD;IACnD,4EAA4E;IAC5E,2EAA2E;IAC3E,qDAAqD;IACrD,2EAA2E;IAC3E,IAAI;IAEJ,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAErD,wCAAwC;IACxC,0DAA0D;IAC1D,yEAAyE;IACzE,qCAAqC;IACrC,4CAA4C;IAC5C,kBAAkB;IAClB,IAAI;IAEJ,sBAAW,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;QACnC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAC"}
@@ -1,82 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const electron_1 = require("electron");
7
- const path_1 = __importDefault(require("path"));
8
- const deferred_1 = require("../../../deferred");
9
- if (process.platform === 'darwin') {
10
- // Electron plist must be modified with this to hide dock icon before start. app.dock.hide flashes the dock before program starts.
11
- // <key>LSUIElement</key>
12
- // <string>1</string>
13
- electron_1.app.dock.hide();
14
- }
15
- let win;
16
- const winQueue = [];
17
- const createWindow = (firstMessage) => {
18
- const message = firstMessage;
19
- win = new electron_1.BrowserWindow({
20
- width: 800,
21
- height: 600,
22
- show: false,
23
- webPreferences: {
24
- backgroundThrottling: false,
25
- preload: path_1.default.join(__dirname, 'electron-plugin-preload.js'),
26
- nodeIntegration: true,
27
- webSecurity: false,
28
- allowRunningInsecureContent: true,
29
- }
30
- });
31
- win.webContents.send('scrypted-init', message);
32
- // win.loadURL('https://webglsamples.org/aquarium/aquarium.html');
33
- console.log(__dirname);
34
- const html = path_1.default.join(__dirname, '../../../../electron', 'electron-plugin.html');
35
- win.loadFile(html);
36
- win.webContents.openDevTools();
37
- win.webContents.ipc.on('scrypted', (e, message) => {
38
- process.send(message);
39
- });
40
- win.webContents.ipc.on('scrypted-stdout', (e, message) => {
41
- process.stdout.write(message);
42
- });
43
- win.webContents.ipc.on('scrypted-stderr', (e, message) => {
44
- process.stderr.write(message);
45
- });
46
- while (winQueue.length) {
47
- processMessage(winQueue.shift());
48
- }
49
- function kill() {
50
- process.exit();
51
- }
52
- win.webContents.on('destroyed', kill);
53
- win.webContents.on('plugin-crashed', kill);
54
- win.on('close', kill);
55
- };
56
- const firstMessage = new deferred_1.Deferred;
57
- function processMessage(message) {
58
- win.webContents.send('scrypted', message);
59
- }
60
- process.on('message', (message) => {
61
- if (!firstMessage.finished) {
62
- firstMessage.resolve(message);
63
- return;
64
- }
65
- if (win)
66
- processMessage(message);
67
- else
68
- winQueue.push(message);
69
- });
70
- process.on('disconnect', () => {
71
- console.error('peer host disconnected, exiting.');
72
- process.exit(1);
73
- });
74
- electron_1.app.on('window-all-closed', () => {
75
- if (process.platform !== 'darwin')
76
- electron_1.app.quit();
77
- });
78
- electron_1.app.whenReady().then(async () => {
79
- const message = await firstMessage.promise;
80
- createWindow(message);
81
- });
82
- //# sourceMappingURL=electron-plugin-remote.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"electron-plugin-remote.js","sourceRoot":"","sources":["../../../../src/plugin/runtime/electron/electron-plugin-remote.ts"],"names":[],"mappings":";;;;;AAAA,uCAA8C;AAC9C,gDAAwB;AACxB,gDAA6C;AAG7C,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;IAChC,kIAAkI;IAClI,yBAAyB;IACzB,qBAAqB;IACrB,cAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC;AAED,IAAI,GAAkB,CAAC;AACvB,MAAM,QAAQ,GAAU,EAAE,CAAC;AAE3B,MAAM,YAAY,GAAG,CAAC,YAAkE,EAAE,EAAE;IACxF,MAAM,OAAO,GAAyD,YAAY,CAAC;IAEnF,GAAG,GAAG,IAAI,wBAAa,CAAC;QACpB,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,KAAK;QACX,cAAc,EAAE;YACZ,oBAAoB,EAAE,KAAK;YAC3B,OAAO,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,4BAA4B,CAAC;YAC3D,eAAe,EAAE,IAAI;YACrB,WAAW,EAAE,KAAK;YAClB,2BAA2B,EAAE,IAAI;SACpC;KACJ,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAE/C,kEAAkE;IAClE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACvB,MAAM,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,sBAAsB,EAAE,sBAAsB,CAAC,CAAC;IAClF,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnB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,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;QACzB,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO;IACX,CAAC;IAED,IAAI,GAAG;QACH,cAAc,CAAC,OAAO,CAAC,CAAC;;QAExB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAEH,cAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAC7B,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAAE,cAAG,CAAC,IAAI,EAAE,CAAA;AACjD,CAAC,CAAC,CAAA;AAEF,cAAG,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;IAC3B,MAAM,OAAO,GAAyD,MAAM,YAAY,CAAC,OAAO,CAAC;IAClG,YAAY,CAAC,OAAO,CAAC,CAAA;AACzB,CAAC,CAAC,CAAC"}
@@ -1,13 +0,0 @@
1
- import { RpcMessage, RpcPeer } from "../../rpc";
2
- import { ChildProcessWorker } from "./child-process-worker";
3
- import { RuntimeWorkerOptions } from "./runtime-worker";
4
- import type { ScryptedRuntime } from '../../runtime';
5
- export declare class ElectronForkWorker extends ChildProcessWorker {
6
- static allocatedDisplays: Set<number>;
7
- allocatedDisplay: number;
8
- constructor(_mainFilename: string, pluginId: string, options: RuntimeWorkerOptions, runtime: ScryptedRuntime, mode: 'default' | 'webgl' | 'webgpu');
9
- kill(): void;
10
- setupRpcPeer(peer: RpcPeer): void;
11
- send(message: RpcMessage, reject?: (e: Error) => void, serializationContext?: any): void;
12
- get pid(): number;
13
- }
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ElectronForkWorker = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const child_process_1 = __importDefault(require("child_process"));
10
- const net_1 = __importDefault(require("net"));
11
- const socket_serializer_1 = require("../socket-serializer");
12
- const child_process_worker_1 = require("./child-process-worker");
13
- const electron_get_1 = require("../../../bin/electron-get");
14
- class ElectronForkWorker extends child_process_worker_1.ChildProcessWorker {
15
- static allocatedDisplays = new Set();
16
- allocatedDisplay;
17
- constructor(_mainFilename, pluginId, options, runtime, mode) {
18
- super(pluginId, options);
19
- const { env } = options;
20
- fs_1.default.chmodSync(electron_get_1.electronBin, 0o755);
21
- const enabledFeatures = ['SharedArrayBuffer'];
22
- const args = [
23
- electron_get_1.electronBin,
24
- '--disable-features=BlockInsecurePrivateNetworkRequests,PrivateNetworkAccessSendPreflights',
25
- ];
26
- if (mode !== 'default') {
27
- args.push('--ignore-gpu-blocklist');
28
- }
29
- if (process.platform === 'linux') {
30
- // crappy but should work.
31
- for (let i = 50; i < 100; i++) {
32
- if (!ElectronForkWorker.allocatedDisplays.has(i)) {
33
- this.allocatedDisplay = i;
34
- break;
35
- }
36
- }
37
- if (!this.allocatedDisplay)
38
- throw new Error('unable to allocate DISPLAY for xvfb-run');
39
- ElectronForkWorker.allocatedDisplays.add(this.allocatedDisplay);
40
- // requires xvfb-run as electron does not support the chrome --headless flag.
41
- // dummy up a DISPLAY env variable. this value numerical because of the way it is.
42
- args.unshift('xvfb-run', '-n', this.allocatedDisplay.toString());
43
- // https://github.com/gpuweb/gpuweb/wiki/Implementation-Status#chromium-chrome-edge-etc
44
- args.push('--no-sandbox');
45
- if (mode === 'webgpu') {
46
- args.push('--enable-unsafe-webgpu', '--disable-vulkan-surface');
47
- enabledFeatures.push('Vulkan');
48
- }
49
- }
50
- args.push(`--enable-features=${enabledFeatures.join(",")}`);
51
- if (process.platform === 'darwin') {
52
- // Electron plist must be modified with this to hide dock icon before start. app.dock.hide flashes the dock before program starts.
53
- // <key>LSUIElement</key>
54
- // <string>1</string>
55
- }
56
- if (options?.pluginDebug) {
57
- args.push(`--remote-debugging-port=${options?.pluginDebug.inspectPort}`);
58
- }
59
- args.push(path_1.default.join(__dirname, 'electron', 'electron-plugin-remote.js'), '--', 'child', this.pluginId);
60
- const bin = args.shift();
61
- this.worker = child_process_1.default.spawn(bin, args, {
62
- stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
63
- env: Object.assign({}, process.env, env),
64
- serialization: 'advanced',
65
- });
66
- this.worker.on('exit', () => {
67
- });
68
- if (options?.pluginDebug?.waitDebug) {
69
- options.pluginDebug.waitDebug.catch(() => { });
70
- options.pluginDebug.waitDebug = Promise.resolve(undefined);
71
- }
72
- this.worker.send({
73
- pluginId,
74
- options: {
75
- ...options,
76
- pluginDebug: options?.pluginDebug ? {
77
- ...options.pluginDebug,
78
- // dont want to send/serialize this.
79
- waitDebug: null,
80
- } : undefined,
81
- },
82
- });
83
- this.setupWorker();
84
- }
85
- kill() {
86
- super.kill();
87
- if (this.worker)
88
- ElectronForkWorker.allocatedDisplays.delete(this.allocatedDisplay);
89
- }
90
- setupRpcPeer(peer) {
91
- this.worker.on('message', (message, sendHandle) => {
92
- if (message.type && sendHandle) {
93
- peer.handleMessage(message, {
94
- sendHandle,
95
- });
96
- }
97
- else if (sendHandle) {
98
- this.emit('rpc', message, sendHandle);
99
- }
100
- else {
101
- peer.handleMessage(message);
102
- }
103
- });
104
- peer.transportSafeArgumentTypes.add(Buffer.name);
105
- peer.transportSafeArgumentTypes.add(Uint8Array.name);
106
- peer.addSerializer(net_1.default.Socket, net_1.default.Socket.name, new socket_serializer_1.SidebandSocketSerializer());
107
- }
108
- send(message, reject, serializationContext) {
109
- try {
110
- if (!this.worker)
111
- throw new Error('fork worker has been killed');
112
- this.worker.send(message, serializationContext?.sendHandle, e => {
113
- if (e && reject)
114
- reject(e);
115
- });
116
- }
117
- catch (e) {
118
- reject?.(e);
119
- }
120
- }
121
- get pid() {
122
- return this.worker?.pid;
123
- }
124
- }
125
- exports.ElectronForkWorker = ElectronForkWorker;
126
- //# sourceMappingURL=electron-worker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"electron-worker.js","sourceRoot":"","sources":["../../../src/plugin/runtime/electron-worker.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,kEAA0C;AAC1C,8CAAsB;AAEtB,4DAAgE;AAChE,iEAA4D;AAG5D,4DAAwD;AAExD,MAAa,kBAAmB,SAAQ,yCAAkB;IACtD,MAAM,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7C,gBAAgB,CAAS;IAEzB,YAAY,aAAqB,EAAE,QAAgB,EAAE,OAA6B,EAAE,OAAwB,EAAE,IAAoC;QAC9I,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAEzB,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QAExB,YAAE,CAAC,SAAS,CAAC,0BAAW,EAAE,KAAK,CAAC,CAAC;QACjC,MAAM,eAAe,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG;YACT,0BAAW;YACX,2FAA2F;SAC9F,CAAC;QAEF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,CACL,wBAAwB,CAC3B,CAAC;QACN,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC/B,0BAA0B;YAC1B,KAAK,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC5B,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC/C,IAAI,CAAC,gBAAgB,GAAG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oBAC/B,UAAU;iBACb,CAAC,CAAC;YACP,CAAC;iBACI,IAAI,UAAU,EAAE,CAAC;gBAClB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;YAC1C,CAAC;iBACI,CAAC;gBACF,IAAI,CAAC,aAAa,CAAC,OAAc,CAAC,CAAC;YACvC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,CAAC,aAAa,CAAC,aAAG,CAAC,MAAM,EAAE,aAAG,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,4CAAwB,EAAE,CAAC,CAAC;IACpF,CAAC;IAED,IAAI,CAAC,OAAmB,EAAE,MAA2B,EAAE,oBAA0B;QAC7E,IAAI,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,MAAM;gBACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;YACnD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE;gBAC5D,IAAI,CAAC,IAAI,MAAM;oBACX,MAAM,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACP,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACH,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC;IAC5B,CAAC;;AA7IL,gDA8IC"}
@@ -1,6 +0,0 @@
1
- <html>
2
- <head>
3
- </head>
4
- <body>
5
- </body>
6
- </html>
@@ -1,70 +0,0 @@
1
- import { startPluginRemote } from "../../plugin-remote-worker";
2
- import { ipcRenderer } from 'electron';
3
- // import { bufferWrapUint8Array } from "./buffer-wrap";
4
- // import { setNpmExecFunctionElectron } from "./set-npm-exec";
5
- import { PassThrough } from "stream";
6
- import { Console } from "console";
7
- import type { RuntimeWorkerOptions } from "../runtime-worker";
8
- import { pipeWorkerConsole } from "../../plugin-console";
9
-
10
- // setNpmExecFunctionElectron();
11
-
12
- ipcRenderer.on('scrypted-init', (e, initMessage: { pluginId: string, options: RuntimeWorkerOptions }) => {
13
- const { pluginId, options } = initMessage;
14
-
15
- for (const [k, v] of Object.entries(options.env || {})) {
16
- process.env[k] = v?.toString();
17
- }
18
-
19
- const originalConsole = console;
20
- const stdout = new PassThrough();
21
- const stderr = new PassThrough();
22
- pipeWorkerConsole({ stdout, stderr }, originalConsole);
23
- stdout.on('data', d => {
24
- ipcRenderer.send('scrypted-stdout', d);
25
- });
26
- stderr.on('data', d => {
27
- ipcRenderer.send('scrypted-stderr', d);
28
- });
29
- const pluginConsole = new Console(stdout, stderr);
30
- (globalThis as any).foo = 3;
31
- global.console = pluginConsole;
32
- (global as any).ss = originalConsole;
33
-
34
- const peer = startPluginRemote('', pluginId, (message, reject, serializationContext) => {
35
- try {
36
- ipcRenderer.send('scrypted', message);
37
- }
38
- catch (e) {
39
- reject?.(e);
40
- }
41
- }, {
42
- sourceURL(filename) {
43
- return `scrypted-electron://${filename}`;
44
- }
45
- });
46
-
47
- // const evalLocal = peer.evalLocal.bind(peer);
48
- // peer.evalLocal = (script, filename, params) => {
49
- // // at some point vscode or chromes source map pathing got confused by
50
- // // file paths and no longer mapped them. by using a custom protocol,
51
- // // the source map paths get properly resolved.
52
- // return evalLocal(script, `scrypted-electron://${filename}`, params);
53
- // }
54
-
55
- peer.transportSafeArgumentTypes.add(Buffer.name);
56
- peer.transportSafeArgumentTypes.add(Uint8Array.name);
57
-
58
- // const deserialize = peer.deserialize;
59
- // peer.deserialize = (value, deserializationContext) => {
60
- // const ret = deserialize.call(peer, value, deserializationContext);
61
- // if (ret instanceof Uint8Array)
62
- // return bufferWrapUint8Array(ret);
63
- // return ret;
64
- // }
65
-
66
- ipcRenderer.on('scrypted', (_, data) => {
67
- peer.handleMessage(data);
68
- })
69
- });
70
-
@@ -1,91 +0,0 @@
1
- import { app, BrowserWindow } from 'electron';
2
- import path from 'path';
3
- import { Deferred } from '../../../deferred';
4
- import { RuntimeWorkerOptions } from '../runtime-worker';
5
-
6
- if (process.platform === 'darwin') {
7
- // Electron plist must be modified with this to hide dock icon before start. app.dock.hide flashes the dock before program starts.
8
- // <key>LSUIElement</key>
9
- // <string>1</string>
10
- app.dock.hide();
11
- }
12
-
13
- let win: BrowserWindow;
14
- const winQueue: any[] = [];
15
-
16
- const createWindow = (firstMessage: { plugindId: string, options: RuntimeWorkerOptions }) => {
17
- const message: { plugindId: string, options: RuntimeWorkerOptions } = firstMessage;
18
-
19
- win = new BrowserWindow({
20
- width: 800,
21
- height: 600,
22
- show: false,
23
- webPreferences: {
24
- backgroundThrottling: false,
25
- preload: path.join(__dirname, 'electron-plugin-preload.js'),
26
- nodeIntegration: true,
27
- webSecurity: false,
28
- allowRunningInsecureContent: true,
29
- }
30
- });
31
- win.webContents.send('scrypted-init', message);
32
-
33
- // win.loadURL('https://webglsamples.org/aquarium/aquarium.html');
34
- console.log(__dirname);
35
- const html = path.join(__dirname, '../../../../electron', 'electron-plugin.html');
36
- win.loadFile(html);
37
- win.webContents.openDevTools();
38
-
39
- win.webContents.ipc.on('scrypted', (e, message) => {
40
- process.send(message);
41
- });
42
- win.webContents.ipc.on('scrypted-stdout', (e, message) => {
43
- process.stdout.write(message);
44
- });
45
- win.webContents.ipc.on('scrypted-stderr', (e, message) => {
46
- process.stderr.write(message);
47
- });
48
-
49
- while (winQueue.length) {
50
- processMessage(winQueue.shift());
51
- }
52
-
53
- function kill() {
54
- process.exit();
55
- }
56
-
57
- win.webContents.on('destroyed', kill);
58
- win.webContents.on('plugin-crashed', kill);
59
- win.on('close', kill);
60
- }
61
-
62
- const firstMessage = new Deferred<any>;
63
- function processMessage(message: any) {
64
- win.webContents.send('scrypted', message);
65
- }
66
-
67
- process.on('message', (message) => {
68
- if (!firstMessage.finished) {
69
- firstMessage.resolve(message);
70
- return;
71
- }
72
-
73
- if (win)
74
- processMessage(message);
75
- else
76
- winQueue.push(message);
77
- });
78
-
79
- process.on('disconnect', () => {
80
- console.error('peer host disconnected, exiting.');
81
- process.exit(1);
82
- });
83
-
84
- app.on('window-all-closed', () => {
85
- if (process.platform !== 'darwin') app.quit()
86
- })
87
-
88
- app.whenReady().then(async () => {
89
- const message: { plugindId: string, options: RuntimeWorkerOptions } = await firstMessage.promise;
90
- createWindow(message)
91
- });
@@ -1,154 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import child_process from 'child_process';
4
- import net from "net";
5
- import { RpcMessage, RpcPeer } from "../../rpc";
6
- import { SidebandSocketSerializer } from "../socket-serializer";
7
- import { ChildProcessWorker } from "./child-process-worker";
8
- import { RuntimeWorkerOptions } from "./runtime-worker";
9
- import type { ScryptedRuntime } from '../../runtime';
10
- import { electronBin } from '../../../bin/electron-get';
11
-
12
- export class ElectronForkWorker extends ChildProcessWorker {
13
- static allocatedDisplays = new Set<number>();
14
- allocatedDisplay: number;
15
-
16
- constructor(_mainFilename: string, pluginId: string, options: RuntimeWorkerOptions, runtime: ScryptedRuntime, mode: 'default' | 'webgl' | 'webgpu') {
17
- super(pluginId, options);
18
-
19
- const { env } = options;
20
-
21
- fs.chmodSync(electronBin, 0o755);
22
- const enabledFeatures = ['SharedArrayBuffer'];
23
- const args = [
24
- electronBin,
25
- '--disable-features=BlockInsecurePrivateNetworkRequests,PrivateNetworkAccessSendPreflights',
26
- ];
27
-
28
- if (mode !== 'default') {
29
- args.push(
30
- '--ignore-gpu-blocklist',
31
- );
32
- }
33
-
34
- if (process.platform === 'linux') {
35
- // crappy but should work.
36
- for (let i = 50; i < 100; i++) {
37
- if (!ElectronForkWorker.allocatedDisplays.has(i)) {
38
- this.allocatedDisplay = i;
39
- break;
40
- }
41
- }
42
-
43
- if (!this.allocatedDisplay)
44
- throw new Error('unable to allocate DISPLAY for xvfb-run');
45
-
46
- ElectronForkWorker.allocatedDisplays.add(this.allocatedDisplay);
47
-
48
- // requires xvfb-run as electron does not support the chrome --headless flag.
49
- // dummy up a DISPLAY env variable. this value numerical because of the way it is.
50
- args.unshift('xvfb-run', '-n', this.allocatedDisplay.toString());
51
- // https://github.com/gpuweb/gpuweb/wiki/Implementation-Status#chromium-chrome-edge-etc
52
- args.push(
53
- '--no-sandbox',
54
- );
55
-
56
- if (mode === 'webgpu') {
57
- args.push(
58
- '--enable-unsafe-webgpu',
59
- '--disable-vulkan-surface',
60
- );
61
- enabledFeatures.push('Vulkan');
62
- }
63
- }
64
- args.push(
65
- `--enable-features=${enabledFeatures.join(",")}`,
66
- )
67
-
68
- if (process.platform === 'darwin') {
69
- // Electron plist must be modified with this to hide dock icon before start. app.dock.hide flashes the dock before program starts.
70
- // <key>LSUIElement</key>
71
- // <string>1</string>
72
- }
73
-
74
- if (options?.pluginDebug) {
75
- args.push(`--remote-debugging-port=${options?.pluginDebug.inspectPort}`);
76
- }
77
-
78
- args.push(
79
- path.join(__dirname, 'electron', 'electron-plugin-remote.js'),
80
- '--', 'child', this.pluginId);
81
-
82
- const bin = args.shift();
83
- this.worker = child_process.spawn(bin, args, {
84
- stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
85
- env: Object.assign({}, process.env, env),
86
- serialization: 'advanced',
87
- });
88
-
89
- this.worker.on('exit', () => {
90
- });
91
-
92
- if (options?.pluginDebug?.waitDebug) {
93
- options.pluginDebug.waitDebug.catch(() => { });
94
- options.pluginDebug.waitDebug = Promise.resolve(undefined);
95
- }
96
-
97
- this.worker.send({
98
- pluginId,
99
- options: {
100
- ...options,
101
- pluginDebug: options?.pluginDebug ? {
102
- ...options.pluginDebug,
103
- // dont want to send/serialize this.
104
- waitDebug: null,
105
- } : undefined,
106
- },
107
- });
108
-
109
- this.setupWorker();
110
- }
111
-
112
- kill(): void {
113
- super.kill();
114
- if (this.worker)
115
- ElectronForkWorker.allocatedDisplays.delete(this.allocatedDisplay);
116
- }
117
-
118
- setupRpcPeer(peer: RpcPeer): void {
119
- this.worker.on('message', (message, sendHandle) => {
120
- if ((message as any).type && sendHandle) {
121
- peer.handleMessage(message as any, {
122
- sendHandle,
123
- });
124
- }
125
- else if (sendHandle) {
126
- this.emit('rpc', message, sendHandle);
127
- }
128
- else {
129
- peer.handleMessage(message as any);
130
- }
131
- });
132
- peer.transportSafeArgumentTypes.add(Buffer.name);
133
- peer.transportSafeArgumentTypes.add(Uint8Array.name);
134
- peer.addSerializer(net.Socket, net.Socket.name, new SidebandSocketSerializer());
135
- }
136
-
137
- send(message: RpcMessage, reject?: (e: Error) => void, serializationContext?: any): void {
138
- try {
139
- if (!this.worker)
140
- throw new Error('fork worker has been killed');
141
- this.worker.send(message, serializationContext?.sendHandle, e => {
142
- if (e && reject)
143
- reject(e);
144
- });
145
- }
146
- catch (e) {
147
- reject?.(e);
148
- }
149
- }
150
-
151
- get pid() {
152
- return this.worker?.pid;
153
- }
154
- }