@holochain/hc-spin 0.200.6 → 0.200.8

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.
@@ -61,7 +61,7 @@ function nanoid(size = 21) {
61
61
  }
62
62
  return id;
63
63
  }
64
- const createHappWindow = async (uiSource, happOrWebhappPath, appId, agentNum, appPort, appDataRootDir) => {
64
+ const createHappWindow = async (uiSource, happOrWebhappPath, appId, agentNum, appPort, appDataRootDir, openDevtools) => {
65
65
  if (!appPort)
66
66
  throw new Error("App port not defined.");
67
67
  const partition = `persist:${agentNum}:${appId}`;
@@ -127,7 +127,8 @@ electron.contextBridge.exposeInMainWorld("__HC_LAUNCHER_ENV__", {
127
127
  happWindow.on("page-title-updated", (evt) => {
128
128
  evt.preventDefault();
129
129
  });
130
- happWindow.webContents.openDevTools();
130
+ if (openDevtools)
131
+ happWindow.webContents.openDevTools();
131
132
  if (uiSource.type === "port") {
132
133
  try {
133
134
  await electron.net.fetch(`http://127.0.0.1:${uiSource.port}/index.html`);
@@ -11739,12 +11740,62 @@ function validateCliArgs(cliArgs, cliOpts, appDataRootDir) {
11739
11740
  uiSource: cliOpts.uiPath ? { type: "path", path: cliOpts.uiPath } : cliOpts.uiPort ? { type: "port", port: cliOpts.uiPort } : { type: "path", path: path.join(appDataRootDir, "apps", appId, "ui") },
11740
11741
  singalingUrl: cliOpts.signalingUrl,
11741
11742
  bootstrapUrl: cliOpts.bootstrapUrl,
11742
- happOrWebhappPath: isHapp ? { type: "happ", path: happOrWebhappPath } : { type: "webhapp", path: happOrWebhappPath }
11743
+ happOrWebhappPath: isHapp ? { type: "happ", path: happOrWebhappPath } : { type: "webhapp", path: happOrWebhappPath },
11744
+ openDevtools: cliOpts.openDevtools ? true : false
11743
11745
  };
11744
11746
  }
11747
+ const menu = electron.Menu.buildFromTemplate([
11748
+ {
11749
+ label: "Options",
11750
+ submenu: [
11751
+ {
11752
+ label: "toggle dev tools (F12)",
11753
+ click: () => {
11754
+ const focusedWindow = electron.BrowserWindow.getFocusedWindow();
11755
+ if (focusedWindow) {
11756
+ focusedWindow.webContents.toggleDevTools();
11757
+ }
11758
+ },
11759
+ accelerator: "F12"
11760
+ },
11761
+ {
11762
+ label: "toggle dev tools (Ctrl+Shift+I)",
11763
+ click: () => {
11764
+ const focusedWindow = electron.BrowserWindow.getFocusedWindow();
11765
+ if (focusedWindow) {
11766
+ focusedWindow.webContents.toggleDevTools();
11767
+ }
11768
+ },
11769
+ visible: false,
11770
+ accelerator: "CommandOrControl+Shift+I"
11771
+ },
11772
+ {
11773
+ label: "Reload (F5)",
11774
+ click: () => {
11775
+ const focusedWindow = electron.BrowserWindow.getFocusedWindow();
11776
+ if (focusedWindow) {
11777
+ focusedWindow.webContents.reload();
11778
+ }
11779
+ },
11780
+ accelerator: "F5"
11781
+ },
11782
+ {
11783
+ label: "Reload (Ctrl+R)",
11784
+ click: () => {
11785
+ const focusedWindow = electron.BrowserWindow.getFocusedWindow();
11786
+ if (focusedWindow) {
11787
+ focusedWindow.webContents.reload();
11788
+ }
11789
+ },
11790
+ visible: false,
11791
+ accelerator: "CommandOrControl+R"
11792
+ }
11793
+ ]
11794
+ }
11795
+ ]);
11745
11796
  const rustUtils = require("@holochain/hc-spin-rust-utils");
11746
11797
  const cli = new commander.Command();
11747
- cli.name("hc-spin").description("CLI to run Holochain aps during development.").version(`0.200.6 (for holochain 0.2.x)`).argument(
11798
+ cli.name("hc-spin").description("CLI to run Holochain aps during development.").version(`0.200.8 (for holochain 0.2.x)`).argument(
11748
11799
  "<path>",
11749
11800
  "Path to .webhapp or .happ file to launch. If a .happ file is passed, either a UI path must be specified via --ui-path or a port pointing to a localhost server via --ui-port"
11750
11801
  ).option(
@@ -11763,7 +11814,7 @@ cli.name("hc-spin").description("CLI to run Holochain aps during development.").
11763
11814
  ).option(
11764
11815
  "--signaling-url <url>",
11765
11816
  "Url of the signaling server to use. By default, hc spin spins up a local development signaling server for you but this argument allows you to specify a custom one."
11766
- );
11817
+ ).option("--open-devtools", "Automatically open the devtools on startup.");
11767
11818
  cli.parse();
11768
11819
  const rl = require("readline").createInterface({
11769
11820
  input: process.stdin,
@@ -11786,6 +11837,7 @@ for (const folder of hcSpinFolders) {
11786
11837
  }
11787
11838
  const DATA_ROOT_DIR = path.join(electron.app.getPath("temp"), `hc-spin-${nanoid(8)}`);
11788
11839
  electron.app.setPath("userData", path.join(DATA_ROOT_DIR, "electron"));
11840
+ electron.Menu.setApplicationMenu(menu);
11789
11841
  const CLI_OPTS = validateCliArgs(cli.args, cli.opts(), DATA_ROOT_DIR);
11790
11842
  const SANDBOX_PROCESSES = [];
11791
11843
  const WINDOW_INFO_MAP = {};
@@ -11954,7 +12006,7 @@ electron.app.whenReady().then(async () => {
11954
12006
  }
11955
12007
  });
11956
12008
  SANDBOX_PROCESSES.push(sandboxHandle);
11957
- for (var i = 0; i < cli.opts().numAgents; i++) {
12009
+ for (var i = 0; i < CLI_OPTS.numAgents; i++) {
11958
12010
  const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], "pass");
11959
12011
  const appPort = portsInfo[i].app_ports[0];
11960
12012
  const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPort}`));
@@ -11965,7 +12017,8 @@ electron.app.whenReady().then(async () => {
11965
12017
  CLI_OPTS.appId,
11966
12018
  i + 1,
11967
12019
  appPort,
11968
- DATA_ROOT_DIR
12020
+ DATA_ROOT_DIR,
12021
+ CLI_OPTS.openDevtools
11969
12022
  );
11970
12023
  WINDOW_INFO_MAP[happWindow.webContents.id] = {
11971
12024
  agentPubKey: appInfo.agent_pub_key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain/hc-spin",
3
- "version": "0.200.6",
3
+ "version": "0.200.8",
4
4
  "description": "CLI to run Holochain aps during development.",
5
5
  "author": "matthme",
6
6
  "homepage": "https://developer.holochain.org",
@@ -35,7 +35,7 @@
35
35
  "@electron-toolkit/preload": "^3.0.0",
36
36
  "@electron-toolkit/utils": "^3.0.0",
37
37
  "@holochain/client": "^0.16.3",
38
- "@holochain/hc-spin-rust-utils": "0.200.2",
38
+ "@holochain/hc-spin-rust-utils": "^0.200.3",
39
39
  "@msgpack/msgpack": "^2.8.0",
40
40
  "commander": "11.1.0",
41
41
  "electron": "^28.1.1",
package/src/main/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { app, IpcMainInvokeEvent, ipcMain, protocol } from 'electron';
1
+ import { app, IpcMainInvokeEvent, ipcMain, protocol, Menu } from 'electron';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
  import { nanoid } from 'nanoid';
@@ -19,6 +19,7 @@ import {
19
19
  } from '@holochain/client';
20
20
  import { validateCliArgs } from './validateArgs';
21
21
  import { encode } from '@msgpack/msgpack';
22
+ import { menu } from './menu';
22
23
 
23
24
  const rustUtils = require('@holochain/hc-spin-rust-utils');
24
25
 
@@ -27,7 +28,7 @@ const cli = new Command();
27
28
  cli
28
29
  .name('hc-spin')
29
30
  .description('CLI to run Holochain aps during development.')
30
- .version(`0.200.6 (for holochain 0.2.x)`)
31
+ .version(`0.200.8 (for holochain 0.2.x)`)
31
32
  .argument(
32
33
  '<path>',
33
34
  'Path to .webhapp or .happ file to launch. If a .happ file is passed, either a UI path must be specified via --ui-path or a port pointing to a localhost server via --ui-port',
@@ -55,7 +56,8 @@ cli
55
56
  .option(
56
57
  '--signaling-url <url>',
57
58
  'Url of the signaling server to use. By default, hc spin spins up a local development signaling server for you but this argument allows you to specify a custom one.',
58
- );
59
+ )
60
+ .option('--open-devtools', 'Automatically open the devtools on startup.');
59
61
 
60
62
  cli.parse();
61
63
  // console.log('Got CLI opts: ', cli.opts());
@@ -92,6 +94,8 @@ const DATA_ROOT_DIR = path.join(app.getPath('temp'), `hc-spin-${nanoid(8)}`);
92
94
 
93
95
  app.setPath('userData', path.join(DATA_ROOT_DIR, 'electron'));
94
96
 
97
+ Menu.setApplicationMenu(menu);
98
+
95
99
  const CLI_OPTS = validateCliArgs(cli.args, cli.opts(), DATA_ROOT_DIR);
96
100
 
97
101
  // const SANDBOX_DIRECTORIES: Array<string> = [];
@@ -317,11 +321,9 @@ app.whenReady().then(async () => {
317
321
 
318
322
  SANDBOX_PROCESSES.push(sandboxHandle);
319
323
 
320
- // console.log('Got CLI_OPTS: ', CLI_OPTS);
321
-
322
324
  // open browser window for each sandbox
323
325
  //
324
- for (var i = 0; i < cli.opts().numAgents; i++) {
326
+ for (var i = 0; i < CLI_OPTS.numAgents; i++) {
325
327
  const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], 'pass');
326
328
 
327
329
  const appPort = portsInfo[i].app_ports[0];
@@ -334,6 +336,7 @@ app.whenReady().then(async () => {
334
336
  i + 1,
335
337
  appPort,
336
338
  DATA_ROOT_DIR,
339
+ CLI_OPTS.openDevtools,
337
340
  );
338
341
  WINDOW_INFO_MAP[happWindow.webContents.id] = {
339
342
  agentPubKey: appInfo.agent_pub_key,
@@ -0,0 +1,51 @@
1
+ import { BrowserWindow, Menu } from 'electron';
2
+
3
+ export const menu = Menu.buildFromTemplate([
4
+ {
5
+ label: 'Options',
6
+ submenu: [
7
+ {
8
+ label: 'toggle dev tools (F12)',
9
+ click: () => {
10
+ const focusedWindow = BrowserWindow.getFocusedWindow();
11
+ if (focusedWindow) {
12
+ focusedWindow.webContents.toggleDevTools();
13
+ }
14
+ },
15
+ accelerator: 'F12',
16
+ },
17
+ {
18
+ label: 'toggle dev tools (Ctrl+Shift+I)',
19
+ click: () => {
20
+ const focusedWindow = BrowserWindow.getFocusedWindow();
21
+ if (focusedWindow) {
22
+ focusedWindow.webContents.toggleDevTools();
23
+ }
24
+ },
25
+ visible: false,
26
+ accelerator: 'CommandOrControl+Shift+I',
27
+ },
28
+ {
29
+ label: 'Reload (F5)',
30
+ click: () => {
31
+ const focusedWindow = BrowserWindow.getFocusedWindow();
32
+ if (focusedWindow) {
33
+ focusedWindow.webContents.reload();
34
+ }
35
+ },
36
+ accelerator: 'F5',
37
+ },
38
+ {
39
+ label: 'Reload (Ctrl+R)',
40
+ click: () => {
41
+ const focusedWindow = BrowserWindow.getFocusedWindow();
42
+ if (focusedWindow) {
43
+ focusedWindow.webContents.reload();
44
+ }
45
+ },
46
+ visible: false,
47
+ accelerator: 'CommandOrControl+R',
48
+ },
49
+ ],
50
+ },
51
+ ]);
@@ -11,6 +11,7 @@ export type CliOpts = {
11
11
  uiPort?: number;
12
12
  signalingUrl?: string;
13
13
  bootstrapUrl?: string;
14
+ openDevtools?: boolean;
14
15
  };
15
16
 
16
17
  export type CliOptsValidated = {
@@ -22,6 +23,7 @@ export type CliOptsValidated = {
22
23
  singalingUrl: string | undefined;
23
24
  bootstrapUrl: string | undefined;
24
25
  happOrWebhappPath: HappOrWebhappPath;
26
+ openDevtools: boolean;
25
27
  };
26
28
 
27
29
  export type HappOrWebhappPath = {
@@ -86,5 +88,6 @@ export function validateCliArgs(
86
88
  happOrWebhappPath: isHapp
87
89
  ? { type: 'happ', path: happOrWebhappPath }
88
90
  : { type: 'webhapp', path: happOrWebhappPath },
91
+ openDevtools: cliOpts.openDevtools ? true : false,
89
92
  };
90
93
  }
@@ -23,6 +23,7 @@ export const createHappWindow = async (
23
23
  agentNum: number,
24
24
  appPort: number,
25
25
  appDataRootDir: string,
26
+ openDevtools: boolean,
26
27
  ): Promise<BrowserWindow> => {
27
28
  // TODO create mapping between installed-app-id's and window ids
28
29
  if (!appPort) throw new Error('App port not defined.');
@@ -104,7 +105,7 @@ electron.contextBridge.exposeInMainWorld("__HC_LAUNCHER_ENV__", {
104
105
  evt.preventDefault();
105
106
  });
106
107
 
107
- happWindow.webContents.openDevTools();
108
+ if (openDevtools) happWindow.webContents.openDevTools();
108
109
 
109
110
  if (uiSource.type === 'port') {
110
111
  try {