mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Update Nunjucks, fix env error dialog, add import/export tracking
This commit is contained in:
parent
2af23f2870
commit
9bf3b9d710
156
app/app.js
156
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) {
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
@ -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;
|
||||
|
@ -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]));
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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());
|
||||
});
|
||||
});
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user