feat(launcher): configurable .tmp cache cleanup in cfg panel
- launcher_cfg_local_actions.svelte: add "Cache Maintenance" block (native-only, gated by is_native && cache_root); number input for max age in hours, "Clean Now" button with status feedback - launcher_background_sync.svelte: read cleanup_tmp_max_age_hours from events_loc.launcher store (default 24h) instead of hardcoded 1440 minutes; setting persists across sessions via persisted store Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { ae_loc, ae_api } from '$lib/stores/ae_stores';
|
||||
import { events_loc } from '$lib/stores/ae_events_stores';
|
||||
import { cleanup_tmp_files } from '$lib/electron/electron_relay';
|
||||
import Launcher_Cfg_Section from './launcher_cfg_section.svelte';
|
||||
|
||||
interface Props {
|
||||
@@ -9,6 +10,17 @@
|
||||
let { on_expand }: Props = $props();
|
||||
|
||||
let selected_reset = $state('');
|
||||
let cleanup_status = $state('');
|
||||
|
||||
async function handle_cleanup_now() {
|
||||
const cache_root = $ae_loc.local_file_cache_path;
|
||||
if (!cache_root) { cleanup_status = 'Error: Cache path not set.'; return; }
|
||||
const max_age_hours = $events_loc.launcher.cleanup_tmp_max_age_hours ?? 24;
|
||||
cleanup_status = 'Cleaning...';
|
||||
const result = await cleanup_tmp_files({ cache_root, max_age_minutes: max_age_hours * 60 });
|
||||
cleanup_status = (result as any).success !== false ? 'Done.' : `Error: ${(result as any).error}`;
|
||||
setTimeout(() => (cleanup_status = ''), 4000);
|
||||
}
|
||||
|
||||
function handle_reset_action(val: string) {
|
||||
if (!val) return;
|
||||
@@ -128,7 +140,39 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 3. Connection Summary (Edit Mode Only) -->
|
||||
<!-- 3. Cache .tmp Cleanup (Native Only) -->
|
||||
{#if $ae_loc.is_native && $ae_loc.local_file_cache_path}
|
||||
<div class="flex flex-col gap-1 border-t border-surface-500/20 pt-2 mt-1">
|
||||
<span class="text-[9px] font-bold uppercase opacity-50 ml-1">Cache Maintenance</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<label for="cleanup_max_age" class="text-[10px] opacity-70 whitespace-nowrap">Max age (hrs):</label>
|
||||
<input
|
||||
id="cleanup_max_age"
|
||||
type="number"
|
||||
min="1"
|
||||
max="168"
|
||||
bind:value={$events_loc.launcher.cleanup_tmp_max_age_hours}
|
||||
class="input input-sm w-16 h-7 text-xs text-center preset-tonal-surface"
|
||||
placeholder="24"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onclick={handle_cleanup_now}
|
||||
class="btn btn-xs preset-tonal-warning hover:preset-filled-warning-500 grow"
|
||||
>
|
||||
<span class="fas fa-broom mr-1"></span> Clean .tmp Now
|
||||
</button>
|
||||
</div>
|
||||
{#if cleanup_status}
|
||||
<span class="text-[9px] italic opacity-60 ml-1">{cleanup_status}</span>
|
||||
{/if}
|
||||
<span class="text-[8px] opacity-40 italic ml-1 leading-tight">
|
||||
Removes stale in-progress download artifacts. Auto-runs on startup.
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- 4. Connection Summary (Edit Mode Only) -->
|
||||
{#if $ae_loc.edit_mode}
|
||||
<div
|
||||
class="col-span-full border-t border-surface-500/20 pt-2 mt-1 flex flex-col gap-1"
|
||||
|
||||
@@ -108,11 +108,12 @@
|
||||
setTimeout(() => refresh_presentation_data(), 3000);
|
||||
setTimeout(() => refresh_presenter_data(), 5000);
|
||||
|
||||
// Clean up stale .tmp files (interrupted downloads) older than 24h.
|
||||
// Run once at startup — sufficient for conference day usage.
|
||||
// Clean up stale .tmp files (interrupted downloads) on startup.
|
||||
// Age threshold is user-configurable (cfg → General → Cache Maintenance), default 24h.
|
||||
const cache_root = $ae_loc.local_file_cache_path;
|
||||
if ($ae_loc.is_native && cache_root) {
|
||||
cleanup_tmp_files({ cache_root }).then((result) => {
|
||||
const max_age_hours = $events_loc.launcher.cleanup_tmp_max_age_hours ?? 24;
|
||||
cleanup_tmp_files({ cache_root, max_age_minutes: max_age_hours * 60 }).then((result) => {
|
||||
if (log_lvl) console.log('Sync: .tmp cleanup complete.', result);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user