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(ui): show background images and custom scenery
baiyuze813fea607626
diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arbindex 60b5929..30eb518 100644--- a/ui/lib/l10n/app_en.arb+++ b/ui/lib/l10n/app_en.arb@@ -1801,5 +1801,39 @@"themeScanlinesDesc": "Overlay faint CRT scanlines on the window. Pixel themes only.","@themeCopyName": {"placeholders": {"name": {"type": "String"}}},"@themeImported": {"placeholders": {"name": {"type": "String"}}},- "@themeImportedWarn": {"placeholders": {"name": {"type": "String"}, "count": {"type": "int"}}}+ "@themeImportedWarn": {"placeholders": {"name": {"type": "String"}, "count": {"type": "int"}}},+ "themeBackground": "Background image",+ "themeBackgroundDesc": "Fills the window behind the sidebar and pages. A scrim on top keeps text readable.",+ "themeBackgroundChoose": "Choose Image…",+ "themeBackgroundChange": "Change…",+ "themeBackgroundRemove": "Remove",+ "themeBlur": "Blur",+ "themeBlurNone": "None",+ "themeBlurLight": "Light",+ "themeBlurStrong": "Strong",+ "themeScrim": "Scrim",+ "themeScrimDesc": "A color laid over the image so text stays readable. It is never lighter than the image needs.",+ "themeScrimAuto": "Auto",+ "themeScrimMore": "Thicker",+ "themeScrimMost": "Thickest",+ "themePanels": "Panels",+ "themePanelsDesc": "How much of the image shows through the sidebar and lists.",+ "themePanelsClear": "Clear",+ "themePanelsMedium": "Medium",+ "themePanelsSolid": "Solid",+ "themeAccentFromImage": "Use image colors",+ "themeAccentFromImageDesc": "Take the accent color from the image.",+ "themeBackgroundPicker": "Also show in Quick Paste",+ "themeScenery": "Show scenery",+ "themeSceneryDesc": "The pictures at the top of pages and the bottom of the sidebar.",+ "themeCopiedForEdit": "Built-in themes can't be changed, so a copy named “{name}” was made and applied",+ "themeBackgroundFootnote": "The background belongs to the current theme. Built-in themes can't be changed: the first change makes a copy. Images stay on this device; JPEG, PNG and GIF are supported.",+ "@themeCopiedForEdit": {"placeholders": {"name": {"type": "String"}}},+ "themeSceneGroup": "Scenery",+ "themeSceneHeader": "Page header",+ "themeSceneHeaderDesc": "A wide picture behind the page titles; its bottom fades into the page. The pixel theme draws a pixel landscape here.",+ "themeSceneSidebar": "Sidebar bottom",+ "themeSceneSidebarDesc": "A small picture at the bottom of the sidebar. The pixel theme draws a small camp here.",+ "themeSceneReset": "Reset",+ "themeSceneFootnote": "Any theme can show your own pictures here. A scrim keeps the page title readable. Scenery is hidden while a background image fills the window."}diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arbindex 9cb3d27..f601bb8 100644--- a/ui/lib/l10n/app_ja.arb+++ b/ui/lib/l10n/app_ja.arb@@ -740,5 +740,38 @@"themeAskAiCopy": "設定をコピー","themeAskAiCopied": "設定をコピーしました","themeScanlines": "走査線",- "themeScanlinesDesc": "ウインドウ全体に薄い CRT 走査線を重ねます。ピクセルテーマのみ"+ "themeScanlinesDesc": "ウインドウ全体に薄い CRT 走査線を重ねます。ピクセルテーマのみ",+ "themeBackground": "背景画像",+ "themeBackgroundDesc": "サイドバーとページの後ろに敷きます。上に重ねるスクリムで文字は読みやすいままです。",+ "themeBackgroundChoose": "画像を選択…",+ "themeBackgroundChange": "変更…",+ "themeBackgroundRemove": "削除",+ "themeBlur": "ぼかし",+ "themeBlurNone": "なし",+ "themeBlurLight": "弱",+ "themeBlurStrong": "強",+ "themeScrim": "スクリム",+ "themeScrimDesc": "画像の上に重ねる色。文字を読みやすく保ち、必要より薄くはなりません。",+ "themeScrimAuto": "自動",+ "themeScrimMore": "濃く",+ "themeScrimMost": "最も濃く",+ "themePanels": "パネル",+ "themePanelsDesc": "サイドバーとリストの下地から背景がどれだけ透けるか。",+ "themePanelsClear": "透明",+ "themePanelsMedium": "普通",+ "themePanelsSolid": "不透明",+ "themeAccentFromImage": "画像の色を使う",+ "themeAccentFromImageDesc": "画像の主な色をアクセントカラーにします。",+ "themeBackgroundPicker": "クイックペーストにも表示",+ "themeScenery": "風景を表示",+ "themeSceneryDesc": "ページ上部とサイドバー下部の画像。",+ "themeCopiedForEdit": "内蔵テーマは変更できないため、「{name}」として複製して適用しました",+ "themeBackgroundFootnote": "背景は現在のテーマに属します。内蔵テーマは変更できないため、最初の変更で複製されます。画像はこのデバイスにのみ保存されます。JPEG、PNG、GIF に対応。",+ "themeSceneGroup": "風景",+ "themeSceneHeader": "ページ上部",+ "themeSceneHeaderDesc": "ページタイトルの後ろに敷く横長の画像。下端はページに溶け込みます。ピクセルテーマではピクセルの風景です。",+ "themeSceneSidebar": "サイドバー下部",+ "themeSceneSidebarDesc": "サイドバー下部の小さな画像。ピクセルテーマでは小さなキャンプです。",+ "themeSceneReset": "元に戻す",+ "themeSceneFootnote": "どのテーマでも自分の画像を置けます。ページタイトルが読めるようにスクリムを自動で重ねます。ウインドウ全体の背景画像があるときは風景を表示しません。"}diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dartindex e73d525..20a893f 100644--- a/ui/lib/l10n/app_localizations.dart+++ b/ui/lib/l10n/app_localizations.dart@@ -4555,6 +4555,204 @@ abstract class AppLocalizations {/// In en, this message translates to:/// **'Overlay faint CRT scanlines on the window. Pixel themes only.'**String get themeScanlinesDesc;++ /// No description provided for @themeBackground.+ ///+ /// In en, this message translates to:+ /// **'Background image'**+ String get themeBackground;++ /// No description provided for @themeBackgroundDesc.+ ///+ /// In en, this message translates to:+ /// **'Fills the window behind the sidebar and pages. A scrim on top keeps text readable.'**+ String get themeBackgroundDesc;++ /// No description provided for @themeBackgroundChoose.+ ///+ /// In en, this message translates to:+ /// **'Choose Image…'**+ String get themeBackgroundChoose;++ /// No description provided for @themeBackgroundChange.+ ///+ /// In en, this message translates to:+ /// **'Change…'**+ String get themeBackgroundChange;++ /// No description provided for @themeBackgroundRemove.+ ///+ /// In en, this message translates to:+ /// **'Remove'**+ String get themeBackgroundRemove;++ /// No description provided for @themeBlur.+ ///+ /// In en, this message translates to:+ /// **'Blur'**+ String get themeBlur;++ /// No description provided for @themeBlurNone.+ ///+ /// In en, this message translates to:+ /// **'None'**+ String get themeBlurNone;++ /// No description provided for @themeBlurLight.+ ///+ /// In en, this message translates to:+ /// **'Light'**+ String get themeBlurLight;++ /// No description provided for @themeBlurStrong.+ ///+ /// In en, this message translates to:+ /// **'Strong'**+ String get themeBlurStrong;++ /// No description provided for @themeScrim.+ ///+ /// In en, this message translates to:+ /// **'Scrim'**+ String get themeScrim;++ /// No description provided for @themeScrimDesc.+ ///+ /// In en, this message translates to:+ /// **'A color laid over the image so text stays readable. It is never lighter than the image needs.'**+ String get themeScrimDesc;++ /// No description provided for @themeScrimAuto.+ ///+ /// In en, this message translates to:+ /// **'Auto'**+ String get themeScrimAuto;++ /// No description provided for @themeScrimMore.+ ///+ /// In en, this message translates to:+ /// **'Thicker'**+ String get themeScrimMore;++ /// No description provided for @themeScrimMost.+ ///+ /// In en, this message translates to:+ /// **'Thickest'**+ String get themeScrimMost;++ /// No description provided for @themePanels.+ ///+ /// In en, this message translates to:+ /// **'Panels'**+ String get themePanels;++ /// No description provided for @themePanelsDesc.+ ///+ /// In en, this message translates to:+ /// **'How much of the image shows through the sidebar and lists.'**+ String get themePanelsDesc;++ /// No description provided for @themePanelsClear.+ ///+ /// In en, this message translates to:+ /// **'Clear'**+ String get themePanelsClear;++ /// No description provided for @themePanelsMedium.+ ///+ /// In en, this message translates to:+ /// **'Medium'**+ String get themePanelsMedium;++ /// No description provided for @themePanelsSolid.+ ///+ /// In en, this message translates to:+ /// **'Solid'**+ String get themePanelsSolid;++ /// No description provided for @themeAccentFromImage.+ ///+ /// In en, this message translates to:+ /// **'Use image colors'**+ String get themeAccentFromImage;++ /// No description provided for @themeAccentFromImageDesc.+ ///+ /// In en, this message translates to:+ /// **'Take the accent color from the image.'**+ String get themeAccentFromImageDesc;++ /// No description provided for @themeBackgroundPicker.+ ///+ /// In en, this message translates to:+ /// **'Also show in Quick Paste'**+ String get themeBackgroundPicker;++ /// No description provided for @themeScenery.+ ///+ /// In en, this message translates to:+ /// **'Show scenery'**+ String get themeScenery;++ /// No description provided for @themeSceneryDesc.+ ///+ /// In en, this message translates to:+ /// **'The pictures at the top of pages and the bottom of the sidebar.'**+ String get themeSceneryDesc;++ /// No description provided for @themeCopiedForEdit.+ ///+ /// In en, this message translates to:+ /// **'Built-in themes can\'t be changed, so a copy named “{name}” was made and applied'**+ String themeCopiedForEdit(String name);++ /// No description provided for @themeBackgroundFootnote.+ ///+ /// In en, this message translates to:+ /// **'The background belongs to the current theme. Built-in themes can\'t be changed: the first change makes a copy. Images stay on this device; JPEG, PNG and GIF are supported.'**+ String get themeBackgroundFootnote;++ /// No description provided for @themeSceneGroup.+ ///+ /// In en, this message translates to:+ /// **'Scenery'**+ String get themeSceneGroup;++ /// No description provided for @themeSceneHeader.+ ///+ /// In en, this message translates to:+ /// **'Page header'**+ String get themeSceneHeader;++ /// No description provided for @themeSceneHeaderDesc.+ ///+ /// In en, this message translates to:+ /// **'A wide picture behind the page titles; its bottom fades into the page. The pixel theme draws a pixel landscape here.'**+ String get themeSceneHeaderDesc;++ /// No description provided for @themeSceneSidebar.+ ///+ /// In en, this message translates to:+ /// **'Sidebar bottom'**+ String get themeSceneSidebar;++ /// No description provided for @themeSceneSidebarDesc.+ ///+ /// In en, this message translates to:+ /// **'A small picture at the bottom of the sidebar. The pixel theme draws a small camp here.'**+ String get themeSceneSidebarDesc;++ /// No description provided for @themeSceneReset.+ ///+ /// In en, this message translates to:+ /// **'Reset'**+ String get themeSceneReset;++ /// No description provided for @themeSceneFootnote.+ ///+ /// In en, this message translates to:+ /// **'Any theme can show your own pictures here. A scrim keeps the page title readable. Scenery is hidden while a background image fills the window.'**+ String get themeSceneFootnote;}class _AppLocalizationsDelegatediff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dartindex 700d493..bac6a77 100644--- a/ui/lib/l10n/app_localizations_en.dart+++ b/ui/lib/l10n/app_localizations_en.dart@@ -2777,4 +2777,114 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get themeScanlinesDesc =>'Overlay faint CRT scanlines on the window. Pixel themes only.';++ @override+ String get themeBackground => 'Background image';++ @override+ String get themeBackgroundDesc =>+ 'Fills the window behind the sidebar and pages. A scrim on top keeps text readable.';++ @override+ String get themeBackgroundChoose => 'Choose Image…';++ @override+ String get themeBackgroundChange => 'Change…';++ @override+ String get themeBackgroundRemove => 'Remove';++ @override+ String get themeBlur => 'Blur';++ @override+ String get themeBlurNone => 'None';++ @override+ String get themeBlurLight => 'Light';++ @override+ String get themeBlurStrong => 'Strong';++ @override+ String get themeScrim => 'Scrim';++ @override+ String get themeScrimDesc =>+ 'A color laid over the image so text stays readable. It is never lighter than the image needs.';++ @override+ String get themeScrimAuto => 'Auto';++ @override+ String get themeScrimMore => 'Thicker';++ @override+ String get themeScrimMost => 'Thickest';++ @override+ String get themePanels => 'Panels';++ @override+ String get themePanelsDesc =>+ 'How much of the image shows through the sidebar and lists.';++ @override+ String get themePanelsClear => 'Clear';++ @override+ String get themePanelsMedium => 'Medium';++ @override+ String get themePanelsSolid => 'Solid';++ @override+ String get themeAccentFromImage => 'Use image colors';++ @override+ String get themeAccentFromImageDesc =>+ 'Take the accent color from the image.';++ @override+ String get themeBackgroundPicker => 'Also show in Quick Paste';++ @override+ String get themeScenery => 'Show scenery';++ @override+ String get themeSceneryDesc =>+ 'The pictures at the top of pages and the bottom of the sidebar.';++ @override+ String themeCopiedForEdit(String name) {+ return 'Built-in themes can\'t be changed, so a copy named “$name” was made and applied';+ }++ @override+ String get themeBackgroundFootnote =>+ 'The background belongs to the current theme. Built-in themes can\'t be changed: the first change makes a copy. Images stay on this device; JPEG, PNG and GIF are supported.';++ @override+ String get themeSceneGroup => 'Scenery';++ @override+ String get themeSceneHeader => 'Page header';++ @override+ String get themeSceneHeaderDesc =>+ 'A wide picture behind the page titles; its bottom fades into the page. The pixel theme draws a pixel landscape here.';++ @override+ String get themeSceneSidebar => 'Sidebar bottom';++ @override+ String get themeSceneSidebarDesc =>+ 'A small picture at the bottom of the sidebar. The pixel theme draws a small camp here.';++ @override+ String get themeSceneReset => 'Reset';++ @override+ String get themeSceneFootnote =>+ 'Any theme can show your own pictures here. A scrim keeps the page title readable. Scenery is hidden while a background image fills the window.';}diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dartindex e17641d..ff72171 100644--- a/ui/lib/l10n/app_localizations_ja.dart+++ b/ui/lib/l10n/app_localizations_ja.dart@@ -2586,4 +2586,108 @@ class AppLocalizationsJa extends AppLocalizations {@overrideString get themeScanlinesDesc => 'ウインドウ全体に薄い CRT 走査線を重ねます。ピクセルテーマのみ';++ @override+ String get themeBackground => '背景画像';++ @override+ String get themeBackgroundDesc => 'サイドバーとページの後ろに敷きます。上に重ねるスクリムで文字は読みやすいままです。';++ @override+ String get themeBackgroundChoose => '画像を選択…';++ @override+ String get themeBackgroundChange => '変更…';++ @override+ String get themeBackgroundRemove => '削除';++ @override+ String get themeBlur => 'ぼかし';++ @override+ String get themeBlurNone => 'なし';++ @override+ String get themeBlurLight => '弱';++ @override+ String get themeBlurStrong => '強';++ @override+ String get themeScrim => 'スクリム';++ @override+ String get themeScrimDesc => '画像の上に重ねる色。文字を読みやすく保ち、必要より薄くはなりません。';++ @override+ String get themeScrimAuto => '自動';++ @override+ String get themeScrimMore => '濃く';++ @override+ String get themeScrimMost => '最も濃く';++ @override+ String get themePanels => 'パネル';++ @override+ String get themePanelsDesc => 'サイドバーとリストの下地から背景がどれだけ透けるか。';++ @override+ String get themePanelsClear => '透明';++ @override+ String get themePanelsMedium => '普通';++ @override+ String get themePanelsSolid => '不透明';++ @override+ String get themeAccentFromImage => '画像の色を使う';++ @override+ String get themeAccentFromImageDesc => '画像の主な色をアクセントカラーにします。';++ @override+ String get themeBackgroundPicker => 'クイックペーストにも表示';++ @override+ String get themeScenery => '風景を表示';++ @override+ String get themeSceneryDesc => 'ページ上部とサイドバー下部の画像。';++ @override+ String themeCopiedForEdit(String name) {+ return '内蔵テーマは変更できないため、「$name」として複製して適用しました';+ }++ @override+ String get themeBackgroundFootnote =>+ '背景は現在のテーマに属します。内蔵テーマは変更できないため、最初の変更で複製されます。画像はこのデバイスにのみ保存されます。JPEG、PNG、GIF に対応。';++ @override+ String get themeSceneGroup => '風景';++ @override+ String get themeSceneHeader => 'ページ上部';++ @override+ String get themeSceneHeaderDesc =>+ 'ページタイトルの後ろに敷く横長の画像。下端はページに溶け込みます。ピクセルテーマではピクセルの風景です。';++ @override+ String get themeSceneSidebar => 'サイドバー下部';++ @override+ String get themeSceneSidebarDesc => 'サイドバー下部の小さな画像。ピクセルテーマでは小さなキャンプです。';++ @override+ String get themeSceneReset => '元に戻す';++ @override+ String get themeSceneFootnote =>+ 'どのテーマでも自分の画像を置けます。ページタイトルが読めるようにスクリムを自動で重ねます。ウインドウ全体の背景画像があるときは風景を表示しません。';}diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dartindex 6f19fa0..9fe8972 100644--- a/ui/lib/l10n/app_localizations_zh.dart+++ b/ui/lib/l10n/app_localizations_zh.dart@@ -2557,6 +2557,109 @@ class AppLocalizationsZh extends AppLocalizations {@overrideString get themeScanlinesDesc => '整个窗口叠一层很淡的 CRT 扫描线,只在像素主题里有效';++ @override+ String get themeBackground => '背景图';++ @override+ String get themeBackgroundDesc => '铺满侧边栏和页面后面。图上盖一层遮罩,文字照样看得清。';++ @override+ String get themeBackgroundChoose => '选择图片…';++ @override+ String get themeBackgroundChange => '更换…';++ @override+ String get themeBackgroundRemove => '移除';++ @override+ String get themeBlur => '模糊';++ @override+ String get themeBlurNone => '不模糊';++ @override+ String get themeBlurLight => '轻微';++ @override+ String get themeBlurStrong => '很强';++ @override+ String get themeScrim => '遮罩';++ @override+ String get themeScrimDesc => '盖在图上的一层颜色,保证文字看得清,不会比需要的更淡。';++ @override+ String get themeScrimAuto => '自动';++ @override+ String get themeScrimMore => '更浓';++ @override+ String get themeScrimMost => '很浓';++ @override+ String get themePanels => '面板';++ @override+ String get themePanelsDesc => '侧边栏和列表底板透出多少背景。';++ @override+ String get themePanelsClear => '通透';++ @override+ String get themePanelsMedium => '适中';++ @override+ String get themePanelsSolid => '不透明';++ @override+ String get themeAccentFromImage => '用图片配色';++ @override+ String get themeAccentFromImageDesc => '用图片的主色作强调色。';++ @override+ String get themeBackgroundPicker => '快捷粘贴窗口也显示';++ @override+ String get themeScenery => '显示风景';++ @override+ String get themeSceneryDesc => '页面顶部和侧边栏底部的图。';++ @override+ String themeCopiedForEdit(String name) {+ return '自带主题不能改,已复制为「$name」并换上';+ }++ @override+ String get themeBackgroundFootnote =>+ '背景图属于当前主题。自带主题不能改,第一次修改时会复制一份。图片只存在这台设备上,支持 JPEG、PNG、GIF。';++ @override+ String get themeSceneGroup => '风景';++ @override+ String get themeSceneHeader => '页面顶部';++ @override+ String get themeSceneHeaderDesc => '铺在页面标题后面的一条宽图,底部渐隐进页面。像素主题这里是像素风景。';++ @override+ String get themeSceneSidebar => '侧边栏底部';++ @override+ String get themeSceneSidebarDesc => '侧边栏底部的一小幅图。像素主题这里是小营地。';++ @override+ String get themeSceneReset => '恢复默认';++ @override+ String get themeSceneFootnote =>+ '任何主题都可以在这里放自己的图,页面标题上会自动盖遮罩保证看得清。设置了整窗背景图时不显示风景。';}/// The translations for Chinese, as used in Hong Kong, using the Han script (`zh_Hant_HK`).@@ -5112,6 +5215,109 @@ class AppLocalizationsZhHantHk extends AppLocalizationsZh {@overrideString get themeScanlinesDesc => '整個視窗疊一層很淡的 CRT 掃描線,只在像素主題裏有效';++ @override+ String get themeBackground => '背景圖';++ @override+ String get themeBackgroundDesc => '鋪滿側邊欄和頁面後面。圖上蓋一層遮罩,文字照樣看得清楚。';++ @override+ String get themeBackgroundChoose => '選擇圖片…';++ @override+ String get themeBackgroundChange => '更換…';++ @override+ String get themeBackgroundRemove => '移除';++ @override+ String get themeBlur => '模糊';++ @override+ String get themeBlurNone => '不模糊';++ @override+ String get themeBlurLight => '輕微';++ @override+ String get themeBlurStrong => '很強';++ @override+ String get themeScrim => '遮罩';++ @override+ String get themeScrimDesc => '蓋在圖上的一層顏色,確保文字看得清楚,不會比需要的更淡。';++ @override+ String get themeScrimAuto => '自動';++ @override+ String get themeScrimMore => '更濃';++ @override+ String get themeScrimMost => '很濃';++ @override+ String get themePanels => '面板';++ @override+ String get themePanelsDesc => '側邊欄和列表底板透出多少背景。';++ @override+ String get themePanelsClear => '通透';++ @override+ String get themePanelsMedium => '適中';++ @override+ String get themePanelsSolid => '不透明';++ @override+ String get themeAccentFromImage => '用圖片配色';++ @override+ String get themeAccentFromImageDesc => '用圖片的主色作強調色。';++ @override+ String get themeBackgroundPicker => '快速貼上視窗也顯示';++ @override+ String get themeScenery => '顯示風景';++ @override+ String get themeSceneryDesc => '頁面頂部和側邊欄底部的圖。';++ @override+ String themeCopiedForEdit(String name) {+ return '內置主題不能修改,已複製為「$name」並套用';+ }++ @override+ String get themeBackgroundFootnote =>+ '背景圖屬於目前的主題。內置主題不能修改,第一次修改時會複製一份。圖片只存在這部裝置上,支援 JPEG、PNG、GIF。';++ @override+ String get themeSceneGroup => '風景';++ @override+ String get themeSceneHeader => '頁面頂部';++ @override+ String get themeSceneHeaderDesc => '鋪在頁面標題後面的一條闊圖,底部漸隱進頁面。像素主題這裏是像素風景。';++ @override+ String get themeSceneSidebar => '側邊欄底部';++ @override+ String get themeSceneSidebarDesc => '側邊欄底部的一小幅圖。像素主題這裏是小營地。';++ @override+ String get themeSceneReset => '恢復預設';++ @override+ String get themeSceneFootnote =>+ '任何主題都可以在這裏放自己的圖,頁面標題上會自動蓋遮罩確保看得清楚。設定了整個視窗的背景圖時不顯示風景。';}/// The translations for Chinese, as used in Taiwan, using the Han script (`zh_Hant_TW`).@@ -7667,4 +7873,107 @@ class AppLocalizationsZhHantTw extends AppLocalizationsZh {@overrideString get themeScanlinesDesc => '整個視窗疊一層很淡的 CRT 掃描線,只在像素主題裡有效';++ @override+ String get themeBackground => '背景圖';++ @override+ String get themeBackgroundDesc => '鋪滿側邊欄和頁面後面。圖上蓋一層遮罩,文字照樣看得清楚。';++ @override+ String get themeBackgroundChoose => '選擇圖片…';++ @override+ String get themeBackgroundChange => '更換…';++ @override+ String get themeBackgroundRemove => '移除';++ @override+ String get themeBlur => '模糊';++ @override+ String get themeBlurNone => '不模糊';++ @override+ String get themeBlurLight => '輕微';++ @override+ String get themeBlurStrong => '很強';++ @override+ String get themeScrim => '遮罩';++ @override+ String get themeScrimDesc => '蓋在圖上的一層顏色,確保文字看得清楚,不會比需要的更淡。';++ @override+ String get themeScrimAuto => '自動';++ @override+ String get themeScrimMore => '更濃';++ @override+ String get themeScrimMost => '很濃';++ @override+ String get themePanels => '面板';++ @override+ String get themePanelsDesc => '側邊欄和列表底板透出多少背景。';++ @override+ String get themePanelsClear => '通透';++ @override+ String get themePanelsMedium => '適中';++ @override+ String get themePanelsSolid => '不透明';++ @override+ String get themeAccentFromImage => '用圖片配色';++ @override+ String get themeAccentFromImageDesc => '用圖片的主色作為強調色。';++ @override+ String get themeBackgroundPicker => '快速貼上視窗也顯示';++ @override+ String get themeScenery => '顯示風景';++ @override+ String get themeSceneryDesc => '頁面頂部和側邊欄底部的圖。';++ @override+ String themeCopiedForEdit(String name) {+ return '內建主題不能修改,已複製為「$name」並套用';+ }++ @override+ String get themeBackgroundFootnote =>+ '背景圖屬於目前的主題。內建主題不能修改,第一次修改時會複製一份。圖片只存在這台裝置上,支援 JPEG、PNG、GIF。';++ @override+ String get themeSceneGroup => '風景';++ @override+ String get themeSceneHeader => '頁面頂部';++ @override+ String get themeSceneHeaderDesc => '鋪在頁面標題後面的一條寬圖,底部漸隱進頁面。像素主題這裡是像素風景。';++ @override+ String get themeSceneSidebar => '側邊欄底部';++ @override+ String get themeSceneSidebarDesc => '側邊欄底部的一小幅圖。像素主題這裡是小營地。';++ @override+ String get themeSceneReset => '恢復預設';++ @override+ String get themeSceneFootnote =>+ '任何主題都可以在這裡放自己的圖,頁面標題上會自動蓋遮罩確保看得清楚。設定了整個視窗的背景圖時不顯示風景。';}diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arbindex 93a5832..a180864 100644--- a/ui/lib/l10n/app_zh.arb+++ b/ui/lib/l10n/app_zh.arb@@ -740,5 +740,38 @@"themeAskAiCopy": "复制配置","themeAskAiCopied": "配置已复制","themeScanlines": "扫描线",- "themeScanlinesDesc": "整个窗口叠一层很淡的 CRT 扫描线,只在像素主题里有效"+ "themeScanlinesDesc": "整个窗口叠一层很淡的 CRT 扫描线,只在像素主题里有效",+ "themeBackground": "背景图",+ "themeBackgroundDesc": "铺满侧边栏和页面后面。图上盖一层遮罩,文字照样看得清。",+ "themeBackgroundChoose": "选择图片…",+ "themeBackgroundChange": "更换…",+ "themeBackgroundRemove": "移除",+ "themeBlur": "模糊",+ "themeBlurNone": "不模糊",+ "themeBlurLight": "轻微",+ "themeBlurStrong": "很强",+ "themeScrim": "遮罩",+ "themeScrimDesc": "盖在图上的一层颜色,保证文字看得清,不会比需要的更淡。",+ "themeScrimAuto": "自动",+ "themeScrimMore": "更浓",+ "themeScrimMost": "很浓",+ "themePanels": "面板",+ "themePanelsDesc": "侧边栏和列表底板透出多少背景。",+ "themePanelsClear": "通透",+ "themePanelsMedium": "适中",+ "themePanelsSolid": "不透明",+ "themeAccentFromImage": "用图片配色",+ "themeAccentFromImageDesc": "用图片的主色作强调色。",+ "themeBackgroundPicker": "快捷粘贴窗口也显示",+ "themeScenery": "显示风景",+ "themeSceneryDesc": "页面顶部和侧边栏底部的图。",+ "themeCopiedForEdit": "自带主题不能改,已复制为「{name}」并换上",+ "themeBackgroundFootnote": "背景图属于当前主题。自带主题不能改,第一次修改时会复制一份。图片只存在这台设备上,支持 JPEG、PNG、GIF。",+ "themeSceneGroup": "风景",+ "themeSceneHeader": "页面顶部",+ "themeSceneHeaderDesc": "铺在页面标题后面的一条宽图,底部渐隐进页面。像素主题这里是像素风景。",+ "themeSceneSidebar": "侧边栏底部",+ "themeSceneSidebarDesc": "侧边栏底部的一小幅图。像素主题这里是小营地。",+ "themeSceneReset": "恢复默认",+ "themeSceneFootnote": "任何主题都可以在这里放自己的图,页面标题上会自动盖遮罩保证看得清。设置了整窗背景图时不显示风景。"}diff --git a/ui/lib/l10n/app_zh_Hant_HK.arb b/ui/lib/l10n/app_zh_Hant_HK.arbindex 0b1deb5..7b1f6c0 100644--- a/ui/lib/l10n/app_zh_Hant_HK.arb+++ b/ui/lib/l10n/app_zh_Hant_HK.arb@@ -740,5 +740,38 @@"themeAskAiCopy": "複製設定","themeAskAiCopied": "設定已複製","themeScanlines": "掃描線",- "themeScanlinesDesc": "整個視窗疊一層很淡的 CRT 掃描線,只在像素主題裏有效"+ "themeScanlinesDesc": "整個視窗疊一層很淡的 CRT 掃描線,只在像素主題裏有效",+ "themeBackground": "背景圖",+ "themeBackgroundDesc": "鋪滿側邊欄和頁面後面。圖上蓋一層遮罩,文字照樣看得清楚。",+ "themeBackgroundChoose": "選擇圖片…",+ "themeBackgroundChange": "更換…",+ "themeBackgroundRemove": "移除",+ "themeBlur": "模糊",+ "themeBlurNone": "不模糊",+ "themeBlurLight": "輕微",+ "themeBlurStrong": "很強",+ "themeScrim": "遮罩",+ "themeScrimDesc": "蓋在圖上的一層顏色,確保文字看得清楚,不會比需要的更淡。",+ "themeScrimAuto": "自動",+ "themeScrimMore": "更濃",+ "themeScrimMost": "很濃",+ "themePanels": "面板",+ "themePanelsDesc": "側邊欄和列表底板透出多少背景。",+ "themePanelsClear": "通透",+ "themePanelsMedium": "適中",+ "themePanelsSolid": "不透明",+ "themeAccentFromImage": "用圖片配色",+ "themeAccentFromImageDesc": "用圖片的主色作強調色。",+ "themeBackgroundPicker": "快速貼上視窗也顯示",+ "themeScenery": "顯示風景",+ "themeSceneryDesc": "頁面頂部和側邊欄底部的圖。",+ "themeCopiedForEdit": "內置主題不能修改,已複製為「{name}」並套用",+ "themeBackgroundFootnote": "背景圖屬於目前的主題。內置主題不能修改,第一次修改時會複製一份。圖片只存在這部裝置上,支援 JPEG、PNG、GIF。",+ "themeSceneGroup": "風景",+ "themeSceneHeader": "頁面頂部",+ "themeSceneHeaderDesc": "鋪在頁面標題後面的一條闊圖,底部漸隱進頁面。像素主題這裏是像素風景。",+ "themeSceneSidebar": "側邊欄底部",+ "themeSceneSidebarDesc": "側邊欄底部的一小幅圖。像素主題這裏是小營地。",+ "themeSceneReset": "恢復預設",+ "themeSceneFootnote": "任何主題都可以在這裏放自己的圖,頁面標題上會自動蓋遮罩確保看得清楚。設定了整個視窗的背景圖時不顯示風景。"}diff --git a/ui/lib/l10n/app_zh_Hant_TW.arb b/ui/lib/l10n/app_zh_Hant_TW.arbindex 5116648..ceb3410 100644--- a/ui/lib/l10n/app_zh_Hant_TW.arb+++ b/ui/lib/l10n/app_zh_Hant_TW.arb@@ -740,5 +740,38 @@"themeAskAiCopy": "複製設定","themeAskAiCopied": "設定已複製","themeScanlines": "掃描線",- "themeScanlinesDesc": "整個視窗疊一層很淡的 CRT 掃描線,只在像素主題裡有效"+ "themeScanlinesDesc": "整個視窗疊一層很淡的 CRT 掃描線,只在像素主題裡有效",+ "themeBackground": "背景圖",+ "themeBackgroundDesc": "鋪滿側邊欄和頁面後面。圖上蓋一層遮罩,文字照樣看得清楚。",+ "themeBackgroundChoose": "選擇圖片…",+ "themeBackgroundChange": "更換…",+ "themeBackgroundRemove": "移除",+ "themeBlur": "模糊",+ "themeBlurNone": "不模糊",+ "themeBlurLight": "輕微",+ "themeBlurStrong": "很強",+ "themeScrim": "遮罩",+ "themeScrimDesc": "蓋在圖上的一層顏色,確保文字看得清楚,不會比需要的更淡。",+ "themeScrimAuto": "自動",+ "themeScrimMore": "更濃",+ "themeScrimMost": "很濃",+ "themePanels": "面板",+ "themePanelsDesc": "側邊欄和列表底板透出多少背景。",+ "themePanelsClear": "通透",+ "themePanelsMedium": "適中",+ "themePanelsSolid": "不透明",+ "themeAccentFromImage": "用圖片配色",+ "themeAccentFromImageDesc": "用圖片的主色作為強調色。",+ "themeBackgroundPicker": "快速貼上視窗也顯示",+ "themeScenery": "顯示風景",+ "themeSceneryDesc": "頁面頂部和側邊欄底部的圖。",+ "themeCopiedForEdit": "內建主題不能修改,已複製為「{name}」並套用",+ "themeBackgroundFootnote": "背景圖屬於目前的主題。內建主題不能修改,第一次修改時會複製一份。圖片只存在這台裝置上,支援 JPEG、PNG、GIF。",+ "themeSceneGroup": "風景",+ "themeSceneHeader": "頁面頂部",+ "themeSceneHeaderDesc": "鋪在頁面標題後面的一條寬圖,底部漸隱進頁面。像素主題這裡是像素風景。",+ "themeSceneSidebar": "側邊欄底部",+ "themeSceneSidebarDesc": "側邊欄底部的一小幅圖。像素主題這裡是小營地。",+ "themeSceneReset": "恢復預設",+ "themeSceneFootnote": "任何主題都可以在這裡放自己的圖,頁面標題上會自動蓋遮罩確保看得清楚。設定了整個視窗的背景圖時不顯示風景。"}diff --git a/ui/lib/main.dart b/ui/lib/main.dartindex e7cb660..af381a4 100644--- a/ui/lib/main.dart+++ b/ui/lib/main.dart@@ -23,6 +23,7 @@ import 'widgets/common.dart';import 'widgets/pairing_dialog.dart';import 'widgets/friends_dialog.dart';import 'widgets/incoming_dialog.dart';+import 'widgets/backdrop.dart';import 'widgets/update_dialog.dart';import 'icons.dart';import 'notices.dart';@@ -112,7 +113,12 @@ class _PasteFerryAppState extends State<PasteFerryApp> {resolveLocale(preferred),builder: (context, child) {appL10n = context.l10n;- return ThemeTextScale(child: PixelScanlinesLayer(on: theme.scanlines, child: child!));+ return ThemeTextScale(+ child: PixelScanlinesLayer(+ on: theme.scanlines,+ child: ThemedBackdrop(controller: theme, window: 'main', child: child!),+ ),+ );},home: const Shell(),);@@ -361,7 +367,8 @@ class _ShellState extends State<Shell> with WidgetsBindingObserver {// 像素主题:页面顶部垫一块场景(夜里的远山、白天的云),其他主题不画child: Stack(children: [- if (context.shape.pixel) const Positioned(left: 0, right: 0, top: 0, child: PixelScene()),+ if (context.showScenery)+ Positioned(left: 0, right: 0, top: 0, child: SceneHeader(controller: state.theme)),Positioned.fill(child: needsService? const ServicePage()@@ -399,7 +406,7 @@ class _Sidebar extends StatelessWidget {return Container(width: 200,decoration: BoxDecoration(- color: p.sidebar,+ color: context.panel(p.sidebar),border: Border(right: BorderSide(color: p.border)),),child: Column(@@ -482,7 +489,7 @@ class _Sidebar extends StatelessWidget {const Spacer(),const _UpdateHint(),// 像素主题:底下一小块营地(深色是帐篷与篝火,浅色是小房子与花)- if (context.shape.pixel) const PixelCamp(),+ if (context.showScenery) SceneSidebar(controller: state.theme),const _ConnectionFooter(),],),diff --git a/ui/lib/mobile/mobile_app.dart b/ui/lib/mobile/mobile_app.dartindex 3f48d83..7cb05d2 100644--- a/ui/lib/mobile/mobile_app.dart+++ b/ui/lib/mobile/mobile_app.dart@@ -10,6 +10,7 @@ import '../icons.dart';import '../main.dart' show AppScope;import '../notices.dart';import '../theme.dart';+import '../widgets/backdrop.dart';import '../widgets/common.dart';import '../widgets/incoming_dialog.dart';import '../widgets/pairing_dialog.dart';@@ -103,7 +104,12 @@ class _MobileAppState extends State<MobileApp> with WidgetsBindingObserver {localeListResolutionCallback: (preferred, _) => resolveLocale(preferred),builder: (context, child) {appL10n = context.l10n;- return ThemeTextScale(child: ToastScope(top: true, child: child!));+ return ThemeTextScale(+ child: ToastScope(+ top: true,+ child: ThemedBackdrop(controller: _state.theme, window: 'mobile', child: child!),+ ),+ );},home: MobileShell(startError: _startError, onRetry: _start),);diff --git a/ui/lib/mobile/records_tab.dart b/ui/lib/mobile/records_tab.dartindex 5893c89..a5fb45f 100644--- a/ui/lib/mobile/records_tab.dart+++ b/ui/lib/mobile/records_tab.dart@@ -13,6 +13,7 @@ import '../widgets/common.dart';import '../pixel_theme.dart';import 'ui.dart';import 'record_actions.dart';+import '../widgets/backdrop.dart';/// 复制记录(design/phone-sync.md 3.2.4 节):搜索、按类型筛选、列表;点开看详情,长按删除。class RecordsTab extends StatefulWidget {@@ -77,7 +78,7 @@ class _RecordsTabState extends State<RecordsTab> {padding: const EdgeInsets.fromLTRB(Insets.lg, 0, Insets.lg, Insets.xl),sliver: DecoratedSliver(decoration: BoxDecoration(- color: p.surface,+ color: context.panel(p.surface),borderRadius: BorderRadius.circular(context.shape.lg),border: Border.all(color: p.border),),@@ -466,7 +467,7 @@ class _MediaBody extends StatelessWidget {Container(clipBehavior: Clip.antiAlias,decoration: BoxDecoration(- color: p.surface,+ color: context.panel(p.surface),borderRadius: BorderRadius.circular(context.shape.lg),border: Border.all(color: p.border),),diff --git a/ui/lib/mobile/send_tab.dart b/ui/lib/mobile/send_tab.dartindex d2a3af1..ed867fc 100644--- a/ui/lib/mobile/send_tab.dart+++ b/ui/lib/mobile/send_tab.dart@@ -15,6 +15,7 @@ import 'file_picker.dart';import 'records_tab.dart' show showRecordSheet;import 'ui.dart';import '../pixel_art.dart';+import '../widgets/backdrop.dart';/// 发送页(design/phone-sync.md 3.2.3 节):手机上的文字发给在线的设备。///@@ -272,7 +273,7 @@ class _SentRecords extends StatelessWidget {),DecoratedBox(decoration: BoxDecoration(- color: p.surface,+ color: context.panel(p.surface),borderRadius: BorderRadius.circular(context.shape.lg),border: Border.all(color: p.border),),diff --git a/ui/lib/mobile/settings_tab.dart b/ui/lib/mobile/settings_tab.dartindex 12e38c2..58df84e 100644--- a/ui/lib/mobile/settings_tab.dart+++ b/ui/lib/mobile/settings_tab.dart@@ -190,6 +190,28 @@ class _SettingsTabState extends State<SettingsTab> with WidgetsBindingObserver {theme.setMode,),),+ // 背景图:选一张照片铺在底下。自带主题不能改,第一次设置时复制一份+ MobileTile(+ title: l.themeBackground,+ subtitle: l.themeBackgroundDesc,+ trailing: Icon(Icons.chevron_right, color: p.textFaint),+ onTap: () => _pick<String>(+ context,+ l.themeBackground,+ [+ ('choose', theme.background == null ? l.themeBackgroundChoose : l.themeBackgroundChange),+ if (theme.background != null) ('remove', l.themeBackgroundRemove),+ ],+ '',+ (v) async {+ if (v == 'remove') return theme.removeBackground();+ final files = await Host.pickFiles(photos: true);+ if (files.isEmpty) return;+ final copied = await theme.setBackgroundImage(files.first.path, l);+ if (copied != null && context.mounted) showToast(context, l.themeCopiedForEdit(copied));+ },+ ),+ ),],);},diff --git a/ui/lib/mobile/ui.dart b/ui/lib/mobile/ui.dartindex f4c6c15..605ec4f 100644--- a/ui/lib/mobile/ui.dart+++ b/ui/lib/mobile/ui.dart@@ -9,6 +9,7 @@ import '../main.dart' show AppScope;import '../theme.dart';import '../pixel_theme.dart';import 'host.dart';+import '../widgets/backdrop.dart';/// 手机 App 的界面部件。样子与手机网页传输(web/phone/src/ui.tsx、App.tsx)一一对应,/// 配色、圆角、间距用桌面的设计系统(theme.dart):两边只是功能多少不同,看起来是同一个产品。@@ -281,7 +282,7 @@ class MobileGroup extends StatelessWidget {Container(clipBehavior: Clip.antiAlias,decoration: BoxDecoration(- color: p.surface,+ color: context.panel(p.surface),borderRadius: BorderRadius.circular(context.shape.lg),border: Border.all(color: p.border),),@@ -457,7 +458,7 @@ class _LanNoticeState extends State<LanNotice> with WidgetsBindingObserver {child: Container(padding: const EdgeInsets.all(Insets.lg),decoration: BoxDecoration(- color: p.surface,+ color: context.panel(p.surface),borderRadius: BorderRadius.circular(context.shape.lg),border: Border.all(color: p.border),),diff --git a/ui/lib/pages/appearance_settings.dart b/ui/lib/pages/appearance_settings.dartindex 617c353..248e848 100644--- a/ui/lib/pages/appearance_settings.dart+++ b/ui/lib/pages/appearance_settings.dart@@ -1,5 +1,6 @@import 'dart:convert';import 'dart:io';+import 'dart:math' as math;import 'package:file_selector/file_selector.dart';import 'package:flutter/material.dart';@@ -104,6 +105,8 @@ class AppearanceSection extends StatelessWidget {],),),+ _SceneSection(theme: theme),+ _BackgroundSection(theme: theme),],);},@@ -141,6 +144,242 @@ Future<void> _run(BuildContext context, Future<void> Function() action) async {}}+/// 「风景」:页面顶部的宽图与侧边栏底部的小图换成自己的图(design/themes.md 第 7.6 节),+/// 像素主题默认是像素风景与营地;也可以整个关掉+class _SceneSection extends StatelessWidget {+ const _SceneSection({required this.theme});++ final ThemeController theme;++ @override+ Widget build(BuildContext context) {+ final l = context.l10n;+ final brightness = Theme.of(context).brightness;+ final scene = theme.spec.scene;++ Widget row(String part, String title, String description) {+ final bytes = theme.sceneImage(part, brightness);+ final set = scene?.shaFor(part, brightness) != null;+ return SettingRow(+ title: title,+ description: description,+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (bytes != null)+ Padding(+ padding: const EdgeInsets.only(right: Insets.md),+ child: ClipRRect(+ borderRadius: BorderRadius.circular(context.shape.pixel ? 0 : context.shape.sm),+ child: Image.memory(bytes, width: 64, height: 40, fit: BoxFit.cover, cacheWidth: 128, gaplessPlayback: true),+ ),+ ),+ OutlinedButton(+ onPressed: () => _choose(context, part),+ child: Text(set ? l.themeBackgroundChange : l.themeBackgroundChoose),+ ),+ if (set) ...[+ const SizedBox(width: Insets.sm),+ TextButton(+ onPressed: () => _run(context, () => theme.resetSceneImage(part)),+ child: Text(l.themeSceneReset),+ ),+ ],+ ],+ ),+ );+ }++ return GroupSection(+ title: l.themeSceneGroup,+ footnote: l.themeSceneFootnote,+ child: GroupBox(+ children: [+ SettingRow(+ title: l.themeScenery,+ description: l.themeSceneryDesc,+ child: SmallSwitch(+ value: theme.spec.scenery,+ onChanged: (v) => _run(context, () async {+ final copied = await theme.setScenery(v, l);+ if (copied != null && context.mounted) showToast(context, l.themeCopiedForEdit(copied));+ }),+ ),+ ),+ if (theme.spec.scenery) ...[+ row('header', l.themeSceneHeader, l.themeSceneHeaderDesc),+ row('sidebar', l.themeSceneSidebar, l.themeSceneSidebarDesc),+ ],+ ],+ ),+ );+ }++ Future<void> _choose(BuildContext context, String part) async {+ final l = context.l10n;+ final file = await openFile(acceptedTypeGroups: const [+ XTypeGroup(label: 'images', extensions: ['jpg', 'jpeg', 'png', 'gif']),+ ]);+ if (file == null || !context.mounted) return;+ await _run(context, () async {+ final copied = await theme.setSceneImage(part, file.path, l);+ if (copied != null && context.mounted) showToast(context, l.themeCopiedForEdit(copied));+ });+ }+}++/// 「背景图」:给当前主题选一张图铺在窗口底下,调模糊、遮罩、面板透明度(design/themes.md 第 7 节)。+/// 档位是几个固定值;AI 通过 MCP 可以写任意值,这里显示最接近的一档+class _BackgroundSection extends StatelessWidget {+ const _BackgroundSection({required this.theme});++ final ThemeController theme;++ static const _blurs = [0.0, 8.0, 24.0];+ static const _panels = [0.7, ThemeBackground.defaultSurfaceOpacity, 1.0];++ static double _nearest(List<double> options, double v) =>+ options.reduce((a, b) => (a - v).abs() <= (b - v).abs() ? a : b);++ @override+ Widget build(BuildContext context) {+ final l = context.l10n;+ final p = context.palette;+ final bg = theme.background;+ final brightness = Theme.of(context).brightness;+ final thumb = theme.backdrop(brightness, 'main', p) ?? theme.backdrop(brightness, 'picker', p);++ // 遮罩「自动」是文字看得清所需的最低浓度,「更浓」「很浓」在它上面加+ final auto = thumb?.minScrim ?? 0.0;+ final scrimLevel = switch ((bg?.scrimOpacity ?? auto) - auto) {+ < 0.075 => 0,+ < 0.225 => 1,+ _ => 2,+ };++ Future<void> edit(void Function(Map<String, dynamic> bg) f) => _run(context, () => theme.editBackground(f));++ return GroupSection(+ title: l.themeBackground,+ footnote: l.themeBackgroundFootnote,+ child: GroupBox(+ children: [+ SettingRow(+ title: l.themeBackground,+ description: l.themeBackgroundDesc,+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (thumb != null)+ Padding(+ padding: const EdgeInsets.only(right: Insets.md),+ child: ClipRRect(+ borderRadius: BorderRadius.circular(context.shape.pixel ? 0 : context.shape.sm),+ child: Image.memory(+ thumb.sharp ?? thumb.blurred!,+ width: 64,+ height: 40,+ fit: BoxFit.cover,+ cacheWidth: 128,+ gaplessPlayback: true,+ ),+ ),+ ),+ OutlinedButton(+ onPressed: () => _choose(context),+ child: Text(bg == null ? l.themeBackgroundChoose : l.themeBackgroundChange),+ ),+ if (bg != null) ...[+ const SizedBox(width: Insets.sm),+ TextButton(+ onPressed: () => _run(context, theme.removeBackground),+ child: Text(l.themeBackgroundRemove),+ ),+ ],+ ],+ ),+ ),+ if (bg != null) ...[+ SettingRow(+ title: l.themeBlur,+ child: Segmented<double>(+ value: _nearest(_blurs, bg.blur),+ segments: [(_blurs[0], l.themeBlurNone), (_blurs[1], l.themeBlurLight), (_blurs[2], l.themeBlurStrong)],+ onChanged: (v) => edit((b) => b['blur'] = v),+ ),+ ),+ SettingRow(+ title: l.themeScrim,+ description: l.themeScrimDesc,+ child: Segmented<int>(+ value: scrimLevel,+ segments: [(0, l.themeScrimAuto), (1, l.themeScrimMore), (2, l.themeScrimMost)],+ onChanged: (v) => edit((b) {+ final scrim = (b['scrim'] as Map?)?.cast<String, dynamic>() ?? <String, dynamic>{};+ if (v == 0) {+ scrim.remove('opacity');+ } else {+ scrim['opacity'] = double.parse(math.min(1.0, auto + 0.15 * v).toStringAsFixed(2));+ }+ if (scrim.isEmpty) {+ b.remove('scrim');+ } else {+ b['scrim'] = scrim;+ }+ }),+ ),+ ),+ SettingRow(+ title: l.themePanels,+ description: l.themePanelsDesc,+ child: Segmented<double>(+ value: _nearest(_panels, bg.surfaceOpacity),+ segments: [+ (_panels[0], l.themePanelsClear),+ (_panels[1], l.themePanelsMedium),+ (_panels[2], l.themePanelsSolid),+ ],+ onChanged: (v) => edit((b) => b['surfaceOpacity'] = v),+ ),+ ),+ SettingRow(+ title: l.themeAccentFromImage,+ description: l.themeAccentFromImageDesc,+ child: SmallSwitch(+ value: bg.accentFromImage,+ onChanged: (v) => edit((b) => b['accentFromImage'] = v),+ ),+ ),+ SettingRow(+ title: l.themeBackgroundPicker,+ child: SmallSwitch(+ value: bg.scope.contains('picker'),+ onChanged: (v) => edit((b) {+ final scope = {...bg.scope};+ v ? scope.add('picker') : scope.remove('picker');+ b['scope'] = scope.toList();+ }),+ ),+ ),+ ],+ ],+ ),+ );+ }++ Future<void> _choose(BuildContext context) async {+ final l = context.l10n;+ final file = await openFile(acceptedTypeGroups: const [+ XTypeGroup(label: 'images', extensions: ['jpg', 'jpeg', 'png', 'gif']),+ ]);+ if (file == null || !context.mounted) return;+ await _run(context, () async {+ final copied = await theme.setBackgroundImage(file.path, l);+ if (copied != null && context.mounted) showToast(context, l.themeCopiedForEdit(copied));+ });+ }+}+/// 一张主题卡片:上面是用这套主题真实渲染的缩略界面,下面是名字;悬停时右边出现「⋯」菜单class _ThemeCard extends StatefulWidget {const _ThemeCard({required this.choice, required this.selected});diff --git a/ui/lib/pages/favorites_page.dart b/ui/lib/pages/favorites_page.dartindex 3423694..f70e9c8 100644--- a/ui/lib/pages/favorites_page.dart+++ b/ui/lib/pages/favorites_page.dart@@ -16,6 +16,7 @@ import '../widgets/image_preview_dialog.dart';import '../widgets/record_hover.dart';import '../pixel_theme.dart';import '../pixel_art.dart';+import '../widgets/backdrop.dart';/// 收藏:另存的一份,不会被自动清理。见 design/quick-paste-and-favorites.md 第 3 节。///@@ -113,7 +114,7 @@ class _FavoritesPageState extends State<FavoritesPage> {padding: const EdgeInsets.fromLTRB(Insets.xl, 0, Insets.xl, Insets.xl),sliver: DecoratedSliver(decoration: BoxDecoration(- color: context.palette.surface,+ color: context.panel(context.palette.surface),borderRadius: BorderRadius.circular(context.shape.md),border: Border.all(color: context.palette.border),),diff --git a/ui/lib/pages/friends_page.dart b/ui/lib/pages/friends_page.dartindex 5b9697e..c404376 100644--- a/ui/lib/pages/friends_page.dart+++ b/ui/lib/pages/friends_page.dart@@ -11,6 +11,7 @@ import '../widgets/common.dart';import '../widgets/friends_dialog.dart';import '../widgets/send_dialog.dart';import 'send_page.dart';+import '../widgets/backdrop.dart';/// 侧边栏的「好友」:左边是好友列表,右边是选中好友的状态、发送与传输记录。/// 底部是「允许这些人给我发文件」和本机显示的名字、头像。@@ -111,7 +112,7 @@ class _FriendsPageState extends State<FriendsPage> {Expanded(child: Container(decoration: BoxDecoration(- color: p.surface,+ color: context.panel(p.surface),borderRadius: BorderRadius.circular(context.shape.md),border: Border.all(color: p.border),),diff --git a/ui/lib/pages/history_page.dart b/ui/lib/pages/history_page.dartindex 3bee538..aeab42a 100644--- a/ui/lib/pages/history_page.dart+++ b/ui/lib/pages/history_page.dart@@ -17,6 +17,7 @@ import '../icons.dart';import '../platform.dart';import '../pixel_theme.dart';import '../pixel_art.dart';+import '../widgets/backdrop.dart';export '../records.dart' show kindIcon, recordTitle, highlightMatches;@@ -137,7 +138,7 @@ class _HistoryPageState extends State<HistoryPage> {padding: const EdgeInsets.fromLTRB(Insets.xl, 0, Insets.xl, Insets.xl),sliver: DecoratedSliver(decoration: BoxDecoration(- color: context.palette.surface,+ color: context.panel(context.palette.surface),borderRadius: BorderRadius.circular(context.shape.md),border: Border.all(color: context.palette.border),),diff --git a/ui/lib/picker/picker_view.dart b/ui/lib/picker/picker_view.dartindex 91bacb3..3c578e7 100644--- a/ui/lib/picker/picker_view.dart+++ b/ui/lib/picker/picker_view.dart@@ -11,6 +11,7 @@ import '../icons.dart';import '../records.dart';import '../theme.dart';import '../widgets/common.dart' show committedText, humanBytes, relativeTime;+import '../widgets/backdrop.dart';import '../widgets/record_hover.dart';import '../pixel_theme.dart';import 'picker_state.dart';@@ -232,18 +233,23 @@ class _PickerViewState extends State<PickerView> {borderRadius: _mac ? BorderRadius.circular(context.shape.lg) : null,border: Border.all(color: p.border),),- child: ListenableBuilder(- listenable: s,- builder: (context, _) => Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- _searchBar(context),- _tabs(context),- Divider(height: 1, color: p.separator),- Expanded(child: _list(context)),- Divider(height: 1, color: p.separator),- _footer(context),- ],+ // 主题的背景图只有 scope 里写了 picker 才显示:窗口小,主要用来快速认字+ child: ThemedBackdrop(+ controller: s.theme,+ window: 'picker',+ child: ListenableBuilder(+ listenable: s,+ builder: (context, _) => Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ _searchBar(context),+ _tabs(context),+ Divider(height: 1, color: p.separator),+ Expanded(child: _list(context)),+ Divider(height: 1, color: p.separator),+ _footer(context),+ ],+ ),),),),diff --git a/ui/lib/scrim.dart b/ui/lib/scrim.dartnew file mode 100644index 0000000..b9ef3aa--- /dev/null+++ b/ui/lib/scrim.dart@@ -0,0 +1,87 @@+import 'dart:math' as math;+import 'dart:typed_data';+import 'dart:ui' as ui;++import 'package:flutter/painting.dart';++import 'theme.dart';++// 背景图上的遮罩至少要多浓(design/themes.md 第 7.2 节)。+//+// 后台服务的分析结果是按纯黑、纯白文字算的;页面上的字是主题的 text、textDim(灰色,要求更高),+// 还要叠在半透明的面板上。所以界面拿缩小的图自己算:遮罩按 sRGB 数值叠上去(与 Flutter 画的一样),+// 每个小块都试一遍,取 95% 的小块都够用的浓度——零星的星星、高光不算。++/// 把图缩到 64 宽,取出 RGBA 像素,给 [minScrim] 用+Future<Uint8List> sampleImage(Uint8List bytes) async {+ final codec = await ui.instantiateImageCodec(bytes, targetWidth: 64);+ final frame = await codec.getNextFrame();+ try {+ final data = await frame.image.toByteData(format: ui.ImageByteFormat.rawRgba);+ return data!.buffer.asUint8List();+ } finally {+ frame.image.dispose();+ codec.dispose();+ }+}++/// 遮罩颜色 [scrim] 至少多浓(0 到 1),正文与次要文字才在图上、侧边栏上、面板上都达到 4.5:1。+/// 遮罩铺满了也不够(遮罩颜色本身和字太像)时返回 1+double minScrim(+ Uint8List rgba, {+ required Color scrim,+ required AppPalette palette,+ required double surfaceOpacity,+}) {+ final texts = [_rgb(palette.text), _rgb(palette.textDim)];+ final panels = [_rgb(palette.surface), _rgb(palette.sidebar)];+ final s = _rgb(scrim);++ bool readable(List<double> c) {+ for (final t in texts) {+ if (_contrast(t, c) < 4.5) return false;+ for (final p in panels) {+ if (_contrast(t, _mix(c, p, surfaceOpacity)) < 4.5) return false;+ }+ }+ return true;+ }++ final need = <double>[];+ for (var i = 0; i + 3 < rgba.length; i += 4) {+ if (rgba[i + 3] == 0) continue;+ final px = [rgba[i].toDouble(), rgba[i + 1].toDouble(), rgba[i + 2].toDouble()];+ var lo = 0.0, hi = 1.0;+ if (readable(px)) {+ hi = 0;+ } else if (!readable(_mix(px, s, 1))) {+ need.add(1);+ continue;+ }+ for (var k = 0; k < 12 && hi > 0; k++) {+ final mid = (lo + hi) / 2;+ readable(_mix(px, s, mid)) ? hi = mid : lo = mid;+ }+ need.add(hi);+ }+ if (need.isEmpty) return 0;+ need.sort();+ return need[((need.length - 1) * 0.95).floor()];+}++List<double> _rgb(Color c) => [c.r * 255, c.g * 255, c.b * 255];++List<double> _mix(List<double> a, List<double> b, double t) =>+ [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];++double _channel(double v) {+ final c = v / 255;+ return c <= 0.04045 ? c / 12.92 : math.pow((c + 0.055) / 1.055, 2.4).toDouble();+}++double _luminance(List<double> c) => 0.2126 * _channel(c[0]) + 0.7152 * _channel(c[1]) + 0.0722 * _channel(c[2]);++double _contrast(List<double> a, List<double> b) {+ final la = _luminance(a), lb = _luminance(b);+ return (math.max(la, lb) + 0.05) / (math.min(la, lb) + 0.05);+}diff --git a/ui/lib/theme.dart b/ui/lib/theme.dartindex ba9458b..ec63741 100644--- a/ui/lib/theme.dart+++ b/ui/lib/theme.dart@@ -50,6 +50,9 @@ class AppThemeSpec {this.typography = AppTypography.standard,this.motion = AppMotion.standard,this.pixelIcons = false,+ this.scenery = true,+ this.scene,+ this.background,});final String id;@@ -62,6 +65,15 @@ class AppThemeSpec {/// 用像素图标([AppIcons] 里的 Pixelarticons),而不是系统风格的图标final bool pixelIcons;+ /// 页面顶部的风景与侧边栏底部的小图(像素主题默认是像素风景与营地);显示背景图时总是不画+ final bool scenery;++ /// 换成导入的图的风景;null 时像素主题画像素风景,其他主题不画+ final ThemeScene? scene;++ /// 铺在窗口最底下的背景图(design/themes.md 第 7 节);null 表示没有+ final ThemeBackground? background;+AppPalette palette(Brightness brightness) => brightness == Brightness.dark ? dark : light;static const standard = AppThemeSpec(id: 'default', light: AppPalette.light, dark: AppPalette.dark);@@ -75,6 +87,80 @@ class AppThemeSpec {static AppThemeSpec byId(String id) => builtins[id] ?? standard;}+/// 风景换成的图(design/themes.md 第 7.6 节),都写成 `user:<sha256>`+@immutable+class ThemeScene {+ const ThemeScene({this.header, this.headerDark, this.sidebar, this.sidebarDark});++ final String? header;+ final String? headerDark;+ final String? sidebar;+ final String? sidebarDark;++ bool get isEmpty => header == null && headerDark == null && sidebar == null && sidebarDark == null;++ /// [part] 是 header 或 sidebar;这个模式下用的图的 sha256,没有时为 null+ String? shaFor(String part, Brightness b) {+ final light = part == 'header' ? header : sidebar;+ final dark = part == 'header' ? headerDark : sidebarDark;+ final ref = b == Brightness.dark ? (dark ?? light) : light;+ return ref != null && ref.startsWith('user:') ? ref.substring(5) : null;+ }+}++/// 背景图怎么铺满窗口+enum BackgroundFit { cover, contain, tile }++/// 主题里的背景图(design/themes.md 第 7.1 节)。图片存在后台服务里,[image] 写成 `user:<sha256>`。+@immutable+class ThemeBackground {+ const ThemeBackground({+ this.image,+ this.imageDark,+ this.fit = BackgroundFit.cover,+ this.align = Alignment.center,+ this.alignName = 'center',+ this.blur = 0,+ this.scrimColor,+ this.scrimOpacity,+ this.surfaceOpacity = defaultSurfaceOpacity,+ this.scope = const {'main', 'mobile'},+ this.accentFromImage = false,+ });++ static const defaultSurfaceOpacity = 0.85;++ final String? image;+ final String? imageDark;+ final BackgroundFit fit;+ final Alignment align;+ final String alignName;++ /// 0 到 40;0 是原图,20 及以上全用后台服务预先算好的模糊版+ final double blur;++ /// 遮罩颜色,null 时用主题的 background+ final Color? scrimColor;++ /// 遮罩浓度,null 时取图片分析给出的下限(至少 0.3);比下限淡时按下限显示+ final double? scrimOpacity;++ /// 侧边栏与分组面板的不透明度,0.6 到 1+ final double surfaceOpacity;++ /// 哪些窗口显示:main(主窗口)、picker(快捷粘贴)、mobile(手机)+ final Set<String> scope;++ /// 用图片的主色作强调色+ final bool accentFromImage;++ /// 这个模式下用的图(`user:<sha256>` 里的 sha256),没有时为 null+ String? shaFor(Brightness b) {+ final ref = b == Brightness.dark ? (imageDark ?? image) : image;+ return ref != null && ref.startsWith('user:') ? ref.substring(5) : null;+ }+}+/// 语义化的颜色角色。页面代码只用这些名字,不判断亮暗模式。@immutableclass AppPalette extends ThemeExtension<AppPalette> {@@ -171,6 +257,32 @@ class AppPalette extends ThemeExtension<AppPalette> {@overrideAppPalette copyWith() => this;+ /// 换掉强调色与它上面的文字色,其余不变(「用图片配色」)+ AppPalette withAccent(Color accent, Color onAccent) => AppPalette(+ accent: accent,+ onAccent: onAccent,+ background: background,+ sidebar: sidebar,+ surface: surface,+ border: border,+ separator: separator,+ text: text,+ textDim: textDim,+ textFaint: textFaint,+ selection: selection,+ hover: hover,+ fill: fill,+ online: online,+ warning: warning,+ danger: danger,+ inverse: inverse,+ onInverse: onInverse,+ borderStrong: _borderStrong,+ bevelLight: bevelLight,+ bevelDark: bevelDark,+ shadow: shadow,+ );+@overrideAppPalette lerp(AppPalette? other, double t) {if (other == null) return this;diff --git a/ui/lib/theme_controller.dart b/ui/lib/theme_controller.dartindex f8dc3b7..bbf579d 100644--- a/ui/lib/theme_controller.dart+++ b/ui/lib/theme_controller.dart@@ -1,4 +1,6 @@import 'dart:convert';+import 'dart:math' as math;+import 'dart:typed_data';import 'package:flutter/material.dart';@@ -7,8 +9,43 @@ import 'gen/pasteferry/v1/daemon.pbgrpc.dart' show DaemonServiceClient;import 'icons.dart';import 'l10n/app_localizations.dart';import 'theme.dart';+import 'scrim.dart';import 'theme_json.dart';+/// 一个窗口要画的背景:设置、取到的图片与分析结果+class Backdrop {+ const Backdrop({+ required this.background,+ required this.sharp,+ required this.blurred,+ required this.info,+ required this.minScrim,+ });++ final ThemeBackground background;+ final Uint8List? sharp;+ final Uint8List? blurred;+ final pb.BackgroundInfo info;++ /// 遮罩至少多浓,文字才看得清(见 scrim.dart);遮罩「自动」就用它+ final double minScrim;++ /// 实际显示的遮罩浓度:比 [minScrim] 淡时按 [minScrim]+ double get scrimOpacity => math.max(background.scrimOpacity ?? minScrim, minScrim).clamp(0.0, 1.0);++ @override+ bool operator ==(Object other) =>+ other is Backdrop &&+ identical(other.background, background) &&+ identical(other.sharp, sharp) &&+ identical(other.blurred, blurred) &&+ identical(other.info, info) &&+ other.minScrim == minScrim;++ @override+ int get hashCode => Object.hash(background, sharp, blurred, info, minScrim);+}+/// 「外观」里的一项主题:软件自带的或自定义的class ThemeChoice {const ThemeChoice({required this.id, required this.names, required this.builtin, required this.spec});@@ -53,7 +90,32 @@ class ThemeController extends ChangeNotifier {/// 现在的主题 id;默认主题是 'default'String get id => _id.isEmpty ? 'default' : _id;- AppThemeSpec get spec => AppThemeSpec.builtins[id] ?? _custom[id] ?? AppThemeSpec.standard;+ AppThemeSpec get spec {+ final s = AppThemeSpec.builtins[id] ?? _custom[id] ?? AppThemeSpec.standard;+ final bg = s.background;+ if (bg == null || !bg.accentFromImage) return s;+ AppPalette pick(AppPalette p, Brightness b) {+ final colors = _infos[bg.shaFor(b)]?.colors ?? const <String>[];+ if (colors.isEmpty) return p;+ final accent = parseColor(colors.first);+ // 强调色上的字取黑或白,哪个对比度高用哪个+ final l = accent.computeLuminance();+ return p.withAccent(accent, (l + 0.05) / 0.05 > 1.05 / (l + 0.05) ? Colors.black : Colors.white);+ }++ return AppThemeSpec(+ id: s.id,+ light: pick(s.light, Brightness.light),+ dark: pick(s.dark, Brightness.dark),+ shape: s.shape,+ typography: s.typography,+ motion: s.motion,+ pixelIcons: s.pixelIcons,+ scenery: s.scenery,+ scene: s.scene,+ background: bg,+ );+ }ThemeMode get mode => switch (_mode) {pb.ThemeMode.THEME_MODE_LIGHT => ThemeMode.light,@@ -63,6 +125,207 @@ class ThemeController extends ChangeNotifier {bool get scanlines => _scanlines;+ // ── 背景图(design/themes.md 第 7 节):图片和分析结果按 sha256 从后台服务取来缓存 ──++ final _images = <String, Uint8List>{};+ final _infos = <String, pb.BackgroundInfo>{};+ final _fetching = <String>{};++ /// 当前主题的背景设置;没有背景图时为 null+ ThemeBackground? get background => spec.background;++ /// 已导入的图片的分析结果;还没取到时为 null(会去取)+ pb.BackgroundInfo? backgroundInfo(String sha) {+ final info = _infos[sha];+ if (info == null) _fetch(sha, blurred: false);+ return info;+ }++ /// [window](main、picker、mobile)在 [brightness] 模式下要画的背景;没有背景图、+ /// 这个窗口不显示、或者图片还没取到时为 null+ Backdrop? backdrop(Brightness brightness, String window, AppPalette palette) {+ final bg = background;+ if (bg == null || !bg.scope.contains(window)) return null;+ final sha = bg.shaFor(brightness);+ if (sha == null) return null;+ // 模糊不在运行时做:0 是原图,20 及以上是后台服务算好的模糊版,中间两张叠起来渐变+ final sharp = bg.blur < 20 ? _image(sha, blurred: false) : null;+ final blurred = bg.blur > 0 ? _image(sha, blurred: true) : null;+ final info = backgroundInfo(sha);+ if ((bg.blur < 20 && sharp == null) || (bg.blur > 0 && blurred == null) || info == null) return null;+ // 按显示出来的那张算:有原图用原图(细节最多),全模糊时用模糊版+ final shown = sharp != null ? sha : '$sha.blur';+ final sample = _samples[shown];+ if (sample == null) {+ _sample(shown, (sharp ?? blurred)!);+ return null;+ }+ final scrim = bg.scrimColor ?? palette.background;+ final key = '$shown ${scrim.toARGB32()} ${palette.text.toARGB32()} ${palette.textDim.toARGB32()} '+ '${palette.surface.toARGB32()} ${palette.sidebar.toARGB32()} ${bg.surfaceOpacity}';+ final min = _minScrims[key] ??=+ minScrim(sample, scrim: scrim, palette: palette, surfaceOpacity: bg.surfaceOpacity);+ return Backdrop(background: bg, sharp: sharp, blurred: blurred, info: info, minScrim: min);+ }++ /// 风景换成的图([part] 是 header 或 sidebar);没换、或者还没取到时为 null+ Uint8List? sceneImage(String part, Brightness brightness) {+ final sha = spec.scene?.shaFor(part, brightness);+ return sha == null ? null : _image(sha, blurred: false);+ }++ /// 页眉图上的遮罩至少多浓,页面标题、说明才看得清;图片还没取到时为 null+ double? sceneScrim(Brightness brightness, AppPalette palette) {+ final sha = spec.scene?.shaFor('header', brightness);+ final bytes = sha == null ? null : _images[sha];+ if (bytes == null) return null;+ final sample = _samples[sha];+ if (sample == null) {+ _sample(sha!, bytes);+ return null;+ }+ final key = 'scene $sha ${palette.background.toARGB32()} ${palette.text.toARGB32()} ${palette.textDim.toARGB32()}';+ return _minScrims[key] ??= minScrim(sample, scrim: palette.background, palette: palette, surfaceOpacity: 1);+ }++ final _samples = <String, Uint8List>{};+ final _minScrims = <String, double>{};++ void _sample(String key, Uint8List bytes) {+ if (!_fetching.add('sample $key')) return;+ sampleImage(bytes).then((s) {+ _samples[key] = s;+ notifyListeners();+ }).catchError((Object _) {}).whenComplete(() => _fetching.remove('sample $key'));+ }++ Uint8List? _image(String sha, {required bool blurred}) {+ final img = _images[blurred ? '$sha.blur' : sha];+ if (img == null) _fetch(sha, blurred: blurred);+ return img;+ }++ void _fetch(String sha, {required bool blurred}) {+ final client = _client;+ final key = blurred ? '$sha.blur' : sha;+ if (client == null || !_fetching.add(key)) return;+ () async {+ try {+ if (!_infos.containsKey(sha)) _infos[sha] = await client.analyzeBackground(pb.BackgroundRef(sha256: sha));+ if (!_images.containsKey(key)) {+ final res = await client.getBackground(pb.GetBackgroundRequest(sha256: sha, blurred: blurred));+ _images[key] = Uint8List.fromList(res.data);+ }+ // 「用图片配色」要等分析结果:强调色变了,ThemeData 要重建+ if (spec.background?.accentFromImage ?? false) revision++;+ notifyListeners();+ } catch (_) {+ // 图片被删了或后台服务没连上:不显示背景,下次再试+ } finally {+ _fetching.remove(key);+ }+ }();+ }++ /// 导入一张图片作背景,返回它的分析结果(sha256 在里面)+ Future<pb.BackgroundInfo> importBackground(String path) async {+ final info = await _client!.importBackground(pb.ImportBackgroundRequest(path: path));+ _infos[info.sha256] = info;+ return info;+ }++ /// 改当前这套自定义主题的背景与场景:[edit] 拿到主题的原始 JSON(没合并 base)就地修改,+ /// 改完保存。换下来的旧图没有主题再用时一并删掉+ Future<pb.PutThemeResponse> editCurrent(void Function(Map<String, dynamic> json) edit) async {+ final m = jsonDecode(await exportJson(id, resolved: false)) as Map<String, dynamic>;+ final before = _refs(m);+ edit(m);+ final res = await save(jsonEncode(m));+ _custom.remove(id);+ await _load(id);+ _changed();+ for (final sha in before.difference(_refs(m))) {+ try {+ await _client!.deleteBackground(pb.BackgroundRef(sha256: sha));+ } catch (_) {+ // 别的主题还在用这张图+ }+ }+ return res;+ }++ /// 改背景、场景前调用:正在用的是自带主题(不能改)时先复制一份并换上,返回副本的名字;+ /// 本来就是自定义主题时返回 null+ Future<String?> ensureEditable(AppLocalizations l) async {+ final current = _themes.where((t) => t.id == id).firstOrNull;+ if (current != null && !current.builtin) return null;+ final from = current ?? _themes.first;+ final newId = await duplicate(from, l.themeCopyName, l);+ await select(newId);+ return _themes.where((t) => t.id == newId).firstOrNull?.displayName(l) ?? newId;+ }++ /// 用 [path] 这张图作当前主题的背景(两种模式同一张),返回 [ensureEditable] 的结果+ Future<String?> setBackgroundImage(String path, AppLocalizations l) async {+ final info = await importBackground(path);+ final copied = await ensureEditable(l);+ await editCurrent((m) {+ final bg = (m['background'] as Map?)?.cast<String, dynamic>() ?? <String, dynamic>{};+ bg['image'] = 'user:${info.sha256}';+ bg.remove('imageDark');+ m['background'] = bg;+ });+ return copied;+ }++ /// 改当前主题的 background 里的几项(模糊、遮罩、面板、范围……)+ Future<void> editBackground(void Function(Map<String, dynamic> bg) edit) => editCurrent((m) {+ final bg = (m['background'] as Map?)?.cast<String, dynamic>() ?? <String, dynamic>{};+ edit(bg);+ m['background'] = bg;+ });++ Future<void> removeBackground() => editCurrent((m) => m.remove('background'));++ /// 用 [path] 这张图换掉风景的 [part](header 或 sidebar),两种模式同一张;返回 [ensureEditable] 的结果+ Future<String?> setSceneImage(String part, String path, AppLocalizations l) async {+ final info = await importBackground(path);+ final copied = await ensureEditable(l);+ await editCurrent((m) {+ final scene = (m['scene'] as Map?)?.cast<String, dynamic>() ?? <String, dynamic>{};+ scene[part] = 'user:${info.sha256}';+ scene.remove('${part}Dark');+ m['scene'] = scene;+ m['scenery'] = true;+ });+ return copied;+ }++ /// 风景的 [part] 恢复成主题原来的样子(像素主题是像素风景)+ Future<void> resetSceneImage(String part) => editCurrent((m) {+ final scene = (m['scene'] as Map?)?.cast<String, dynamic>() ?? <String, dynamic>{};+ scene+ ..remove(part)+ ..remove('${part}Dark');+ scene.isEmpty ? m.remove('scene') : m['scene'] = scene;+ });++ /// 像素风景开关,返回 [ensureEditable] 的结果+ Future<String?> setScenery(bool on, AppLocalizations l) async {+ final copied = await ensureEditable(l);+ await editCurrent((m) => m['scenery'] = on);+ return copied;+ }++ static Set<String> _refs(Map<String, dynamic> theme) {+ final bg = (theme['background'] as Map?) ?? const {};+ final scene = (theme['scene'] as Map?) ?? const {};+ return {+ for (final v in [bg['image'], bg['imageDark'], ...scene.values])+ if (v is String && v.startsWith('user:')) v.substring(5),+ };+ }+List<ThemeChoice> get themes => _themes;/// 连上后台服务后调用:取主题列表,配置里指定的自定义主题也取来@@ -213,6 +476,18 @@ class ThemeController extends ChangeNotifier {notifyListeners();}+ /// 测试与截图用:直接填入背景图与分析结果。要真的解码图片,在测试里放进 tester.runAsync+ @visibleForTesting+ Future<void> debugSeedBackground(String sha, Uint8List image, pb.BackgroundInfo info, {Uint8List? blurred}) async {+ _images[sha] = image;+ _images['$sha.blur'] = blurred ?? image;+ _infos[sha] = info;+ _samples[sha] = await sampleImage(image);+ _samples['$sha.blur'] = await sampleImage(blurred ?? image);+ revision++;+ notifyListeners();+ }+Future<void> delete(String themeId) async {await _client!.deleteTheme(pb.ThemeRef(id: themeId));_custom.remove(themeId);diff --git a/ui/lib/theme_json.dart b/ui/lib/theme_json.dartindex 162a75e..52d3052 100644--- a/ui/lib/theme_json.dart+++ b/ui/lib/theme_json.dart@@ -67,9 +67,74 @@ AppThemeSpec parseTheme(Object json, {AppThemeSpec? base}) {steps: (motionMap['steps'] as num?)?.toInt() ?? b.motion.steps,),pixelIcons: m.containsKey('icons') ? m['icons'] == 'pixel' : b.pixelIcons,+ scenery: m['scenery'] as bool? ?? b.scenery,+ scene: m.containsKey('scene') ? _scene(m['scene']) : b.scene,+ background: m.containsKey('background') ? _background(m['background']) : b.background,);}+const _alignments = {+ 'center': Alignment.center,+ 'top': Alignment.topCenter,+ 'bottom': Alignment.bottomCenter,+ 'left': Alignment.centerLeft,+ 'right': Alignment.centerRight,+ 'topLeft': Alignment.topLeft,+ 'topRight': Alignment.topRight,+ 'bottomLeft': Alignment.bottomLeft,+ 'bottomRight': Alignment.bottomRight,+};++/// `background` 字段;没有图片时为 null+ThemeBackground? _background(Object? json) {+ final m = (json as Map?)?.cast<String, dynamic>();+ if (m == null || (m['image'] == null && m['imageDark'] == null)) return null;+ final scrim = (m['scrim'] as Map?)?.cast<String, dynamic>() ?? const {};+ final align = m['align'] as String? ?? 'center';+ return ThemeBackground(+ image: m['image'] as String?,+ imageDark: m['imageDark'] as String?,+ fit: BackgroundFit.values.where((f) => f.name == m['fit']).firstOrNull ?? BackgroundFit.cover,+ align: _alignments[align] ?? Alignment.center,+ alignName: _alignments.containsKey(align) ? align : 'center',+ blur: ((m['blur'] as num?)?.toDouble() ?? 0).clamp(0, 40),+ scrimColor: scrim['color'] == null ? null : parseColor(scrim['color'] as String),+ scrimOpacity: (scrim['opacity'] as num?)?.toDouble().clamp(0, 1),+ surfaceOpacity:+ ((m['surfaceOpacity'] as num?)?.toDouble() ?? ThemeBackground.defaultSurfaceOpacity).clamp(0.6, 1),+ scope: (m['scope'] as List?)?.cast<String>().toSet() ?? const {'main', 'mobile'},+ accentFromImage: m['accentFromImage'] as bool? ?? false,+ );+}++ThemeScene? _scene(Object? json) {+ final m = (json as Map?)?.cast<String, dynamic>() ?? const {};+ final s = ThemeScene(+ header: m['header'] as String?,+ headerDark: m['headerDark'] as String?,+ sidebar: m['sidebar'] as String?,+ sidebarDark: m['sidebarDark'] as String?,+ );+ return s.isEmpty ? null : s;+}++/// [themeToJson] 里的 `background`+Map<String, Object?> backgroundToJson(ThemeBackground b) => {+ if (b.image != null) 'image': b.image,+ if (b.imageDark != null) 'imageDark': b.imageDark,+ 'fit': b.fit.name,+ 'align': b.alignName,+ 'blur': b.blur,+ if (b.scrimColor != null || b.scrimOpacity != null)+ 'scrim': {+ if (b.scrimColor != null) 'color': formatColor(b.scrimColor!),+ if (b.scrimOpacity != null) 'opacity': b.scrimOpacity,+ },+ 'surfaceOpacity': b.surfaceOpacity,+ 'scope': b.scope.toList(),+ 'accentFromImage': b.accentFromImage,+ };+/// 只写了部分颜色时,其余取 [base]AppPalette _palette(Object? json, AppPalette base) {final m = (json as Map?)?.cast<String, dynamic>() ?? const {};@@ -164,5 +229,14 @@ Map<String, Object?> themeToJson(AppThemeSpec s, {Map<String, String> name = con},'motion': s.motion.style.name,'icons': s.pixelIcons ? 'pixel' : 'system',+ 'scenery': s.scenery,+ if (s.scene != null)+ 'scene': {+ if (s.scene!.header != null) 'header': s.scene!.header,+ if (s.scene!.headerDark != null) 'headerDark': s.scene!.headerDark,+ if (s.scene!.sidebar != null) 'sidebar': s.scene!.sidebar,+ if (s.scene!.sidebarDark != null) 'sidebarDark': s.scene!.sidebarDark,+ },+ if (s.background != null) 'background': backgroundToJson(s.background!),};}diff --git a/ui/lib/widgets/backdrop.dart b/ui/lib/widgets/backdrop.dartnew file mode 100644index 0000000..036a5bd--- /dev/null+++ b/ui/lib/widgets/backdrop.dart@@ -0,0 +1,217 @@+import 'dart:math' as math;+import 'dart:typed_data';++import 'package:flutter/material.dart';++import '../pixel_art.dart';+import '../theme.dart';+import '../theme_controller.dart';++/// 窗口最底下的背景图层(design/themes.md 第 7.5 节):图片、遮罩,上面是内容。+///+/// 包在 MaterialApp 的 builder 里,主窗口、快捷粘贴窗口、手机 App 各一个。有背景图时+/// 页面底色(scaffoldBackgroundColor)换成透明,侧边栏与分组面板按 surfaceOpacity 半透明+/// (见 [BackdropContext.panel]);对话框、菜单、悬停预览仍然不透明。+///+/// 模糊不在运行时做(Windows 与 Linux 上全窗口模糊很耗显卡):后台服务导入时就算好一张模糊版,+/// blur 在 0 到 20 之间时把模糊版按比例叠在原图上。+class ThemedBackdrop extends StatelessWidget {+ const ThemedBackdrop({super.key, required this.controller, required this.window, required this.child});++ final ThemeController controller;++ /// main、picker 或 mobile,对应主题里 background.scope 的取值+ final String window;+ final Widget child;++ @override+ Widget build(BuildContext context) {+ final theme = Theme.of(context);+ final d = controller.backdrop(theme.brightness, window, context.palette);+ final scenery = controller.spec.scenery;+ if (d == null) return BackdropScope(backdrop: null, scenery: scenery, child: child);++ final bg = d.background;+ final scrim = bg.scrimColor ?? context.palette.background;+ // 遮罩只能比文字需要的更浓(d.minScrim,按主题的文字颜色算)+ final opacity = d.scrimOpacity;+ final mix = (bg.blur / 20).clamp(0.0, 1.0);++ return BackdropScope(+ backdrop: d,+ scenery: scenery,+ child: Stack(+ fit: StackFit.expand,+ children: [+ if (d.sharp != null) _BackdropImage(bytes: d.sharp!, background: bg),+ if (d.blurred != null) _BackdropImage(bytes: d.blurred!, background: bg, opacity: d.sharp == null ? 1 : mix),+ ColoredBox(color: scrim.withValues(alpha: scrim.a * opacity)),+ Theme(data: theme.copyWith(scaffoldBackgroundColor: Colors.transparent), child: child),+ ],+ ),+ );+ }+}++class _BackdropImage extends StatelessWidget {+ const _BackdropImage({required this.bytes, required this.background, this.opacity = 1});++ final Uint8List bytes;+ final ThemeBackground background;+ final double opacity;++ @override+ Widget build(BuildContext context) {+ final dpr = MediaQuery.devicePixelRatioOf(context);+ final fade = opacity < 1 ? AlwaysStoppedAnimation(opacity) : null;+ if (background.fit == BackgroundFit.tile) {+ // 平铺的多是像素画:只按整数倍放大,不插值+ final n = math.max(1, dpr.round());+ return Image.memory(+ bytes,+ scale: dpr / n,+ repeat: ImageRepeat.repeat,+ alignment: background.align,+ filterQuality: FilterQuality.none,+ opacity: fade,+ gaplessPlayback: true,+ );+ }+ // 按窗口大小解码一次,不把 4K 原图整张放进内存;大小按 512 取整,拖动窗口时不反复解码+ final size = MediaQuery.sizeOf(context);+ final side = ((math.max(size.width, size.height) * dpr / 512).ceil() * 512).clamp(512, 4096);+ return Image(+ image: ResizeImage(MemoryImage(bytes), width: side, height: side, policy: ResizeImagePolicy.fit),+ fit: background.fit == BackgroundFit.contain ? BoxFit.contain : BoxFit.cover,+ alignment: background.align,+ filterQuality: FilterQuality.medium,+ opacity: fade,+ gaplessPlayback: true,+ );+ }+}++/// 把背景的状态传给下面的页面+class BackdropScope extends InheritedWidget {+ const BackdropScope({super.key, required this.backdrop, required this.scenery, required super.child});++ /// 正在显示的背景图;没有时为 null+ final Backdrop? backdrop;++ /// 主题允许画像素场景+ final bool scenery;++ static BackdropScope? maybeOf(BuildContext context) => context.dependOnInheritedWidgetOfExactType<BackdropScope>();++ @override+ bool updateShouldNotify(BackdropScope old) => old.backdrop != backdrop || old.scenery != scenery;+}++extension BackdropContext on BuildContext {+ /// 侧边栏、分组面板这类大块底色:有背景图时按 surfaceOpacity 半透明,让图透出来+ Color panel(Color color) {+ final b = BackdropScope.maybeOf(this)?.backdrop;+ return b == null ? color : color.withValues(alpha: color.a * b.background.surfaceOpacity);+ }++ /// 风景(页面顶部的图与侧边栏底部的小图):主题没关掉、也没有显示整窗背景图时才画。+ /// 画什么由 [SceneHeader]、[SceneSidebar] 决定+ bool get showScenery {+ final scope = BackdropScope.maybeOf(this);+ return scope == null || (scope.scenery && scope.backdrop == null);+ }+}++/// 页面顶部的风景:主题换了图(scene.header)就画图,否则像素主题画像素风景,其他主题不画。+/// 图的底部渐隐进页面;页面标题叠在上面,所以盖一层主题底色的遮罩,浓到文字看得清为止+class SceneHeader extends StatelessWidget {+ const SceneHeader({super.key, required this.controller, this.height = 180});++ final ThemeController controller;+ final double height;++ @override+ Widget build(BuildContext context) {+ final brightness = Theme.of(context).brightness;+ final p = context.palette;+ final bytes = controller.sceneImage('header', brightness);+ final scrim = controller.sceneScrim(brightness, p);+ if (controller.spec.scene?.shaFor('header', brightness) == null) {+ return context.shape.pixel ? PixelScene(height: height) : const SizedBox.shrink();+ }+ if (bytes == null || scrim == null) return SizedBox(height: height);+ return SizedBox(+ height: height,+ width: double.infinity,+ child: _Fade(+ top: false,+ child: Stack(+ fit: StackFit.expand,+ children: [+ _SceneImage(bytes: bytes),+ ColoredBox(color: p.background.withValues(alpha: scrim)),+ ],+ ),+ ),+ );+ }+}++/// 侧边栏底部的小图:主题换了图(scene.sidebar)就画图,否则像素主题画营地,其他主题不画。+/// 上面没有文字,不加遮罩,顶部渐隐进侧边栏+class SceneSidebar extends StatelessWidget {+ const SceneSidebar({super.key, required this.controller});++ final ThemeController controller;++ @override+ Widget build(BuildContext context) {+ final brightness = Theme.of(context).brightness;+ if (controller.spec.scene?.shaFor('sidebar', brightness) == null) {+ return context.shape.pixel ? const PixelCamp() : const SizedBox.shrink();+ }+ final bytes = controller.sceneImage('sidebar', brightness);+ if (bytes == null) return const SizedBox(height: 96);+ return SizedBox(height: 96, width: double.infinity, child: _Fade(top: true, child: _SceneImage(bytes: bytes)));+ }+}++class _SceneImage extends StatelessWidget {+ const _SceneImage({required this.bytes});++ final Uint8List bytes;++ @override+ Widget build(BuildContext context) {+ final dpr = MediaQuery.devicePixelRatioOf(context);+ final width = ((MediaQuery.sizeOf(context).width * dpr / 512).ceil() * 512).clamp(512, 4096);+ return Image(+ image: ResizeImage(MemoryImage(bytes), width: width, policy: ResizeImagePolicy.fit),+ fit: BoxFit.cover,+ filterQuality: FilterQuality.medium,+ gaplessPlayback: true,+ );+ }+}++/// 一头渐隐成透明:[top] 时上边渐隐,否则下边+class _Fade extends StatelessWidget {+ const _Fade({required this.top, required this.child});++ final bool top;+ final Widget child;++ @override+ Widget build(BuildContext context) {+ return ShaderMask(+ blendMode: BlendMode.dstIn,+ shaderCallback: (rect) => LinearGradient(+ begin: top ? Alignment.bottomCenter : Alignment.topCenter,+ end: top ? Alignment.topCenter : Alignment.bottomCenter,+ colors: const [Colors.white, Colors.white, Colors.transparent],+ stops: const [0, 0.55, 1],+ ).createShader(rect),+ child: child,+ );+ }+}diff --git a/ui/lib/widgets/common.dart b/ui/lib/widgets/common.dartindex 0228c88..b4d9a55 100644--- a/ui/lib/widgets/common.dart+++ b/ui/lib/widgets/common.dart@@ -8,6 +8,7 @@ import '../theme.dart';import '../i18n.dart';import '../icons.dart';import '../pixel_art.dart';+import 'backdrop.dart';/// 页面统一的标题区。保证各页视觉节奏一致。class PageHeader extends StatelessWidget {@@ -102,7 +103,7 @@ class GroupBox extends StatelessWidget {Widget build(BuildContext context) {return Container(clipBehavior: Clip.antiAlias,- decoration: context.shape.box(color: context.palette.surface, border: context.palette.border),+ decoration: context.shape.box(color: context.panel(context.palette.surface), border: context.palette.border),child: Column(crossAxisAlignment: CrossAxisAlignment.stretch,children: [@@ -516,7 +517,7 @@ class Notice extends StatelessWidget {final icon = this.icon ?? AppIcons.exclamationmarkCircle;return Container(padding: const EdgeInsets.fromLTRB(Insets.lg, Insets.md, Insets.md, Insets.md),- decoration: context.shape.box(color: p.surface, border: p.border),+ decoration: context.shape.box(color: context.panel(p.surface), border: p.border),child: Row(children: [Icon(icon, size: 18, color: iconColor ?? p.warning),diff --git a/ui/test/backdrop_test.dart b/ui/test/backdrop_test.dartnew file mode 100644index 0000000..aef652f--- /dev/null+++ b/ui/test/backdrop_test.dart@@ -0,0 +1,223 @@+import 'dart:typed_data';++import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';++import 'package:pasteferry_ui/gen/pasteferry/v1/daemon.pb.dart' as pb;+import 'package:pasteferry_ui/pixel_art.dart';+import 'package:pasteferry_ui/pixel_theme.dart';+import 'package:pasteferry_ui/scrim.dart';+import 'package:pasteferry_ui/theme.dart';+import 'package:pasteferry_ui/theme_controller.dart';+import 'package:pasteferry_ui/theme_json.dart';+import 'package:pasteferry_ui/widgets/backdrop.dart';++// 1×1 的 PNG+final _png = Uint8List.fromList([+ 0x89,+ 0x50,+ 0x4E,+ 0x47,+ 0x0D,+ 0x0A,+ 0x1A,+ 0x0A,+ 0x00,+ 0x00,+ 0x00,+ 0x0D,+ 0x49,+ 0x48,+ 0x44,+ 0x52,+ 0x00,+ 0x00,+ 0x00,+ 0x01,+ 0x00,+ 0x00,+ 0x00,+ 0x01,+ 0x08,+ 0x06,+ 0x00,+ 0x00,+ 0x00,+ 0x1F,+ 0x15,+ 0xC4,+ 0x89,+ 0x00,+ 0x00,+ 0x00,+ 0x0D,+ 0x49,+ 0x44,+ 0x41,+ 0x54,+ 0x78,+ 0x9C,+ 0x63,+ 0xF8,+ 0xCF,+ 0xC0,+ 0xF0,+ 0x1F,+ 0x00,+ 0x05,+ 0x00,+ 0x01,+ 0xFF,+ 0x89,+ 0x99,+ 0x3D,+ 0x1D,+ 0x00,+ 0x00,+ 0x00,+ 0x00,+ 0x49,+ 0x45,+ 0x4E,+ 0x44,+ 0xAE,+ 0x42,+ 0x60,+ 0x82,+]);++final _sha = 'b' * 64;++AppThemeSpec _photo({double blur = 0, List<String> scope = const ['main', 'mobile'], bool accent = false}) =>+ parseTheme({+ 'schema': 1,+ 'id': 'photo',+ 'base': 'pixel',+ 'background': {+ 'image': 'user:$_sha',+ 'blur': blur,+ 'surfaceOpacity': 0.7,+ 'scope': scope,+ 'accentFromImage': accent,+ },+ });++Future<ThemeController> _controller(WidgetTester? tester, AppThemeSpec spec) async {+ final c = ThemeController()+ ..debugSeed(+ themes: [ThemeChoice(id: spec.id, names: const {}, builtin: false, spec: spec)],+ id: spec.id,+ );+ final info = pb.BackgroundInfo(sha256: _sha, colors: ['#FFE066']);+ tester == null+ ? await c.debugSeedBackground(_sha, _png, info)+ : await tester.runAsync(() => c.debugSeedBackground(_sha, _png, info));+ return c;+}++Widget _app(ThemeController c, String window, Widget child) => MaterialApp(+ theme: buildTheme(Brightness.dark, spec: c.spec),+ home: ThemedBackdrop(controller: c, window: window, child: child),+);++void main() {+ testWidgets('有背景图:铺图、加遮罩,面板半透明,像素风景不画', (tester) async {+ final c = await _controller(tester, _photo());+ late BuildContext inner;+ await tester.pumpWidget(+ _app(+ c,+ 'main',+ Builder(+ builder: (context) {+ inner = context;+ return const SizedBox();+ },+ ),+ ),+ );+ expect(find.byType(Image), findsOneWidget);+ // 图是纯白,深色主题的浅色字要靠遮罩压暗:遮罩是 background 色,浓度是算出来的下限+ final scrim = tester.widget<ColoredBox>(+ find.descendant(of: find.byType(ThemedBackdrop), matching: find.byType(ColoredBox)).first,+ );+ final min = c.backdrop(Brightness.dark, 'main', pixelTheme.dark)!.minScrim;+ expect(min, greaterThan(0.5));+ expect(scrim.color.a, closeTo(min, 0.01));+ expect(inner.panel(const Color(0xFF202020)).a, closeTo(0.7, 0.01));+ expect(inner.showScenery, isFalse);+ expect(Theme.of(inner).scaffoldBackgroundColor, Colors.transparent);+ });++ testWidgets('模糊在 0 到 20 之间:原图上叠模糊版', (tester) async {+ await tester.pumpWidget(_app(await _controller(tester, _photo(blur: 10)), 'main', const SizedBox()));+ expect(find.byType(Image), findsNWidgets(2));+ await tester.pumpWidget(_app(await _controller(tester, _photo(blur: 30)), 'main', const SizedBox()));+ expect(find.byType(Image), findsOneWidget);+ });++ testWidgets('scope 里没有这个窗口时不显示,像素风景照常', (tester) async {+ late BuildContext inner;+ await tester.pumpWidget(+ _app(+ await _controller(tester, _photo()),+ 'picker',+ Builder(+ builder: (context) {+ inner = context;+ return const SizedBox();+ },+ ),+ ),+ );+ expect(find.byType(Image), findsNothing);+ expect(inner.panel(const Color(0xFF202020)).a, 1);+ expect(inner.showScenery, isTrue);+ });++ testWidgets('用图片配色:强调色取图片主色,上面的字取对比度高的黑或白', (tester) async {+ final p = (await _controller(tester, _photo(accent: true))).spec.dark;+ expect(p.accent, const Color(0xFFFFE066));+ expect(p.onAccent, Colors.black);+ expect(p.background, pixelTheme.dark.background);+ });++ test('遮罩下限:深色图上浅色主题的字要靠浅色遮罩,同色系的图不用遮罩', () {+ final light = pixelTheme.light;+ final dark = pixelTheme.dark;+ final onDark = minScrim(_solid(30, 20, 50), scrim: light.background, palette: light, surfaceOpacity: 0.85);+ expect(onDark, greaterThan(0.7));+ expect(minScrim(_solid(250, 250, 248), scrim: light.background, palette: light, surfaceOpacity: 0.85), 0);+ expect(minScrim(_solid(17, 18, 21), scrim: dark.background, palette: dark, surfaceOpacity: 0.85), 0);+ // 遮罩颜色和字一样深,铺满也看不清+ expect(minScrim(_solid(20, 20, 20), scrim: light.text, palette: light, surfaceOpacity: 1), 1);+ });++ testWidgets('风景换成自己的图:页眉画图加遮罩,没换的侧边栏仍是像素营地', (tester) async {+ final spec = parseTheme({+ 'schema': 1,+ 'id': 'scene',+ 'base': 'pixel',+ 'scene': {'header': 'user:$_sha'},+ });+ final c = await _controller(tester, spec);+ await tester.pumpWidget(+ MaterialApp(+ theme: buildTheme(Brightness.dark, spec: c.spec),+ home: Column(+ children: [+ SceneHeader(controller: c),+ SceneSidebar(controller: c),+ ],+ ),+ ),+ );+ expect(find.byType(Image), findsOneWidget);+ expect(find.byType(PixelScene), findsNothing);+ expect(find.byType(PixelCamp), findsOneWidget);+ });+}++Uint8List _solid(int r, int g, int b) => Uint8List.fromList([+ for (var i = 0; i < 16; i++) ...[r, g, b, 255],+]);diff --git a/ui/test/theme_json_test.dart b/ui/test/theme_json_test.dartindex ecf059e..d0e38b2 100644--- a/ui/test/theme_json_test.dart+++ b/ui/test/theme_json_test.dart@@ -24,6 +24,47 @@ void main() {}});+ test('背景图与像素风景:读进来、导出再读回来不变', () {+ final sha = 'a' * 64;+ final s = parseTheme({+ 'schema': 1,+ 'id': 'photo',+ 'base': 'pixel',+ 'scenery': false,+ 'background': {+ 'image': 'user:$sha',+ 'fit': 'tile',+ 'align': 'bottomLeft',+ 'blur': 50,+ 'scrim': {'color': '#000000', 'opacity': 0.4},+ 'surfaceOpacity': 0.7,+ 'scope': ['main', 'picker'],+ 'accentFromImage': true,+ },+ });+ final bg = s.background!;+ expect(s.scenery, isFalse);+ expect(bg.shaFor(Brightness.light), sha);+ expect(bg.shaFor(Brightness.dark), sha, reason: '没有 imageDark 时深色也用同一张');+ expect(bg.fit, BackgroundFit.tile);+ expect(bg.align, Alignment.bottomLeft);+ expect(bg.blur, 40, reason: '超出范围按 40 算');+ expect(bg.scrimColor, const Color(0xFF000000));+ expect(bg.scope, {'main', 'picker'});+ expect(bg.accentFromImage, isTrue);++ final back = parseTheme(jsonEncode(themeToJson(s)), base: AppThemeSpec.standard);+ expect(back.scenery, isFalse);+ expect(back.background!.image, 'user:$sha');+ expect(back.background!.alignName, 'bottomLeft');+ expect(back.background!.scrimOpacity, 0.4);+ expect(back.background!.surfaceOpacity, 0.7);++ expect(parseTheme({'schema': 1, 'id': 'x', 'background': {'fit': 'cover'}}).background, isNull,+ reason: '没写图片就是没有背景图');+ expect(pixelTheme.scenery, isTrue);+ });+test('只改强调色:其余从 base 补齐', () {final s = parseTheme({'schema': 1,diff --git a/ui/tool/screenshots/screenshots_test.dart b/ui/tool/screenshots/screenshots_test.dartindex 6095a00..67e7c67 100644--- a/ui/tool/screenshots/screenshots_test.dart+++ b/ui/tool/screenshots/screenshots_test.dart@@ -6,6 +6,7 @@// 放在 tool/ 而非 test/:它依赖本机字体,不该随 flutter test 在 CI 上跑。// ignore_for_file: invalid_use_of_visible_for_testing_memberimport 'dart:async';+import 'dart:convert';import 'dart:io';import 'dart:ui' show ImageByteFormat;@@ -22,6 +23,7 @@ import 'package:pasteferry_ui/theme.dart';import 'package:pasteferry_ui/theme_controller.dart';import 'package:pasteferry_ui/theme_json.dart';import 'package:pasteferry_ui/widgets/avatar.dart';+import 'package:pasteferry_ui/widgets/backdrop.dart';import 'package:pasteferry_ui/widgets/friend_send_dialog.dart';import 'package:pasteferry_ui/widgets/friends_dialog.dart';import 'package:pasteferry_ui/widgets/nearby_dialog.dart';@@ -49,6 +51,29 @@ final AppThemeSpec _spec = switch (Platform.environment['SCREENSHOT_THEME_FILE']null => AppThemeSpec.byId(Platform.environment['SCREENSHOT_THEME'] ?? ''),};+/// 背景图:SCREENSHOT_BACKGROUND 指向一个目录,里面是后台服务导入后的 sharp.img、blur.img+/// 与分析结果 info.json;主题(SCREENSHOT_THEME_FILE)里的 background.image 要写它的 sha256+Future<void> _seedBackground(ThemeController theme) async {+ final dir = Platform.environment['SCREENSHOT_BACKGROUND'];+ if (dir == null) return;+ final info = jsonDecode(File('$dir/info.json').readAsStringSync()) as Map<String, dynamic>;+ if (!theme.themes.any((t) => t.id == _spec.id)) {+ theme.debugSeed(themes: [...theme.themes, ThemeChoice(id: _spec.id, names: const {}, builtin: false, spec: _spec)]);+ }+ theme.debugSeed(id: _spec.id);+ await theme.debugSeedBackground(+ info['SHA256'] as String,+ File('$dir/sharp.img').readAsBytesSync(),+ BackgroundInfo(+ sha256: info['SHA256'] as String,+ colors: (info['Colors'] as List).cast<String>(),+ minScrimDark: (info['MinScrimDark'] as num).toDouble(),+ minScrimLight: (info['MinScrimLight'] as num).toDouble(),+ ),+ blurred: File('$dir/blur.img').readAsBytesSync(),+ );+}+ThemeData _theme(Brightness brightness) =>buildTheme(brightness, spec: _spec, fontFamily: 'SF', fontFamilyFallback: _cjk);@@ -459,6 +484,8 @@ Future<void> _render(required bool settle,}) async {+ // 背景图要真的解码、取样(算遮罩浓度),在测试的假时钟外面做+ await tester.runAsync(() => _seedBackground(state.theme));final theme = _theme(brightness);await tester.pumpWidget(RepaintBoundary(key: _boundary,@@ -466,7 +493,8 @@ Future<void> _render(state: state,child: MaterialApp(debugShowCheckedModeBanner: false,- builder: _textScale,+ builder: (context, child) =>+ _textScale(context, ThemedBackdrop(controller: state.theme, window: 'main', child: child!)),theme: theme,locale: _locale,supportedLocales: supportedLocales,@@ -817,6 +845,19 @@ void main() {await _shoot(tester, 'appearance', state: appearanceDemo(), section: Section.settings);});+ // 「背景图」一节在外观页最下面;配合 SCREENSHOT_BACKGROUND 看设置了背景图的样子+ for (final dark in [false, true]) {+ testWidgets(dark ? 'appearance-background-dark' : 'appearance-background', (tester) async {+ await _shoot(tester, dark ? 'appearance-background-dark' : 'appearance-background',+ state: appearanceDemo(),+ section: Section.settings,+ brightness: dark ? Brightness.dark : Brightness.light, arrange: () async {+ await tester.ensureVisible(find.text(_t('背景图', 'Background image', '背景画像', tw: '背景圖', hk: '背景圖')).first);+ await tester.pump();+ });+ });+ }+testWidgets('appearance-dark', (tester) async {await _shoot(tester, 'appearance-dark', state: appearanceDemo(), section: Section.settings, brightness: Brightness.dark);});