|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import { useApp, useTheme } from '@/composables' |
3 | 3 | import { i18n, ipc } from '@/electron' |
| 4 | +import { RouterName } from '@/router' |
4 | 5 | import { LoaderCircle } from 'lucide-vue-next' |
5 | 6 | import { loadWASM } from 'onigasm' |
6 | 7 | import onigasmFile from 'onigasm/lib/onigasm.wasm?url' |
| 8 | +import { useRoute } from 'vue-router' |
7 | 9 | import { Toaster } from 'vue-sonner' |
8 | 10 | import { loadGrammars } from './components/editor/grammars' |
9 | 11 | import { registerIPCListeners } from './ipc' |
10 | 12 | import { notifications } from './services/notifications' |
11 | 13 |
|
12 | 14 | const { isSponsored, isAppLoading } = useApp() |
| 15 | +const route = useRoute() |
13 | 16 |
|
14 | 17 | const showLoader = ref(false) |
15 | | -let loaderTimer: ReturnType<typeof setTimeout> | null = null |
16 | 18 |
|
17 | | -loaderTimer = setTimeout(() => { |
18 | | - showLoader.value = true |
19 | | -}, 300) |
| 19 | +const isMainRoute = computed(() => route.name === RouterName.main) |
| 20 | +const isLoaderVisible = computed(() => isMainRoute.value && isAppLoading.value) |
20 | 21 |
|
21 | | -watch(isAppLoading, (value) => { |
22 | | - if (!value) { |
23 | | - clearTimeout(loaderTimer!) |
24 | | - showLoader.value = false |
25 | | - } |
26 | | -}) |
| 22 | +watch( |
| 23 | + isLoaderVisible, |
| 24 | + (value) => { |
| 25 | + if (!value) { |
| 26 | + showLoader.value = false |
| 27 | + return |
| 28 | + } |
| 29 | +
|
| 30 | + const timer = setTimeout(() => { |
| 31 | + showLoader.value = true |
| 32 | + }, 300) |
| 33 | +
|
| 34 | + onWatcherCleanup(() => clearTimeout(timer)) |
| 35 | + }, |
| 36 | + { immediate: true }, |
| 37 | +) |
| 38 | +
|
| 39 | +watch( |
| 40 | + isMainRoute, |
| 41 | + (value) => { |
| 42 | + if (!value) { |
| 43 | + isAppLoading.value = false |
| 44 | + } |
| 45 | + }, |
| 46 | + { immediate: true }, |
| 47 | +) |
27 | 48 |
|
28 | 49 | useTheme() |
29 | 50 |
|
@@ -51,11 +72,11 @@ init() |
51 | 72 | </div> |
52 | 73 | <RouterView /> |
53 | 74 | <div |
54 | | - v-if="isAppLoading" |
| 75 | + v-if="isLoaderVisible" |
55 | 76 | class="bg-bg absolute inset-0 z-50 flex flex-col items-center justify-center" |
56 | 77 | > |
57 | 78 | <template v-if="showLoader"> |
58 | | - App loading... |
| 79 | + {{ i18n.t("loading") }} |
59 | 80 | <LoaderCircle class="text-text-muted mt-4 h-5 w-5 animate-spin" /> |
60 | 81 | </template> |
61 | 82 | </div> |
|
0 commit comments