|
| 1 | +const bt = require('backtrace-node'); |
| 2 | +const electron = require('electron'); |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | + |
| 6 | +function ElectronExample() { |
| 7 | + this.initializeRemoteLogging = function() { |
| 8 | + const token = 'token'; |
| 9 | + const endpoint = `https://submit.backtrace.io/universe/${token}`; |
| 10 | + this._backtraceClient = bt.initialize({ |
| 11 | + endpoint: endpoint + '/json', |
| 12 | + timeout: 20000, |
| 13 | + }); |
| 14 | + |
| 15 | + electron.crashReporter.start({ |
| 16 | + productName: 'Your product name', |
| 17 | + companyName: 'My Company, Inc', |
| 18 | + submitURL: endpoint + '/minidump', |
| 19 | + uploadToServer: true, |
| 20 | + }); |
| 21 | + }; |
| 22 | + |
| 23 | + this.readDataFromFileStorage = async function() { |
| 24 | + this._backtraceClient.memorize('ipc-method::invoke-main', this); |
| 25 | + try { |
| 26 | + this._backtraceClient.memorize('ipc-method::invoke-main', 'before reading'); |
| 27 | + this.readFile(); |
| 28 | + } catch (e) { |
| 29 | + await this._backtraceClient.reportAsync( |
| 30 | + e, |
| 31 | + { |
| 32 | + attribute: 'attribute', |
| 33 | + numberAttribute: 123132, |
| 34 | + foo: false, |
| 35 | + }, |
| 36 | + ['path', 'to', 'my', 'files'], |
| 37 | + ); |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + function forwardMessage(msg) { |
| 42 | + this.ipcReply(msg); |
| 43 | + } |
| 44 | + function ipcReply(msg) { |
| 45 | + electron.ipcRenderer.send(msg); |
| 46 | + } |
| 47 | + |
| 48 | + function readFile() { |
| 49 | + fs.readFileSync('path to not existing file'); |
| 50 | + } |
| 51 | + |
| 52 | + this.invokeInvalidIpcCommunication = async function() { |
| 53 | + try { |
| 54 | + this.forwardMessage('msg'); |
| 55 | + } catch (err) { |
| 56 | + await this._backtraceClient.reportAsync(err); |
| 57 | + } |
| 58 | + }; |
| 59 | +} |
| 60 | + |
| 61 | +async function createWindow() { |
| 62 | + win = new electron.BrowserWindow({ |
| 63 | + width: 400, |
| 64 | + height: 500, |
| 65 | + darkTheme: true, |
| 66 | + }); |
| 67 | + win.loadURL(path.join(__dirname, 'renderer', 'index.html')); |
| 68 | + |
| 69 | + electron.app.setBadgeCount(1); |
| 70 | + electron.ipcMain.on('invoke-main', async () => { |
| 71 | + await electronExample.readDataFromFileStorage(); |
| 72 | + }); |
| 73 | + |
| 74 | + electron.ipcMain.on('invoke-main-2', async () => { |
| 75 | + await electronExample.invokeInvalidIpcCommunication(); |
| 76 | + }); |
| 77 | + |
| 78 | + electron.ipcMain.on('crash-process', () => { |
| 79 | + process.crash(); |
| 80 | + }); |
| 81 | +} |
| 82 | + |
| 83 | +const electronExample = new ElectronExample(); |
| 84 | +electronExample.initializeRemoteLogging(); |
| 85 | +let win; |
| 86 | + |
| 87 | +electron.app.on('ready', createWindow); |
| 88 | +electron.app.on('activate', () => { |
| 89 | + if (win === null) { |
| 90 | + createWindow(); |
| 91 | + } |
| 92 | +}); |
0 commit comments