Skip to content

Commit 2872a38

Browse files
committed
refactor: simplify loader timer logic and localize loading text
1 parent 5293052 commit 2872a38

3 files changed

Lines changed: 48 additions & 14 deletions

File tree

src/main/i18n/locales/en_US/ui.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"copied": "Copied",
123123
"currencyUnavailable": "Currency rates service unavailable"
124124
},
125+
"loading": "App loading...",
125126
"placeholder": {
126127
"emptyTagList": "Add tags to snippets to see them here",
127128
"emptyFoldersList": "No Folders",

src/renderer/App.vue

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,50 @@
11
<script setup lang="ts">
22
import { useApp, useTheme } from '@/composables'
33
import { i18n, ipc } from '@/electron'
4+
import { RouterName } from '@/router'
45
import { LoaderCircle } from 'lucide-vue-next'
56
import { loadWASM } from 'onigasm'
67
import onigasmFile from 'onigasm/lib/onigasm.wasm?url'
8+
import { useRoute } from 'vue-router'
79
import { Toaster } from 'vue-sonner'
810
import { loadGrammars } from './components/editor/grammars'
911
import { registerIPCListeners } from './ipc'
1012
import { notifications } from './services/notifications'
1113
1214
const { isSponsored, isAppLoading } = useApp()
15+
const route = useRoute()
1316
1417
const showLoader = ref(false)
15-
let loaderTimer: ReturnType<typeof setTimeout> | null = null
1618
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)
2021
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+
)
2748
2849
useTheme()
2950
@@ -51,11 +72,11 @@ init()
5172
</div>
5273
<RouterView />
5374
<div
54-
v-if="isAppLoading"
75+
v-if="isLoaderVisible"
5576
class="bg-bg absolute inset-0 z-50 flex flex-col items-center justify-center"
5677
>
5778
<template v-if="showLoader">
58-
App loading...
79+
{{ i18n.t("loading") }}
5980
<LoaderCircle class="text-text-muted mt-4 h-5 w-5 animate-spin" />
6081
</template>
6182
</div>

src/renderer/components/sidebar/library/Library.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,23 @@ async function initGetSnippets() {
7979
}
8080
8181
async function initApp() {
82-
await Promise.all([initGetFolders(), initGetSnippets()])
82+
isAppLoading.value = true
83+
84+
const results = await Promise.allSettled([
85+
initGetFolders(),
86+
initGetSnippets(),
87+
])
88+
89+
results.forEach((result) => {
90+
if (result.status === 'rejected') {
91+
console.error('App init error:', result.reason)
92+
}
93+
})
94+
8395
isAppLoading.value = false
8496
}
8597
86-
initApp()
98+
void initApp()
8799
88100
async function onFolderClick({
89101
id,

0 commit comments

Comments
 (0)