generated from electron/electron-quick-start-typescript
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
105 lines (88 loc) · 3.32 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { BrowserWindow, app, crashReporter, ipcMain, shell } from "electron";
import * as path from "path";
import { unhandledRejection } from "./crasher";
const { database, name, version } = require("../../package.json");
const { add } = require('../addon.node');
// Required: Handle native crashes in Electron and native add-ins
crashReporter.start({
submitURL: `https://${database}.bugsplat.com/post/electron/v2/crash.php`,
ignoreSystemCrashHandler: true,
uploadToServer: true,
rateLimit: false,
globalExtra: {
"product": name,
"version": version,
"key": "en-US",
"email": "fred@bugsplat.com",
"comments": "BugSplat rocks!",
}
})
// Recommended: Initialize BugSplat with database name, app name, and version to catch JavaScript errors
import { BugSplatNode as BugSplat } from "bugsplat-node"
const bugsplat = new BugSplat(database, name, version)
// Recommended: The following methods allow further customization
bugsplat.setDefaultAppKey("main")
bugsplat.setDefaultUser("Fred")
bugsplat.setDefaultEmail("fred@bedrock.com")
bugsplat.setDefaultDescription("description")
bugsplat.setDefaultAdditionalFilePaths(["./src/assets/attachment.txt"])
// Recommended: Post to BugSplat when unhandledRejections and uncaughtExceptions occur
const javaScriptErrorHandler = async (error: Error) => {
await bugsplat.post(error);
app.quit();
}
process.on("unhandledRejection", javaScriptErrorHandler)
process.on("uncaughtException", javaScriptErrorHandler)
// Optional: Uncomment to send an Error to BugSplat manually
//bugsplat.post(new Error("foobar!")).then(({ error, response, original }) => console.log(error, response, original))
function createWindow() {
// Create the browser window.
const mainWindow = new BrowserWindow({
height: 600,
width: 800,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
preload: path.join(__dirname, "preload.js"),
},
});
// and load the index.html of the app.
mainWindow.loadFile(path.join(__dirname, "../../index.html"));
// Maximize the window so the buttons aren't hidden
mainWindow.maximize()
// Open the DevTools.
mainWindow.webContents.openDevTools();
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", () => {
createWindow();
app.on("activate", function () {
// On macOS it"s common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
ipcMain.on("trigger:user-main-crash", function () {
console.log(`on.trigger:user-main-crash`);
unhandledRejection("unhandledRejection: main process");
});
ipcMain.on("trigger:native-main-crash", function () {
process.crash();
});
ipcMain.on("trigger:addon-main-crash", function () {
console.log("add = ", add(7, 3));
});
ipcMain.on('open-external-url-event', (event, url) => {
event.returnValue = 'Message received!'
shell.openExternal(url);
})