diff --git a/app/app.js b/app/app.js index 9110ae1b6..f432df0c9 100644 --- a/app/app.js +++ b/app/app.js @@ -18,13 +18,14 @@ ravenClient.patchGlobal(); const electron = require('electron'); const request = require('request'); const path = require('path'); -const appVersion = require('./app.json').version; +const {version: appVersion, productName: appName} = require('./app.json'); const {LocalStorage} = require('node-localstorage'); const { app, dialog, shell, ipcMain, + ipcRenderer, autoUpdater, Menu, BrowserWindow, @@ -238,19 +239,36 @@ app.on('ready', () => { if (IS_MAC) { template.push({ label: "Application", - role: "window", - submenu: [{ - label: "About Application", - selector: "orderFrontStandardAboutPanel:" - }, { - type: "separator" - }, { - label: "Quit", - accelerator: "Command+Q", - click: function () { - app.quit(); + submenu: [ + { + label: `About ${appName}`, + selector: "orderFrontStandardAboutPanel:" + }, + {type: "separator"}, + { + label: "Preferences", + accelerator: "CmdOrCtrl+,", + click: function () { + const window = BrowserWindow.getFocusedWindow(); + window.webContents.send('show-preferences'); + } + }, + {type: "separator"}, + { + role: "hide" + }, + { + role: "hideothers" + }, + {type: "separator"}, + { + label: "Quit", + accelerator: "Command+Q", + click: function () { + app.quit(); + } } - }] + ] }) } @@ -285,61 +303,77 @@ app.on('ready', () => { }] }, { label: "View", + submenu: [ + { + role: 'togglefullscreen' + }, + { + label: "Actual Size", + accelerator: "CmdOrCtrl+0", + click: () => { + const window = BrowserWindow.getFocusedWindow(); + const zoomFactor = 1; + window.webContents.setZoomFactor(zoomFactor); + saveZoomFactor(zoomFactor); + } + }, + { + label: "Zoom In", + accelerator: IS_MAC ? "CmdOrCtrl+Plus" : "CmdOrCtrl+=", + click: () => { + let zoomFactor = getZoomFactor(); + zoomFactor = Math.min(1.8, zoomFactor + 0.1); + + const window = BrowserWindow.getFocusedWindow(); + window.webContents.setZoomFactor(zoomFactor); + + saveZoomFactor(zoomFactor); + } + }, + { + label: "Zoom Out", + accelerator: "CmdOrCtrl+-", + click: () => { + let zoomFactor = getZoomFactor(); + zoomFactor = Math.max(0.5, zoomFactor - 0.1); + + const window = BrowserWindow.getFocusedWindow(); + window.webContents.setZoomFactor(zoomFactor); + + saveZoomFactor(zoomFactor); + } + } + ] + }, { + label: "Window", role: "window", - submenu: [{ - role: 'minimize' - }, { - role: 'close' - }, { - label: "Actual Size", - accelerator: "CmdOrCtrl+0", - click: () => { - const window = BrowserWindow.getFocusedWindow(); - const zoomFactor = 1; - window.webContents.setZoomFactor(zoomFactor); - saveZoomFactor(zoomFactor); + submenu: [ + { + role: 'minimize' + }, + { + role: 'close' } - }, { - label: "Zoom In", - accelerator: IS_MAC ? "CmdOrCtrl+Plus" : "CmdOrCtrl+=", - click: () => { - let zoomFactor = getZoomFactor(); - zoomFactor = Math.min(1.8, zoomFactor + 0.1); - - const window = BrowserWindow.getFocusedWindow(); - window.webContents.setZoomFactor(zoomFactor); - - saveZoomFactor(zoomFactor); - } - }, { - label: "Zoom Out", - accelerator: "CmdOrCtrl+-", - click: () => { - let zoomFactor = getZoomFactor(); - zoomFactor = Math.max(0.5, zoomFactor - 0.1); - - const window = BrowserWindow.getFocusedWindow(); - window.webContents.setZoomFactor(zoomFactor); - - saveZoomFactor(zoomFactor); - } - }] + ] }, { label: "Help", role: "help", id: "help", - submenu: [{ - label: "Report an Issue...", - click: () => { - electron.shell.openExternal('mailto:support@insomnia.rest'); + submenu: [ + { + label: "Report an Issue...", + click: () => { + electron.shell.openExternal('mailto:support@insomnia.rest'); + } + }, + { + label: "Insomnia Help", + accelerator: "CmdOrCtrl+?", + click: () => { + electron.shell.openExternal('http://insomnia.rest'); + } } - }, { - label: "Insomnia Help", - accelerator: "CmdOrCtrl+?", - click: () => { - electron.shell.openExternal('http://insomnia.rest'); - } - }] + ] }]); if (IS_DEV) { diff --git a/app/app.json b/app/app.json index 80946b67f..7158efd87 100644 --- a/app/app.json +++ b/app/app.json @@ -14,8 +14,10 @@ "httpsnippet": "git@github.com:gschier/httpsnippet.git#39d2fb0449f33711e5cc71a4d42b0e5b808426b4", "nedb": "^1.8.0", "node-localstorage": "^1.3.0", + "nunjucks": "^2.4.2", "raven": "^0.12.1", "request": "^2.71.0", - "tough-cookie": "^2.3.1" + "tough-cookie": "^2.3.1", + "traverse": "^0.6.6" } } diff --git a/app/containers/App.js b/app/containers/App.js index 880202570..1efe226b0 100644 --- a/app/containers/App.js +++ b/app/containers/App.js @@ -431,6 +431,10 @@ class App extends Component { setInterval(() => { ipcRenderer.send('check-for-updates'); }, CHECK_FOR_UPDATES_INTERVAL); + + ipcRenderer.on('show-preferences', () => { + getModal(SettingsModal).show(); + }) } componentWillUnmount () { diff --git a/app/css/components/editor.scss b/app/css/components/editor.scss index d5e8ef6f7..f9c3f6c91 100644 --- a/app/css/components/editor.scss +++ b/app/css/components/editor.scss @@ -74,6 +74,7 @@ border-radius: 0; font-size: $font-size-md; padding: $padding-xs $padding-sm; + z-index: 99999; .CodeMirror-lint-message-error { background-image: none; diff --git a/app/database/index.js b/app/database/index.js index 733b5b388..6d25500b0 100644 --- a/app/database/index.js +++ b/app/database/index.js @@ -50,7 +50,7 @@ const MODEL_DEFAULTS = { metaFilter: '' }), [TYPE_ENVIRONMENT]: () => ({ - name: 'Base Environment', + name: 'New Environment', data: {}, }), [TYPE_COOKIE_JAR]: () => ({ @@ -564,7 +564,7 @@ export function environmentGetOrCreateForWorkspace (workspace) { const parentId = workspace._id; return find(TYPE_ENVIRONMENT, {parentId}).then(environments => { if (environments.length === 0) { - return environmentCreate({parentId}) + return environmentCreate({parentId, name: 'Base Environment'}) } else { return new Promise(resolve => resolve(environments[0])); } diff --git a/app/lib/render.js b/app/lib/render.js index fc6180ecb..367eeda10 100644 --- a/app/lib/render.js +++ b/app/lib/render.js @@ -1,4 +1,5 @@ import nunjucks from 'nunjucks'; +import traverse from 'traverse'; import * as db from '../database' import {TYPE_WORKSPACE} from '../database/index'; @@ -30,30 +31,20 @@ export function getRenderedRequest (request) { Object.assign(renderContext, environment); } - let template; - + // Make a copy so no one gets mad :) + const renderedRequest = Object.assign({}, request); try { - template = JSON.stringify(request); - } catch (e) { - // Failed to parse Request as JSON - throw new Error(`Bad Request: "${e.message}"`); - } - - let renderedJSON; - try { - renderedJSON = render(template, renderContext); + traverse(renderedRequest).forEach(function (x) { + if (typeof x === 'string') { + this.update(render(x, renderContext)); + } + }); } catch (e) { // Failed to render Request throw new Error(`Render Failed: "${e.message}"`); } - let renderedRequest = null; - try { - renderedRequest = JSON.parse(renderedJSON); - } catch (e) { - // Failed to parse rendered request - throw new Error(`Parse Failed: "${e.message}"`); - } + console.log('RENDERED', renderedRequest); // Default the proto if it doesn't exist if (renderedRequest.url.indexOf('://') === -1) { diff --git a/app/redux/modules/global.js b/app/redux/modules/global.js index 01acd1379..397142733 100644 --- a/app/redux/modules/global.js +++ b/app/redux/modules/global.js @@ -3,6 +3,7 @@ import fs from 'fs'; import {importJSON, exportJSON} from '../../lib/export/database'; import * as db from '../../database/index'; +import {trackEvent} from '../../lib/analytics'; const LOAD_START = 'global/load-start'; const LOAD_STOP = 'global/load-stop'; @@ -52,7 +53,8 @@ export function importFile (workspace) { buttonLabel: 'Import', properties: ['openFile'], filters: [{ - name: 'Insomnia Import', extensions: ['json'] + // Allow empty extension and JSON + name: 'Insomnia Import', extensions: ['', 'json'] }] }; @@ -60,6 +62,7 @@ export function importFile (workspace) { if (!paths) { // It was cancelled, so let's bail out dispatch(loadStop()); + trackEvent('Import Cancel'); return; } @@ -68,8 +71,15 @@ export function importFile (workspace) { fs.readFile(path, 'utf8', (err, data) => { // Unset the current active request first because we might be updating it db.workspaceUpdate(workspace, {metaActiveRequestId: null}).then(() => { - err || importJSON(workspace, data); dispatch(loadStop()); + if (err) { + trackEvent('Import Fail'); + console.warn('Import Failed', err); + return; + } + + importJSON(workspace, data); + trackEvent('Import'); }); }) }) @@ -92,12 +102,19 @@ export function exportFile (parentDoc = null) { electron.remote.dialog.showSaveDialog(options, filename => { if (!filename) { + trackEvent('Export Cancel'); // It was cancelled, so let's bail out dispatch(loadStop()); return; } fs.writeFile(filename, json, {}, err => { + if (err) { + console.warn('Export failed', err); + trackEvent('Export Fail'); + return; + } + trackEvent('Export'); dispatch(loadStop()); }); }); diff --git a/package.json b/package.json index 9fd06a062..00dd359d9 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "mousetrap": "^1.6.0", "nedb": "^1.8.0", "node-localstorage": "^1.3.0", - "nunjucks": "^1.3.4", + "nunjucks": "^2.4.2", "raven": "^0.12.1", "react": "^15.2.0", "react-dnd": "^2.1.4", @@ -64,7 +64,8 @@ "redux-logger": "^2.6.1", "redux-thunk": "^2.0.1", "request": "^2.74.0", - "tough-cookie": "^2.3.1" + "tough-cookie": "^2.3.1", + "traverse": "^0.6.6" }, "devDependencies": { "babel-core": "^6.7.2",