@holochain/hc-spin 0.100.1 → 0.100.3

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`);
@@ -11736,12 +11737,62 @@ function validateCliArgs(cliArgs, cliOpts, appDataRootDir) {
11736
11737
  holochainPath,
11737
11738
  numAgents,
11738
11739
  uiSource: cliOpts.uiPath ? { type: "path", path: cliOpts.uiPath } : cliOpts.uiPort ? { type: "port", port: cliOpts.uiPort } : { type: "path", path: path.join(appDataRootDir, "apps", appId, "ui") },
11739
- happOrWebhappPath: isHapp ? { type: "happ", path: happOrWebhappPath } : { type: "webhapp", path: happOrWebhappPath }
11740
+ happOrWebhappPath: isHapp ? { type: "happ", path: happOrWebhappPath } : { type: "webhapp", path: happOrWebhappPath },
11741
+ openDevtools: cliOpts.openDevtools ? true : false
11740
11742
  };
11741
11743
  }
11744
+ const menu = electron.Menu.buildFromTemplate([
11745
+ {
11746
+ label: "Options",
11747
+ submenu: [
11748
+ {
11749
+ label: "toggle dev tools (F12)",
11750
+ click: () => {
11751
+ const focusedWindow = electron.BrowserWindow.getFocusedWindow();
11752
+ if (focusedWindow) {
11753
+ focusedWindow.webContents.toggleDevTools();
11754
+ }
11755
+ },
11756
+ accelerator: "F12"
11757
+ },
11758
+ {
11759
+ label: "toggle dev tools (Ctrl+Shift+I)",
11760
+ click: () => {
11761
+ const focusedWindow = electron.BrowserWindow.getFocusedWindow();
11762
+ if (focusedWindow) {
11763
+ focusedWindow.webContents.toggleDevTools();
11764
+ }
11765
+ },
11766
+ visible: false,
11767
+ accelerator: "CommandOrControl+Shift+I"
11768
+ },
11769
+ {
11770
+ label: "Reload (F5)",
11771
+ click: () => {
11772
+ const focusedWindow = electron.BrowserWindow.getFocusedWindow();
11773
+ if (focusedWindow) {
11774
+ focusedWindow.webContents.reload();
11775
+ }
11776
+ },
11777
+ accelerator: "F5"
11778
+ },
11779
+ {
11780
+ label: "Reload (Ctrl+R)",
11781
+ click: () => {
11782
+ const focusedWindow = electron.BrowserWindow.getFocusedWindow();
11783
+ if (focusedWindow) {
11784
+ focusedWindow.webContents.reload();
11785
+ }
11786
+ },
11787
+ visible: false,
11788
+ accelerator: "CommandOrControl+R"
11789
+ }
11790
+ ]
11791
+ }
11792
+ ]);
11742
11793
  const rustUtils = require("@holochain/hc-spin-rust-utils");
11743
11794
  const cli = new commander.Command();
11744
- cli.name("hc-spin").description("CLI to run Holochain apps during development.").version(`0.100.1 (for holochain 0.1.x)`).argument(
11795
+ cli.name("hc-spin").description("CLI to run Holochain apps during development.").version(`0.100.3 (for holochain 0.1.x)`).argument(
11745
11796
  "<path>",
11746
11797
  "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"
11747
11798
  ).option(
@@ -11754,7 +11805,7 @@ cli.name("hc-spin").description("CLI to run Holochain apps during development.")
11754
11805
  ).option("--ui-path <path>", "Path to the folder containing the index.html of the webhapp's UI.").option(
11755
11806
  "--ui-port <number>",
11756
11807
  "Port pointing to a localhost dev server that serves your UI assets."
11757
- );
11808
+ ).option("--open-devtools", "Automatically open the devtools on startup.");
11758
11809
  cli.parse();
11759
11810
  const rl = require("readline").createInterface({
11760
11811
  input: process.stdin,
@@ -11777,6 +11828,7 @@ for (const folder of hcSpinFolders) {
11777
11828
  }
11778
11829
  const DATA_ROOT_DIR = path.join(electron.app.getPath("temp"), `hc-spin-${nanoid(8)}`);
11779
11830
  electron.app.setPath("userData", path.join(DATA_ROOT_DIR, "electron"));
11831
+ electron.Menu.setApplicationMenu(menu);
11780
11832
  const CLI_OPTS = validateCliArgs(cli.args, cli.opts(), DATA_ROOT_DIR);
11781
11833
  const SANDBOX_PROCESSES = [];
11782
11834
  const WINDOW_INFO_MAP = {};
@@ -11907,7 +11959,7 @@ electron.app.whenReady().then(async () => {
11907
11959
  }
11908
11960
  });
11909
11961
  SANDBOX_PROCESSES.push(sandboxHandle);
11910
- for (var i = 0; i < cli.opts().numAgents; i++) {
11962
+ for (var i = 0; i < CLI_OPTS.numAgents; i++) {
11911
11963
  const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], "pass");
11912
11964
  const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPorts[i]}`));
