diff --git a/buf.gen.yaml b/buf.gen.yaml index 8e4f358..d395264 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -9,7 +9,7 @@ inputs: plugins: - remote: buf.build/bufbuild/es:v2.2.5 - out: gen + out: public/gen # https://github.com/bufbuild/protobuf-es/blob/main/MANUAL.md#plugin-options opt: - js_import_style=legacy_commonjs diff --git a/package.json b/package.json index eff751d..66f4fc7 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,7 @@ }, "scripts": { "react-start": "react-scripts start", - "copy-gen": "cp -r gen/ build/gen/", - "react-build": "react-scripts build && npm run copy-gen", + "react-build": "react-scripts build", "react-test": "react-scripts test", "react-eject": "react-scripts eject", "electron-build": "electron-builder", @@ -78,11 +77,7 @@ "productName": "Drivechain Launcher", "files": [ "build/**/*", - "public/**/*", - "gen/**/*", - "node_modules/@bufbuild/**/*", - "node_modules/@connectrpc/**/*", - "node_modules/fs-extra/**/*" + "public/**/*" ], "directories": { "buildResources": "public", @@ -144,7 +139,6 @@ "entitlements": "entitlements.mac.plist", "entitlementsInherit": "entitlements.mac.plist", "extendInfo": { - "NSAppleEventsUsageDescription": "Please allow access to script browser applications to detect drivechain nodes.", "NSCameraUsageDescription": "Application requests access to the device's camera.", "NSMicrophoneUsageDescription": "Application requests access to the device's microphone.", "NSDocumentsFolderUsageDescription": "Application requests access to the user's Documents folder.", diff --git a/public/electron.js b/public/electron.js index eeb96fe..b4fdc8f 100644 --- a/public/electron.js +++ b/public/electron.js @@ -301,6 +301,7 @@ function setupIPCHandlers() { ipcMain.handle("stop-chain", async (event, chainId) => { try { + console.log(`[${chainId}] Stopping chain...`); return await chainManager.stopChain(chainId); } catch (error) { console.error("Failed to stop chain:", error); diff --git a/gen/cusf/common/v1/common_pb.d.ts b/public/gen/cusf/common/v1/common_pb.d.ts similarity index 100% rename from gen/cusf/common/v1/common_pb.d.ts rename to public/gen/cusf/common/v1/common_pb.d.ts diff --git a/gen/cusf/common/v1/common_pb.js b/public/gen/cusf/common/v1/common_pb.js similarity index 100% rename from gen/cusf/common/v1/common_pb.js rename to public/gen/cusf/common/v1/common_pb.js diff --git a/gen/cusf/crypto/v1/crypto_pb.d.ts b/public/gen/cusf/crypto/v1/crypto_pb.d.ts similarity index 100% rename from gen/cusf/crypto/v1/crypto_pb.d.ts rename to public/gen/cusf/crypto/v1/crypto_pb.d.ts diff --git a/gen/cusf/crypto/v1/crypto_pb.js b/public/gen/cusf/crypto/v1/crypto_pb.js similarity index 100% rename from gen/cusf/crypto/v1/crypto_pb.js rename to public/gen/cusf/crypto/v1/crypto_pb.js diff --git a/gen/cusf/mainchain/v1/common_pb.d.ts b/public/gen/cusf/mainchain/v1/common_pb.d.ts similarity index 100% rename from gen/cusf/mainchain/v1/common_pb.d.ts rename to public/gen/cusf/mainchain/v1/common_pb.d.ts diff --git a/gen/cusf/mainchain/v1/common_pb.js b/public/gen/cusf/mainchain/v1/common_pb.js similarity index 100% rename from gen/cusf/mainchain/v1/common_pb.js rename to public/gen/cusf/mainchain/v1/common_pb.js diff --git a/gen/cusf/mainchain/v1/validator_pb.d.ts b/public/gen/cusf/mainchain/v1/validator_pb.d.ts similarity index 100% rename from gen/cusf/mainchain/v1/validator_pb.d.ts rename to public/gen/cusf/mainchain/v1/validator_pb.d.ts diff --git a/gen/cusf/mainchain/v1/validator_pb.js b/public/gen/cusf/mainchain/v1/validator_pb.js similarity index 100% rename from gen/cusf/mainchain/v1/validator_pb.js rename to public/gen/cusf/mainchain/v1/validator_pb.js diff --git a/gen/cusf/mainchain/v1/wallet_pb.d.ts b/public/gen/cusf/mainchain/v1/wallet_pb.d.ts similarity index 100% rename from gen/cusf/mainchain/v1/wallet_pb.d.ts rename to public/gen/cusf/mainchain/v1/wallet_pb.d.ts diff --git a/gen/cusf/mainchain/v1/wallet_pb.js b/public/gen/cusf/mainchain/v1/wallet_pb.js similarity index 100% rename from gen/cusf/mainchain/v1/wallet_pb.js rename to public/gen/cusf/mainchain/v1/wallet_pb.js diff --git a/gen/cusf/sidechain/v1/sidechain_pb.d.ts b/public/gen/cusf/sidechain/v1/sidechain_pb.d.ts similarity index 100% rename from gen/cusf/sidechain/v1/sidechain_pb.d.ts rename to public/gen/cusf/sidechain/v1/sidechain_pb.d.ts diff --git a/gen/cusf/sidechain/v1/sidechain_pb.js b/public/gen/cusf/sidechain/v1/sidechain_pb.js similarity index 100% rename from gen/cusf/sidechain/v1/sidechain_pb.js rename to public/gen/cusf/sidechain/v1/sidechain_pb.js diff --git a/public/modules/bitWindowClient.js b/public/modules/bitWindowClient.js index b690e35..2cdf539 100644 --- a/public/modules/bitWindowClient.js +++ b/public/modules/bitWindowClient.js @@ -5,8 +5,7 @@ class BitWindowClient { this.config = { baseURL: 'http://127.0.0.1:8080', headers: { - 'Content-Type': 'application/connect+json', - 'Connect-Protocol-Version': '1' + 'Content-Type': 'application/json', } }; this.connected = false; @@ -22,7 +21,7 @@ class BitWindowClient { ); return response.data; } catch (error) { - console.error(`BitWindow Connect call failed (${service}/${method}):`, error.message); + console.error(`BitWindow Connect call failed (${this.config.baseURL}/${service}/${method}):`, error.message); throw error; } } @@ -30,7 +29,7 @@ class BitWindowClient { async checkConnection() { try { // Use BitcoindService for status check - await this.makeConnectRequest('bitcoind.v1.BitcoindService', 'GetBlockchainInfo', {}); + await this.makeConnectRequest('health.v1.HealthService', 'Check', {}); return true; } catch (error) { return false; diff --git a/public/modules/chainManager.js b/public/modules/chainManager.js index 86cfd5f..64ef62a 100644 --- a/public/modules/chainManager.js +++ b/public/modules/chainManager.js @@ -245,31 +245,23 @@ class ChainManager { // Wait for the app to start await new Promise((resolve, reject) => { childProcess.on('exit', async (code) => { + console.log(`[${chainId}] BitWindow exited with code ${code}`); + if (code === 0) { - // Check if BitWindow is actually running using AppleScript - const checkProcess = spawn('osascript', ['-e', 'tell application "System Events" to count processes whose name is "bitwindow"']); - const isRunning = await new Promise((resolve) => { - checkProcess.stdout.on('data', (data) => { - resolve(parseInt(data.toString().trim()) > 0); - }); - checkProcess.on('error', () => resolve(false)); - }); + const isRunning = await this.bitWindowClient.waitForConnection(); if (isRunning) { + console.log(`[${chainId}] BitWindow is running`); // Store process info this.runningProcesses[chainId] = {}; // Start process checker const checkInterval = setInterval(async () => { - const checkProcess = spawn('osascript', ['-e', 'tell application "System Events" to count processes whose name is "bitwindow"']); - const stillRunning = await new Promise((resolve) => { - checkProcess.stdout.on('data', (data) => { - resolve(parseInt(data.toString().trim()) > 0); - }); - checkProcess.on('error', () => resolve(false)); - }); + const stillRunning = await this.bitWindowClient.checkConnection(); if (!stillRunning) { + console.log(`[${chainId}] BitWindow is NOT running`); + // BitWindow was closed clearInterval(this.processCheckers.get(chainId)); this.processCheckers.delete(chainId); @@ -481,6 +473,7 @@ class ChainManager { async stopChain(chainId) { const childProcess = this.runningProcesses[chainId]; if (!childProcess) { + console.log(`[${chainId}] Process not found!`); return { success: false, error: "Process not found" }; } @@ -497,13 +490,14 @@ class ChainManager { // Kill both processes if (process.platform === 'darwin') { + console.log(`[${chainId}] Killing BitWindow processes`); const killBitWindow = spawn('killall', ['bitwindow']); const killBitWindowd = spawn('killall', ['bitwindowd']); // Wait for both kill commands to complete await Promise.all([ - new Promise(resolve => killBitWindow.on('exit', resolve)), - new Promise(resolve => killBitWindowd.on('exit', resolve)) + new Promise(resolve => killBitWindow.on('exit', resolve)).then(() => console.log(`[${chainId}] bitwindow killed`)), + new Promise(resolve => killBitWindowd.on('exit', resolve)).then(() => console.log(`[${chainId}] bitwindowd killed`)) ]); // Let the process checker detect the stop and update status @@ -511,10 +505,8 @@ class ChainManager { const maxWaitTime = 5000; // 5 second timeout const startTime = Date.now(); - const waitInterval = setInterval(() => { - const checkProcess = spawn('osascript', ['-e', 'tell application "System Events" to count processes whose name is "bitwindow"']); - checkProcess.stdout.on('data', (data) => { - const isRunning = parseInt(data.toString().trim()) > 0; + const waitInterval = setInterval(async () => { + const isRunning = await this.bitWindowClient.checkConnection(); if (!isRunning || Date.now() - startTime > maxWaitTime) { clearInterval(waitInterval); @@ -534,7 +526,6 @@ class ChainManager { resolve(); } - }); }, 100); }); } else { diff --git a/public/modules/enforcerClient.js b/public/modules/enforcerClient.js index 70c618c..f68c4a5 100644 --- a/public/modules/enforcerClient.js +++ b/public/modules/enforcerClient.js @@ -1,6 +1,6 @@ const { createClient } = require("@connectrpc/connect"); const { createGrpcTransport } = require("@connectrpc/connect-node"); -const { ValidatorService } = require("../../gen/cusf/mainchain/v1/validator_pb.js"); +const { ValidatorService } = require("../gen/cusf/mainchain/v1/validator_pb.js"); const transport = createGrpcTransport({ baseUrl: "http://0.0.0.0:50051", // Note: localhost does NOT work here