@holochain/hc-spin 0.200.13 → 0.200.15

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/cli/cli.js CHANGED
@@ -1,36 +1,39 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require('child_process');
2
+ const { spawn, spawnSync } = require('child_process');
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
5
 
6
- let electronBinary;
7
- let pathStr =
8
- process.platform === 'win32'
9
- ? '../node_modules/electron/dist/electron.exe'
10
- : '../node_modules/.bin/electron';
11
-
12
- // recursively look for electron binary in node_modules folder
13
- for (let i = 0; i < 7; i++) {
14
- const maybeElectronBinary = path.resolve(__dirname, pathStr);
15
- if (fs.existsSync(maybeElectronBinary)) {
16
- electronBinary = maybeElectronBinary;
17
- break;
18
- } else {
19
- pathStr = '../' + pathStr;
20
- }
21
- }
6
+ let electronBinary = process.env.ELECTRON_BINARY;
7
+
8
+ if (!electronBinary) {
9
+ // Check whether electron is installed globally and compare with the expected version
10
+ const electronHandleTemp = spawnSync('electron', ['--version']);
22
11
 
23
- // https://github.com/electron/electron/issues/17972
24
- if (process.platform === 'linux') {
25
- let chromeSandboxPathStr = '../node_modules/electron/dist/chrome-sandbox';
26
- // recursively look for electron binary in node_modules folder
27
- for (let i = 0; i < 7; i++) {
28
- const maybeChromeSandbox = path.resolve(__dirname, chromeSandboxPathStr);
29
- if (fs.existsSync(maybeChromeSandbox)) {
30
- fs.chmodSync(maybeChromeSandbox, 0o4755);
31
- break;
12
+ if (electronHandleTemp.stdout) {
13
+ if (!electronHandleTemp.stdout.toString().startsWith('v###REPLACE_AT_BUILD_TIME###')) {
14
+ console.warn(
15
+ 'WARNING: Found a globally installed electron version but it does not match the version requirements of hc-spin (v29.x). The electron binary from node_modules will be used instead.',
16
+ );
32
17
  } else {
33
- chromeSandboxPathStr = '../' + chromeSandboxPathStr;
18
+ electronBinary = 'electron';
19
+ }
20
+ }
21
+
22
+ if (!electronBinary) {
23
+ let pathStr =
24
+ process.platform === 'win32'
25
+ ? '../node_modules/electron/dist/electron.exe'
26
+ : '../node_modules/.bin/electron';
27
+
28
+ // recursively look for electron binary in node_modules folder
29
+ for (let i = 0; i < 7; i++) {
30
+ const maybeElectronBinary = path.resolve(__dirname, pathStr);
31
+ if (fs.existsSync(maybeElectronBinary)) {
32
+ electronBinary = maybeElectronBinary;
33
+ break;
34
+ } else {
35
+ pathStr = '../' + pathStr;
36
+ }
34
37
  }
35
38
  }
36
39
  }
package/dist/cli.js CHANGED
@@ -1,36 +1,39 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require('child_process');
2
+ const { spawn, spawnSync } = require('child_process');
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
5
 
6
- let electronBinary;
7
- let pathStr =
8
- process.platform === 'win32'
9
- ? '../node_modules/electron/dist/electron.exe'
10
- : '../node_modules/.bin/electron';
11
-
12
- // recursively look for electron binary in node_modules folder
13
- for (let i = 0; i < 7; i++) {
14
- const maybeElectronBinary = path.resolve(__dirname, pathStr);
15
- if (fs.existsSync(maybeElectronBinary)) {
16
- electronBinary = maybeElectronBinary;
17
- break;
18
- } else {
19
- pathStr = '../' + pathStr;
20
- }
21
- }
6
+ let electronBinary = process.env.ELECTRON_BINARY;
7
+
8
+ if (!electronBinary) {
9
+ // Check whether electron is installed globally and compare with the expected version
10
+ const electronHandleTemp = spawnSync('electron', ['--version']);
22
11
 
23
- // https://github.com/electron/electron/issues/17972
24
- if (process.platform === 'linux') {
25
- let chromeSandboxPathStr = '../node_modules/electron/dist/chrome-sandbox';
26
- // recursively look for electron binary in node_modules folder
27
- for (let i = 0; i < 7; i++) {
28
- const maybeChromeSandbox = path.resolve(__dirname, chromeSandboxPathStr);
29
- if (fs.existsSync(maybeChromeSandbox)) {
30
- fs.chmodSync(maybeChromeSandbox, 0o4755);
31
- break;
12
+ if (electronHandleTemp.stdout) {
13
+ if (!electronHandleTemp.stdout.toString().startsWith('v29.')) {
14
+ console.warn(
15
+ 'WARNING: Found a globally installed electron version but it does not match the version requirements of hc-spin (v29.x). The electron binary from node_modules will be used instead.',
16
+ );
32
17
  } else {
33
- chromeSandboxPathStr = '../' + chromeSandboxPathStr;
18
+ electronBinary = 'electron';
19
+ }
20
+ }
21
+
22
+ if (!electronBinary) {
23
+ let pathStr =
24
+ process.platform === 'win32'
25
+ ? '../node_modules/electron/dist/electron.exe'
26
+ : '../node_modules/.bin/electron';
27
+
28
+ // recursively look for electron binary in node_modules folder
29
+ for (let i = 0; i < 7; i++) {
30
+ const maybeElectronBinary = path.resolve(__dirname, pathStr);
31
+ if (fs.existsSync(maybeElectronBinary)) {
32
+ electronBinary = maybeElectronBinary;
33
+ break;
34
+ } else {
35
+ pathStr = '../' + pathStr;
36
+ }
34
37
  }
35
38
  }
36
39
  }
@@ -115,6 +115,7 @@ electron.contextBridge.exposeInMainWorld("__HC_LAUNCHER_ENV__", {
115
115
  title: `Agent ${agentNum} - ${appId}`,
116
116
  webPreferences: {
117
117
  preload: preloadPath,
118
+ sandbox: true,
118
119
  partition
119
120
  }
120
121
  });
@@ -11860,7 +11861,13 @@ electron.protocol.registerSchemesAsPrivileged([
11860
11861
  contextMenu({
11861
11862
  showSaveImageAs: true,
11862
11863
  showSearchWithGoogle: false,
11863
- showInspectElement: true
11864
+ showInspectElement: true,
11865
+ append: (_defaultActions, _parameters, browserWindow) => [
11866
+ {
11867
+ label: "Reload",
11868
+ click: () => browserWindow.reload()
11869
+ }
11870
+ ]
11864
11871
  });
11865
11872
  const handleSignZomeCall = async (e, request) => {
11866
11873
  const windowInfo = WINDOW_INFO_MAP[e.sender.id];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain/hc-spin",
3
- "version": "0.200.13",
3
+ "version": "0.200.15",
4
4
  "holochainVersion": "0.2.x",
5
5
  "description": "CLI to run Holochain aps during development.",
6
6
  "author": "matthme",
@@ -30,7 +30,7 @@
30
30
  "typecheck": "npm run typecheck:node && npm run typecheck:web",
31
31
  "start": "electron-vite preview",
32
32
  "dev": "electron-vite dev",
33
- "build": "rimraf dist && npm run typecheck && electron-vite build && mv ./out ./dist && cp ./cli/cli.js ./dist/cli.js"
33
+ "build": "rimraf dist && npm run typecheck && electron-vite build && mv ./out ./dist && cp ./cli/cli.js ./dist/cli.js && node ./scripts/replace-electron-version.js"
34
34
  },
35
35
  "dependencies": {
36
36
  "@electron-toolkit/preload": "^3.0.0",
@@ -39,7 +39,7 @@
39
39
  "@holochain/hc-spin-rust-utils": "^0.200.3",
40
40
  "@msgpack/msgpack": "^2.8.0",
41
41
  "commander": "11.1.0",
42
- "electron": "^28.1.1",
42
+ "electron": "^29.3.1",
43
43
  "electron-context-menu": "3.6.1",
44
44
  "get-port": "7.0.0",
45
45
  "nanoid": "5.0.4",
@@ -0,0 +1,11 @@
1
+ const fs = require('fs');
2
+
3
+ const packageJsonString = fs.readFileSync('package.json');
4
+ const packageJson = JSON.parse(packageJsonString);
5
+ const electronVersion = packageJson.dependencies.electron;
6
+ const majorElectronVersion = electronVersion.replace('^', '').slice(0, 3);
7
+ console.log('electron version: ', majorElectronVersion);
8
+
9
+ const cliJs = fs.readFileSync('./dist/cli.js', 'utf-8');
10
+ const modifiedCliJs = cliJs.replace('###REPLACE_AT_BUILD_TIME###', majorElectronVersion);
11
+ fs.writeFileSync('./dist/cli.js', modifiedCliJs);
package/src/main/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { app, IpcMainInvokeEvent, ipcMain, protocol, Menu } from 'electron';
1
+ import { app, IpcMainInvokeEvent, ipcMain, protocol, Menu, BrowserWindow } from 'electron';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
  import { nanoid } from 'nanoid';
@@ -119,6 +119,12 @@ contextMenu({
119
119
  showSaveImageAs: true,
120
120
  showSearchWithGoogle: false,
121
121
  showInspectElement: true,
122
+ append: (_defaultActions, _parameters, browserWindow) => [
123
+ {
124
+ label: 'Reload',
125
+ click: () => (browserWindow as BrowserWindow).reload(),
126
+ },
127
+ ],
122
128
  });
123
129
 
124
130
  const handleSignZomeCall = async (e: IpcMainInvokeEvent, request: CallZomeRequest) => {
@@ -88,6 +88,7 @@ electron.contextBridge.exposeInMainWorld("__HC_LAUNCHER_ENV__", {
88
88
  title: `Agent ${agentNum} - ${appId}`,
89
89
  webPreferences: {
90
90
  preload: preloadPath,
91
+ sandbox: true,
91
92
  partition,
92
93
  },
93
94
  });