2017-09-25 21:32:58 +00:00
|
|
|
import * as React from 'react';
|
2017-02-26 21:12:51 +00:00
|
|
|
import ReactDOM from 'react-dom';
|
2018-06-25 17:42:50 +00:00
|
|
|
import { Provider } from 'react-redux';
|
2017-03-08 05:52:17 +00:00
|
|
|
import App from './containers/app';
|
2017-08-23 03:33:07 +00:00
|
|
|
import * as models from '../models';
|
2017-10-31 18:05:35 +00:00
|
|
|
import * as db from '../common/database';
|
2018-06-25 17:42:50 +00:00
|
|
|
import { init as initStore } from './redux/modules';
|
2019-04-18 00:50:03 +00:00
|
|
|
import * as legacySync from '../sync-legacy';
|
2018-06-25 17:42:50 +00:00
|
|
|
import { init as initPlugins } from '../plugins';
|
2017-03-12 00:31:23 +00:00
|
|
|
import './css/index.less';
|
2020-06-03 04:27:05 +00:00
|
|
|
import { getAppId, getAppLongName, isDevelopment } from '../common/constants';
|
2019-04-18 00:50:03 +00:00
|
|
|
import { setFont, setTheme } from '../plugins/misc';
|
|
|
|
import { AppContainer } from 'react-hot-loader';
|
|
|
|
import { DragDropContext } from 'react-dnd';
|
|
|
|
import DNDBackend from './dnd-backend';
|
2020-04-26 20:33:39 +00:00
|
|
|
import { trackEvent } from '../common/analytics';
|
2020-06-03 04:27:05 +00:00
|
|
|
import { APP_ID_DESIGNER, APP_ID_INSOMNIA } from '../../config';
|
2020-08-20 18:44:08 +00:00
|
|
|
import * as styledComponents from 'styled-components';
|
2016-03-16 05:49:42 +00:00
|
|
|
|
2017-11-24 01:39:53 +00:00
|
|
|
// Handy little helper
|
|
|
|
document.body.setAttribute('data-platform', process.platform);
|
2020-04-26 20:33:39 +00:00
|
|
|
document.title = getAppLongName();
|
2017-11-24 01:39:53 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
(async function() {
|
2017-11-20 16:07:36 +00:00
|
|
|
await db.initClient();
|
2018-07-18 00:48:10 +00:00
|
|
|
await initPlugins();
|
|
|
|
|
|
|
|
const settings = await models.settings.getOrCreate();
|
|
|
|
await setTheme(settings.theme);
|
2018-10-17 17:26:19 +00:00
|
|
|
await setFont(settings);
|
2016-11-30 03:55:27 +00:00
|
|
|
|
|
|
|
// Create Redux store
|
|
|
|
const store = await initStore();
|
|
|
|
|
2017-03-12 00:31:23 +00:00
|
|
|
const context = DragDropContext(DNDBackend);
|
2017-03-03 01:44:07 +00:00
|
|
|
const render = Component => {
|
2019-04-18 00:50:03 +00:00
|
|
|
const DnDComponent = context(Component);
|
2017-03-03 01:44:07 +00:00
|
|
|
ReactDOM.render(
|
|
|
|
<AppContainer>
|
|
|
|
<Provider store={store}>
|
2019-04-18 00:50:03 +00:00
|
|
|
<DnDComponent />
|
2017-03-03 01:44:07 +00:00
|
|
|
</Provider>
|
|
|
|
</AppContainer>,
|
2018-12-12 17:36:11 +00:00
|
|
|
document.getElementById('root'),
|
2017-03-03 01:44:07 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-04-18 00:50:03 +00:00
|
|
|
render(App);
|
2017-03-03 01:44:07 +00:00
|
|
|
|
|
|
|
// Hot Module Replacement API
|
|
|
|
if (module.hot) {
|
2019-04-18 00:50:03 +00:00
|
|
|
// module.hot.accept('./containers/app', () => {
|
|
|
|
// render(App);
|
|
|
|
// });
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-30 03:55:27 +00:00
|
|
|
|
2020-06-03 04:27:05 +00:00
|
|
|
const appId = getAppId();
|
2020-04-26 20:33:39 +00:00
|
|
|
|
2020-06-03 04:27:05 +00:00
|
|
|
// Legacy sync not part of Designer
|
|
|
|
if (appId === APP_ID_DESIGNER) {
|
|
|
|
legacySync.disableForSession();
|
|
|
|
} else if (appId === APP_ID_INSOMNIA) {
|
|
|
|
// Do things that can wait
|
|
|
|
const { enableSyncBeta } = await models.settings.getOrCreate();
|
|
|
|
if (enableSyncBeta) {
|
|
|
|
console.log('[app] Enabling sync beta');
|
|
|
|
legacySync.disableForSession();
|
|
|
|
} else {
|
|
|
|
process.nextTick(legacySync.init);
|
|
|
|
}
|
|
|
|
}
|
2016-10-02 20:57:00 +00:00
|
|
|
})();
|
2017-08-23 03:33:07 +00:00
|
|
|
|
|
|
|
// Export some useful things for dev
|
|
|
|
if (isDevelopment()) {
|
|
|
|
window.models = models;
|
2017-10-31 18:05:35 +00:00
|
|
|
window.db = db;
|
2017-08-23 03:33:07 +00:00
|
|
|
}
|
2017-11-18 22:47:54 +00:00
|
|
|
|
2020-08-20 18:44:08 +00:00
|
|
|
// Styled components is added to the window object here, for plugins to use.
|
|
|
|
// UI plugins built with webpack (such as insomnia-plugin-kong-portal) define styled-components as an external resolved
|
|
|
|
// from the window object. This is to ensure there is only one instance of styled-components on the page.
|
|
|
|
// Because styled-components are loaded at runtime, they don't have direct access to modules in the electron bundle
|
|
|
|
window['styled-components'] = styledComponents;
|
|
|
|
|
2017-11-18 22:47:54 +00:00
|
|
|
// Catch uncaught errors and report them
|
|
|
|
if (window && !isDevelopment()) {
|
|
|
|
window.addEventListener('error', e => {
|
|
|
|
console.error('Uncaught Error', e);
|
2020-04-26 20:33:39 +00:00
|
|
|
trackEvent('Error', 'Uncaught Error');
|
2017-11-18 22:47:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener('unhandledRejection', e => {
|
|
|
|
console.error('Unhandled Promise', e);
|
2020-04-26 20:33:39 +00:00
|
|
|
trackEvent('Error', 'Uncaught Promise');
|
2017-11-18 22:47:54 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function showUpdateNotification() {
|
2017-11-24 01:39:53 +00:00
|
|
|
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,
|
2018-12-12 17:36:11 +00:00
|
|
|
sticky: true,
|
2017-11-24 01:39:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
const { ipcRenderer } = require('electron');
|
2017-11-24 01:39:53 +00:00
|
|
|
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);
|
|
|
|
});
|