2017-05-03 17:48:23 +00:00
|
|
|
import electron from 'electron';
|
|
|
|
import path from 'path';
|
2018-06-25 17:42:50 +00:00
|
|
|
import { Curl } from 'insomnia-libcurl';
|
2017-05-03 17:48:23 +00:00
|
|
|
import fs from 'fs';
|
2017-11-18 22:47:54 +00:00
|
|
|
import LocalStorage from './local-storage';
|
2018-06-25 17:42:50 +00:00
|
|
|
import {
|
|
|
|
CHANGELOG_BASE_URL,
|
2018-12-11 23:11:54 +00:00
|
|
|
MNEMONIC_SYM,
|
2018-06-25 17:42:50 +00:00
|
|
|
getAppLongName,
|
|
|
|
getAppName,
|
|
|
|
getAppVersion,
|
|
|
|
isDevelopment,
|
2018-12-12 17:36:11 +00:00
|
|
|
isMac,
|
2018-06-25 17:42:50 +00:00
|
|
|
} from '../common/constants';
|
2017-11-20 16:07:36 +00:00
|
|
|
import * as misc from '../common/misc';
|
2017-05-03 17:48:23 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
const { app, Menu, BrowserWindow, shell, dialog } = electron;
|
2017-05-03 17:48:23 +00:00
|
|
|
|
2017-06-22 19:37:24 +00:00
|
|
|
const DEFAULT_WIDTH = 1100;
|
|
|
|
const DEFAULT_HEIGHT = 550;
|
|
|
|
const MINIMUM_WIDTH = 500;
|
|
|
|
const MINIMUM_HEIGHT = 400;
|
|
|
|
|
2017-05-03 17:48:23 +00:00
|
|
|
let mainWindow = null;
|
|
|
|
let localStorage = null;
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function init() {
|
2017-05-24 16:25:22 +00:00
|
|
|
initLocalStorage();
|
|
|
|
initContextMenus();
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function createWindow() {
|
2017-05-03 17:48:23 +00:00
|
|
|
const zoomFactor = getZoomFactor();
|
2018-06-25 17:42:50 +00:00
|
|
|
const { bounds, fullscreen, maximize } = getBounds();
|
|
|
|
const { x, y, width, height } = bounds;
|
2017-05-03 17:48:23 +00:00
|
|
|
|
|
|
|
// Make sure we don't place the window outside of the visible space
|
|
|
|
let maxX = 0;
|
|
|
|
let maxY = 0;
|
|
|
|
for (const d of electron.screen.getAllDisplays()) {
|
|
|
|
// Set the maximum placement location to 50 pixels short of the end
|
|
|
|
maxX = Math.max(maxX, d.bounds.x + d.bounds.width - 50);
|
|
|
|
maxY = Math.max(maxY, d.bounds.y + d.bounds.height - 50);
|
|
|
|
}
|
|
|
|
const finalX = Math.min(maxX, x);
|
|
|
|
const finalY = Math.min(maxX, y);
|
|
|
|
|
|
|
|
mainWindow = new BrowserWindow({
|
|
|
|
// Make sure we don't initialize the window outside the bounds
|
|
|
|
x: finalX,
|
|
|
|
y: finalY,
|
|
|
|
fullscreen: fullscreen,
|
|
|
|
fullscreenable: true,
|
|
|
|
title: getAppName(),
|
2017-06-22 19:37:24 +00:00
|
|
|
width: width || DEFAULT_WIDTH,
|
|
|
|
height: height || DEFAULT_HEIGHT,
|
2017-06-26 19:12:18 +00:00
|
|
|
minHeight: MINIMUM_HEIGHT,
|
|
|
|
minWidth: MINIMUM_WIDTH,
|
2017-05-03 17:48:23 +00:00
|
|
|
acceptFirstMouse: true,
|
|
|
|
icon: path.resolve(__dirname, 'static/icon.png'),
|
|
|
|
webPreferences: {
|
2018-12-12 17:36:11 +00:00
|
|
|
zoomFactor: zoomFactor,
|
|
|
|
},
|
2017-05-03 17:48:23 +00:00
|
|
|
});
|
|
|
|
|
2017-06-29 17:39:09 +00:00
|
|
|
// BrowserWindow doesn't have an option for this, so we have to do it manually :(
|
|
|
|
if (maximize) {
|
|
|
|
mainWindow.maximize();
|
|
|
|
}
|
|
|
|
|
2018-05-23 04:28:25 +00:00
|
|
|
mainWindow.on('resize', e => saveBounds());
|
2017-05-03 17:48:23 +00:00
|
|
|
|
2018-05-23 04:28:25 +00:00
|
|
|
mainWindow.on('maximize', e => saveBounds());
|
2017-06-29 17:39:09 +00:00
|
|
|
|
2018-05-23 04:28:25 +00:00
|
|
|
mainWindow.on('unmaximize', e => saveBounds());
|
2017-05-03 17:48:23 +00:00
|
|
|
|
2018-05-23 04:28:25 +00:00
|
|
|
mainWindow.on('move', e => saveBounds());
|
2017-05-03 17:48:23 +00:00
|
|
|
|
|
|
|
mainWindow.on('unresponsive', e => {
|
|
|
|
showUnresponsiveModal();
|
|
|
|
});
|
|
|
|
|
2019-05-08 20:13:26 +00:00
|
|
|
// Open generic links (<a .../>) in default browser
|
|
|
|
mainWindow.webContents.on('will-navigate', (e, url) => {
|
2019-05-08 20:32:28 +00:00
|
|
|
if (url === appUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('[app] Navigate to ' + url);
|
2019-05-08 20:13:26 +00:00
|
|
|
e.preventDefault();
|
|
|
|
electron.shell.openExternal(url);
|
|
|
|
});
|
|
|
|
|
2017-11-24 01:39:53 +00:00
|
|
|
// Load the html of the app.
|
2018-03-30 16:46:01 +00:00
|
|
|
const url = process.env.APP_RENDER_URL;
|
|
|
|
const appUrl = url || `file://${app.getAppPath()}/renderer.html`;
|
|
|
|
console.log(`[main] Loading ${appUrl}`);
|
2017-11-24 01:39:53 +00:00
|
|
|
mainWindow.loadURL(appUrl);
|
2017-05-03 17:48:23 +00:00
|
|
|
|
|
|
|
// Emitted when the window is closed.
|
|
|
|
mainWindow.on('closed', () => {
|
|
|
|
// Dereference the window object, usually you would store windows
|
|
|
|
// in an array if your app supports multi windows, this is the time
|
|
|
|
// when you should delete the corresponding element.
|
|
|
|
mainWindow = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
const applicationMenu = {
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Application`,
|
2017-05-03 17:48:23 +00:00
|
|
|
submenu: [
|
2018-06-25 17:42:50 +00:00
|
|
|
...(isMac()
|
2018-12-11 23:11:54 +00:00
|
|
|
? [{ label: `A${MNEMONIC_SYM}bout ${getAppName()}`, role: 'about' }, { type: 'separator' }]
|
2018-06-25 17:42:50 +00:00
|
|
|
: []),
|
2017-05-03 17:48:23 +00:00
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Preferences`,
|
2018-06-25 17:42:50 +00:00
|
|
|
click: function(menuItem, window, e) {
|
2017-05-03 17:48:23 +00:00
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.webContents.send('toggle-preferences');
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-05-03 17:48:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Changelog`,
|
2018-06-25 17:42:50 +00:00
|
|
|
click: function(menuItem, window, e) {
|
2017-05-03 17:48:23 +00:00
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-23 21:57:08 +00:00
|
|
|
misc.clickLink(`${CHANGELOG_BASE_URL}/${getAppVersion()}/`);
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-05-03 17:48:23 +00:00
|
|
|
},
|
2019-04-23 22:38:53 +00:00
|
|
|
...(isMac()
|
|
|
|
? [
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'hide' },
|
|
|
|
{ role: 'hideothers' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: `${MNEMONIC_SYM}Quit`, accelerator: 'CmdOrCtrl+Q', click: () => app.quit() },
|
|
|
|
]
|
|
|
|
: []),
|
2018-12-12 17:36:11 +00:00
|
|
|
],
|
2017-05-03 17:48:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const editMenu = {
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Edit`,
|
2017-05-03 17:48:23 +00:00
|
|
|
submenu: [
|
2018-12-11 23:11:54 +00:00
|
|
|
{ label: `${MNEMONIC_SYM}Undo`, accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
|
|
|
|
{ label: `${MNEMONIC_SYM}Redo`, accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
|
2018-06-25 17:42:50 +00:00
|
|
|
{ type: 'separator' },
|
2018-12-11 23:11:54 +00:00
|
|
|
{ label: `Cu${MNEMONIC_SYM}t`, accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
|
|
|
|
{ label: `${MNEMONIC_SYM}Copy`, accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
|
|
|
|
{ label: `${MNEMONIC_SYM}Paste`, accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
|
2018-06-25 17:42:50 +00:00
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Select ${MNEMONIC_SYM}All`,
|
2018-06-25 17:42:50 +00:00
|
|
|
accelerator: 'CmdOrCtrl+A',
|
2018-12-12 17:36:11 +00:00
|
|
|
selector: 'selectAll:',
|
|
|
|
},
|
|
|
|
],
|
2017-05-03 17:48:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const viewMenu = {
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}View`,
|
2017-05-03 17:48:23 +00:00
|
|
|
submenu: [
|
2018-12-11 23:11:54 +00:00
|
|
|
{ label: `Toggle ${MNEMONIC_SYM}Full Screen`, role: 'togglefullscreen' },
|
2017-05-03 17:48:23 +00:00
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Actual Size`,
|
2017-05-03 17:48:23 +00:00
|
|
|
accelerator: 'CmdOrCtrl+0',
|
|
|
|
click: () => {
|
2019-04-18 00:50:03 +00:00
|
|
|
const w = BrowserWindow.getFocusedWindow();
|
|
|
|
if (!w || !w.webContents) {
|
2017-05-03 17:48:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const zoomFactor = 1;
|
2019-04-18 00:50:03 +00:00
|
|
|
w.webContents.setZoomFactor(zoomFactor);
|
2017-05-03 17:48:23 +00:00
|
|
|
saveZoomFactor(zoomFactor);
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-05-03 17:48:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Zoom ${MNEMONIC_SYM}In`,
|
2019-04-18 00:50:03 +00:00
|
|
|
accelerator: 'CmdOrCtrl+=',
|
2017-05-03 17:48:23 +00:00
|
|
|
click: () => {
|
2019-04-18 00:50:03 +00:00
|
|
|
const w = BrowserWindow.getFocusedWindow();
|
|
|
|
if (!w || !w.webContents) {
|
2017-05-03 17:48:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const zoomFactor = Math.min(1.8, getZoomFactor() + 0.05);
|
2019-04-18 00:50:03 +00:00
|
|
|
w.webContents.setZoomFactor(zoomFactor);
|
2017-05-03 17:48:23 +00:00
|
|
|
|
|
|
|
saveZoomFactor(zoomFactor);
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-05-03 17:48:23 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Zoom ${MNEMONIC_SYM}Out`,
|
2017-05-03 17:48:23 +00:00
|
|
|
accelerator: 'CmdOrCtrl+-',
|
|
|
|
click: () => {
|
2019-04-18 00:50:03 +00:00
|
|
|
const w = BrowserWindow.getFocusedWindow();
|
|
|
|
if (!w || !w.webContents) {
|
2017-05-03 17:48:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const zoomFactor = Math.max(0.5, getZoomFactor() - 0.05);
|
2019-04-18 00:50:03 +00:00
|
|
|
w.webContents.setZoomFactor(zoomFactor);
|
2017-05-03 17:48:23 +00:00
|
|
|
saveZoomFactor(zoomFactor);
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-05-03 17:48:23 +00:00
|
|
|
},
|
2017-09-17 14:25:31 +00:00
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Toggle ${MNEMONIC_SYM}DevTools`,
|
2018-12-12 17:36:11 +00:00
|
|
|
click: () => mainWindow.toggleDevTools(),
|
|
|
|
},
|
|
|
|
],
|
2017-05-03 17:48:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const windowMenu = {
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Window`,
|
2017-05-03 17:48:23 +00:00
|
|
|
role: 'window',
|
2018-12-11 23:11:54 +00:00
|
|
|
submenu: [
|
|
|
|
{ label: `${MNEMONIC_SYM}Minimize`, role: 'minimize' },
|
2018-12-12 17:36:11 +00:00
|
|
|
...(isMac() ? [{ label: `${MNEMONIC_SYM}Close`, role: 'close' }] : []),
|
|
|
|
],
|
2017-05-03 17:48:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const helpMenu = {
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Help`,
|
2017-05-03 17:48:23 +00:00
|
|
|
role: 'help',
|
|
|
|
id: 'help',
|
|
|
|
submenu: [
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Contact ${MNEMONIC_SYM}Support`,
|
2017-05-03 17:48:23 +00:00
|
|
|
click: () => {
|
2017-11-08 17:12:36 +00:00
|
|
|
shell.openExternal('https://insomnia.rest/support/');
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-05-03 17:48:23 +00:00
|
|
|
},
|
2017-08-04 16:54:11 +00:00
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Keyboard Shortcuts`,
|
|
|
|
accelerator: 'CmdOrCtrl+Shift+?',
|
2019-04-18 00:50:03 +00:00
|
|
|
click: (menuItem, w, e) => {
|
|
|
|
if (!w || !w.webContents) {
|
2017-08-04 16:54:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-18 00:50:03 +00:00
|
|
|
w.webContents.send('toggle-preferences-shortcuts');
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-08-04 16:54:11 +00:00
|
|
|
},
|
2017-10-10 16:47:49 +00:00
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Show App ${MNEMONIC_SYM}Data Folder`,
|
2019-04-18 00:50:03 +00:00
|
|
|
click: (menuItem, w, e) => {
|
2018-11-06 02:39:50 +00:00
|
|
|
const directory = misc.getDataDirectory();
|
2017-10-10 16:47:49 +00:00
|
|
|
shell.showItemInFolder(directory);
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-10-10 16:47:49 +00:00
|
|
|
},
|
2017-05-03 17:48:23 +00:00
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Insomnia ${MNEMONIC_SYM}Help`,
|
|
|
|
accelerator: !isMac() ? 'F1' : null,
|
2017-05-03 17:48:23 +00:00
|
|
|
click: () => {
|
2017-11-08 17:12:36 +00:00
|
|
|
shell.openExternal('https://support.insomnia.rest');
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2017-05-03 17:48:23 +00:00
|
|
|
};
|
|
|
|
|
2018-03-30 16:46:01 +00:00
|
|
|
if (!isMac()) {
|
|
|
|
helpMenu.submenu.unshift({
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}About`,
|
2018-03-30 16:46:01 +00:00
|
|
|
click: () => {
|
|
|
|
dialog.showMessageBox({
|
|
|
|
type: 'info',
|
|
|
|
title: getAppName(),
|
|
|
|
message: getAppLongName(),
|
|
|
|
detail: [
|
|
|
|
'Version ' + getAppVersion(),
|
2018-11-20 01:38:50 +00:00
|
|
|
'Shell ' + process.versions.electron,
|
2018-03-30 16:46:01 +00:00
|
|
|
'Node ' + process.versions.node,
|
|
|
|
'V8 ' + process.versions.v8,
|
|
|
|
'Architecture ' + process.arch,
|
|
|
|
'', // Blank line before libcurl
|
2018-12-12 17:36:11 +00:00
|
|
|
Curl.getVersion(),
|
|
|
|
].join('\n'),
|
2018-03-30 16:46:01 +00:00
|
|
|
});
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2018-03-30 16:46:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-03 17:48:23 +00:00
|
|
|
const developerMenu = {
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Developer`,
|
2017-05-03 17:48:23 +00:00
|
|
|
position: 'before=help',
|
2018-06-25 17:42:50 +00:00
|
|
|
submenu: [
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Reload`,
|
2018-06-25 17:42:50 +00:00
|
|
|
accelerator: 'Shift+F5',
|
2018-12-12 17:36:11 +00:00
|
|
|
click: () => mainWindow.reload(),
|
2018-06-25 17:42:50 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Toggle ${MNEMONIC_SYM}DevTools`,
|
2018-06-25 17:42:50 +00:00
|
|
|
accelerator: 'Alt+CmdOrCtrl+I',
|
2018-12-12 17:36:11 +00:00
|
|
|
click: () => mainWindow.toggleDevTools(),
|
2018-06-25 17:42:50 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Resize to Defaul${MNEMONIC_SYM}t`,
|
2018-06-25 17:42:50 +00:00
|
|
|
click: () =>
|
|
|
|
mainWindow.setBounds({
|
|
|
|
x: 100,
|
|
|
|
y: 100,
|
|
|
|
width: DEFAULT_WIDTH,
|
2018-12-12 17:36:11 +00:00
|
|
|
height: DEFAULT_HEIGHT,
|
|
|
|
}),
|
2018-06-25 17:42:50 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `Take ${MNEMONIC_SYM}Screenshot`,
|
2018-06-25 17:42:50 +00:00
|
|
|
click: function() {
|
|
|
|
mainWindow.capturePage(image => {
|
|
|
|
const buffer = image.toPNG();
|
|
|
|
const dir = app.getPath('desktop');
|
2018-10-17 16:42:33 +00:00
|
|
|
fs.writeFileSync(path.join(dir, `Screenshot-${new Date()}.png`), buffer);
|
2018-06-25 17:42:50 +00:00
|
|
|
});
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2017-05-03 17:48:23 +00:00
|
|
|
};
|
|
|
|
|
2017-11-01 14:54:57 +00:00
|
|
|
const toolsMenu = {
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Tools`,
|
2018-06-25 17:42:50 +00:00
|
|
|
submenu: [
|
|
|
|
{
|
2018-12-11 23:11:54 +00:00
|
|
|
label: `${MNEMONIC_SYM}Reload Plugins`,
|
2018-06-25 17:42:50 +00:00
|
|
|
click: () => {
|
2019-04-18 00:50:03 +00:00
|
|
|
const w = BrowserWindow.getFocusedWindow();
|
|
|
|
if (!w || !w.webContents) {
|
2018-06-25 17:42:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-01 14:54:57 +00:00
|
|
|
|
2019-04-18 00:50:03 +00:00
|
|
|
w.webContents.send('reload-plugins');
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2017-11-01 14:54:57 +00:00
|
|
|
};
|
|
|
|
|
2017-05-03 17:48:23 +00:00
|
|
|
let template = [];
|
|
|
|
|
|
|
|
template.push(applicationMenu);
|
|
|
|
template.push(editMenu);
|
|
|
|
template.push(viewMenu);
|
|
|
|
template.push(windowMenu);
|
2017-11-01 14:54:57 +00:00
|
|
|
template.push(toolsMenu);
|
2017-05-03 17:48:23 +00:00
|
|
|
template.push(helpMenu);
|
|
|
|
|
|
|
|
if (isDevelopment() || process.env.INSOMNIA_FORCE_DEBUG) {
|
|
|
|
template.push(developerMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
|
|
|
|
|
|
|
|
return mainWindow;
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function showUnresponsiveModal() {
|
|
|
|
dialog.showMessageBox(
|
|
|
|
{
|
|
|
|
type: 'info',
|
|
|
|
buttons: ['Cancel', 'Reload'],
|
|
|
|
defaultId: 1,
|
|
|
|
cancelId: 0,
|
|
|
|
title: 'Unresponsive',
|
2018-12-12 17:36:11 +00:00
|
|
|
message: 'Insomnia has become unresponsive. Do you want to reload?',
|
2018-06-25 17:42:50 +00:00
|
|
|
},
|
|
|
|
id => {
|
|
|
|
if (id === 1) {
|
|
|
|
mainWindow.destroy();
|
|
|
|
createWindow();
|
|
|
|
}
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
);
|
2017-05-03 17:48:23 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function saveBounds() {
|
2017-05-03 17:48:23 +00:00
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fullscreen = mainWindow.isFullScreen();
|
|
|
|
|
|
|
|
// Only save the size if we're not in fullscreen
|
|
|
|
if (!fullscreen) {
|
|
|
|
localStorage.setItem('bounds', mainWindow.getBounds());
|
2017-06-29 17:39:09 +00:00
|
|
|
localStorage.setItem('maximize', mainWindow.isMaximized());
|
2017-05-03 17:48:23 +00:00
|
|
|
localStorage.setItem('fullscreen', false);
|
|
|
|
} else {
|
|
|
|
localStorage.setItem('fullscreen', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function getBounds() {
|
2017-05-03 17:48:23 +00:00
|
|
|
let bounds = {};
|
|
|
|
let fullscreen = false;
|
2017-06-29 17:39:09 +00:00
|
|
|
let maximize = false;
|
2017-05-03 17:48:23 +00:00
|
|
|
try {
|
|
|
|
bounds = localStorage.getItem('bounds', {});
|
|
|
|
fullscreen = localStorage.getItem('fullscreen', false);
|
2017-06-29 17:39:09 +00:00
|
|
|
maximize = localStorage.getItem('maximize', false);
|
2017-05-03 17:48:23 +00:00
|
|
|
} catch (e) {
|
|
|
|
// This should never happen, but if it does...!
|
|
|
|
console.error('Failed to parse window bounds', e);
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
return { bounds, fullscreen, maximize };
|
2017-05-03 17:48:23 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function saveZoomFactor(zoomFactor) {
|
2017-05-03 17:48:23 +00:00
|
|
|
localStorage.setItem('zoomFactor', zoomFactor);
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function getZoomFactor() {
|
2017-05-03 17:48:23 +00:00
|
|
|
let zoomFactor = 1;
|
|
|
|
try {
|
|
|
|
zoomFactor = localStorage.getItem('zoomFactor', 1);
|
|
|
|
} catch (e) {
|
|
|
|
// This should never happen, but if it does...!
|
|
|
|
console.error('Failed to parse zoomFactor', e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return zoomFactor;
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function initLocalStorage() {
|
2018-11-06 02:39:50 +00:00
|
|
|
const localStoragePath = path.join(misc.getDataDirectory(), 'localStorage');
|
2017-05-03 17:48:23 +00:00
|
|
|
localStorage = new LocalStorage(localStoragePath);
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function initContextMenus() {
|
2017-05-24 16:25:22 +00:00
|
|
|
require('electron-context-menu')({});
|
|
|
|
}
|