From 13dd942f48ce7df2174e9881bec761270f7cf191 Mon Sep 17 00:00:00 2001 From: Shubham Kain Date: Mon, 16 Nov 2026 23:24:45 +0530 Subject: [PATCH 1/3] feat(newtab): add original-resolution custom wallpapers --- crates/zephium-core/src/preferences.rs | 3 ++ frame/messages/en.json | 2 ++ .../domain/preferences/preferences.svelte.ts | 1 + frame/src/domain/resources/index.ts | 9 +++++- frame/src/domain/resources/media.ts | 16 +++++++++- .../src/domain/resources/tests/media.test.ts | 31 +++++++++++++++++-- .../newtab/components/CustomBackground.svelte | 29 +++++++++++------ .../features/newtab/components/NewTab.svelte | 3 +- .../components/sections/NewTabPage.svelte | 22 +++++++++++-- 9 files changed, 98 insertions(+), 18 deletions(-) diff --git a/crates/zephium-core/src/preferences.rs b/crates/zephium-core/src/preferences.rs index 8341e231d..1736c9128 100644 --- a/crates/zephium-core/src/preferences.rs +++ b/crates/zephium-core/src/preferences.rs @@ -17,6 +17,7 @@ pub const KEYS: &[&str] = &[ "ui.newtab-tasks", "ui.newtab-background", "ui.newtab-image", + "ui.newtab-image-original", "ui.newtab-dim", "ui.newtab-wordmark", "ui.newtab-trackers", @@ -318,6 +319,7 @@ pub fn value_allowed(key: &str, value: &str) -> bool { | "ui.newtab-name" | "ui.newtab-clock" | "ui.newtab-tasks" + | "ui.newtab-image-original" | "ui.newtab-dim" | "ui.newtab-wordmark" | "ui.newtab-trackers" @@ -349,6 +351,7 @@ mod tests { #[test] fn newtab_customization_accepts_only_local_images_and_closed_choices() { for key in [ + "ui.newtab-image-original", "ui.newtab-dim", "ui.newtab-wordmark", "ui.newtab-trackers", diff --git a/frame/messages/en.json b/frame/messages/en.json index a3ef2cd37..282bd327b 100644 --- a/frame/messages/en.json +++ b/frame/messages/en.json @@ -3932,6 +3932,8 @@ "ntp_sky": "Zephium sky", "ntp_own_image": "Your own image", "ntp_choose_image": "Choose image…", + "ntp_image_original": "Use original wallpaper resolution", + "ntp_image_original_help": "Display custom wallpapers at their original resolution. May increase memory usage, especially with 4K and 5K images.", "ntp_image_failed": "Choose an image that Zephium can open.", "ntp_dim": "Dim", "ntp_dim_help": "Darken the image to make text easier to read.", diff --git a/frame/src/domain/preferences/preferences.svelte.ts b/frame/src/domain/preferences/preferences.svelte.ts index 9a4c3a65d..18f3f0128 100644 --- a/frame/src/domain/preferences/preferences.svelte.ts +++ b/frame/src/domain/preferences/preferences.svelte.ts @@ -21,6 +21,7 @@ const defaults = { "ui.newtab-tasks": "true", "ui.newtab-background": "sky", "ui.newtab-image": "", + "ui.newtab-image-original": "false", "ui.newtab-dim": "false", "ui.newtab-wordmark": "true", "ui.newtab-trackers": "true", diff --git a/frame/src/domain/resources/index.ts b/frame/src/domain/resources/index.ts index 67d78bb27..3efe6c7d3 100644 --- a/frame/src/domain/resources/index.ts +++ b/frame/src/domain/resources/index.ts @@ -7,6 +7,13 @@ export type { TaskStep, TaskList, } from "$shared/ipc/bindings"; -export { mediaUrl, mediaSize, pageFrameUrl, pictureUrl, recordMediaUrl } from "./media"; +export { + mediaUrl, + mediaOriginalUrl, + mediaSize, + pageFrameUrl, + pictureUrl, + recordMediaUrl, +} from "./media"; export type { MediaAssetV1, WorkPicture } from "./media"; export { OwnedObjects } from "./owned-objects"; diff --git a/frame/src/domain/resources/media.ts b/frame/src/domain/resources/media.ts index a8d2b5aa6..c2a79f372 100644 --- a/frame/src/domain/resources/media.ts +++ b/frame/src/domain/resources/media.ts @@ -29,6 +29,12 @@ export function mediaUrl(profile: string, digest: string, width = 720): string | return `${base}${profile}/${digest}?w=${width}`; } +/** Request the original image without thumbnail scaling. */ +export function mediaOriginalUrl(profile: string, digest: string): string | null { + if (!DIGEST.test(digest) || !PROFILE.test(profile)) return null; + return `${base}${profile}/${digest}`; +} + export function mediaSize(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`; @@ -47,13 +53,21 @@ export function recordMediaUrl(media: WorkRecordMediaRefV1): string | null { media.height > 240 ) return null; + const encoded = btoa(JSON.stringify(media)) .replaceAll("+", "-") .replaceAll("/", "_") .replace(/=+$/u, ""); + return `${base}record/${encoded}`; } -export type WorkPicture = { profile: string; digest: string; record?: WorkRecordMediaRefV1 }; + +export type WorkPicture = { + profile: string; + digest: string; + record?: WorkRecordMediaRefV1; +}; + export function pictureUrl(picture: WorkPicture, width = 720): string | null { return picture.record ? recordMediaUrl(picture.record) diff --git a/frame/src/domain/resources/tests/media.test.ts b/frame/src/domain/resources/tests/media.test.ts index a00bb516f..e52fa204c 100644 --- a/frame/src/domain/resources/tests/media.test.ts +++ b/frame/src/domain/resources/tests/media.test.ts @@ -1,5 +1,5 @@ import { expect, test } from "vitest"; -import { mediaUrl, pictureUrl, recordMediaUrl } from "../media"; +import { mediaUrl, mediaOriginalUrl, pictureUrl, recordMediaUrl } from "../media"; import type { WorkRecordMediaRefV1 } from "$shared/ipc/bindings"; const PROFILE = "01M3CTWDG20GFZPACD7905RSRJ"; @@ -11,6 +11,21 @@ test("a picture is asked for at the width it is shown, and a large view asks for expect(mediaUrl(PROFILE, "nope")).toBeNull(); }); +test("original wallpaper URLs bypass thumbnail scaling without weakening validation", () => { + const original = mediaOriginalUrl(PROFILE, DIGEST); + + expect(original).not.toBeNull(); + expect(original).toMatch(/\/01M3CTWDG20GFZPACD7905RSRJ\/a{64}$/u); + expect(original).not.toContain("?w="); + + // Optimized requests must continue using the thumbnail pipeline. + expect(mediaUrl(PROFILE, DIGEST, 1600)).toMatch(/\?w=1600$/u); + + // Original-resolution requests retain profile and digest validation. + expect(mediaOriginalUrl(PROFILE, "invalid")).toBeNull(); + expect(mediaOriginalUrl("invalid", DIGEST)).toBeNull(); +}); + test("record pictures retain exact local custody and never turn into a remote image fetch", () => { const record: WorkRecordMediaRefV1 = { profile: PROFILE, @@ -26,15 +41,27 @@ test("record pictures retain exact local custody and never turn into a remote im height: 100, origin: "native_crop", }; + const url = recordMediaUrl(record)!; + expect(url).toContain("/record/"); expect(url).not.toContain("?w="); + const encoded = url.split("/record/")[1]!; + expect(JSON.parse(atob(encoded.replaceAll("-", "+").replaceAll("_", "/")))).toEqual(record); + expect(pictureUrl({ profile: PROFILE, digest: DIGEST, record }, 1600)).toBe(url); + expect(recordMediaUrl({ ...record, record: 1 })).not.toBe(url); expect(recordMediaUrl({ ...record, digest: "b".repeat(64) })).not.toBe(url); - expect(recordMediaUrl({ ...record, profile: "01M3CTWDG20GFZPACD7905RSRK" })).not.toBe(url); + expect( + recordMediaUrl({ + ...record, + profile: "01M3CTWDG20GFZPACD7905RSRK", + }), + ).not.toBe(url); + expect(recordMediaUrl({ ...record, width: 321 })).toBeNull(); expect(recordMediaUrl({ ...record, source: "not-a-native-digest" })).toBeNull(); }); diff --git a/frame/src/features/newtab/components/CustomBackground.svelte b/frame/src/features/newtab/components/CustomBackground.svelte index 3ffc3ef23..9c1d16e22 100644 --- a/frame/src/features/newtab/components/CustomBackground.svelte +++ b/frame/src/features/newtab/components/CustomBackground.svelte @@ -1,12 +1,13 @@ {#if src} - {#if dim}
{/if} + {#if dim} +
+ {/if} {/if}