11<script setup lang="ts">
2- import { LoaderCircleIcon , ShieldCheckIcon , TrashIcon } from ' @modrinth/assets'
2+ import { LoaderCircleIcon , TrashIcon } from ' @modrinth/assets'
33import {
4- Admonition ,
54 Button ,
65 defineMessages ,
76 injectNotificationManager ,
@@ -14,14 +13,6 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
1413import { invoke } from ' @tauri-apps/api/core'
1514import { computed , ref , watch } from ' vue'
1615
17- import {
18- storeVerificationReport as report ,
19- verifyingStore ,
20- verifyStore ,
21- } from ' @/components/ui/download-manager/store-verification'
22- import { useAppEvent } from ' @/composables/use-app-event'
23- import { injectAppSettingsModal } from ' @/features/settings/app-settings-modal/context'
24- import { get_all as getRunningProcesses } from ' @/helpers/process'
2516
2617type StoreUsage = {
2718 unique_bytes: number
@@ -33,7 +24,6 @@ type StoreUsage = {
3324}
3425
3526const { handleError } = injectNotificationManager ()
36- const settingsModal = injectAppSettingsModal ()
3727const { formatMessage } = useVIntl ()
3828const formatBytes = useFormatBytes ()
3929const gibibyte = 1024 ** 3
@@ -64,27 +54,11 @@ watch(
6454watch (storeUsageError , (error ) => {
6555 if (error ) handleError (error )
6656})
67- const runningProcessesKey = [' processes' , ' running' ] as const
68- const { data : runningProcesses, error : runningProcessesError } = useQuery ({
69- queryKey: runningProcessesKey ,
70- queryFn: getRunningProcesses ,
71- })
72- const hasRunningInstances = computed (() => (runningProcesses .value ?.length ?? 0 ) > 0 )
73- watch (runningProcessesError , (error ) => {
74- if (error ) handleError (error )
75- })
76- useAppEvent (' process' , () => queryClient .invalidateQueries ({ queryKey: runningProcessesKey }))
7757const busy = computed (
78- () =>
79- calculating .value ||
80- actionMutation .isPending .value ||
81- cacheLimitMutation .isPending .value ||
82- verifyingStore .value ,
83- )
84- const clearing = computed (
85- () => actionMutation .isPending .value && actionMutation .variables .value === ' clear' ,
58+ () => calculating .value || clearMutation .isPending .value || cacheLimitMutation .isPending .value ,
8659)
87- const clearedBytes = computed (() => actionMutation .data .value ?? null )
60+ const clearing = computed (() => clearMutation .isPending .value )
61+ const clearedBytes = computed (() => clearMutation .data .value ?? null )
8862const totalBytes = computed (
8963 () => (storeUsage .value ?.unique_bytes ?? 0 ) + (storeUsage .value ?.private_copy_bytes ?? 0 ),
9064)
@@ -126,22 +100,6 @@ const messages = defineMessages({
126100 id: ' app.settings.resource-management.store.clearing' ,
127101 defaultMessage: ' Clearing…' ,
128102 },
129- repair: {
130- id: ' app.settings.resource-management.store.repair' ,
131- defaultMessage: ' Verify and repair' ,
132- },
133- repairing: {
134- id: ' app.settings.resource-management.store.repairing' ,
135- defaultMessage: ' Verifying and repairing…' ,
136- },
137- repairDescription: {
138- id: ' app.settings.resource-management.store.repair.verify-description' ,
139- defaultMessage: ' Check for missing or damaged files and repair them.' ,
140- },
141- repairRunningDescription: {
142- id: ' app.settings.resource-management.store.repair.running-description' ,
143- defaultMessage: ' This will close any running instances.' ,
144- },
145103 clearDescription: {
146104 id: ' app.settings.resource-management.store.clear.description' ,
147105 defaultMessage: ' Delete unused downloaded content' ,
@@ -167,23 +125,6 @@ const messages = defineMessages({
167125 id: ' app.settings.resource-management.store.nothing-to-clear' ,
168126 defaultMessage: ' No unused content to clear.' ,
169127 },
170- verified: {
171- id: ' app.settings.resource-management.store.verified' ,
172- defaultMessage: ' Verification complete' ,
173- },
174- attention: {
175- id: ' app.settings.resource-management.store.attention' ,
176- defaultMessage: ' Some files still need attention' ,
177- },
178- result: {
179- id: ' app.settings.resource-management.store.verification-result' ,
180- defaultMessage:
181- ' Checked {checked, plural, one {# file} other {# files}} and made {repaired, plural, one {# repair} other {# repairs}}.' ,
182- },
183- issues: {
184- id: ' app.settings.resource-management.store.issues' ,
185- defaultMessage: ' View {count, plural, one {# issue} other {# issues}}' ,
186- },
187128})
188129
189130const categories = computed (() => {
@@ -211,27 +152,16 @@ const categories = computed(() => {
211152 ]
212153})
213154
214- const actionMutation = useMutation ({
215- mutationFn : async (action : ' clear' | ' repair' ) => {
216- if (action === ' repair' ) {
217- const verification = verifyStore ()
218- settingsModal .close ()
219- await verification
220- return null
221- }
222- return invoke <number >(' plugin:settings|store_cleanup' )
223- },
224- onMutate : () => {
225- report .value = null
226- },
155+ const clearMutation = useMutation ({
156+ mutationFn : () => invoke <number >(' plugin:settings|store_cleanup' ),
227157 onSuccess : () => queryClient .invalidateQueries ({ queryKey: storeUsageKey }),
228158 onError: handleError ,
229159})
230160
231- function runAction( action : ' clear ' | ' repair ' ) {
161+ function clearUnused( ) {
232162 if (busy .value ) return
233- actionMutation .reset ()
234- actionMutation .mutate (action )
163+ clearMutation .reset ()
164+ clearMutation .mutate ()
235165}
236166
237167const cacheLimitMutation = useMutation ({
@@ -321,33 +251,13 @@ function saveCacheLimit() {
321251 </div >
322252
323253 <div class =" flex flex-wrap items-center gap-2" >
324- <Button
325- v-tooltip ="
326- formatMessage (
327- hasRunningInstances ? messages .repairRunningDescription : messages .repairDescription ,
328- )
329- "
330- :type =" hasRunningInstances ? ' colored' : ' base' "
331- :color =" hasRunningInstances ? ' orange' : undefined "
332- :disabled =" busy || ! storeUsage || storeUsage .object_count === 0 "
333- :loading =" verifyingStore "
334- @click =" runAction (' repair' )"
335- >
336- <LoaderCircleIcon
337- v-if =" verifyingStore "
338- class="motion-safe:animate-spin "
339- aria-hidden="true"
340- />
341- <ShieldCheckIcon v-else aria-hidden="true" />
342- {{ formatMessage(verifyingStore ? messages.repairing : messages.repair) }}
343- </Button >
344254 <Button
345255 v-tooltip =" formatMessage (messages .clearDescription )"
346256 type="colored"
347257 color="red"
348258 :disabled =" busy || ! storeUsage || storeUsage .unused_cache_bytes === 0 "
349259 :loading =" clearing "
350- @click =" runAction ( ' clear ' ) "
260+ @click =" clearUnused "
351261 >
352262 <LoaderCircleIcon v-if =" clearing " class="motion-safe:animate-spin " aria-hidden="true" />
353263 <TrashIcon v-else aria-hidden="true" />
@@ -356,32 +266,7 @@ function saveCacheLimit() {
356266 </div >
357267
358268 <div aria-live =" polite" class =" empty:hidden" >
359- <Admonition
360- v-if =" report "
361- :type =" report .issues .length ? ' warning' : ' success' "
362- :header =" formatMessage (report .issues .length ? messages .attention : messages .verified )"
363- >
364- <p class =" m-0" >
365- {{
366- formatMessage(messages.result, { checked: report.checked, repaired: report.repaired })
367- }}
368- </p >
369- <details v-if =" report.issues.length" class =" mt-2" >
370- <summary class =" cursor-pointer font-semibold" >
371- {{ formatMessage(messages.issues, { count: report.issues.length }) }}
372- </summary >
373- <ul class =" mb-0 flex flex-col gap-2 pl-5" >
374- <li
375- v-for =" (issue, index) in report.issues"
376- :key =" `${issue.sha512}-${index}`"
377- class =" break-words"
378- >
379- {{ issue.message }}
380- </li >
381- </ul >
382- </details >
383- </Admonition >
384- <p v-else-if =" clearedBytes !== null" class =" m-0 text-sm text-green" >
269+ <p v-if =" clearedBytes !== null" class =" m-0 text-sm text-green" >
385270 {{
386271 clearedBytes > 0
387272 ? formatMessage(messages.cleared, { size: formatBytes(clearedBytes, 1) })
0 commit comments