mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Simplified app launch logic (#626)
This commit is contained in:
parent
8650d99665
commit
5603680cef
@ -95,9 +95,10 @@ export function createWindow () {
|
||||
trackEvent('Window', 'Unresponsive');
|
||||
});
|
||||
|
||||
// and load the app.html of the app.
|
||||
// TODO: Use path.join for this
|
||||
mainWindow.loadURL(`file://${__dirname}/renderer.html`);
|
||||
// Load the html of the app.
|
||||
const appUrl = process.env.APP_RENDER_URL || `file://${__dirname}/renderer.html`;
|
||||
console.log(`[main] Loading ${process.env.APP_RENDER_URL}`);
|
||||
mainWindow.loadURL(appUrl);
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', () => {
|
||||
|
@ -3,65 +3,11 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Insomnia</title>
|
||||
<meta http-equiv="Content-Security-Policy"
|
||||
content="default-src * insomnia://*; img-src blob: data: * insomnia://*; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src blob: data: mediastream: * insomnia://*;">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<div id="dropdowns-container"></div>
|
||||
<div id="tooltips-container"></div>
|
||||
<script>
|
||||
// HOT RELOADING IN DEV
|
||||
(function () {
|
||||
const script = document.createElement('script');
|
||||
script.async = true; // Make Chrome not warn about cross-origin script blocking
|
||||
script.src = process.env.HOT
|
||||
? 'http://localhost:3333/bundle.js'
|
||||
: 'bundle.js';
|
||||
|
||||
document.write(script.outerHTML);
|
||||
|
||||
if (process.env.HOT) {
|
||||
const msg = 'Waiting for build server. The initial build can ' +
|
||||
'take over a minute on slower hardware.';
|
||||
document.querySelector('#root').innerHTML = `<p>${msg}</p>`;
|
||||
}
|
||||
}());
|
||||
</script>
|
||||
<script>
|
||||
// UPDATE HANDLERS
|
||||
(function () {
|
||||
function showUpdateNotification () {
|
||||
console.log('[app] Update Available');
|
||||
|
||||
// eslint-disable-next-line no-new
|
||||
new window.Notification('Insomnia Update Ready', {
|
||||
body: 'Relaunch the app for it to take effect',
|
||||
silent: true,
|
||||
sticky: true
|
||||
});
|
||||
}
|
||||
|
||||
const {ipcRenderer} = require('electron');
|
||||
ipcRenderer.on('update-available', () => {
|
||||
// Give it a few seconds before showing this. Sometimes, when
|
||||
// you relaunch too soon it doesn't work the first time.
|
||||
setTimeout(showUpdateNotification, 1000 * 10);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<script>
|
||||
(function () {
|
||||
const {productName, version} = require('./package.json');
|
||||
if (process.env.INSOMNIA_ENV === 'development') {
|
||||
document.title = `${productName}`;
|
||||
} else {
|
||||
document.title = `${productName} v${version}`;
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// SOME HELPERS
|
||||
document.body.setAttribute('data-platform', process.platform);
|
||||
</script>
|
||||
<script src="bundle.js" type="application/javascript"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -14,6 +14,9 @@ import './css/index.less';
|
||||
import {isDevelopment} from '../common/constants';
|
||||
import {trackEvent, trackPageView} from '../common/analytics';
|
||||
|
||||
// Handy little helper
|
||||
document.body.setAttribute('data-platform', process.platform);
|
||||
|
||||
(async function () {
|
||||
await db.initClient();
|
||||
|
||||
@ -35,6 +38,9 @@ import {trackEvent, trackPageView} from '../common/analytics';
|
||||
|
||||
render(DndComponent);
|
||||
|
||||
// Track the page view
|
||||
trackPageView();
|
||||
|
||||
// Hot Module Replacement API
|
||||
if (module.hot) {
|
||||
module.hot.accept('./containers/app', () => {
|
||||
@ -66,5 +72,20 @@ if (window && !isDevelopment()) {
|
||||
});
|
||||
}
|
||||
|
||||
// Track the page view
|
||||
trackPageView();
|
||||
function showUpdateNotification () {
|
||||
console.log('[app] Update Available');
|
||||
|
||||
// eslint-disable-next-line no-new
|
||||
new window.Notification('Insomnia Update Ready', {
|
||||
body: 'Relaunch the app for it to take effect',
|
||||
silent: true,
|
||||
sticky: true
|
||||
});
|
||||
}
|
||||
|
||||
const {ipcRenderer} = require('electron');
|
||||
ipcRenderer.on('update-available', () => {
|
||||
// Give it a few seconds before showing this. Sometimes, when
|
||||
// you relaunch too soon it doesn't work the first time.
|
||||
setTimeout(showUpdateNotification, 1000 * 10);
|
||||
});
|
||||
|
35
package-lock.json
generated
35
package-lock.json
generated
@ -1567,7 +1567,7 @@
|
||||
"deep-equal": "1.0.1",
|
||||
"dns-equal": "1.0.0",
|
||||
"dns-txt": "2.0.2",
|
||||
"multicast-dns": "6.1.1",
|
||||
"multicast-dns": "6.2.0",
|
||||
"multicast-dns-service-types": "1.1.0"
|
||||
}
|
||||
},
|
||||
@ -6653,17 +6653,6 @@
|
||||
"requires": {
|
||||
"pkg-dir": "2.0.0",
|
||||
"resolve-cwd": "2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"pkg-dir": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-2.0.0.tgz",
|
||||
"integrity": "sha1-9tXREJ4Z1j7fQo4L1X4Sd3YVM0s=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"find-up": "2.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imurmurhash": {
|
||||
@ -10405,9 +10394,9 @@
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"multicast-dns": {
|
||||
"version": "6.1.1",
|
||||
"resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-6.1.1.tgz",
|
||||
"integrity": "sha1-bn3oalcIcqsXBYrepxYLvsqBTd4=",
|
||||
"version": "6.2.0",
|
||||
"resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-6.2.0.tgz",
|
||||
"integrity": "sha512-tnQqWkuWYHCOVRveiWQf+5KjHUnEmtxUycTy1esL4prQjXoT4qpndIS4fH63zObmHNxIHke3YHRnQrXYpXHf2A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"dns-packet": "1.2.2",
|
||||
@ -18303,22 +18292,22 @@
|
||||
}
|
||||
},
|
||||
"webpack-dev-middleware": {
|
||||
"version": "1.12.0",
|
||||
"resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-1.12.0.tgz",
|
||||
"integrity": "sha1-007++y7dp+HTtdvgcolRMhllFwk=",
|
||||
"version": "1.12.1",
|
||||
"resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-1.12.1.tgz",
|
||||
"integrity": "sha512-UzyVg/CKBKkymDpqOoQ4mWTs9zQp0DPCY8zbol9K0tPhqoM+JU5knKGXyMQ/Cdrmzb9Cw3eetm67fIsJ7u7ryg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"memory-fs": "0.4.1",
|
||||
"mime": "1.4.1",
|
||||
"mime": "1.5.0",
|
||||
"path-is-absolute": "1.0.1",
|
||||
"range-parser": "1.2.0",
|
||||
"time-stamp": "2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"mime": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz",
|
||||
"integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==",
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.5.0.tgz",
|
||||
"integrity": "sha512-v/jMDoK/qKptnTuC3YUNbIj8uUYvTCIHzVu9BHldKSWja48wusAtfjlcBlqnFrqClu3yf69ScDxBPrIyFnF51g==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
@ -18354,7 +18343,7 @@
|
||||
"spdy": "3.4.7",
|
||||
"strip-ansi": "3.0.1",
|
||||
"supports-color": "4.5.0",
|
||||
"webpack-dev-middleware": "1.12.0",
|
||||
"webpack-dev-middleware": "1.12.1",
|
||||
"yargs": "6.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -27,6 +27,9 @@
|
||||
"build": "node ./scripts/build.js",
|
||||
"build-n-package": "npm run build && npm run package"
|
||||
},
|
||||
"dev": {
|
||||
"webpack-dev-server-port": 3333
|
||||
},
|
||||
"jest": {
|
||||
"setupFiles": [
|
||||
"./__jest__/setup.js"
|
||||
@ -146,13 +149,13 @@
|
||||
"less-loader": "^4.0.5",
|
||||
"ncp": "^2.0.0",
|
||||
"npm": "^5.5.1",
|
||||
"react-hot-loader": "^3.0.0-beta.6",
|
||||
"react-hot-loader": "^3.1.3",
|
||||
"redux-mock-store": "^1.0.2",
|
||||
"rimraf": "^2.6.2",
|
||||
"style-loader": "^0.19.0",
|
||||
"url-loader": "^0.6.2",
|
||||
"webpack": "^3.5.5",
|
||||
"webpack-dev-server": "^2.4.1",
|
||||
"webpack-dev-server": "^2.9.4",
|
||||
"webpack-target-electron-renderer": "^0.4.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,27 @@
|
||||
const webpack = require('webpack');
|
||||
const baseConfig = require('./webpack.config.base.babel');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
const PORT = 3333;
|
||||
const port = pkg.dev['webpack-dev-server-port'];
|
||||
|
||||
module.exports = {
|
||||
...baseConfig,
|
||||
devtool: 'eval-source-map',
|
||||
entry: [
|
||||
'react-hot-loader/patch',
|
||||
`webpack-dev-server/client?http://localhost:${port}`,
|
||||
'webpack/hot/only-dev-server',
|
||||
...baseConfig.entry
|
||||
],
|
||||
output: {
|
||||
...baseConfig.output,
|
||||
publicPath: `http://localhost:${PORT}/`
|
||||
publicPath: '/'
|
||||
},
|
||||
devServer: {
|
||||
hot: true,
|
||||
hotOnly: true,
|
||||
port: PORT,
|
||||
publicPath: `http://localhost:${PORT}/`
|
||||
host: 'localhost',
|
||||
port: port,
|
||||
publicPath: '/',
|
||||
hot: true
|
||||
},
|
||||
plugins: [
|
||||
...baseConfig.plugins,
|
||||
|
@ -1,6 +1,7 @@
|
||||
const webpack = require('webpack');
|
||||
const path = require('path');
|
||||
const productionConfig = require('./webpack.config.production.babel');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
let devtool;
|
||||
let plugins;
|
||||
@ -12,8 +13,10 @@ const output = {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
output.path = path.join(__dirname, '../app');
|
||||
devtool = 'eval-source-map';
|
||||
const port = pkg.dev['webpack-dev-server-port'];
|
||||
plugins = [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.APP_RENDER_URL': JSON.stringify(`http://localhost:${port}/renderer.html`),
|
||||
'process.env.NODE_ENV': JSON.stringify('development'),
|
||||
'process.env.INSOMNIA_ENV': JSON.stringify('development')
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user