11913
11965
  const appInfo = await appWs.appInfo({ installed_app_id: CLI_OPTS.appId });
@@ -11917,7 +11969,8 @@ electron.app.whenReady().then(async () => {
11917
11969
  CLI_OPTS.appId,
11918
11970
  i + 1,
11919
11971
  appPorts[i],
11920
- DATA_ROOT_DIR
11972
+ DATA_ROOT_DIR,
11973
+ CLI_OPTS.openDevtools
11921
11974
  );
11922
11975
  WINDOW_INFO_MAP[happWindow.webContents.id] = {
11923
11976
  agentPubKey: appInfo.agent_pub_key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain/hc-spin",
3
- "version": "0.100.1",
3
+ "version": "0.100.3",
4
4
  "description": "CLI to run Holochain aps during development.",
5
5
  "author": "matthme",
6
6
  "homepage": "https://developer.holochain.org",
@@ -23,7 +23,7 @@
23
23
  "@electron-toolkit/preload": "^3.0.0",
24
24
  "@electron-toolkit/utils": "^3.0.0",
25
25
  "@holochain/client": "^0.16.3",
26
- "@holochain/hc-spin-rust-utils": "0.100.1",
26
+ "@holochain/hc-spin-rust-utils": "^0.100.2",
27
27
  "@msgpack/msgpack": "^2.8.0",
28
28
  "commander": "11.1.0",
29
29
  "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
  randomNonce,
20
20
  } from '@holochain/client';
21
21
  import { validateCliArgs } from './validateArgs';
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 apps during development.')
30
- .version(`0.100.1 (for holochain 0.1.x)`)
31
+ .version(`0.100.3 (for holochain 0.1.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',
@@ -46,7 +47,8 @@ cli
46
47
  .option(
47
48
  '--ui-port <number>',
48
49
  'Port pointing to a localhost dev server that serves your UI assets.',
49
- );
50
+ )
51
+ .option('--open-devtools', 'Automatically open the devtools on startup.');
50
52
 
51
53
  cli.parse();
52
54
  // console.log('Got CLI opts: ', cli.opts());
@@ -83,6 +85,8 @@ const DATA_ROOT_DIR = path.join(app.getPath('temp'), `hc-spin-${nanoid(8)}`);
83
85
 
84
86
  app.setPath('userData', path.join(DATA_ROOT_DIR, 'electron'));
85
87
 
88
+ Menu.setApplicationMenu(menu);
89
+
86
90
  const CLI_OPTS = validateCliArgs(cli.args, cli.opts(), DATA_ROOT_DIR);
87
91
 
88
92
  // const SANDBOX_DIRECTORIES: Array<string> = [];
@@ -270,7 +274,7 @@ app.whenReady().then(async () => {
270
274
 
271
275
  // open browser window for each sandbox
272
276
  //
273
- for (var i = 0; i < cli.opts().numAgents; i++) {
277
+ for (var i = 0; i < CLI_OPTS.numAgents; i++) {
274
278
  const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], 'pass');
275
279
 
276
280
  const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPorts[i]}`));
@@ -282,6 +286,7 @@ app.whenReady().then(async () => {
282
286
  i + 1,
283
287
  appPorts[i],
284
288
  DATA_ROOT_DIR,
289
+ CLI_OPTS.openDevtools,
285
290
  );
286
291
  WINDOW_INFO_MAP[happWindow.webContents.id] = {
287
292
  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
+ ]);
@@ -8,6 +8,7 @@ export type CliOpts = {
8
8
  numAgents?: number;
9
9
  uiPath?: string;
10
10
  uiPort?: number;
11
+ openDevtools?: boolean;
11
12
  };
12
13
 
13
14
  export type CliOptsValidated = {
@@ -16,6 +17,7 @@ export type CliOptsValidated = {
16
17
  numAgents: number;
17
18
  uiSource: UISource;
18
19
  happOrWebhappPath: HappOrWebhappPath;
20
+ openDevtools: boolean;
19
21
  };
20
22
 
21
23
  export type HappOrWebhappPath = {
@@ -77,5 +79,6 @@ export function validateCliArgs(
77
79
  happOrWebhappPath: isHapp
78
80
  ? { type: 'happ', path: happOrWebhappPath }
79
81
  : { type: 'webhapp', path: happOrWebhappPath },
82
+ openDevtools: cliOpts.openDevtools ? true : false,
80
83
  };
81
84
  }
@@ -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 {