@holochain/hc-spin 0.100.0 → 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.
- package/dist/main/index.js +28 -10
- package/package.json +3 -3
- package/src/main/index.ts +10 -4
- package/src/main/validateArgs.ts +3 -0
- package/src/main/windows.ts +16 -3
package/dist/main/index.js
CHANGED
|
@@ -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}`;
|
|
@@ -96,12 +96,12 @@ electron.contextBridge.exposeInMainWorld("__HC_LAUNCHER_ENV__", {
|
|
|
96
96
|
} else {
|
|
97
97
|
try {
|
|
98
98
|
const iconResponse = await electron.net.fetch(`http://127.0.0.1:${uiSource.port}/icon.png`);
|
|
99
|
-
|
|
100
|
-
if (buffer.byteLength === 0 && agentNum === 1) {
|
|
99
|
+
if (iconResponse.status === 404 && agentNum === 1) {
|
|
101
100
|
console.warn(
|
|
102
101
|
"\n\n+++++ WARNING +++++\n[hc-spin] No icon.png found. It is recommended to put an icon.png file (1024x1024 pixel) in the root of your UI assets directory which can be used by the Holochain Launcher.\n+++++++++++++++++++\n\n"
|
|
103
102
|
);
|
|
104
103
|
}
|
|
104
|
+
const buffer = await iconResponse.arrayBuffer();
|
|
105
105
|
icon = electron.nativeImage.createFromBuffer(Buffer.from(buffer));
|
|
106
106
|
} catch (e) {
|
|
107
107
|
console.error("Failed to get icon.png: ", e);
|
|
@@ -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
|
-
|
|
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.
|
|
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,
|
|
@@ -11844,7 +11857,11 @@ async function spawnSandboxes(nAgents, happPath, appId) {
|
|
|
11844
11857
|
appPortsString += `${appPort},`;
|
|
11845
11858
|
appPorts.push(appPort);
|
|
11846
11859
|
}
|
|
11847
|
-
|
|
11860
|
+
if (nAgents === 1) {
|
|
11861
|
+
generateArgs.push(`--run=${appPortsString.slice(0, appPortsString.length - 1)}`);
|
|
11862
|
+
} else {
|
|
11863
|
+
generateArgs.push("--run", appPortsString.slice(0, appPortsString.length - 1));
|
|
11864
|
+
}
|
|
11848
11865
|
generateArgs.push(happPath, "network", "mdns");
|
|
11849
11866
|
let readyConductors = 0;
|
|
11850
11867
|
const sandboxPaths = [];
|
|
@@ -11903,7 +11920,7 @@ electron.app.whenReady().then(async () => {
|
|
|
11903
11920
|
}
|
|
11904
11921
|
});
|
|
11905
11922
|
SANDBOX_PROCESSES.push(sandboxHandle);
|
|
11906
|
-
for (var i = 0; i <
|
|
11923
|
+
for (var i = 0; i < CLI_OPTS.numAgents; i++) {
|
|
11907
11924
|
const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], "pass");
|
|
11908
11925
|
const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPorts[i]}`));
|
|
11909
11926
|
const appInfo = await appWs.appInfo({ installed_app_id: CLI_OPTS.appId });
|
|
@@ -11913,7 +11930,8 @@ electron.app.whenReady().then(async () => {
|
|
|
11913
11930
|
CLI_OPTS.appId,
|
|
11914
11931
|
i + 1,
|
|
11915
11932
|
appPorts[i],
|
|
11916
|
-
DATA_ROOT_DIR
|
|
11933
|
+
DATA_ROOT_DIR,
|
|
11934
|
+
CLI_OPTS.openDevtools
|
|
11917
11935
|
);
|
|
11918
11936
|
WINDOW_INFO_MAP[happWindow.webContents.id] = {
|
|
11919
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.
|
|
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",
|
|
@@ -23,12 +23,12 @@
|
|
|
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",
|
|
27
|
+
"@msgpack/msgpack": "^2.8.0",
|
|
26
28
|
"commander": "11.1.0",
|
|
27
29
|
"electron": "^28.1.1",
|
|
28
30
|
"electron-context-menu": "3.6.1",
|
|
29
31
|
"get-port": "7.0.0",
|
|
30
|
-
"@holochain/hc-spin-rust-utils": "0.100.1",
|
|
31
|
-
"@msgpack/msgpack": "^2.8.0",
|
|
32
32
|
"nanoid": "5.0.4",
|
|
33
33
|
"split": "1.0.1"
|
|
34
34
|
},
|
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.
|
|
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());
|
|
@@ -173,7 +174,11 @@ async function spawnSandboxes(
|
|
|
173
174
|
appPortsString += `${appPort},`;
|
|
174
175
|
appPorts.push(appPort);
|
|
175
176
|
}
|
|
176
|
-
|
|
177
|
+
if (nAgents === 1) {
|
|
178
|
+
generateArgs.push(`--run=${appPortsString.slice(0, appPortsString.length - 1)}`);
|
|
179
|
+
} else {
|
|
180
|
+
generateArgs.push('--run', appPortsString.slice(0, appPortsString.length - 1));
|
|
181
|
+
}
|
|
177
182
|
|
|
178
183
|
// const adminPorts: number[] = [];
|
|
179
184
|
// let adminPortsString = '';
|
|
@@ -266,7 +271,7 @@ app.whenReady().then(async () => {
|
|
|
266
271
|
|
|
267
272
|
// open browser window for each sandbox
|
|
268
273
|
//
|
|
269
|
-
for (var i = 0; i <
|
|
274
|
+
for (var i = 0; i < CLI_OPTS.numAgents; i++) {
|
|
270
275
|
const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], 'pass');
|
|
271
276
|
|
|
272
277
|
const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPorts[i]}`));
|
|
@@ -278,6 +283,7 @@ app.whenReady().then(async () => {
|
|
|
278
283
|
i + 1,
|
|
279
284
|
appPorts[i],
|
|
280
285
|
DATA_ROOT_DIR,
|
|
286
|
+
CLI_OPTS.openDevtools,
|
|
281
287
|
);
|
|
282
288
|
WINDOW_INFO_MAP[happWindow.webContents.id] = {
|
|
283
289
|
agentPubKey: appInfo.agent_pub_key,
|
package/src/main/validateArgs.ts
CHANGED
|
@@ -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
|
}
|
package/src/main/windows.ts
CHANGED
|
@@ -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.');
|
|
@@ -67,12 +68,12 @@ electron.contextBridge.exposeInMainWorld("__HC_LAUNCHER_ENV__", {
|
|
|
67
68
|
} else {
|
|
68
69
|
try {
|
|
69
70
|
const iconResponse = await net.fetch(`http://127.0.0.1:${uiSource.port}/icon.png`);
|
|
70
|
-
|
|
71
|
-
if (buffer.byteLength === 0 && agentNum === 1) {
|
|
71
|
+
if (iconResponse.status === 404 && agentNum === 1) {
|
|
72
72
|
console.warn(
|
|
73
73
|
'\n\n+++++ WARNING +++++\n[hc-spin] No icon.png found. It is recommended to put an icon.png file (1024x1024 pixel) in the root of your UI assets directory which can be used by the Holochain Launcher.\n+++++++++++++++++++\n\n',
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
|
+
const buffer = await iconResponse.arrayBuffer();
|
|
76
77
|
icon = nativeImage.createFromBuffer(Buffer.from(buffer));
|
|
77
78
|
} catch (e) {
|
|
78
79
|
console.error('Failed to get icon.png: ', e);
|
|
@@ -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 {
|