William O'Beirne 5542791af8 Electron Alpha Prep (#1665)
* Adjust update flow to not auto update, not publish in CI

* Revert "Adjust update flow to not auto update, not publish in CI"

This reverts commit 74fb382ce8d8cd9e227703ccfa8d6310bffd9dda.

* First pass at new app version modal

* Added app alpha notice that either warns you about alpha, or blocks the whole app.

* Improve newer version detection, add unit tests

* Remove native auto update behavior

* Notice once per session

* copy changes per PR review
2018-04-24 22:29:34 -05:00

77 lines
1.9 KiB
TypeScript

import { BrowserWindow, Menu, shell } from 'electron';
import { URL } from 'url';
import MENU from './menu';
import { APP_TITLE } from '../constants';
const isDevelopment = process.env.NODE_ENV !== 'production';
// Cached reference, preventing recreations
let window: BrowserWindow | null;
// Construct new BrowserWindow
export default function getWindow() {
if (window) {
return window;
}
window = new BrowserWindow({
title: APP_TITLE,
backgroundColor: '#fbfbfb',
width: 1220,
height: process.platform === 'darwin' ? 680 : 720,
minWidth: 480,
minHeight: 400,
titleBarStyle: 'hidden',
webPreferences: {
devTools: true,
nodeIntegration: false,
contextIsolation: true
}
});
const appUrl = isDevelopment ? `http://localhost:3000` : `file://${__dirname}/index.html`;
window.loadURL(appUrl);
window.on('closed', () => {
window = null;
});
window.webContents.on('new-window', (ev: any, urlStr: string) => {
// Kill all new window requests by default
ev.preventDefault();
// Only allow HTTPS urls to actually be opened
const url = new URL(urlStr);
if (url.protocol === 'https:') {
shell.openExternal(urlStr);
} else {
console.warn(`Blocked request to open new window '${urlStr}', only HTTPS links are allowed`);
}
});
// TODO: Figure out updater release process
// window.webContents.on('did-finish-load', () => {
// updater(window!);
// });
window.webContents.on('devtools-opened', () => {
window!.focus();
setImmediate(() => {
window!.focus();
});
});
if (isDevelopment) {
window.webContents.on('did-fail-load', () => {
setTimeout(() => {
if (window && window.webContents) {
window.webContents.reload();
}
}, 500);
});
}
Menu.setApplicationMenu(Menu.buildFromTemplate(MENU));
return window;
}