2016-07-18 19:44:46 +00:00
|
|
|
if (require('electron-squirrel-startup')) {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2016-11-10 02:53:06 +00:00
|
|
|
import raven from 'raven';
|
|
|
|
import request from 'request';
|
|
|
|
import path from 'path';
|
|
|
|
import electron from 'electron';
|
2016-11-10 05:47:20 +00:00
|
|
|
import * as packageJSON from './package.json';
|
2016-11-10 21:03:12 +00:00
|
|
|
import LocalStorage from './common/LocalStorage';
|
2016-11-22 19:42:10 +00:00
|
|
|
import installExtension, {REACT_DEVELOPER_TOOLS} from 'electron-devtools-installer';
|
2016-11-10 02:53:06 +00:00
|
|
|
|
2016-09-14 23:25:19 +00:00
|
|
|
// Some useful helpers
|
|
|
|
const IS_DEV = process.env.INSOMNIA_ENV === 'development';
|
|
|
|
const IS_MAC = process.platform === 'darwin';
|
|
|
|
const IS_WINDOWS = process.platform === 'win32';
|
|
|
|
const IS_LINUX = !IS_MAC && !IS_WINDOWS;
|
|
|
|
|
2016-11-29 20:55:31 +00:00
|
|
|
const ravenClient = new raven.Client('https://786e43ae199c4757a9ea4a48a9abd17d@sentry.io/109702', {
|
2016-11-10 02:53:06 +00:00
|
|
|
environment: process.env.INSOMNIA_ENV || 'production',
|
|
|
|
release: require('./package.json').version,
|
|
|
|
logger: 'electron.main'
|
|
|
|
});
|
2016-08-17 22:44:03 +00:00
|
|
|
|
2016-09-13 02:09:35 +00:00
|
|
|
if (!IS_DEV) {
|
|
|
|
ravenClient.patchGlobal();
|
|
|
|
}
|
2016-08-17 22:44:03 +00:00
|
|
|
|
2016-11-10 02:53:06 +00:00
|
|
|
const {app, dialog, shell, ipcMain, autoUpdater, Menu, BrowserWindow, webContents} = electron;
|
|
|
|
const {version: appVersion, productName: appName} = packageJSON;
|
2016-10-27 05:37:40 +00:00
|
|
|
|
2016-07-18 19:44:46 +00:00
|
|
|
const UPDATE_URLS = {
|
2016-09-21 19:03:40 +00:00
|
|
|
// Add `r` param to help cache bust
|
2016-09-22 23:18:46 +00:00
|
|
|
darwin: `https://updates.insomnia.rest/builds/check/mac?v=${appVersion}`,
|
|
|
|
linux: `https://updates.insomnia.rest/builds/check/linux?v=${appVersion}`,
|
|
|
|
win32: `https://downloads.insomnia.rest/win`
|
2016-07-18 19:44:46 +00:00
|
|
|
};
|
2016-07-14 01:12:42 +00:00
|
|
|
|
2016-08-20 20:41:44 +00:00
|
|
|
const DOWNLOAD_URL = 'http://download.insomnia.rest';
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
const localStoragePath = path.join(app.getPath('userData'), 'localStorage');
|
|
|
|
const localStorage = new LocalStorage(localStoragePath);
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
let mainWindow = null;
|
2016-08-23 20:54:11 +00:00
|
|
|
let hasPromptedForUpdates = false;
|
2016-03-22 18:20:05 +00:00
|
|
|
|
2016-05-01 19:56:30 +00:00
|
|
|
// Enable this for CSS grid layout :)
|
2016-07-16 07:22:08 +00:00
|
|
|
app.commandLine.appendSwitch('enable-experimental-web-platform-features');
|
2016-05-01 19:56:30 +00:00
|
|
|
|
2016-09-13 17:29:09 +00:00
|
|
|
process.on('uncaughtException', e => {
|
|
|
|
if (IS_DEV) {
|
|
|
|
console.error(e);
|
|
|
|
} else {
|
|
|
|
ravenClient.captureError(e, {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-17 22:44:03 +00:00
|
|
|
autoUpdater.on('error', e => {
|
2016-09-13 02:09:35 +00:00
|
|
|
if (IS_DEV) {
|
|
|
|
console.error(e);
|
2016-10-27 03:41:30 +00:00
|
|
|
} else {
|
|
|
|
// Don't report autoUpdater error. They are way too noisy
|
2016-09-13 02:09:35 +00:00
|
|
|
}
|
2016-08-17 22:44:03 +00:00
|
|
|
});
|
2016-07-14 01:12:42 +00:00
|
|
|
|
|
|
|
autoUpdater.on('update-not-available', () => {
|
|
|
|
console.log('-- Update Not Available --')
|
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('update-available', () => {
|
|
|
|
console.log('-- Update Available --');
|
|
|
|
});
|
|
|
|
|
2016-07-21 21:34:38 +00:00
|
|
|
autoUpdater.on('update-downloaded', (e, releaseNotes, releaseName, releaseDate, updateUrl) => {
|
|
|
|
console.log(`-- Update Downloaded ${releaseName} --`);
|
2016-10-11 19:47:38 +00:00
|
|
|
showUpdateNotification();
|
2016-07-14 01:12:42 +00:00
|
|
|
});
|
|
|
|
|
2016-08-17 22:44:03 +00:00
|
|
|
function checkForUpdates () {
|
2016-10-11 19:47:38 +00:00
|
|
|
if (hasPromptedForUpdates) {
|
|
|
|
// We've already prompted for updates. Don't bug the user anymore
|
2016-09-13 02:09:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-11 19:47:38 +00:00
|
|
|
if (IS_DEV) {
|
2016-10-21 17:20:36 +00:00
|
|
|
console.log('-- Skipping update check in Development --');
|
2016-08-23 20:54:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-20 20:41:44 +00:00
|
|
|
if (IS_LINUX) {
|
|
|
|
try {
|
|
|
|
request.get(UPDATE_URLS.linux, null, (err, response) => {
|
|
|
|
if (err) {
|
|
|
|
ravenClient.captureError(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.statusCode === 200) {
|
|
|
|
showDownloadModal(response.body);
|
|
|
|
} else {
|
|
|
|
// No update available (should be STATUS=204)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
ravenClient.captureException(e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
autoUpdater.setFeedURL(UPDATE_URLS[process.platform]);
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
} catch (e) {
|
|
|
|
// This will fail in development
|
|
|
|
}
|
2016-08-17 22:44:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-13 02:09:35 +00:00
|
|
|
function showUnresponsiveModal () {
|
|
|
|
dialog.showMessageBox({
|
|
|
|
type: 'info',
|
2016-10-11 21:06:25 +00:00
|
|
|
buttons: ['Cancel', 'Reload'],
|
2016-09-13 02:09:35 +00:00
|
|
|
defaultId: 1,
|
|
|
|
cancelId: 0,
|
|
|
|
title: 'Unresponsive',
|
|
|
|
message: 'Insomnia has become unresponsive. Do you want to reload?'
|
|
|
|
}, id => {
|
|
|
|
if (id === 1) {
|
|
|
|
mainWindow.destroy();
|
|
|
|
createWindow();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-11 19:47:38 +00:00
|
|
|
function showUpdateNotification () {
|
|
|
|
if (hasPromptedForUpdates) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-23 20:54:11 +00:00
|
|
|
|
2016-10-11 19:47:38 +00:00
|
|
|
const window = BrowserWindow.getFocusedWindow();
|
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-11 21:06:25 +00:00
|
|
|
window.webContents.send('update-available');
|
2016-10-11 19:47:38 +00:00
|
|
|
hasPromptedForUpdates = true;
|
2016-07-22 22:27:04 +00:00
|
|
|
}
|
2016-07-21 21:34:38 +00:00
|
|
|
|
2016-11-23 19:49:10 +00:00
|
|
|
function trackEvent (...args) {
|
|
|
|
const window = BrowserWindow.getFocusedWindow();
|
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.webContents.send('analytics-track-event', args);
|
|
|
|
}
|
|
|
|
|
2016-08-20 20:41:44 +00:00
|
|
|
function showDownloadModal (version) {
|
2016-08-23 20:54:11 +00:00
|
|
|
hasPromptedForUpdates = true;
|
|
|
|
|
2016-08-20 20:41:44 +00:00
|
|
|
dialog.showMessageBox({
|
|
|
|
type: 'info',
|
2016-10-11 19:47:38 +00:00
|
|
|
buttons: ['Download', 'Later'],
|
2016-08-20 20:41:44 +00:00
|
|
|
defaultId: 0,
|
|
|
|
cancelId: 1,
|
2016-08-22 21:58:24 +00:00
|
|
|
title: 'Insomnia Update Available',
|
|
|
|
message: `Exciting news!\n\nVersion ${version} of Insomnia is now available.\n\n\n~Gregory`
|
2016-08-20 20:41:44 +00:00
|
|
|
}, id => {
|
|
|
|
if (id === 0) {
|
|
|
|
console.log('-- Installing Update --');
|
|
|
|
shell.openExternal(DOWNLOAD_URL);
|
|
|
|
} else {
|
|
|
|
console.log('-- Cancel Update --');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-21 21:34:38 +00:00
|
|
|
ipcMain.on('check-for-updates', () => {
|
|
|
|
console.log('-- Checking for Updates --');
|
2016-08-17 22:44:03 +00:00
|
|
|
checkForUpdates();
|
2016-07-21 21:34:38 +00:00
|
|
|
});
|
|
|
|
|
2016-08-17 22:44:03 +00:00
|
|
|
function saveBounds () {
|
2016-09-14 23:25:19 +00:00
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-09 17:57:26 +00:00
|
|
|
const fullscreen = mainWindow.isFullScreen();
|
2016-09-14 23:25:19 +00:00
|
|
|
|
|
|
|
// Only save the size if we're not in fullscreen
|
2016-09-09 17:57:26 +00:00
|
|
|
if (!fullscreen) {
|
2016-11-10 05:47:20 +00:00
|
|
|
localStorage.setItem('bounds', mainWindow.getBounds());
|
|
|
|
localStorage.setItem('fullscreen', false);
|
2016-09-14 23:25:19 +00:00
|
|
|
} else {
|
2016-11-10 05:47:20 +00:00
|
|
|
localStorage.setItem('fullscreen', true);
|
2016-09-09 17:57:26 +00:00
|
|
|
}
|
2016-07-29 17:18:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 22:44:03 +00:00
|
|
|
function getBounds () {
|
2016-07-29 17:18:04 +00:00
|
|
|
let bounds = {};
|
2016-09-09 17:57:26 +00:00
|
|
|
let fullscreen = false;
|
2016-07-29 17:18:04 +00:00
|
|
|
try {
|
2016-11-10 05:47:20 +00:00
|
|
|
bounds = localStorage.getItem('bounds', {});
|
|
|
|
fullscreen = localStorage.getItem('fullscreen', false);
|
2016-07-29 17:18:04 +00:00
|
|
|
} catch (e) {
|
|
|
|
// This should never happen, but if it does...!
|
|
|
|
console.error('Failed to parse window bounds', e);
|
|
|
|
}
|
|
|
|
|
2016-09-09 17:57:26 +00:00
|
|
|
return {bounds, fullscreen};
|
2016-07-29 17:18:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 22:44:03 +00:00
|
|
|
function saveZoomFactor (zoomFactor) {
|
2016-11-10 05:47:20 +00:00
|
|
|
localStorage.setItem('zoomFactor', zoomFactor);
|
2016-07-29 17:18:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 22:44:03 +00:00
|
|
|
function getZoomFactor () {
|
2016-07-29 17:18:04 +00:00
|
|
|
let zoomFactor = 1;
|
|
|
|
try {
|
2016-11-10 05:47:20 +00:00
|
|
|
zoomFactor = localStorage.getItem('zoomFactor', 1);
|
2016-07-29 17:18:04 +00:00
|
|
|
} catch (e) {
|
|
|
|
// This should never happen, but if it does...!
|
|
|
|
console.error('Failed to parse zoomFactor', e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return zoomFactor;
|
|
|
|
}
|
|
|
|
|
2016-07-09 04:49:09 +00:00
|
|
|
// Quit when all windows are closed (except on Mac).
|
2016-04-20 02:14:53 +00:00
|
|
|
app.on('window-all-closed', () => {
|
2016-03-23 18:34:39 +00:00
|
|
|
if (!IS_MAC) {
|
2016-11-18 01:25:45 +00:00
|
|
|
app.quit();
|
2016-11-18 01:23:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-09 17:57:26 +00:00
|
|
|
// Mac-only, when the user clicks the doc icon
|
|
|
|
app.on('activate', (e, hasVisibleWindows) => {
|
2016-09-14 23:25:19 +00:00
|
|
|
// Create a new window when clicking the doc icon if there isn't one open
|
2016-09-09 17:57:26 +00:00
|
|
|
if (!hasVisibleWindows) {
|
2016-10-27 01:29:25 +00:00
|
|
|
try {
|
|
|
|
createWindow()
|
|
|
|
} catch (e) {
|
|
|
|
// This might happen if 'ready' hasn't fired yet. So we're just going
|
|
|
|
// to silence these errors.
|
|
|
|
console.log('-- App not ready to "activate" yet --');
|
|
|
|
}
|
2016-09-09 17:57:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// When the app is first launched
|
2016-04-20 02:14:53 +00:00
|
|
|
app.on('ready', () => {
|
2016-09-09 17:57:26 +00:00
|
|
|
createWindow();
|
2016-10-11 21:06:25 +00:00
|
|
|
checkForUpdates();
|
2016-09-09 17:57:26 +00:00
|
|
|
});
|
2016-08-17 22:44:03 +00:00
|
|
|
|
2016-09-09 17:57:26 +00:00
|
|
|
function createWindow () {
|
2016-07-29 17:18:04 +00:00
|
|
|
const zoomFactor = getZoomFactor();
|
2016-09-09 17:57:26 +00:00
|
|
|
const {bounds, fullscreen} = getBounds();
|
2016-10-11 19:47:38 +00:00
|
|
|
const {x, y, width, height} = bounds;
|
|
|
|
|
|
|
|
// 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);
|
2016-03-22 18:20:05 +00:00
|
|
|
|
2016-07-29 17:18:04 +00:00
|
|
|
mainWindow = new BrowserWindow({
|
2016-10-11 19:47:38 +00:00
|
|
|
// Make sure we don't initialize the window outside the bounds
|
|
|
|
x: finalX,
|
|
|
|
y: finalY,
|
2016-09-09 17:57:26 +00:00
|
|
|
fullscreen: fullscreen,
|
|
|
|
fullscreenable: true,
|
2016-09-13 02:09:35 +00:00
|
|
|
title: appName,
|
2016-07-29 17:18:04 +00:00
|
|
|
width: width || 1200,
|
|
|
|
height: height || 600,
|
|
|
|
minHeight: 500,
|
|
|
|
minWidth: 500,
|
|
|
|
acceptFirstMouse: true,
|
|
|
|
webPreferences: {
|
|
|
|
zoomFactor: zoomFactor
|
2016-07-27 20:07:50 +00:00
|
|
|
}
|
2016-07-29 17:18:04 +00:00
|
|
|
});
|
2016-07-25 22:27:29 +00:00
|
|
|
|
2016-11-23 19:49:10 +00:00
|
|
|
let _resizeTimeout = null;
|
|
|
|
mainWindow.on('resize', e => {
|
|
|
|
saveBounds();
|
|
|
|
|
|
|
|
clearTimeout(_resizeTimeout);
|
|
|
|
_resizeTimeout = setTimeout(() => {
|
|
|
|
trackEvent('Window', 'Resize');
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
mainWindow.on('move', e => {
|
|
|
|
saveBounds();
|
|
|
|
trackEvent('Window', 'Move');
|
|
|
|
});
|
|
|
|
mainWindow.on('unresponsive', e => {
|
|
|
|
showUnresponsiveModal();
|
|
|
|
trackEvent('Window', 'Unresponsive');
|
|
|
|
});
|
2016-04-20 16:15:19 +00:00
|
|
|
|
2016-07-29 17:18:04 +00:00
|
|
|
// and load the app.html of the app.
|
2016-09-17 05:46:44 +00:00
|
|
|
mainWindow.loadURL(`file://${__dirname}/main.html`);
|
2016-07-27 20:07:50 +00:00
|
|
|
|
2016-07-29 17:18:04 +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;
|
2016-11-23 19:49:10 +00:00
|
|
|
trackEvent('Window', 'Close');
|
2016-07-29 17:18:04 +00:00
|
|
|
});
|
2016-07-27 20:07:50 +00:00
|
|
|
|
2016-08-25 19:44:51 +00:00
|
|
|
require('electron-context-menu')({});
|
|
|
|
|
2016-08-22 20:08:22 +00:00
|
|
|
var template = [
|
|
|
|
{
|
2016-08-17 20:58:44 +00:00
|
|
|
label: "Application",
|
2016-08-22 19:05:17 +00:00
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: `About ${appName}`,
|
2016-08-22 20:05:42 +00:00
|
|
|
role: 'about',
|
|
|
|
visible: IS_MAC
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator",
|
|
|
|
visible: IS_MAC
|
2016-08-22 19:05:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Preferences",
|
|
|
|
accelerator: "CmdOrCtrl+,",
|
2016-08-22 20:05:42 +00:00
|
|
|
click: function (menuItem, window, e) {
|
2016-09-14 23:25:19 +00:00
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return
|
2016-08-23 20:54:11 +00:00
|
|
|
}
|
2016-09-14 23:25:19 +00:00
|
|
|
|
|
|
|
window.webContents.send('toggle-preferences');
|
2016-11-23 19:49:10 +00:00
|
|
|
trackEvent('App Menu', 'Preferences');
|
2016-08-22 19:05:17 +00:00
|
|
|
}
|
|
|
|
},
|
2016-11-23 19:59:26 +00:00
|
|
|
{
|
|
|
|
label: "Changelog",
|
|
|
|
click: function (menuItem, window, e) {
|
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
window.webContents.send('toggle-changelog');
|
|
|
|
trackEvent('App Menu', 'Changelog');
|
|
|
|
}
|
|
|
|
},
|
2016-08-22 19:05:17 +00:00
|
|
|
{
|
2016-08-23 20:54:11 +00:00
|
|
|
type: "separator",
|
|
|
|
visible: IS_MAC
|
2016-08-22 19:05:17 +00:00
|
|
|
},
|
|
|
|
{
|
2016-08-23 20:54:11 +00:00
|
|
|
role: "hide",
|
|
|
|
visible: IS_MAC
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "hideothers",
|
|
|
|
visible: IS_MAC
|
2016-08-22 19:05:17 +00:00
|
|
|
},
|
|
|
|
{type: "separator"},
|
|
|
|
{
|
|
|
|
label: "Quit",
|
|
|
|
accelerator: "Command+Q",
|
|
|
|
click: function () {
|
|
|
|
app.quit();
|
|
|
|
}
|
2016-08-17 20:58:44 +00:00
|
|
|
}
|
2016-08-22 19:05:17 +00:00
|
|
|
]
|
2016-08-22 20:08:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Edit",
|
|
|
|
submenu: [{
|
|
|
|
label: "Undo",
|
|
|
|
accelerator: "CmdOrCtrl+Z",
|
|
|
|
selector: "undo:"
|
|
|
|
}, {
|
|
|
|
label: "Redo",
|
|
|
|
accelerator: "Shift+CmdOrCtrl+Z",
|
|
|
|
selector: "redo:"
|
|
|
|
}, {
|
|
|
|
type: "separator"
|
|
|
|
}, {
|
|
|
|
label: "Cut",
|
|
|
|
accelerator: "CmdOrCtrl+X",
|
|
|
|
selector: "cut:"
|
|
|
|
}, {
|
|
|
|
label: "Copy",
|
|
|
|
accelerator: "CmdOrCtrl+C",
|
|
|
|
selector: "copy:"
|
|
|
|
}, {
|
|
|
|
label: "Paste",
|
|
|
|
accelerator: "CmdOrCtrl+V",
|
|
|
|
selector: "paste:"
|
|
|
|
}, {
|
|
|
|
label: "Select All",
|
|
|
|
accelerator: "CmdOrCtrl+A",
|
|
|
|
selector: "selectAll:"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "View",
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
role: 'togglefullscreen'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Actual Size",
|
|
|
|
accelerator: "CmdOrCtrl+0",
|
|
|
|
click: () => {
|
|
|
|
const window = BrowserWindow.getFocusedWindow();
|
2016-09-14 23:25:19 +00:00
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return;
|
2016-09-13 02:09:35 +00:00
|
|
|
}
|
2016-09-14 23:25:19 +00:00
|
|
|
|
|
|
|
const zoomFactor = 1;
|
|
|
|
window.webContents.setZoomFactor(zoomFactor);
|
|
|
|
saveZoomFactor(zoomFactor);
|
2016-11-23 19:49:10 +00:00
|
|
|
trackEvent('App Menu', 'Zoom Reset');
|
2016-08-22 20:08:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Zoom In",
|
|
|
|
accelerator: IS_MAC ? "CmdOrCtrl+Plus" : "CmdOrCtrl+=",
|
|
|
|
click: () => {
|
|
|
|
const window = BrowserWindow.getFocusedWindow();
|
2016-09-14 23:25:19 +00:00
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return;
|
2016-09-13 02:09:35 +00:00
|
|
|
}
|
2016-09-14 23:25:19 +00:00
|
|
|
|
2016-10-26 22:13:16 +00:00
|
|
|
const zoomFactor = Math.min(1.8, getZoomFactor() + 0.05);
|
2016-09-14 23:25:19 +00:00
|
|
|
window.webContents.setZoomFactor(zoomFactor);
|
|
|
|
|
|
|
|
saveZoomFactor(zoomFactor);
|
2016-11-23 19:49:10 +00:00
|
|
|
trackEvent('App Menu', 'Zoom In');
|
2016-08-22 20:08:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Zoom Out",
|
|
|
|
accelerator: "CmdOrCtrl+-",
|
|
|
|
click: () => {
|
|
|
|
const window = BrowserWindow.getFocusedWindow();
|
2016-09-14 23:25:19 +00:00
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return;
|
2016-09-13 02:09:35 +00:00
|
|
|
}
|
2016-09-14 23:25:19 +00:00
|
|
|
|
2016-10-26 22:13:16 +00:00
|
|
|
const zoomFactor = Math.max(0.5, getZoomFactor() - 0.05);
|
2016-09-14 23:25:19 +00:00
|
|
|
window.webContents.setZoomFactor(zoomFactor);
|
|
|
|
saveZoomFactor(zoomFactor);
|
2016-11-23 19:49:10 +00:00
|
|
|
trackEvent('App Menu', 'Zoom Out');
|
2016-08-22 20:08:22 +00:00
|
|
|
}
|
2016-09-12 20:04:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Toggle Sidebar",
|
|
|
|
accelerator: "CmdOrCtrl+\\",
|
|
|
|
click: () => {
|
|
|
|
const window = BrowserWindow.getFocusedWindow();
|
2016-09-14 23:25:19 +00:00
|
|
|
if (!window || !window.webContents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.webContents.send('toggle-sidebar');
|
2016-11-23 19:49:10 +00:00
|
|
|
trackEvent('App Menu', 'Toggle Sidebar');
|
2016-09-12 20:04:15 +00:00
|
|
|
}
|
2016-08-22 19:05:17 +00:00
|
|
|
}
|
2016-08-22 20:08:22 +00:00
|
|
|
]
|
|
|
|
}, {
|
|
|
|
label: "Window",
|
|
|
|
role: "window",
|
|
|
|
submenu: [
|
2016-11-29 20:55:31 +00:00
|
|
|
{role: 'minimize'},
|
|
|
|
...(IS_MAC ? [{role: 'close'}] : [])
|
2016-08-22 20:08:22 +00:00
|
|
|
]
|
|
|
|
}, {
|
|
|
|
label: "Help",
|
|
|
|
role: "help",
|
|
|
|
id: "help",
|
|
|
|
submenu: [
|
|
|
|
{
|
2016-09-13 17:39:11 +00:00
|
|
|
label: "Contact Support",
|
2016-08-22 20:08:22 +00:00
|
|
|
click: () => {
|
2016-11-23 19:49:10 +00:00
|
|
|
trackEvent('App Menu', 'Contact');
|
2016-10-11 19:47:38 +00:00
|
|
|
shell.openExternal('mailto:support@insomnia.rest');
|
2016-08-22 20:08:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2016-09-13 17:39:55 +00:00
|
|
|
label: "Insomnia Help",
|
2016-08-22 20:08:22 +00:00
|
|
|
accelerator: "CmdOrCtrl+?",
|
2016-11-23 19:49:10 +00:00
|
|
|
click: (e) => {
|
|
|
|
trackEvent('App Menu', 'Help');
|
2016-10-11 19:47:38 +00:00
|
|
|
shell.openExternal('http://docs.insomnia.rest');
|
2016-08-22 20:08:22 +00:00
|
|
|
}
|
2016-08-22 19:05:17 +00:00
|
|
|
}
|
2016-08-22 20:08:22 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
2016-04-20 17:38:27 +00:00
|
|
|
|
2016-07-29 17:18:04 +00:00
|
|
|
if (IS_DEV) {
|
2016-11-22 19:42:10 +00:00
|
|
|
installExtension(REACT_DEVELOPER_TOOLS)
|
|
|
|
.then((name) => console.log(`Added Extension: ${name}`))
|
|
|
|
.catch((err) => console.log('An error occurred: ', err));
|
|
|
|
|
2016-07-29 17:18:04 +00:00
|
|
|
template.push({
|
|
|
|
label: 'Developer',
|
|
|
|
position: 'before=help',
|
|
|
|
submenu: [{
|
|
|
|
label: 'Reload',
|
|
|
|
accelerator: 'Command+R',
|
2016-08-17 22:44:03 +00:00
|
|
|
click: function () {
|
2016-07-29 17:18:04 +00:00
|
|
|
mainWindow.reload();
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
label: 'Toggle DevTools',
|
|
|
|
accelerator: 'Alt+Command+I',
|
2016-08-17 22:44:03 +00:00
|
|
|
click: function () {
|
2016-07-29 17:18:04 +00:00
|
|
|
mainWindow.toggleDevTools();
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
|
2016-09-09 17:57:26 +00:00
|
|
|
}
|