handle app crash

This commit is contained in:
Jan Prochazka
2021-03-27 08:28:21 +01:00
parent f1c70f6f82
commit 11436c065c
3 changed files with 43 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
import PluginsProvider from './plugins/PluginsProvider.svelte';
import Screen from './Screen.svelte';
import './utility/errorHandler';
</script>
<PluginsProvider />

View File

@@ -0,0 +1,30 @@
import localforage from 'localforage';
window.onunhandledrejection = async e => {
console.log('Unhandler error, CRASH!!!', e);
const lastDbGateCrashJson = localStorage.getItem('lastDbGateCrash');
const lastDbGateCrash = lastDbGateCrashJson ? JSON.parse(lastDbGateCrashJson) : null;
if (lastDbGateCrash && new Date().getTime() - lastDbGateCrash < 30 * 1000) {
if (
window.confirm(
'Sorry, DbGate has crashed again.\nDo you want to clear local user data to avoid crashing after next reload?'
)
) {
localStorage.clear();
try {
await localforage.clear();
} catch (err) {
console.error('Error clearing app data', err);
}
window.location.reload();
} else {
localStorage.setItem('lastDbGateCrash', JSON.stringify(new Date().getTime()));
window.location.reload();
}
} else {
window.alert('Sorry, DbGate has crashed.\nAfter OK DbGate will be reloaded');
localStorage.setItem('lastDbGateCrash', JSON.stringify(new Date().getTime()));
window.location.reload();
}
};

View File

@@ -6,6 +6,7 @@ import resolveApi from './resolveApi';
import { findFileFormat } from '../plugins/fileformats';
import { showModal } from '../modals/modalTools';
import ImportExportModal from '../modals/ImportExportModal.svelte';
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
let uploadListener;
@@ -21,15 +22,20 @@ export default function uploadFiles(files) {
const ext = get(extensions);
const electron = getElectron();
files.forEach(async file => {
if (parseInt(file.size, 10) >= 4 * 1024 * 1024) {
// to big file
if (electron && canOpenByElectron(file.path, ext)) {
openElectronFileCore(file.path, ext);
return;
}
console.log('FILE', file);
if (electron && canOpenByElectron(file.path, ext)) {
openElectronFileCore(file.path, ext);
const maxSize = 32 * 1024 * 1024;
if (parseInt(file.size, 10) >= maxSize) {
showModal(ErrorMessageModal, {
title: 'Upload error',
message: `File is too big, current size is ${Math.round(
file.size / 1024
).toLocaleString()} KB, max allowed size is ${Math.round(maxSize / 1024).toLocaleString()} KB`,
});
// to big file
return;
}