Skip to content

Commit 4f6c87c

Browse files
author
cpl121
committed
feat: update minifirefly to store logs
1 parent f4d6b2f commit 4f6c87c

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

main.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
const { app, BrowserWindow } = require('electron')
1+
const { app, BrowserWindow, ipcMain } = require('electron')
22
const path = require('node:path')
33

44
let win
55

6+
let versionDetails = {
7+
upToDate: true,
8+
currentVersion: app.getVersion(),
9+
newVersion: '',
10+
newVersionReleaseDate: new Date(),
11+
changelog: '',
12+
}
13+
614
function createWindow() {
715
win = new BrowserWindow({
816
webPreferences: {
@@ -17,6 +25,15 @@ function createWindow() {
1725
win.openDevTools();
1826
}
1927

28+
ipcMain.handle('get-path', (_e, path) => {
29+
const allowedPaths = ['userData']
30+
if (allowedPaths.indexOf(path) === -1) {
31+
throw Error(`Path ${path} is not allowed`)
32+
}
33+
return app.getPath(path)
34+
})
35+
ipcMain.handle('get-version-details', (_e) => versionDetails)
36+
2037
app.on('window-all-closed', () => {
2138
if (process.platform !== 'darwin') {
2239
app.quit()

preload.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require('reflect-metadata');
2-
const { contextBridge } = require('electron')
2+
const { ipcRenderer, contextBridge } = require('electron')
33
const { SecretManager, Wallet, Utils } = require('@iota/sdk');
4+
const IotaSdk = require('@iota/sdk')
45
const fs = require('node:fs');
56

67
function bindMethodsAcrossContextBridge(prototype, object) {
@@ -12,9 +13,11 @@ function bindMethodsAcrossContextBridge(prototype, object) {
1213
})
1314
}
1415

16+
const node = process.env["MINIFIREFLY_NODE"]
17+
1518
// IOTA
1619
const WALLET_DB_PATH = 'MINIFIREFLY-DB';
17-
const NODE_URL = process.env["MINIFIREFLY_NODE"]
20+
const NODE_URL = node
1821
const STRONGHOLD_PASSWORD = 'firefly';
1922
const STRONGHOLD_SNAPSHOT_PATH = 'MINIFIREFLY-DB/minifirefly.stronghold';
2023
const strongholdSecretManager = {
@@ -24,6 +27,29 @@ const strongholdSecretManager = {
2427
},
2528
};
2629

30+
31+
32+
try {
33+
ipcRenderer.invoke('get-path', 'userData').then(async (baseDir) => {
34+
const logDir = `${baseDir}/logs`
35+
if (!fs.existsSync(logDir)) {
36+
fs.mkdirSync(logDir)
37+
}
38+
const versionDetails = await ipcRenderer.invoke('get-version-details')
39+
const today = new Date().toISOString().slice(0, 16).replace('T', '-').replace(':', '-')
40+
const loggerOptions = {
41+
colorEnabled: true,
42+
name: `${logDir}/minifirefly-v${versionDetails.currentVersion}-d${today}.log`,
43+
levelFilter: 'debug',
44+
targetExclusions: ['h2', 'hyper', 'rustls', 'message_handler'],
45+
}
46+
IotaSdk.initLogger(loggerOptions)
47+
48+
})
49+
} catch (err) {
50+
console.error('[Preload Context] Error:', err)
51+
}
52+
2753
contextBridge.exposeInMainWorld('__MINIFIREFLY__', {
2854
async createWallet() {
2955
const secretManager = SecretManager.create(strongholdSecretManager);
@@ -64,11 +90,25 @@ contextBridge.exposeInMainWorld('__MINIFIREFLY__', {
6490
bipPath: {
6591
coinType: 1,
6692
},
67-
secretManager: strongholdSecretManager,
93+
secretManager: null,
6894
};
6995

7096
const wallet = await Wallet.create(walletOptions);
7197
bindMethodsAcrossContextBridge(Wallet.prototype, wallet)
98+
await wallet.sync({
99+
forceSyncing: true,
100+
account: {
101+
basicOutputs: true,
102+
aliasOutputs: true,
103+
},
104+
wallet: {
105+
basicOutputs: false,
106+
accountOutputs: false,
107+
},
108+
syncIncomingTransactions: true,
109+
syncNativeTokenFoundries: true,
110+
syncImplicitAccounts: true,
111+
})
72112
return wallet
73113
},
74114
removeWallet() {

0 commit comments

Comments
 (0)