Stackedit/src/index.js

62 lines
1.7 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';
2022-07-02 05:09:24 +00:00
import versionsDescription from './data/versions';
2017-07-23 18:42:08 +00:00
if (!indexedDB) {
2022-07-02 05:09:24 +00:00
throw new Error('不支持您的浏览器,请升级到最新版本。');
}
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) {
2022-07-02 05:09:24 +00:00
const versionDesc = versionsDescription[VERSION];
store.dispatch('notification/info', `StackEdit中文版刚刚更新了${versionDesc}`);
setTimeout(() => localStorage.removeItem('updated'), 3000);
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 {
2022-07-02 05:09:24 +00:00
await store.dispatch('notification/confirm', '将StackEdit中文版添加到您的主屏幕上');
2018-09-21 09:12:05 +00:00
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),
});