-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
260 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,92 @@ | ||
const { app, BrowserWindow, Menu, ipcMain } = require('electron') | ||
const path = require('path') | ||
const appSettings = require('./electron/appSettings'); | ||
const { app, BrowserWindow, Menu, ipcMain } = require("electron"); | ||
const path = require("path"); | ||
const appSettings = require("./electron/appSettings"); | ||
let win; | ||
let isDev = !app.isPackaged | ||
let isDev = !app.isPackaged; | ||
|
||
require('./electron/eventBus'); | ||
!isDev && require('./shared/sentry'); | ||
require("./electron/eventBus"); | ||
!isDev && require("./shared/sentry"); | ||
|
||
const getBrowserWindowInstance = () => { | ||
return new BrowserWindow({ | ||
show: false, | ||
width: 560, | ||
height: 690, | ||
center: true, | ||
resizable: isDev, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
scrollBounce: true, | ||
devTools: isDev, | ||
preload: path.join(__dirname, 'shared', 'sentry.js'), | ||
nativeWindowOpen: true | ||
}, | ||
icon: path.join(__dirname, 'assets/icons/icon.png') | ||
}) | ||
} | ||
|
||
function createWindow() { | ||
// Create the browser window. | ||
win = new BrowserWindow({ | ||
show: false, | ||
width: 560, | ||
height: 690, | ||
center: true, | ||
resizable: isDev, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
scrollBounce: true, | ||
devTools: isDev, | ||
preload: path.join(__dirname, 'shared', 'sentry.js') | ||
}, | ||
icon: path.join(__dirname, 'assets/icons/icon.png') | ||
}) | ||
|
||
win = getBrowserWindowInstance(); | ||
isDev && win.webContents.openDevTools(); | ||
|
||
const menu = Menu.buildFromTemplate([ | ||
{ role: 'fileMenu' }, | ||
{ role: 'editMenu'}, | ||
{ role: "fileMenu" }, | ||
{ role: "editMenu" }, | ||
{ | ||
label: 'Debug', | ||
submenu: [ | ||
{ | ||
label: 'Show browser', | ||
click() { | ||
appSettings.toggle('showBrowser'); | ||
}, | ||
type: 'checkbox', | ||
checked: appSettings.get('showBrowser'), | ||
accelerator: 'CmdOrCtrl+Shift+B' | ||
label: "Debug", | ||
submenu: [ | ||
{ | ||
label: "Show browser", | ||
click() { | ||
appSettings.toggle("showBrowser"); | ||
}, | ||
] | ||
type: "checkbox", | ||
checked: appSettings.get("showBrowser"), | ||
accelerator: "CmdOrCtrl+Shift+B" | ||
} | ||
] | ||
} | ||
]) | ||
]); | ||
Menu.setApplicationMenu(menu); | ||
|
||
win.once('ready-to-show', () => { | ||
win.show() | ||
}) | ||
win.once("ready-to-show", () => { | ||
win.show(); | ||
}); | ||
|
||
// and load the index.html of the app. | ||
win.loadURL( | ||
isDev | ||
? 'http://localhost:1234/' | ||
? "http://localhost:1234/" | ||
: `file://${path.join(__dirname, "./dist/index.html")}` | ||
) | ||
); | ||
|
||
win.webContents.on("new-window", function(event, url) { | ||
win.webContents.on("new-window", function(event, url, frameName, disposition, options) { | ||
event.preventDefault(); | ||
if (frameName === "modal") { | ||
// open window as modal | ||
event.preventDefault(); | ||
Object.assign(options, { | ||
modal: true, | ||
parent: win, | ||
width: 500, | ||
height: 500 | ||
}); | ||
event.newGuest = new BrowserWindow(options); | ||
} | ||
}); | ||
|
||
win.on("closed", () => (win = null)); | ||
} | ||
|
||
app.whenReady().then(createWindow) | ||
app.whenReady().then(createWindow); | ||
|
||
ipcMain.on('anteater.error', () => { | ||
console.log('Error triggered in main processes'); | ||
throw new Error('Error triggered in main processes'); | ||
ipcMain.on("anteater.error", () => { | ||
console.log("Error triggered in main processes"); | ||
throw new Error("Error triggered in main processes"); | ||
}); | ||
|
||
ipcMain.on('anteater.crash', () => { | ||
console.log('process.crash()'); | ||
ipcMain.on("anteater.crash", () => { | ||
console.log("process.crash()"); | ||
process.crash(); | ||
}); |
Oops, something went wrong.