@holochain/hc-spin 0.100.1 → 0.100.2

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,19 @@ 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();
132
+ happWindow.webContents.on("before-input-event", (e, input) => {
133
+ if (input.code === "F12") {
134
+ e.preventDefault();
135
+ if (happWindow.webContents.isDevToolsOpened()) {
136
+ happWindow.webContents.closeDevTools();
137
+ } else {
138
+ happWindow.webContents.openDevTools();
139
+ happWindow.webContents.focus();
140
+ }
141
+ }
142
+ });
131
143
  if (uiSource.type === "port") {
132
144
  try {
133
145
  await electron.net.fetch(`http://127.0.0.1:${uiSource.port}/index.html`);
@@ -11736,12 +11748,13 @@ function validateCliArgs(cliArgs, cliOpts, appDataRootDir) {
11736
11748
  holochainPath,
11737
11749
  numAgents,
11738
11750
  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 }
11751
+ happOrWebhappPath: isHapp ? { type: "happ", path: happOrWebhappPath } : { type: "webhapp", path: happOrWebhappPath },
11752
+ openDevtools: cliOpts.openDevtools ? true : false
11740
11753
  };
11741
11754
  }
11742
11755
  const rustUtils = require("@holochain/hc-spin-rust-utils");
11743
11756
  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(
11757
+ cli.name("hc-spin").description("CLI to run Holochain apps during development.").version(`0.100.2 (for holochain 0.1.x)`).argument(
11745
11758
  "<path>",
11746
11759
  "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
11760
  ).option(
@@ -11754,7 +11767,7 @@ cli.name("hc-spin").description("CLI to run Holochain apps during development.")
11754
11767
  ).option("--ui-path <path>", "Path to the folder containing the index.html of the webhapp's UI.").option(
11755
11768
  "--ui-port <number>",
11756
11769
  "Port pointing to a localhost dev server that serves your UI assets."
11757
- );
11770
+ ).option("--open-devtools", "Automatically open the devtools on startup.");
11758
11771
  cli.parse();
11759
11772
  const rl = require("readline").createInterface({
11760
11773
  input: process.stdin,
@@ -11907,7 +11920,7 @@ electron.app.whenReady().then(async () => {
11907
11920
  }
11908
11921
  });
11909
11922
  SANDBOX_PROCESSES.push(sandboxHandle);
11910
- for (var i = 0; i < cli.opts().numAgents; i++) {
11923
+ for (var i = 0; i < CLI_OPTS.numAgents; i++) {
11911
11924
  const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], "pass");
11912
11925
  const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPorts[i]}`));
11913
11926
  const appInfo = await appWs.appInfo({ installed_app_id: CLI_OPTS.appId });
@@ -11917,7 +11930,8 @@ electron.app.whenReady().then(async () => {
11917
11930
  CLI_OPTS.appId,
11918
11931
  i + 1,
11919
11932
  appPorts[i],
11920
- DATA_ROOT_DIR
11933
+ DATA_ROOT_DIR,
11934
+ CLI_OPTS.openDevtools
11921
11935
  );
11922
11936
  WINDOW_INFO_MAP[happWindow.webContents.id] = {
11923
11937
  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.2",
4
4
  "description": "CLI to run Holochain aps during development.",
5
5
  "author": "matthme",
6
6
  "homepage": "https://developer.holochain.org",
package/src/main/index.ts CHANGED
@@ -27,7 +27,7 @@ const cli = new Command();
27
27
  cli
28
28
  .name('hc-spin')
29
29
  .description('CLI to run Holochain apps during development.')
30
- .version(`0.100.1 (for holochain 0.1.x)`)
30
+ .version(`0.100.2 (for holochain 0.1.x)`)
31
31
  .argument(
32
32
  '<path>',
33
33
  '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 +46,8 @@ cli
46
46
  .option(
47
47
  '--ui-port <number>',
48
48
  'Port pointing to a localhost dev server that serves your UI assets.',
49
- );
49
+ )
50
+ .option('--open-devtools', 'Automatically open the devtools on startup.');
50
51
 
51
52
  cli.parse();
52
53
  // console.log('Got CLI opts: ', cli.opts());
@@ -270,7 +271,7 @@ app.whenReady().then(async () => {
270
271
 
271
272
  // open browser window for each sandbox
272
273
  //
273
- for (var i = 0; i < cli.opts().numAgents; i++) {
274
+ for (var i = 0; i < CLI_OPTS.numAgents; i++) {
274
275
  const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], 'pass');
275
276
 
276
277
  const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPorts[i]}`));
@@ -282,6 +283,7 @@ app.whenReady().then(async () => {
282
283
  i + 1,
283
284
  appPorts[i],
284
285
  DATA_ROOT_DIR,
286
+ CLI_OPTS.openDevtools,
285
287
  );
286
288
  WINDOW_INFO_MAP[happWindow.webContents.id] = {
287
289
  agentPubKey: appInfo.agent_pub_key,
@@ -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,19 @@ electron.contextBridge.exposeInMainWorld("__HC_LAUNCHER_ENV__", {
104
105
  evt.preventDefault();
105
106
  });
106
107
 
107
- happWindow.webContents.openDevTools();
108
+ if (openDevtools) happWindow.webContents.openDevTools();
109
+
110
+ happWindow.webContents.on('before-input-event', (e, input) => {
111
+ if (input.code === 'F12') {
112
+ e.preventDefault();
113
+ if (happWindow.webContents.isDevToolsOpened()) {
114
+ happWindow.webContents.closeDevTools();
115
+ } else {
116
+ happWindow.webContents.openDevTools();
117
+ happWindow.webContents.focus();
118
+ }
119
+ }
120
+ });
108
121
 
109
122
  if (uiSource.type === 'port') {
110
123
  try {