Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions public/modules/bitWindowClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,15 +21,15 @@ 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;
}
}

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;
Expand Down
35 changes: 13 additions & 22 deletions public/modules/chainManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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" };
}

Expand All @@ -497,24 +490,23 @@ 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
await new Promise(resolve => {
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);

Expand All @@ -534,7 +526,6 @@ class ChainManager {

resolve();
}
});
}, 100);
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion public/modules/enforcerClient.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down