2021-07-22 23:04:56 +00:00
|
|
|
// eslint-disable-next-line simple-import-sort/imports
|
|
|
|
import { ipcRenderer } from 'electron';
|
2021-05-12 06:35:00 +00:00
|
|
|
import React from 'react';
|
2017-02-26 21:12:51 +00:00
|
|
|
import ReactDOM from 'react-dom';
|
2021-07-22 23:04:56 +00:00
|
|
|
import { hot } from 'react-hot-loader';
|
2018-06-25 17:42:50 +00:00
|
|
|
import { Provider } from 'react-redux';
|
2020-08-20 18:44:08 +00:00
|
|
|
import * as styledComponents from 'styled-components';
|
2021-07-22 23:04:56 +00:00
|
|
|
|
|
|
|
import { trackEvent } from '../common/analytics';
|
|
|
|
import { getAppLongName, isDevelopment } from '../common/constants';
|
|
|
|
import { database as db } from '../common/database';
|
2020-10-13 16:05:41 +00:00
|
|
|
import { initializeLogging } from '../common/log';
|
2021-07-22 23:04:56 +00:00
|
|
|
import * as models from '../models';
|
|
|
|
import { initNewOAuthSession } from '../network/o-auth-2/misc';
|
|
|
|
import { init as initPlugins } from '../plugins';
|
2021-12-14 14:26:36 +00:00
|
|
|
import { applyColorScheme } from '../plugins/misc';
|
2021-07-22 23:04:56 +00:00
|
|
|
import App from './containers/app';
|
|
|
|
import { init as initStore } from './redux/modules';
|
|
|
|
|
|
|
|
import './css/index.less'; // this import must come after `App`. the reason is not yet known.
|
2020-10-13 16:05:41 +00:00
|
|
|
|
|
|
|
initializeLogging();
|
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();
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2020-10-09 20:33:21 +00:00
|
|
|
if (settings.clearOAuth2SessionOnRestart) {
|
|
|
|
initNewOAuthSession();
|
|
|
|
}
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2021-03-13 03:38:54 +00:00
|
|
|
await applyColorScheme(settings);
|
2021-12-14 14:26:36 +00:00
|
|
|
|
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()) {
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION needs window augmentation
|
2017-08-23 03:33:07 +00:00
|
|
|
window.models = models;
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION needs window augmentation
|
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 => {
|
2021-07-28 18:57:52 +00:00
|
|
|
console.error('Uncaught Error', e.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 => {
|
2021-07-28 18:57:52 +00:00
|
|
|
console.error('Unhandled Promise', e.reason);
|
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,
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION
|
2018-12-12 17:36:11 +00:00
|
|
|
sticky: true,
|
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);
|
|
|
|
});
|