open tabs on startup fix

This commit is contained in:
Jan Prochazka
2021-04-02 09:04:06 +02:00
parent 9ed6932c1e
commit 94b41fecbc

View File

@@ -1,6 +1,8 @@
<script lang="ts">
import { onMount } from 'svelte';
import { openFavorite } from '../appobj/FavoriteFileAppObject.svelte';
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
import { showModal } from '../modals/modalTools';
import { openedTabs } from '../stores';
import { useFavorites } from './metadataLoaders';
@@ -20,10 +22,28 @@
opened = true;
if ($openedTabs.find(x => !x.closedTime)) return;
const { hash } = document.location;
const openFavoriteName = hash && hash.startsWith('#favorite=') ? hash.substring('#favorite='.length) : null;
const openTabdata = hash && hash.startsWith('#tabdata=') ? hash.substring('#tabdata='.length) : null;
for (const favorite of list.filter(x => x.openOnStartup)) {
openFavorite(favorite);
if (openFavoriteName) {
const open = list.find(x => x.urlPath == openFavoriteName);
if (open) {
openFavorite(open);
window.history.replaceState(null, null, ' ');
}
} else if (openTabdata) {
try {
const json = JSON.parse(decodeURIComponent(openTabdata));
openFavorite(json);
window.history.replaceState(null, null, ' ');
} catch (err) {
showModal(ErrorMessageModal, { message: err.message });
}
} else if (!$openedTabs.find(x => x.closedTime == null)) {
for (const favorite of list.filter(x => x.openOnStartup)) {
openFavorite(favorite);
}
}
}
</script>