diff --git a/src/routes/events/[event_id]/(launcher)/cfg_components/launcher_cfg_wallpaper.svelte b/src/routes/events/[event_id]/(launcher)/cfg_components/launcher_cfg_wallpaper.svelte index 60a18220..d1e12588 100644 --- a/src/routes/events/[event_id]/(launcher)/cfg_components/launcher_cfg_wallpaper.svelte +++ b/src/routes/events/[event_id]/(launcher)/cfg_components/launcher_cfg_wallpaper.svelte @@ -4,7 +4,7 @@ import { events_func } from '$lib/ae_events/ae_events_functions'; import { events_loc } from '$lib/stores/ae_events_stores'; import * as native from '$lib/electron/electron_relay'; import Launcher_Cfg_Section from './launcher_cfg_section.svelte'; -import { FlaskConical, Image, Monitor, RotateCcw, Save, Zap } from '@lucide/svelte'; +import { FlaskConical, Image, RotateCcw, Save, Zap } from '@lucide/svelte'; interface Props { on_expand?: () => void; @@ -19,11 +19,20 @@ type NativeDeviceLike = { [key: string]: unknown; }; +const PRIMARY_PRESETS = [ + { label: 'OSIT Default', value: 'https://static.oneskyit.com/images/site_background.webp' }, +] as const; + +const EXTERNAL_PRESETS = [ + { label: 'CMSC', value: 'https://static.oneskyit.com/c/CMSC/images/CMSC_AE_Launcher_bg_secondary.png' }, + { label: 'LCI', value: 'https://static.oneskyit.com/c/LCI/images/LCI_AE_Launcher_bg_secondary.png' }, + { label: 'LCI Alt', value: 'https://static.oneskyit.com/c/LCI/images/LCI_AE_Launcher_bg_secondary_bak.jpg' }, + { label: 'BGH', value: 'https://static.oneskyit.com/c/BGH/images/BGH_AE_Launcher_bg_secondary.png' }, +] as const; + let url_input = $state(''); let url_external_input = $state(''); -let save_status = $state(''); -let apply_status = $state(''); -let restore_status = $state(''); +let status = $state(''); let last_device_id: string | null = null; let linux_test_popup_open = $state(false); @@ -73,19 +82,14 @@ $effect(() => { sync_from_device(); }); -function set_save_status(msg: string) { - save_status = msg; - setTimeout(() => { if (save_status === msg) save_status = ''; }, 3000); +function set_status(msg: string, duration = 4000) { + status = msg; + if (msg) setTimeout(() => { if (status === msg) status = ''; }, duration); } -function set_apply_status(msg: string) { - apply_status = msg; - setTimeout(() => { if (apply_status === msg) apply_status = ''; }, 4000); -} - -async function handle_save() { +async function handle_save(): Promise { const device_id = get_device_id(); - if (!device_id) { set_save_status('No device loaded'); return; } + if (!device_id) return false; const native_device = get_native_device(); const other_json_obj = parse_other_json(native_device?.other_json); @@ -110,7 +114,6 @@ async function handle_save() { } const other_json = JSON.stringify(other_json_obj); - set_save_status('Saving...'); const result = await events_func.update_ae_obj__event_device({ api_cfg: $ae_api, @@ -119,22 +122,21 @@ async function handle_save() { log_lvl: 0 }); - if (!result) { set_save_status('Save failed'); return; } + if (!result) return false; const store_loc = $ae_loc as { native_device?: NativeDeviceLike }; store_loc.native_device = { ...get_native_device(), ...result, other_json }; - set_save_status('Saved'); + return true; } -async function handle_apply() { +async function handle_apply(): Promise<{ success: boolean; linux_test?: boolean }> { const url = url_input.trim(); const url_ext = url_external_input.trim(); - if (!url && !url_ext) { set_apply_status('Enter a URL first'); return; } + if (!url && !url_ext) return { success: false }; // If only external is set, target only that display so the built-in stays unchanged. const display = !url && url_ext ? 'external' : 'all'; - set_apply_status('Downloading & applying...'); const result = await native.set_wallpaper({ url: url || undefined, url_external: url_ext || undefined, @@ -146,34 +148,44 @@ async function handle_apply() { if (result?.success && (result as any).linux_test_mode) { linux_test_popup_data = result as Record; linux_test_popup_open = true; - set_apply_status('Linux dev mode — see popup'); + return { success: true, linux_test: true }; } else if (result?.success) { $events_loc.launcher.wallpaper_applied_url = url || null; $events_loc.launcher.wallpaper_applied_url_external = url_ext || null; - set_apply_status('Applied ✓'); + return { success: true }; + } + return { success: false }; +} + +async function handle_save_and_apply() { + const device_id = get_device_id(); + if (!device_id) { set_status('No device loaded'); return; } + + set_status('Saving...'); + const saved = await handle_save(); + if (!saved) { set_status('Save failed'); return; } + + set_status('Applying...'); + const { success, linux_test } = await handle_apply(); + if (!success) { + set_status('Saved — apply failed'); + } else if (linux_test) { + set_status('Linux dev mode — see popup'); } else { - set_apply_status(`Error: ${(result as any)?.error ?? 'Unknown error'}`); + set_status('Saved & Applied ✓'); } } async function handle_restore_default() { - restore_status = 'Restoring...'; + set_status('Restoring...'); const result = await native.restore_macos_default_wallpaper('all'); if (result?.success) { // Clear tracked applied URL so the next config URL re-applies correctly. $events_loc.launcher.wallpaper_applied_url = null; $events_loc.launcher.wallpaper_applied_url_external = null; - restore_status = 'Restored ✓'; + set_status('Restored ✓'); } else { - restore_status = `Error: ${(result as any)?.error ?? 'Unknown error'}`; - } - setTimeout(() => { if (restore_status.startsWith('Restored') || restore_status.startsWith('Error')) restore_status = ''; }, 4000); -} - -async function handle_save_and_apply() { - await handle_save(); - if (save_status !== 'Save failed' && save_status !== 'No device loaded') { - await handle_apply(); + set_status(`Restore failed: ${(result as { error?: string })?.error ?? 'Unknown'}`); } } @@ -200,7 +212,7 @@ const section_description = $derived( {#if $ae_loc.edit_mode && !$ae_loc.is_native}
+ class="bg-warning-500/10 border-warning-500/30 mb-2 flex items-center gap-2 rounded-lg border px-2 py-1.5"> Dev Preview — Apply requires Electron; Save works from any device @@ -208,131 +220,99 @@ const section_description = $derived(
{/if} -
-

- Desktop Background Images -

-

- Paste an HTTPS image URL. Save writes it to this device's config so all - devices auto-apply on their next heartbeat. Apply sets it immediately on - this machine. -

+ {#if !get_device_id()} +
+ No device record loaded — Save requires a native device config. +
+ {/if} - {#if !get_device_id()} -
- No device record loaded — Save requires a native device config. -
- {/if} +
- -
-
- -

- All Displays -

- {#if is_applied} - Applied ✓ - {:else if $events_loc.launcher.wallpaper_applied_url} - Pending apply - {/if} + +
+

Primary Display

+
+ {#each PRIMARY_PRESETS as preset (preset.value)} + + {/each}
- {#if $events_loc.launcher.wallpaper_applied_url && $events_loc.launcher.wallpaper_applied_url !== url_input.trim()} -

- Applied: {$events_loc.launcher.wallpaper_applied_url} -

+ placeholder="https://… or select a preset above" + class="input input-sm preset-tonal-surface h-7 w-full text-[10px]" /> + {#if is_applied} +

Applied ✓

{/if} -
+
- -
-
- -

- External / Projector - (optional) -

-
-

- Leave blank to use the same image on all displays. + +

+

+ External / Projector + (optional)

+
+ {#each EXTERNAL_PRESETS as preset (preset.value)} + + {/each} +
-
- - -
- - + placeholder="Blank = use primary on all displays" + class="input input-sm preset-tonal-surface h-7 w-full text-[10px]" />
- - - {#if $ae_loc.is_native || $ae_loc.edit_mode} + +
+ {#if $ae_loc.is_native || $ae_loc.edit_mode} + + {/if} +
+ + {#if status} +
+ {status} +
{/if} - {#if save_status} -
- {save_status} -
- {/if} - {#if apply_status} -
- {apply_status} -
- {/if} - {#if restore_status} -
- {restore_status} -
- {/if}
@@ -369,7 +349,7 @@ const section_description = $derived(
Display Target -
+
{linux_test_popup_data.display ?? 'all'}
@@ -377,7 +357,7 @@ const section_description = $derived( {#if linux_test_popup_data.url}
Primary URL -
+
{linux_test_popup_data.url}
@@ -386,7 +366,7 @@ const section_description = $derived( {#if linux_test_popup_data.url_external}
External / Projector URL -
+
{linux_test_popup_data.url_external}
@@ -394,7 +374,7 @@ const section_description = $derived(
Would Have Run -
+
{#each (linux_test_popup_data.would_run as string[]) as cmd}
{cmd}
{/each}