insomnia/packages/insomnia-app/app/ui/index.js

91 lines
2.4 KiB
JavaScript
Raw Normal View History

import * as React from 'react';
import ReactDOM from 'react-dom';
2018-06-25 17:42:50 +00:00
import { AppContainer } from 'react-hot-loader';
import { Provider } from 'react-redux';
import { DragDropContext } from 'react-dnd';
import App from './containers/app';
2017-08-23 03:33:07 +00:00
import * as models from '../models';
import * as db from '../common/database';
2018-06-25 17:42:50 +00:00
import { init as initStore } from './redux/modules';
import { init as initSync } from '../sync';
import { init as initPlugins } from '../plugins';
import DNDBackend from './dnd-backend';
import './css/index.less';
2018-06-25 17:42:50 +00:00
import { isDevelopment } from '../common/constants';
import { setTheme, setFont } from '../plugins/misc';
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);
2018-06-25 17:42:50 +00:00
(async function() {
await db.initClient();
2018-07-18 00:48:10 +00:00
await initPlugins();
const settings = await models.settings.getOrCreate();
await setTheme(settings.theme);
await setFont(settings);
2016-11-30 03:55:27 +00:00
// Create Redux store
const store = await initStore();
const context = DragDropContext(DNDBackend);
const DndComponent = context(App);
const render = Component => {
ReactDOM.render(
<AppContainer>
<Provider store={store}>
2018-06-25 17:42:50 +00:00
<Component />
</Provider>
</AppContainer>,
document.getElementById('root'),
);
};
render(DndComponent);
// Hot Module Replacement API
if (module.hot) {
module.hot.accept('./containers/app', () => {
render(DndComponent);
});
}
2016-11-30 03:55:27 +00:00
// Do things that can wait
process.nextTick(initSync);
})();
2017-08-23 03:33:07 +00:00
// Export some useful things for dev
if (isDevelopment()) {
window.models = models;
window.db = db;
2017-08-23 03:33:07 +00:00
}
// Catch uncaught errors and report them
if (window && !isDevelopment()) {
window.addEventListener('error', e => {
console.error('Uncaught Error', e);
});
window.addEventListener('unhandledRejection', e => {
console.error('Unhandled Promise', e);
});
}
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,
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);
});