PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.
Dart airdrop-alternativeclipboardclipboard-sharingclipboard-synccopy-pastecross-platformend-to-end-encryptionfile-syncfile-transferfluttergolanglinuxmacosnat-traversalp2pself-hostedtailscaleuniversal-clipboardwebrtcwindows
feat(core): let themes replace the scenery with pictures
baiyuze2b21e395a1b3
diff --git a/client-core/cmd/pasteferry-cli/mcp.go b/client-core/cmd/pasteferry-cli/mcp.goindex cd56387..8d15868 100644--- a/client-core/cmd/pasteferry-cli/mcp.go+++ b/client-core/cmd/pasteferry-cli/mcp.go@@ -37,7 +37,9 @@ var mcpVersions = []string{"2025-06-18", "2025-03-26"}const mcpInstructions = `PasteFerry themes. A theme is a JSON document (call theme_schema for the format and what every color role is used for). ` +`Typical flow: theme_list → theme_get a built-in theme with resolved=true as a starting point → write a new theme with your own id and "base" set to that theme, overriding only what you change → theme_validate → fix any contrast warnings → theme_save → theme_apply. ` +- `Built-in themes ("default", "pixel") cannot be overwritten. Background images must be imported first with background_import, then referenced as "user:<sha256>".`+ `Built-in themes ("default", "pixel") cannot be overwritten. Background images must be imported first with background_import, then referenced as "user:<sha256>"; ` ++ `the image fills the whole window behind the pages, and the scenery is hidden while it shows. ` ++ `To replace only the scenery (the strip behind the page header and the picture at the bottom of the sidebar, pixel art in the pixel theme), import pictures the same way and set scene.header / scene.sidebar.`// themeClient 是 MCP 用到的那几个 RPC;测试里换成假的type themeClient interface {@@ -460,7 +462,7 @@ func mcpTools() []any {map[string]any{"name": "background_import","title": "Import a background image",- "description": "Import a background image from a file on this computer or from base64 data (no URLs). The image is re-encoded without metadata (EXIF/GPS removed) and analyzed. Reference it in a theme as background.image = \"user:<sha256>\". The analysis gives average luminance, how busy it is, its main colors (good accent candidates) and the minimum scrim opacity that keeps text readable.",+ "description": "Import an image from a file on this computer or from base64 data (no URLs), for a window background or the scenery. The image is re-encoded without metadata (EXIF/GPS removed) and analyzed. Reference it in a theme as background.image, scene.header or scene.sidebar = \"user:<sha256>\". The analysis gives average luminance, how busy it is, its main colors (good accent candidates) and the minimum scrim opacity that keeps text readable.","inputSchema": obj(map[string]any{"path": map[string]any{"type": "string", "description": "Path of a PNG, JPEG or GIF file on this computer."},"base64": map[string]any{"type": "string", "description": "Image bytes as base64 (a data: URI prefix is allowed). Use instead of path."},diff --git a/client-core/cmd/pasteferry-cli/mcp_schema.go b/client-core/cmd/pasteferry-cli/mcp_schema.goindex 2f41bfd..bb4afe5 100644--- a/client-core/cmd/pasteferry-cli/mcp_schema.go+++ b/client-core/cmd/pasteferry-cli/mcp_schema.go@@ -105,21 +105,28 @@ func themeSchema() map[string]any {"unit": num(1, 8, "Size of one pixel step for the pixel corner style (notch, bevel, hard shadow offset). Default 2."),"shadow": enum("soft: blurred shadows. hard: solid offset shadows under floating layers only (pixel look). none: flat.", "soft", "hard", "none"),}),- "motion": enum("Animation style: smooth transitions, stepped (frame-by-frame, pixel look) or reduced (no animation).", "smooth", "stepped", "reduced"),- "icons": enum("Icon set: system (macOS/Fluent style) or pixel (Pixelarticons).", "system", "pixel"),- "background": strictObj("Optional background image behind the pages. Import images with background_import first.", map[string]any{- "image": map[string]any{"type": "string", "pattern": "^(asset:[a-z0-9-]{1,40}|user:[0-9a-f]{64})$", "description": "\"user:<sha256>\" from background_import, or \"asset:<name>\" for a bundled image."},- "imageDark": map[string]any{"type": "string", "pattern": "^(asset:[a-z0-9-]{1,40}|user:[0-9a-f]{64})$", "description": "Different image for dark mode; omit to use image in both modes."},+ "motion": enum("Animation style: smooth transitions, stepped (frame-by-frame, pixel look) or reduced (no animation).", "smooth", "stepped", "reduced"),+ "icons": enum("Icon set: system (macOS/Fluent style) or pixel (Pixelarticons).", "system", "pixel"),+ "scenery": map[string]any{"type": "boolean", "description": "Scenery on/off: the strip behind the page header and the picture at the bottom of the sidebar. With the pixel corner style it is pixel art (a landscape and a small camp) unless scene replaces it; set false for a plainer look. Always hidden while a background image shows."},+ "scene": strictObj("Replace the scenery with your own pictures (any corner style). Import images with background_import first. Wide images suit the header (about 900×180 visible, cropped to fill; the bottom fades into the page and the page title sits on it, so a scrim is added automatically); the sidebar picture is 200×96 at the bottom of the sidebar, its top fades into the sidebar.", map[string]any{+ "header": map[string]any{"type": "string", "pattern": "^user:[0-9a-f]{64}$", "description": "\"user:<sha256>\" shown behind the page header."},+ "headerDark": map[string]any{"type": "string", "pattern": "^user:[0-9a-f]{64}$", "description": "Different header picture for dark mode; omit to use header in both modes."},+ "sidebar": map[string]any{"type": "string", "pattern": "^user:[0-9a-f]{64}$", "description": "\"user:<sha256>\" shown at the bottom of the sidebar."},+ "sidebarDark": map[string]any{"type": "string", "pattern": "^user:[0-9a-f]{64}$", "description": "Different sidebar picture for dark mode; omit to use sidebar in both modes."},+ }),+ "background": strictObj("Optional background image filling the window behind the sidebar and pages (desktop main window and the phone app by default). Import images with background_import first. While it shows, the page background is transparent, a scrim keeps text readable and panels become translucent.", map[string]any{+ "image": map[string]any{"type": "string", "pattern": "^user:[0-9a-f]{64}$", "description": "\"user:<sha256>\" from background_import."},+ "imageDark": map[string]any{"type": "string", "pattern": "^user:[0-9a-f]{64}$", "description": "Different image for dark mode; omit to use image in both modes."},"fit": enum("How the image fills the window. tile repeats it (for small pixel-art patterns).", "cover", "contain", "tile"),"align": enum("Which part stays visible when cropped.", "center", "top", "bottom", "left", "right", "topLeft", "topRight", "bottomLeft", "bottomRight"),- "blur": num(0, 40, "Blur radius; higher keeps text more readable over busy photos."),- "scrim": strictObj("Color laid over the image so text stays readable. Use at least the min_scrim value from the image analysis.", map[string]any{+ "blur": num(0, 40, "Blur, 0 to 40 (0 = sharp, 20 or more = fully blurred); higher keeps text more readable over busy photos."),+ "scrim": strictObj("Color laid over the image so text stays readable. Defaults to the theme's background color. The app never shows it lighter than the theme's text and textDim need for 4.5:1 over this image (it measures that itself; the analysis' min_scrim_dark / min_scrim_light are the minimums for pure white / black text).", map[string]any{"color": color("Scrim color: usually black for dark themes and white for light ones."),- "opacity": num(0, 1, "Scrim opacity."),+ "opacity": num(0, 1, "Scrim opacity. Default: the minimum the text needs; set higher for a calmer look."),}),- "surfaceOpacity": num(0.6, 1, "Opacity of panels over the image; lower shows more of the image. Raise it when the image is busy (high luminance_spread)."),+ "surfaceOpacity": num(0.6, 1, "Opacity of the sidebar and panels over the image; lower shows more of the image. Default 0.85. Raise it when the image is busy (high luminance_spread)."),"scope": map[string]any{"type": "array", "items": enum("Where to show the image.", "main", "picker", "mobile"), "description": "Windows that show the image; default main and mobile."},- "accentFromImage": map[string]any{"type": "boolean", "description": "Use the image's main color as accent."},+ "accentFromImage": map[string]any{"type": "boolean", "description": "Use the image's main color as accent (onAccent becomes black or white, whichever reads better)."},}),},}diff --git a/client-core/internal/theme/store.go b/client-core/internal/theme/store.goindex a55f5bd..903741b 100644--- a/client-core/internal/theme/store.go+++ b/client-core/internal/theme/store.go@@ -287,11 +287,12 @@ func (s *Store) Delete(id string) error {// userImages 是主题 t 自己引用的导入背景图的 sha256func (s *Store) userImages(t Theme) []string {- if t.Background == nil {- return nil+ refs := t.Scene.images()+ if t.Background != nil {+ refs = append(refs, t.Background.Image, t.Background.ImageDark)}var out []string- for _, img := range []string{t.Background.Image, t.Background.ImageDark} {+ for _, img := range refs {if sha, ok := strings.CutPrefix(img, "user:"); ok {out = append(out, sha)}diff --git a/client-core/internal/theme/theme.go b/client-core/internal/theme/theme.goindex 2c2c59c..bbd8e42 100644--- a/client-core/internal/theme/theme.go+++ b/client-core/internal/theme/theme.go@@ -60,7 +60,11 @@ type Theme struct {Shape *Shape `json:"shape,omitempty"`Motion string `json:"motion,omitempty"` // smooth、stepped、reducedIcons string `json:"icons,omitempty"` // system、pixel- Background *Background `json:"background,omitempty"`+ // 页面顶部的风景与侧边栏底部的小图:像素边角的主题默认画像素风景,Scene 可以换成自己的图;+ // false 时都不画。显示整窗背景图时总是不画+ Scenery *bool `json:"scenery,omitempty"`+ Scene *Scene `json:"scene,omitempty"`+ Background *Background `json:"background,omitempty"`}type Typography struct {@@ -89,6 +93,22 @@ type Scrim struct {Opacity *float64 `json:"opacity,omitempty"`}+// Scene 把风景换成导入的图(design/themes.md 第 7.6 节):Header 铺在页面标题后面,+// Sidebar 在侧边栏底部。都写成 "user:<sha256>";*Dark 是深色模式另用的一张+type Scene struct {+ Header string `json:"header,omitempty"`+ HeaderDark string `json:"headerDark,omitempty"`+ Sidebar string `json:"sidebar,omitempty"`+ SidebarDark string `json:"sidebarDark,omitempty"`+}++func (c *Scene) images() []string {+ if c == nil {+ return nil+ }+ return []string{c.Header, c.HeaderDark, c.Sidebar, c.SidebarDark}+}+// Background 是背景图,见 design/themes.md 第 7 节type Background struct {// "asset:<名字>" 是 App 自带的图,"user:<sha256>" 是 ImportBackground 导入的图@@ -249,6 +269,11 @@ func validate(t Theme) error {if t.Icons != "" && !oneOf(t.Icons, "system", "pixel") {return invalid("icons 只能是 system 或 pixel,不能是 %q", t.Icons)}+ for _, img := range t.Scene.images() {+ if img != "" && !userRef.MatchString(img) {+ return invalid("scene 里的图片要写成 user:<sha256>(先用 background_import 导入),不能是 %q", img)+ }+ }if b := t.Background; b != nil {for _, img := range []string{b.Image, b.ImageDark} {if img != "" && !assetRef.MatchString(img) && !userRef.MatchString(img) {@@ -401,6 +426,26 @@ func merge(base, child Theme) Theme {if child.Icons != "" {out.Icons = child.Icons}+ if child.Scenery != nil {+ out.Scenery = child.Scenery+ }+ if c := child.Scene; c != nil {+ sc := Scene{}+ if base.Scene != nil {+ sc = *base.Scene+ }+ for _, f := range []struct {+ dst *string+ src string+ }{+ {&sc.Header, c.Header}, {&sc.HeaderDark, c.HeaderDark}, {&sc.Sidebar, c.Sidebar}, {&sc.SidebarDark, c.SidebarDark},+ } {+ if f.src != "" {+ *f.dst = f.src+ }+ }+ out.Scene = &sc+ }if c := child.Background; c != nil {b := Background{}if base.Background != nil {diff --git a/client-core/internal/theme/theme_test.go b/client-core/internal/theme/theme_test.goindex 5539855..0036262 100644--- a/client-core/internal/theme/theme_test.go+++ b/client-core/internal/theme/theme_test.go@@ -88,6 +88,7 @@ func TestValidate(t *testing.T) {func TestMergeWithBase(t *testing.T) {s := newStore(t)put(t, s, `{"schema":1,"id":"mint","name":{"zh-Hans":"薄荷"},"base":"pixel","modes":{"dark":{"accent":"#7CF2C2"}}}`)+ put(t, s, `{"schema":1,"id":"mint-photo","base":"mint","scenery":false}`)raw, err := s.Get("mint", false)if err != nil {@@ -118,6 +119,21 @@ func TestMergeWithBase(t *testing.T) {t.Errorf("名字、base 不对:%v %s", r.Name, r.Base)}+ data, err = s.Get("mint-photo", true)+ if err != nil {+ t.Fatal(err)+ }+ var photo Theme+ if err := json.Unmarshal(data, &photo); err != nil {+ t.Fatal(err)+ }+ if photo.Scenery == nil || *photo.Scenery || photo.Modes["dark"]["accent"] != "#7CF2C2" {+ t.Errorf("scenery 应当保留,颜色沿用 mint:%s", data)+ }+ if err := s.Delete("mint-photo"); err != nil {+ t.Fatal(err)+ }+infos, err := s.List()if err != nil {t.Fatal(err)@@ -356,3 +372,35 @@ func TestAnalyzeBackground(t *testing.T) {t.Errorf("没有这张图:%v", err)}}++func TestSceneImages(t *testing.T) {+ s := newStore(t)+ var buf bytes.Buffer+ png.Encode(&buf, solid(8, 8, color.RGBA{200, 120, 60, 255}))+ info, err := s.ImportBackground(buf.Bytes(), "")+ if err != nil {+ t.Fatal(err)+ }+ if _, _, err := s.Put([]byte(`{"schema":1,"id":"x","scene":{"header":"user:` + strings.Repeat("c", 64) + `"}}`)); err == nil {+ t.Error("没导入的图不能写进 scene")+ }+ if _, _, err := s.Put([]byte(`{"schema":1,"id":"x","scene":{"sidebar":"asset:camp"}}`)); err == nil {+ t.Error("scene 只接受 user: 图片")+ }+ put(t, s, `{"schema":1,"id":"camp","base":"pixel","scene":{"header":"user:`+info.SHA256+`"}}`)+ put(t, s, `{"schema":1,"id":"camp2","base":"camp","scene":{"sidebar":"user:`+info.SHA256+`"}}`)+ data, err := s.Get("camp2", true)+ if err != nil {+ t.Fatal(err)+ }+ var r Theme+ if err := json.Unmarshal(data, &r); err != nil {+ t.Fatal(err)+ }+ if r.Scene == nil || r.Scene.Header != "user:"+info.SHA256 || r.Scene.Sidebar != "user:"+info.SHA256 {+ t.Errorf("scene 应当逐项合并:%s", data)+ }+ if err := s.DeleteBackground(info.SHA256); !errors.Is(err, ErrInUse) {+ t.Errorf("scene 还在用的图不能删:%v", err)+ }+}