|
1 | 1 | const { app, BrowserWindow, ipcMain, shell } = require("electron");
|
| 2 | + |
| 3 | +// Disable sandbox for Linux |
| 4 | +if (process.platform === 'linux') { |
| 5 | + app.commandLine.appendSwitch('no-sandbox'); |
| 6 | + app.commandLine.appendSwitch('disable-setuid-sandbox'); |
| 7 | + process.env.ELECTRON_DISABLE_SANDBOX = '1'; |
| 8 | +} |
2 | 9 | const path = require("path");
|
3 | 10 | const fs = require("fs-extra");
|
4 | 11 | const isDev = require("electron-is-dev");
|
@@ -42,6 +49,7 @@ function createWindow() {
|
42 | 49 | contextIsolation: true,
|
43 | 50 | nodeIntegration: false,
|
44 | 51 | preload: path.join(__dirname, "preload.js"),
|
| 52 | + sandbox: false |
45 | 53 | },
|
46 | 54 | });
|
47 | 55 | mainWindow.loadURL(
|
@@ -304,6 +312,40 @@ function setupIPCHandlers() {
|
304 | 312 | }
|
305 | 313 | });
|
306 | 314 |
|
| 315 | + // Get wallet starter data |
| 316 | + ipcMain.handle("get-wallet-starter", async (event, type) => { |
| 317 | + try { |
| 318 | + const walletDir = path.join(app.getPath('userData'), 'wallet_starters'); |
| 319 | + let filePath; |
| 320 | + |
| 321 | + switch (type) { |
| 322 | + case 'master': |
| 323 | + filePath = path.join(walletDir, 'master_starter.json'); |
| 324 | + break; |
| 325 | + case 'layer1': |
| 326 | + filePath = path.join(walletDir, 'l1_starter.json'); |
| 327 | + break; |
| 328 | + case 'thunder': |
| 329 | + filePath = path.join(walletDir, 'sidechain_9_starter.json'); |
| 330 | + break; |
| 331 | + case 'bitnames': |
| 332 | + filePath = path.join(walletDir, 'sidechain_2_starter.json'); |
| 333 | + break; |
| 334 | + default: |
| 335 | + throw new Error('Invalid wallet type'); |
| 336 | + } |
| 337 | + |
| 338 | + if (await fs.pathExists(filePath)) { |
| 339 | + const data = await fs.readJson(filePath); |
| 340 | + return { success: true, data: data.mnemonic }; |
| 341 | + } |
| 342 | + return { success: false, error: 'Wallet starter not found' }; |
| 343 | + } catch (error) { |
| 344 | + console.error('Error reading wallet starter:', error); |
| 345 | + return { success: false, error: error.message }; |
| 346 | + } |
| 347 | + }); |
| 348 | + |
307 | 349 | // Advanced wallet handlers
|
308 | 350 | ipcMain.handle("preview-wallet", async (event, options) => {
|
309 | 351 | try {
|
@@ -347,6 +389,47 @@ function setupIPCHandlers() {
|
347 | 389 | return await updateManager.checkForUpdates();
|
348 | 390 | });
|
349 | 391 |
|
| 392 | + ipcMain.handle("apply-updates", async (event, chainIds) => { |
| 393 | + try { |
| 394 | + // First stop any running chains |
| 395 | + for (const chainId of chainIds) { |
| 396 | + const status = await chainManager.getChainStatus(chainId); |
| 397 | + if (status === 'running' || status === 'ready') { |
| 398 | + await chainManager.stopChain(chainId); |
| 399 | + } |
| 400 | + } |
| 401 | + |
| 402 | + // Delete existing binaries and download updates |
| 403 | + for (const chainId of chainIds) { |
| 404 | + const chain = config.chains.find(c => c.id === chainId); |
| 405 | + if (!chain) continue; |
| 406 | + |
| 407 | + // Get extract path |
| 408 | + const platform = process.platform; |
| 409 | + const extractDir = chain.extract_dir?.[platform]; |
| 410 | + if (!extractDir) continue; |
| 411 | + |
| 412 | + const downloadsDir = app.getPath("downloads"); |
| 413 | + const extractPath = path.join(downloadsDir, extractDir); |
| 414 | + |
| 415 | + // Delete existing binary directory |
| 416 | + await fs.remove(extractPath); |
| 417 | + |
| 418 | + // Download and extract new binary |
| 419 | + const url = chain.download.urls[platform]; |
| 420 | + if (!url) continue; |
| 421 | + |
| 422 | + await fs.ensureDir(extractPath); |
| 423 | + downloadManager.startDownload(chainId, url, extractPath); |
| 424 | + } |
| 425 | + |
| 426 | + return { success: true }; |
| 427 | + } catch (error) { |
| 428 | + console.error('Failed to apply updates:', error); |
| 429 | + return { success: false, error: error.message }; |
| 430 | + } |
| 431 | + }); |
| 432 | + |
350 | 433 | ipcMain.handle("get-balance-btc", async (event, options) => {
|
351 | 434 | try {
|
352 | 435 | return await fastWithdrawalManager.getBalanceBTC();
|
@@ -384,33 +467,74 @@ function setupIPCHandlers() {
|
384 | 467 | }
|
385 | 468 | });
|
386 | 469 |
|
| 470 | + // Wallet directory handlers |
| 471 | + ipcMain.handle("delete-wallet-starters-dir", async () => { |
| 472 | + try { |
| 473 | + const walletDir = path.join(app.getPath('userData'), 'wallet_starters'); |
| 474 | + if (await fs.pathExists(walletDir)) { |
| 475 | + await fs.remove(walletDir); |
| 476 | + } |
| 477 | + return { success: true }; |
| 478 | + } catch (error) { |
| 479 | + console.error('Failed to delete wallet starters directory:', error); |
| 480 | + return { success: false, error: error.message }; |
| 481 | + } |
| 482 | + }); |
| 483 | + |
| 484 | + ipcMain.handle("init-wallet-dirs", async () => { |
| 485 | + try { |
| 486 | + const walletDir = path.join(app.getPath('userData'), 'wallet_starters'); |
| 487 | + const mnemonicsDir = path.join(walletDir, 'mnemonics'); |
| 488 | + await fs.ensureDir(walletDir); |
| 489 | + await fs.ensureDir(mnemonicsDir); |
| 490 | + return { success: true }; |
| 491 | + } catch (error) { |
| 492 | + console.error('Failed to initialize wallet directories:', error); |
| 493 | + return { success: false, error: error.message }; |
| 494 | + } |
| 495 | + }); |
| 496 | + |
387 | 497 | ipcMain.handle('force-kill', () => {
|
388 | 498 | forceKillAllProcesses();
|
389 | 499 | });
|
390 | 500 | }
|
391 | 501 |
|
392 |
| -app.whenReady().then(async () => { |
393 |
| - await loadConfig(); |
394 |
| - |
395 |
| - // Initialize managers |
396 |
| - directoryManager = new DirectoryManager(config); |
397 |
| - await directoryManager.setupChainDirectories(); |
398 |
| - |
399 |
| - const configManager = new ConfigManager(configPath); |
400 |
| - await configManager.loadConfig(); |
401 |
| - await configManager.setupExtractDirectories(); |
402 |
| - |
403 |
| - createWindow(); |
404 |
| - |
405 |
| - chainManager = new ChainManager(mainWindow, config); |
406 |
| - walletManager = new WalletManager(config); |
407 |
| - fastWithdrawalManager = new FastWithdrawalManager(); |
408 |
| - apiManager = new ApiManager(); |
409 |
| - updateManager = new UpdateManager(config, chainManager); |
410 |
| - downloadManager = new DownloadManager(mainWindow, config); |
411 |
| - |
412 |
| - setupIPCHandlers(); |
413 |
| -}); |
| 502 | +async function initialize() { |
| 503 | + try { |
| 504 | + await loadConfig(); |
| 505 | + |
| 506 | + // Initialize managers that don't depend on mainWindow |
| 507 | + directoryManager = new DirectoryManager(config); |
| 508 | + await directoryManager.setupChainDirectories(); |
| 509 | + |
| 510 | + const configManager = new ConfigManager(configPath); |
| 511 | + await configManager.loadConfig(); |
| 512 | + await configManager.setupExtractDirectories(); |
| 513 | + |
| 514 | + walletManager = new WalletManager(config); |
| 515 | + fastWithdrawalManager = new FastWithdrawalManager(); |
| 516 | + apiManager = new ApiManager(); |
| 517 | + |
| 518 | + // Create window first |
| 519 | + createWindow(); |
| 520 | + |
| 521 | + // Then initialize managers that need mainWindow |
| 522 | + chainManager = new ChainManager(mainWindow, config); |
| 523 | + updateManager = new UpdateManager(config, chainManager); |
| 524 | + downloadManager = new DownloadManager(mainWindow, config); |
| 525 | + |
| 526 | + // Finally setup IPC handlers after everything is initialized |
| 527 | + setupIPCHandlers(); |
| 528 | + } catch (error) { |
| 529 | + console.error('Initialization error:', error); |
| 530 | + app.quit(); |
| 531 | + } |
| 532 | +} |
| 533 | + |
| 534 | +// Disable sandbox |
| 535 | +app.commandLine.appendSwitch('no-sandbox'); |
| 536 | + |
| 537 | +app.whenReady().then(initialize); |
414 | 538 |
|
415 | 539 | let isShuttingDown = false;
|
416 | 540 | let forceKillTimeout;
|
|
0 commit comments