2020-06-02 12:08:53 +02:00
|
|
|
const { app, BrowserWindow, shell } = require("electron")
|
2020-05-18 12:01:09 +02:00
|
|
|
const { join } = require("path")
|
|
|
|
const { homedir } = require("os")
|
|
|
|
const isDev = require("electron-is-dev")
|
|
|
|
const { autoUpdater } = require("electron-updater")
|
|
|
|
const unhandled = require("electron-unhandled")
|
2020-05-07 14:33:25 +02:00
|
|
|
|
2020-05-18 12:01:09 +02:00
|
|
|
require("dotenv").config({ path: join(homedir(), ".budibase", ".env") })
|
2020-05-14 22:18:36 +02:00
|
|
|
|
2020-05-16 19:19:36 +02:00
|
|
|
if (isDev) {
|
|
|
|
unhandled({
|
2020-05-18 12:01:09 +02:00
|
|
|
showDialog: true,
|
|
|
|
})
|
2020-05-16 19:19:36 +02:00
|
|
|
}
|
2020-05-14 22:18:36 +02:00
|
|
|
|
2020-05-18 19:05:36 +02:00
|
|
|
const APP_URL = "http://localhost:4001/_builder"
|
2020-05-18 12:01:09 +02:00
|
|
|
const APP_TITLE = "Budibase Builder"
|
2020-05-07 14:52:24 +02:00
|
|
|
|
2020-05-16 19:19:36 +02:00
|
|
|
let win
|
2020-05-15 19:13:18 +02:00
|
|
|
|
2020-06-02 12:08:53 +02:00
|
|
|
function handleRedirect(e, url) {
|
|
|
|
e.preventDefault()
|
|
|
|
shell.openExternal(url)
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:33:29 +02:00
|
|
|
async function createWindow() {
|
|
|
|
app.server = await require("./app")()
|
2020-05-18 12:01:09 +02:00
|
|
|
win = new BrowserWindow({ width: 1920, height: 1080 })
|
|
|
|
win.setTitle(APP_TITLE)
|
|
|
|
win.loadURL(APP_URL)
|
2020-05-14 22:18:36 +02:00
|
|
|
if (isDev) {
|
2020-05-18 12:01:09 +02:00
|
|
|
win.webContents.openDevTools()
|
2020-05-14 22:18:36 +02:00
|
|
|
} else {
|
2020-05-18 12:01:09 +02:00
|
|
|
autoUpdater.checkForUpdatesAndNotify()
|
2020-05-14 22:18:36 +02:00
|
|
|
}
|
2020-06-02 12:08:53 +02:00
|
|
|
|
|
|
|
// open _blank in default browser
|
|
|
|
win.webContents.on("new-window", handleRedirect)
|
|
|
|
win.webContents.on("will-navigate", handleRedirect)
|
2020-05-07 14:33:25 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 22:18:36 +02:00
|
|
|
app.whenReady().then(createWindow)
|
|
|
|
|
|
|
|
// Quit when all windows are closed.
|
|
|
|
app.on("window-all-closed", () => {
|
2020-05-18 12:01:09 +02:00
|
|
|
// On macOS it is common for applications and their menu bar
|
|
|
|
// to stay active until the user quits explicitly with Cmd + Q
|
|
|
|
if (process.platform !== "darwin") app.quit()
|
|
|
|
})
|
2020-05-14 22:18:36 +02:00
|
|
|
|
|
|
|
app.on("activate", () => {
|
2020-05-18 12:01:09 +02:00
|
|
|
// 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 (win === null) createWindow()
|
|
|
|
})
|