2021-02-02 22:23:42 +00:00
|
|
|
import { hot } from 'react-hot-loader';
|
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';
|
|
|
|
import { init as initPlugins } from '../plugins';
|
2017-03-12 00:31:23 +00:00
|
|
|
import './css/index.less';
|
2021-02-25 20:13:37 +00:00
|
|
|
import { getAppLongName, isDevelopment } from '../common/constants';
|
2019-04-18 00:50:03 +00:00
|
|
|
import { setFont, setTheme } from '../plugins/misc';
|
2020-04-26 20:33:39 +00:00
|
|
|
import { trackEvent } from '../common/analytics';
|
2020-08-20 18:44:08 +00:00
|
|
|
import * as styledComponents from 'styled-components';
|
2020-10-09 20:33:21 +00:00
|
|
|
import { initNewOAuthSession } from '../network/o-auth-2/misc';
|
2020-10-13 16:05:41 +00:00
|
|
|
import { initializeLogging } from '../common/log';
|
|
|
|
|
|
|
|
initializeLogging();
|
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();
|
2020-10-09 20:33:21 +00:00
|
|
|
if (settings.clearOAuth2SessionOnRestart) {
|
|
|
|
initNewOAuthSession();
|
|
|
|
}
|
2018-07-18 00:48:10 +00:00
|
|
|
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();
|
|
|
|
|
2021-02-02 22:23:42 +00:00
|
|
|
const render = App => {
|
|
|
|
const TheHottestApp = hot(module)(App);
|
2017-03-03 01:44:07 +00:00
|
|
|
ReactDOM.render(
|
2021-02-02 22:23:42 +00:00
|
|
|
<Provider store={store}>
|
|
|
|
<TheHottestApp />
|
|
|
|
</Provider>,
|
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);
|
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
|
|
|
});
|
|
|
|
|
2020-10-13 16:05:41 +00:00
|
|
|
window.addEventListener('unhandledrejection', e => {
|
2017-11-18 22:47:54 +00:00
|
|
|
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);
|
|
|
|
});
|