This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export ipc handlers to dedicated file
- Loading branch information
1 parent
4bdc9a3
commit af2f3ac
Showing
4 changed files
with
94 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { ipcMain } from 'electron'; | ||
import { stopCli } from './cli/cli'; | ||
import spawnBalanceCheck from './cli/commands/balanceCommand'; | ||
import { resumeBuyXmr, spawnBuyXmr } from './cli/commands/buyXmrCommand'; | ||
import spawnCancelRefund from './cli/commands/cancelRefundCommand'; | ||
import spawnWithdrawBtc from './cli/commands/withdrawBtcCommand'; | ||
import spawnListSellersCommand from './cli/commands/listSellersCommand'; | ||
import { getCliLogFile } from './cli/dirs'; | ||
import { spawnTor, stopTor } from './tor'; | ||
import logger from '../utils/logger'; | ||
import { mainWindow } from './main'; | ||
|
||
export default function registerIpcHandlers() { | ||
ipcMain.handle('stop-cli', stopCli); | ||
|
||
ipcMain.handle('spawn-balance-check', spawnBalanceCheck); | ||
|
||
ipcMain.handle( | ||
'spawn-buy-xmr', | ||
(_event, provider, redeemAddress, refundAddress) => | ||
spawnBuyXmr(provider, redeemAddress, refundAddress) | ||
); | ||
|
||
ipcMain.handle('resume-buy-xmr', (_event, swapId) => resumeBuyXmr(swapId)); | ||
|
||
ipcMain.handle('spawn-cancel-refund', (_event, swapId) => | ||
spawnCancelRefund(swapId) | ||
); | ||
|
||
ipcMain.handle('spawn-withdraw-btc', (_event, address) => | ||
spawnWithdrawBtc(address) | ||
); | ||
|
||
ipcMain.handle('spawn-list-sellers', (_event, rendezvousPointAddress) => | ||
spawnListSellersCommand(rendezvousPointAddress) | ||
); | ||
|
||
ipcMain.handle('get-cli-log-path', (_event, swapId) => getCliLogFile(swapId)); | ||
|
||
ipcMain.handle('spawn-tor', spawnTor); | ||
|
||
ipcMain.handle('stop-tor', stopTor); | ||
} | ||
|
||
export function sendSnackbarAlertToRenderer( | ||
message: string, | ||
variant: string, | ||
autoHideDuration: number | null, | ||
key: string | null | ||
) { | ||
function send() { | ||
logger.debug( | ||
{ message, variant, autoHideDuration, key }, | ||
'Attempting to send snackbar alert to renderer' | ||
); | ||
if (mainWindow) { | ||
if ( | ||
mainWindow.webContents.isDestroyed() || | ||
mainWindow.webContents.isLoading() | ||
) { | ||
logger.debug( | ||
'Main window is loading, waiting for it to finish before sending snackbar alert' | ||
); | ||
mainWindow.webContents.once('did-finish-load', () => | ||
setTimeout(send, 5000) | ||
); | ||
} else { | ||
logger.debug( | ||
{ message, variant, autoHideDuration, key }, | ||
'Sending snackbar alert to renderer' | ||
); | ||
mainWindow?.webContents.send( | ||
'display-snackbar-alert', | ||
message, | ||
variant, | ||
autoHideDuration, | ||
key | ||
); | ||
} | ||
} else { | ||
setTimeout(send, 1000); | ||
} | ||
} | ||
|
||
send(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters