mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 06:46:00 +00:00
handle app crash
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
||||||
import Screen from './Screen.svelte';
|
import Screen from './Screen.svelte';
|
||||||
|
import './utility/errorHandler';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<PluginsProvider />
|
<PluginsProvider />
|
||||||
|
|||||||
30
packages/web/src/utility/errorHandler.ts
Normal file
30
packages/web/src/utility/errorHandler.ts
Normal 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();
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -6,6 +6,7 @@ import resolveApi from './resolveApi';
|
|||||||
import { findFileFormat } from '../plugins/fileformats';
|
import { findFileFormat } from '../plugins/fileformats';
|
||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
|
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||||
|
|
||||||
let uploadListener;
|
let uploadListener;
|
||||||
|
|
||||||
@@ -21,15 +22,20 @@ export default function uploadFiles(files) {
|
|||||||
const ext = get(extensions);
|
const ext = get(extensions);
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
files.forEach(async file => {
|
files.forEach(async file => {
|
||||||
if (parseInt(file.size, 10) >= 4 * 1024 * 1024) {
|
if (electron && canOpenByElectron(file.path, ext)) {
|
||||||
// to big file
|
openElectronFileCore(file.path, ext);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('FILE', file);
|
const maxSize = 32 * 1024 * 1024;
|
||||||
|
if (parseInt(file.size, 10) >= maxSize) {
|
||||||
if (electron && canOpenByElectron(file.path, ext)) {
|
showModal(ErrorMessageModal, {
|
||||||
openElectronFileCore(file.path, ext);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user