Stackedit/src/index.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-07-23 18:42:08 +00:00
import Vue from 'vue';
import 'babel-polyfill';
import 'indexeddbshim/dist/indexeddbshim';
2017-09-26 22:54:26 +00:00
import * as OfflinePluginRuntime from 'offline-plugin/runtime';
2018-06-07 23:56:11 +00:00
import './extensions';
2017-07-23 18:42:08 +00:00
import './services/optional';
2018-06-07 23:56:11 +00:00
import './icons';
2017-08-06 00:58:39 +00:00
import App from './components/App';
import store from './store';
import localDbSvc from './services/localDbSvc';
2017-07-23 18:42:08 +00:00
if (!indexedDB) {
throw new Error('Your browser is not supported. Please upgrade to the latest version.');
}
2018-05-06 00:46:33 +00:00
OfflinePluginRuntime.install({
onUpdateReady: () => {
// Tells to new SW to take control immediately
OfflinePluginRuntime.applyUpdate();
},
2018-05-13 13:27:33 +00:00
onUpdated: async () => {
2018-05-06 00:46:33 +00:00
if (!store.state.light) {
2018-05-13 13:27:33 +00:00
await localDbSvc.sync();
localStorage.updated = true;
// Reload the webpage to load into the new version
window.location.reload();
2018-05-06 00:46:33 +00:00
}
},
});
if (localStorage.updated) {
store.dispatch('notification/info', 'StackEdit has just updated itself!');
setTimeout(() => localStorage.removeItem('updated'), 2000);
2017-09-26 22:54:26 +00:00
}
2018-09-21 09:12:05 +00:00
if (!localStorage.installPrompted) {
window.addEventListener('beforeinstallprompt', async (promptEvent) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
promptEvent.preventDefault();
try {
await store.dispatch('notification/confirm', 'Add StackEdit to your home screen?');
promptEvent.prompt();
await promptEvent.userChoice;
} catch (err) {
// Cancel
}
localStorage.installPrompted = true;
});
}
2017-07-23 18:42:08 +00:00
Vue.config.productionTip = false;
/* eslint-disable no-new */
new Vue({
el: '#app',
store,
render: h => h(App),
});