aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-client/src/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-client/src/main.js')
-rw-r--r--packages/meshbay-client/src/main.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/packages/meshbay-client/src/main.js b/packages/meshbay-client/src/main.js
index 22e0162..8dcc2ae 100644
--- a/packages/meshbay-client/src/main.js
+++ b/packages/meshbay-client/src/main.js
@@ -744,7 +744,36 @@ function registerBridge() {
} catch { return null; }
}
- ipcMain.handle('node:start', async () => {
+ function provisionNode(hubUrl, username) {
+ const configDir = path.join(os.homedir(), '.config', 'meshbay');
+ fs.mkdirSync(configDir, { recursive: true });
+
+ const configFile = nodeConfigPath();
+ if (!fs.existsSync(configFile)) {
+ const toml = [
+ '[hub]',
+ `url = "${hubUrl}"`,
+ `username = "${username}"`,
+ '',
+ '[node]',
+ 'quic_port = 19010',
+ 'ui_port = 18000',
+ '',
+ '[keystore]',
+ `unlock_file = "${path.join(configDir, 'unlock.key')}"`,
+ '',
+ ].join('\n');
+ fs.writeFileSync(configFile, toml, { mode: 0o600 });
+ }
+
+ const unlockFile = path.join(configDir, 'unlock.key');
+ if (!fs.existsSync(unlockFile)) {
+ const key = crypto.randomBytes(32).toString('base64url');
+ fs.writeFileSync(unlockFile, key + '\n', { mode: 0o600 });
+ }
+ }
+
+ ipcMain.handle('node:start', async (_e, opts) => {
const already = await probeNode();
if (already) return { started: true, ...already };
@@ -752,6 +781,10 @@ function registerBridge() {
throw new Error('Automatic node start is only supported on Linux');
}
+ if (opts && opts.hubUrl && opts.username) {
+ provisionNode(opts.hubUrl, opts.username);
+ }
+
const deadline = Date.now() + 15000;
const configFile = nodeConfigPath();
let launched = false;