Skip to content

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.

feat(ui): split settings into categories

baiyuze3c283f912f21
diff --git a/ui/lib/app_state.dart b/ui/lib/app_state.dart
index 2ea5cd1..9db460f 100644
--- a/ui/lib/app_state.dart
+++ b/ui/lib/app_state.dart
@@ -204,8 +204,13 @@ class AppState extends ChangeNotifier implements RecordDetails {
)
.lastOrNull;
- /// 让主窗口切到某一页("send"、"settings"),比如好友连不上时点了「打开服务…」
+ /// 让主窗口切到某一页("send"、"settings"),比如好友连不上时点了「打开服务…」。
+ /// "settings:connection" 这样的写法直接进设置里的某一类
void requestPage(String page) {
+ if (page.startsWith('settings:')) {
+ _settingsCategory = page.substring('settings:'.length);
+ page = 'settings';
+ }
_pageRequest = page;
_pageRequestSerial++;
notifyListeners();
@@ -214,6 +219,15 @@ class AppState extends ChangeNotifier implements RecordDetails {
String get pageRequest => _pageRequest;
int get pageRequestSerial => _pageRequestSerial;
+ String? _settingsCategory;
+
+ /// 设置页取走要打开的类别(只取一次)
+ String? takeSettingsCategory() {
+ final c = _settingsCategory;
+ _settingsCategory = null;
+ return c;
+ }
+
/// 正在搜索复制记录(搜索词不是空白)。
bool get searching => _historySearch.active;
String get searchQuery => _historySearch.query.trim();
diff --git a/ui/lib/icons.dart b/ui/lib/icons.dart
index 34fd1b9..eea2b32 100644
--- a/ui/lib/icons.dart
+++ b/ui/lib/icons.dart
@@ -58,6 +58,11 @@ abstract final class AppIcons {
static IconData get chevronUpDown =>
_pick(CupertinoIcons.chevron_up_chevron_down, FluentIcons.chevron_up_down_24_regular);
static IconData get link => _pick(CupertinoIcons.link, FluentIcons.link_24_regular);
+ // 设置首页各类别
+ static IconData get globe => _pick(CupertinoIcons.globe, FluentIcons.globe_24_regular);
+ static IconData get sync => _pick(CupertinoIcons.arrow_2_circlepath, FluentIcons.arrow_sync_24_regular);
+ static IconData get archive => _pick(CupertinoIcons.archivebox, FluentIcons.archive_24_regular);
+ static IconData get info => _pick(CupertinoIcons.info_circle, FluentIcons.info_24_regular);
static IconData get star => _pick(CupertinoIcons.star, FluentIcons.star_24_regular);
static IconData get starFill => _pick(CupertinoIcons.star_fill, FluentIcons.star_24_filled);
static IconData get keyboard => _pick(CupertinoIcons.keyboard, FluentIcons.keyboard_24_regular);
diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arb
index 925ddc3..638e422 100644
--- a/ui/lib/l10n/app_en.arb
+++ b/ui/lib/l10n/app_en.arb
@@ -1556,5 +1556,13 @@
"receiveFromEveryoneDesc": "Anyone on the same network can send you files for 10 minutes. You accept each batch.",
"everyoneEnded": "Everyone is off; back to Contacts Only.",
"friendsCountTooltip": "Contacts",
- "waitingAccept": "Waiting…"
+ "waitingAccept": "Waiting…",
+ "settingsConnection": "Connection",
+ "settingsGeneralSummary": "Launch at login, device name, language",
+ "settingsConnectionSummary": "Service, your own server, local network",
+ "settingsSyncSummary": "Real-time sync, size limit, what to sync",
+ "settingsQuickPasteSummary": "Shortcut and what happens after you pick",
+ "settingsSendSummary": "Receiving files, save location",
+ "settingsStorageSummary": "How long history is kept, space used",
+ "settingsAboutSummary": "Version, updates, feedback"
}
diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arb
index a9d9a93..2158670 100644
--- a/ui/lib/l10n/app_ja.arb
+++ b/ui/lib/l10n/app_ja.arb
@@ -603,5 +603,13 @@
"receiveFromEveryoneDesc": "同じネットワークの誰でも 10 分間送れます。毎回あなたが受け入れます。",
"everyoneEnded": "「すべての人」が終了し、「連絡先のみ」に戻りました。",
"friendsCountTooltip": "連絡先",
- "waitingAccept": "承認待ち"
+ "waitingAccept": "承認待ち",
+ "settingsConnection": "接続",
+ "settingsGeneralSummary": "ログイン時の起動、デバイス名、言語",
+ "settingsConnectionSummary": "サービス、自前のサーバー、ローカルネットワーク",
+ "settingsSyncSummary": "リアルタイム同期、自動同期の上限、同期する内容",
+ "settingsQuickPasteSummary": "ショートカット、選んだ後の動作",
+ "settingsSendSummary": "ファイルの受信、保存先",
+ "settingsStorageSummary": "履歴の保存期間と使用量",
+ "settingsAboutSummary": "バージョン、アップデート、フィードバック"
}
diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dart
index e2dd9cf..19ae2a6 100644
--- a/ui/lib/l10n/app_localizations.dart
+++ b/ui/lib/l10n/app_localizations.dart
@@ -3733,6 +3733,54 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Waiting…'**
String get waitingAccept;
+
+ /// No description provided for @settingsConnection.
+ ///
+ /// In en, this message translates to:
+ /// **'Connection'**
+ String get settingsConnection;
+
+ /// No description provided for @settingsGeneralSummary.
+ ///
+ /// In en, this message translates to:
+ /// **'Launch at login, device name, language'**
+ String get settingsGeneralSummary;
+
+ /// No description provided for @settingsConnectionSummary.
+ ///
+ /// In en, this message translates to:
+ /// **'Service, your own server, local network'**
+ String get settingsConnectionSummary;
+
+ /// No description provided for @settingsSyncSummary.
+ ///
+ /// In en, this message translates to:
+ /// **'Real-time sync, size limit, what to sync'**
+ String get settingsSyncSummary;
+
+ /// No description provided for @settingsQuickPasteSummary.
+ ///
+ /// In en, this message translates to:
+ /// **'Shortcut and what happens after you pick'**
+ String get settingsQuickPasteSummary;
+
+ /// No description provided for @settingsSendSummary.
+ ///
+ /// In en, this message translates to:
+ /// **'Receiving files, save location'**
+ String get settingsSendSummary;
+
+ /// No description provided for @settingsStorageSummary.
+ ///
+ /// In en, this message translates to:
+ /// **'How long history is kept, space used'**
+ String get settingsStorageSummary;
+
+ /// No description provided for @settingsAboutSummary.
+ ///
+ /// In en, this message translates to:
+ /// **'Version, updates, feedback'**
+ String get settingsAboutSummary;
}
class _AppLocalizationsDelegate
diff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dart
index 289c712..75d36e6 100644
--- a/ui/lib/l10n/app_localizations_en.dart
+++ b/ui/lib/l10n/app_localizations_en.dart
@@ -2282,4 +2282,30 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get waitingAccept => 'Waiting…';
+
+ @override
+ String get settingsConnection => 'Connection';
+
+ @override
+ String get settingsGeneralSummary => 'Launch at login, device name, language';
+
+ @override
+ String get settingsConnectionSummary =>
+ 'Service, your own server, local network';
+
+ @override
+ String get settingsSyncSummary => 'Real-time sync, size limit, what to sync';
+
+ @override
+ String get settingsQuickPasteSummary =>
+ 'Shortcut and what happens after you pick';
+
+ @override
+ String get settingsSendSummary => 'Receiving files, save location';
+
+ @override
+ String get settingsStorageSummary => 'How long history is kept, space used';
+
+ @override
+ String get settingsAboutSummary => 'Version, updates, feedback';
}
diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dart
index e6d73ea..78ff933 100644
--- a/ui/lib/l10n/app_localizations_ja.dart
+++ b/ui/lib/l10n/app_localizations_ja.dart
@@ -2114,4 +2114,28 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get waitingAccept => '承認待ち';
+
+ @override
+ String get settingsConnection => '接続';
+
+ @override
+ String get settingsGeneralSummary => 'ログイン時の起動、デバイス名、言語';
+
+ @override
+ String get settingsConnectionSummary => 'サービス、自前のサーバー、ローカルネットワーク';
+
+ @override
+ String get settingsSyncSummary => 'リアルタイム同期、自動同期の上限、同期する内容';
+
+ @override
+ String get settingsQuickPasteSummary => 'ショートカット、選んだ後の動作';
+
+ @override
+ String get settingsSendSummary => 'ファイルの受信、保存先';
+
+ @override
+ String get settingsStorageSummary => '履歴の保存期間と使用量';
+
+ @override
+ String get settingsAboutSummary => 'バージョン、アップデート、フィードバック';
}
diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dart
index ce4c0d0..351c022 100644
--- a/ui/lib/l10n/app_localizations_zh.dart
+++ b/ui/lib/l10n/app_localizations_zh.dart
@@ -2089,6 +2089,30 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get waitingAccept => '等待接受';
+
+ @override
+ String get settingsConnection => '连接';
+
+ @override
+ String get settingsGeneralSummary => '开机启动、设备名称、语言';
+
+ @override
+ String get settingsConnectionSummary => '服务、自建服务器、局域网';
+
+ @override
+ String get settingsSyncSummary => '实时同步、自动同步上限、同步哪些内容';
+
+ @override
+ String get settingsQuickPasteSummary => '快捷键、选中后的操作';
+
+ @override
+ String get settingsSendSummary => '接收文件、保存位置';
+
+ @override
+ String get settingsStorageSummary => '记录保留多久、占用空间';
+
+ @override
+ String get settingsAboutSummary => '版本、更新、反馈';
}
/// The translations for Chinese, as used in Hong Kong, using the Han script (`zh_Hant_HK`).
@@ -4176,6 +4200,30 @@ class AppLocalizationsZhHantHk extends AppLocalizationsZh {
@override
String get waitingAccept => '等待接受';
+
+ @override
+ String get settingsConnection => '連接';
+
+ @override
+ String get settingsGeneralSummary => '開機啟動、裝置名稱、語言';
+
+ @override
+ String get settingsConnectionSummary => '服務、自建伺服器、區域網絡';
+
+ @override
+ String get settingsSyncSummary => '即時同步、自動同步上限、同步哪些內容';
+
+ @override
+ String get settingsQuickPasteSummary => '快速鍵、選取後的動作';
+
+ @override
+ String get settingsSendSummary => '接收檔案、儲存位置';
+
+ @override
+ String get settingsStorageSummary => '記錄保留多久、佔用空間';
+
+ @override
+ String get settingsAboutSummary => '版本、更新、回報';
}
/// The translations for Chinese, as used in Taiwan, using the Han script (`zh_Hant_TW`).
@@ -6263,4 +6311,28 @@ class AppLocalizationsZhHantTw extends AppLocalizationsZh {
@override
String get waitingAccept => '等待接受';
+
+ @override
+ String get settingsConnection => '連線';
+
+ @override
+ String get settingsGeneralSummary => '開機啟動、裝置名稱、語言';
+
+ @override
+ String get settingsConnectionSummary => '服務、自架伺服器、區域網路';
+
+ @override
+ String get settingsSyncSummary => '即時同步、自動同步上限、同步哪些內容';
+
+ @override
+ String get settingsQuickPasteSummary => '快速鍵、選取後的動作';
+
+ @override
+ String get settingsSendSummary => '接收檔案、儲存位置';
+
+ @override
+ String get settingsStorageSummary => '記錄保留多久、佔用空間';
+
+ @override
+ String get settingsAboutSummary => '版本、更新、回報';
}
diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arb
index c671863..a4ac96d 100644
--- a/ui/lib/l10n/app_zh.arb
+++ b/ui/lib/l10n/app_zh.arb
@@ -603,5 +603,13 @@
"receiveFromEveryoneDesc": "同一局域网里的人都能发,每次由你接受;10 分钟后改回「仅限好友」。",
"everyoneEnded": "「所有人」已结束,改回「仅限好友」。",
"friendsCountTooltip": "好友",
- "waitingAccept": "等待接受"
+ "waitingAccept": "等待接受",
+ "settingsConnection": "连接",
+ "settingsGeneralSummary": "开机启动、设备名称、语言",
+ "settingsConnectionSummary": "服务、自建服务器、局域网",
+ "settingsSyncSummary": "实时同步、自动同步上限、同步哪些内容",
+ "settingsQuickPasteSummary": "快捷键、选中后的操作",
+ "settingsSendSummary": "接收文件、保存位置",
+ "settingsStorageSummary": "记录保留多久、占用空间",
+ "settingsAboutSummary": "版本、更新、反馈"
}
diff --git a/ui/lib/l10n/app_zh_Hant_HK.arb b/ui/lib/l10n/app_zh_Hant_HK.arb
index 83ee96d..3c26f6c 100644
--- a/ui/lib/l10n/app_zh_Hant_HK.arb
+++ b/ui/lib/l10n/app_zh_Hant_HK.arb
@@ -603,5 +603,13 @@
"receiveFromEveryoneDesc": "同一區域網絡裏的人都能傳,每次由你接受;10 分鐘後改回「只限好友」。",
"everyoneEnded": "「所有人」已結束,改回「只限好友」。",
"friendsCountTooltip": "好友",
- "waitingAccept": "等待接受"
+ "waitingAccept": "等待接受",
+ "settingsConnection": "連接",
+ "settingsGeneralSummary": "開機啟動、裝置名稱、語言",
+ "settingsConnectionSummary": "服務、自建伺服器、區域網絡",
+ "settingsSyncSummary": "即時同步、自動同步上限、同步哪些內容",
+ "settingsQuickPasteSummary": "快速鍵、選取後的動作",
+ "settingsSendSummary": "接收檔案、儲存位置",
+ "settingsStorageSummary": "記錄保留多久、佔用空間",
+ "settingsAboutSummary": "版本、更新、回報"
}
diff --git a/ui/lib/l10n/app_zh_Hant_TW.arb b/ui/lib/l10n/app_zh_Hant_TW.arb
index f79f529..aa9cec8 100644
--- a/ui/lib/l10n/app_zh_Hant_TW.arb
+++ b/ui/lib/l10n/app_zh_Hant_TW.arb
@@ -603,5 +603,13 @@
"receiveFromEveryoneDesc": "同一區域網路裡的人都能傳,每次由你接受;10 分鐘後改回「僅限好友」。",
"everyoneEnded": "「所有人」已結束,改回「僅限好友」。",
"friendsCountTooltip": "好友",
- "waitingAccept": "等待接受"
+ "waitingAccept": "等待接受",
+ "settingsConnection": "連線",
+ "settingsGeneralSummary": "開機啟動、裝置名稱、語言",
+ "settingsConnectionSummary": "服務、自架伺服器、區域網路",
+ "settingsSyncSummary": "即時同步、自動同步上限、同步哪些內容",
+ "settingsQuickPasteSummary": "快速鍵、選取後的動作",
+ "settingsSendSummary": "接收檔案、儲存位置",
+ "settingsStorageSummary": "記錄保留多久、佔用空間",
+ "settingsAboutSummary": "版本、更新、回報"
}
diff --git a/ui/lib/pages/quick_paste_settings.dart b/ui/lib/pages/quick_paste_settings.dart
index 95d7742..8ce7fe0 100644
--- a/ui/lib/pages/quick_paste_settings.dart
+++ b/ui/lib/pages/quick_paste_settings.dart
@@ -15,9 +15,12 @@ import '../widgets/common.dart';
/// 设置页的「快捷粘贴」一节:开关、快捷键、选中后直接粘贴还是只复制,以及各平台要用户处理的事
/// (Mac 的辅助功能权限、Linux Wayland 的系统快捷键)。见 design/quick-paste-and-favorites.md 第 9 节。
class QuickPasteSection extends StatelessWidget {
- const QuickPasteSection({super.key, required this.config, required this.onUpdate});
+ const QuickPasteSection({super.key, required this.config, required this.onUpdate, this.titled = true});
final Config config;
+
+ /// 单独占一页时不再重复标题
+ final bool titled;
final Future<void> Function(Config next) onUpdate;
@override
@@ -34,7 +37,7 @@ class QuickPasteSection extends StatelessWidget {
final systemShortcut = qp?.hotkeySource == 'system_shortcut';
return GroupSection(
- title: l.quickPaste,
+ title: titled ? l.quickPaste : '',
child: GroupBox(
children: [
SettingRow(
diff --git a/ui/lib/pages/send_settings.dart b/ui/lib/pages/send_settings.dart
index 4ae6ad4..c5c7e50 100644
--- a/ui/lib/pages/send_settings.dart
+++ b/ui/lib/pages/send_settings.dart
@@ -14,9 +14,12 @@ import '../widgets/send_dialog.dart' show revealLabel;
/// 设置页里的「隔空传送」一组:接不接收、存到哪里、收到时通知。见 design/send-files.md 第 3 节。
class SendSection extends StatefulWidget {
- const SendSection({super.key, required this.config, required this.onUpdate});
+ const SendSection({super.key, required this.config, required this.onUpdate, this.titled = true});
final Config config;
+
+ /// 单独占一页时不再重复标题
+ final bool titled;
final Future<void> Function(Config next) onUpdate;
@override
@@ -68,7 +71,7 @@ class _SendSectionState extends State<SendSection> {
final custom = cfg.receiveDir.isNotEmpty;
final p = context.palette;
return GroupSection(
- title: l.navSend,
+ title: widget.titled ? l.navSend : '',
footnote: l.receiveFootnote(Wording.thisDeviceInText),
child: GroupBox(
children: [
diff --git a/ui/lib/pages/settings_page.dart b/ui/lib/pages/settings_page.dart
index fa91e99..4969e23 100644
--- a/ui/lib/pages/settings_page.dart
+++ b/ui/lib/pages/settings_page.dart
@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:fixnum/fixnum.dart';
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import '../app_state.dart';
import '../application_lifecycle.dart';
@@ -35,6 +36,11 @@ class _SettingsPageState extends State<SettingsPage> {
String? _lastLoadedServer;
String? _lastLoadedName;
+ /// 打开的类别;为空时显示类别列表
+ _Category? _category;
+
+ void _open(_Category c) => setState(() => _category = c);
+
@override
void dispose() {
_serverController.dispose();
@@ -67,6 +73,9 @@ class _SettingsPageState extends State<SettingsPage> {
return const Center(child: CircularProgressIndicator(strokeWidth: 2.5));
}
_syncControllers(cfg);
+ // 好友连不上时点「打开服务…」等:直接进到某一类
+ final requested = _Category.byName(state.takeSettingsCategory());
+ if (requested != null) _category = requested;
final p = context.palette;
final l = context.l10n;
@@ -82,442 +91,428 @@ class _SettingsPageState extends State<SettingsPage> {
(true, false) => (p.danger, l.notConnected, l.disconnectedDesc),
};
- return Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- PageHeader(title: l.navSettings),
- Expanded(
- child: ListView(
- padding: const EdgeInsets.fromLTRB(
- Insets.xl,
- 0,
- Insets.xl,
- Insets.xxl,
- ),
+ final groups = <_Category, List<Widget>>{
+ _Category.general: [
+ GroupSection(
+ title: '',
+ child: GroupBox(
children: [
- GroupSection(
- title: l.general,
- child: GroupBox(
- children: [
- SettingRow(
- title: l.launchAtLogin,
- description: l.launchAtLoginDesc,
- child: SmallSwitch(
- value: cfg.launchAtLogin,
- onChanged: _startupSaving || !state.service.available
- ? null
- : (v) async {
- setState(() => _startupSaving = true);
- try {
- await state.setLaunchAtLogin(v);
- } catch (e) {
- if (context.mounted) {
- showToast(
- context,
- AppState.describeError(e),
- error: true,
- );
- }
- } finally {
- if (mounted) {
- setState(() => _startupSaving = false);
- }
- }
- },
- ),
- ),
- SettingRow(
- title: l.quitApp,
- description: l.quitAppDesc,
- child: OutlinedButton(
- onPressed: () => requestApplicationQuit(context, state),
- child: Text(l.quitApp),
- ),
- ),
- ],
+ SettingRow(
+ title: l.launchAtLogin,
+ description: l.launchAtLoginDesc,
+ child: SmallSwitch(
+ value: cfg.launchAtLogin,
+ onChanged: _startupSaving || !state.service.available
+ ? null
+ : (v) async {
+ setState(() => _startupSaving = true);
+ try {
+ await state.setLaunchAtLogin(v);
+ } catch (e) {
+ if (context.mounted) {
+ showToast(
+ context,
+ AppState.describeError(e),
+ error: true,
+ );
+ }
+ } finally {
+ if (mounted) {
+ setState(() => _startupSaving = false);
+ }
+ }
+ },
),
),
- GroupSection(
- title: l.server,
- child: GroupBox(
- children: [
- SettingRow(
- title: l.useOfficialService,
- description: l.officialServiceDesc,
- child: SmallSwitch(
- value: state.officialEnabled,
- onChanged: _serverSaving
- ? null
- : (v) => _setOfficial(state, cfg, v),
- ),
- ),
- SettingRow(
- title: l.customServer,
- description: l.signalingUrlDesc,
- child: SizedBox(
- width: 360,
- child: Row(
- children: [
- Expanded(
- child: TextField(
- controller: _serverController,
- style: context.text.bodyMedium?.copyWith(
- fontFamily: monoFamily,
- fontSize: 12,
- ),
- decoration: InputDecoration(
- hintText: l.signalingUrlPlaceholder,
- ),
- onChanged: (_) =>
- setState(() => _serverDirty = true),
- onSubmitted: (_) => _saveServer(state, cfg),
+ SettingRow(
+ title: l.quitApp,
+ description: l.quitAppDesc,
+ child: OutlinedButton(
+ onPressed: () => requestApplicationQuit(context, state),
+ child: Text(l.quitApp),
+ ),
+ ),
+ ],
+ ),
+ ),
+ GroupSection(
+ title: Wording.thisDevice,
+ child: GroupBox(
+ children: [
+ SettingRow(
+ title: l.deviceName,
+ child: SizedBox(
+ width: 220,
+ child: TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ suffixIcon: _nameDirty
+ ? IconButton(
+ tooltip: l.save,
+ icon: Icon(
+ AppIcons.checkmark,
+ size: 14,
+ color: p.accent,
),
- ),
- const SizedBox(width: 8),
- FilledButton(
- onPressed: _serverSaving
- ? null
- : () => _saveServer(state, cfg),
- child: Text(l.saveAndConnect),
- ),
- ],
- ),
- ),
- ),
- SettingRow(
- title: l.publicStun,
- description: l.publicStunDesc,
- child: SmallSwitch(
- value: !cfg.onlyOwnStun,
- onChanged: (v) => _update(state, cfg..onlyOwnStun = !v),
- ),
- ),
- SettingRow(
- title: l.connectionStatus,
- description: statusDesc,
- child: StatusDot(color: statusColor, label: statusLabel),
+ onPressed: () => _saveName(state, cfg),
+ )
+ : null,
),
+ onChanged: (_) => setState(() => _nameDirty = true),
+ onSubmitted: (_) => _saveName(state, cfg),
+ ),
+ ),
+ ),
+ SettingRow(
+ title: l.language,
+ child: _Dropdown<String>(
+ value: cfg.language,
+ // 语言名用各自的写法,选错了语言的人也认得出自己的
+ items: [
+ MapEntry('', l.languageSystem),
+ const MapEntry('zh-Hans', '简体中文'),
+ const MapEntry('zh-Hant-TW', '繁體中文(台灣)'),
+ const MapEntry('zh-Hant-HK', '繁體中文(香港)'),
+ const MapEntry('en', 'English'),
+ const MapEntry('ja', '日本語'),
],
+ onChanged: (v) => _update(state, cfg..language = v),
),
),
- GroupSection(
- title: l.localNetwork,
- child: GroupBox(
- children: [
- SettingRow(
- title: l.lanDiscovery,
- description: l.lanDiscoveryDesc,
- child: SmallSwitch(
- value: !cfg.lanDisabled,
- onChanged: (v) => _update(state, cfg..lanDisabled = !v),
- ),
- ),
- if (Platform.isMacOS)
- SettingRow(
- title: l.macLocalNetwork,
- description: l.macLocalNetworkDesc,
- child: OutlinedButton(
- onPressed: () => _allowLocalNetwork(state, null),
- child: Text(l.openSystemSettings),
- ),
+ ],
+ ),
+ ),
+ if (state.service.available)
+ GroupSection(
+ title: l.backgroundSync,
+ child: GroupBox(
+ children: [
+ SettingRow(
+ title: l.backgroundService,
+ description: l.backgroundServiceDesc,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ OutlinedButton(
+ onPressed: () =>
+ _serviceAction(state.restartService, l.restarted),
+ child: Text(l.restart),
),
- if (Platform.isWindows)
- SettingRow(
- title: l.allowLan,
- description: l.allowLanDesc,
- child: OutlinedButton(
- onPressed: () =>
- _allowLocalNetwork(state, l.allowLanDone),
- child: Text(l.allow),
- ),
+ const SizedBox(width: Insets.sm),
+ OutlinedButton(
+ onPressed: () => _confirmDisable(state),
+ child: Text(l.disableEllipsis),
),
- ],
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ _Category.connection: [
+ GroupSection(
+ title: l.server,
+ child: GroupBox(
+ children: [
+ SettingRow(
+ title: l.useOfficialService,
+ description: l.officialServiceDesc,
+ child: SmallSwitch(
+ value: state.officialEnabled,
+ onChanged: _serverSaving
+ ? null
+ : (v) => _setOfficial(state, cfg, v),
),
),
- GroupSection(
- title: Wording.thisDevice,
- child: GroupBox(
- children: [
- SettingRow(
- title: l.deviceName,
- child: SizedBox(
- width: 220,
+ SettingRow(
+ title: l.customServer,
+ description: l.signalingUrlDesc,
+ child: SizedBox(
+ width: 360,
+ child: Row(
+ children: [
+ Expanded(
child: TextField(
- controller: _nameController,
+ controller: _serverController,
+ style: context.text.bodyMedium?.copyWith(
+ fontFamily: monoFamily,
+ fontSize: 12,
+ ),
decoration: InputDecoration(
- suffixIcon: _nameDirty
- ? IconButton(
- tooltip: l.save,
- icon: Icon(
- AppIcons.checkmark,
- size: 14,
- color: p.accent,
- ),
- onPressed: () => _saveName(state, cfg),
- )
- : null,
+ hintText: l.signalingUrlPlaceholder,
),
- onChanged: (_) => setState(() => _nameDirty = true),
- onSubmitted: (_) => _saveName(state, cfg),
+ onChanged: (_) => setState(() => _serverDirty = true),
+ onSubmitted: (_) => _saveServer(state, cfg),
),
),
- ),
- SettingRow(
- title: l.language,
- child: _Dropdown<String>(
- value: cfg.language,
- // 语言名用各自的写法,选错了语言的人也认得出自己的
- items: [
- MapEntry('', l.languageSystem),
- const MapEntry('zh-Hans', '简体中文'),
- const MapEntry('zh-Hant-TW', '繁體中文(台灣)'),
- const MapEntry('zh-Hant-HK', '繁體中文(香港)'),
- const MapEntry('en', 'English'),
- const MapEntry('ja', '日本語'),
- ],
- onChanged: (v) => _update(state, cfg..language = v),
+ const SizedBox(width: 8),
+ FilledButton(
+ onPressed: _serverSaving
+ ? null
+ : () => _saveServer(state, cfg),
+ child: Text(l.saveAndConnect),
),
- ),
- ],
+ ],
+ ),
),
),
- QuickPasteSection(
- config: cfg,
- onUpdate: (next) => _update(state, next),
+ SettingRow(
+ title: l.publicStun,
+ description: l.publicStunDesc,
+ child: SmallSwitch(
+ value: !cfg.onlyOwnStun,
+ onChanged: (v) => _update(state, cfg..onlyOwnStun = !v),
+ ),
),
- GroupSection(
- title: l.sync,
- child: GroupBox(
- children: [
- SettingRow(
- title: l.realtimeSync,
- description: l.realtimeSyncDesc,
- child: SmallSwitch(
- value: !cfg.realtimeSyncDisabled,
- onChanged: (v) => _update(
- state,
- cfg.deepCopy()..realtimeSyncDisabled = !v,
- ),
- ),
- ),
- SettingRow(
- title: l.syncBacklog,
- description: l.syncBacklogDesc,
- child: SmallSwitch(
- value: cfg.syncBacklog,
- onChanged: (v) =>
- _update(state, cfg.deepCopy()..syncBacklog = v),
- ),
- ),
- SettingRow(
- title: l.autoSyncLimit,
- description: l.autoSyncLimitDesc,
- child: _ThresholdSelector(
- value: cfg.autoSyncThresholdBytes.toInt(),
- onChanged: (v) => _update(
- state,
- cfg..autoSyncThresholdBytes = Int64(v),
+ SettingRow(
+ title: l.connectionStatus,
+ description: statusDesc,
+ child: StatusDot(color: statusColor, label: statusLabel),
+ ),
+ ],
+ ),
+ ),
+ GroupSection(
+ title: l.localNetwork,
+ child: GroupBox(
+ children: [
+ SettingRow(
+ title: l.lanDiscovery,
+ description: l.lanDiscoveryDesc,
+ child: SmallSwitch(
+ value: !cfg.lanDisabled,
+ onChanged: (v) => _update(state, cfg..lanDisabled = !v),
+ ),
+ ),
+ if (Platform.isMacOS)
+ SettingRow(
+ title: l.macLocalNetwork,
+ description: l.macLocalNetworkDesc,
+ child: OutlinedButton(
+ onPressed: () => _allowLocalNetwork(state, null),
+ child: Text(l.openSystemSettings),
+ ),
+ ),
+ if (Platform.isWindows)
+ SettingRow(
+ title: l.allowLan,
+ description: l.allowLanDesc,
+ child: OutlinedButton(
+ onPressed: () => _allowLocalNetwork(state, l.allowLanDone),
+ child: Text(l.allow),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ _Category.sync: [
+ GroupSection(
+ title: l.sync,
+ child: GroupBox(
+ children: [
+ SettingRow(
+ title: l.realtimeSync,
+ description: l.realtimeSyncDesc,
+ child: SmallSwitch(
+ value: !cfg.realtimeSyncDisabled,
+ onChanged: (v) =>
+ _update(state, cfg.deepCopy()..realtimeSyncDisabled = !v),
+ ),
+ ),
+ SettingRow(
+ title: l.syncBacklog,
+ description: l.syncBacklogDesc,
+ child: SmallSwitch(
+ value: cfg.syncBacklog,
+ onChanged: (v) =>
+ _update(state, cfg.deepCopy()..syncBacklog = v),
+ ),
+ ),
+ SettingRow(
+ title: l.autoSyncLimit,
+ description: l.autoSyncLimitDesc,
+ child: _ThresholdSelector(
+ value: cfg.autoSyncThresholdBytes.toInt(),
+ onChanged: (v) =>
+ _update(state, cfg..autoSyncThresholdBytes = Int64(v)),
+ ),
+ ),
+ SettingRow(
+ title: l.largeFileNotifications,
+ description: switch (state.notificationStatus?.permission) {
+ 'allowed' => l.notificationsAllowed,
+ 'not_requested' => l.notificationsNotRequested,
+ 'denied' => l.notificationsDenied,
+ 'unknown' => l.notificationsUnknown,
+ _ => l.notificationsUnavailable,
+ },
+ child:
+ state.notificationStatus?.supported == true &&
+ !(Platform.isLinux &&
+ state.notificationStatus?.permission == 'unknown')
+ ? TextButton(
+ onPressed: () async {
+ try {
+ await state.requestNotifications();
+ } catch (e) {
+ if (context.mounted) {
+ showToast(
+ context,
+ AppState.describeError(e),
+ error: true,
+ );
+ }
+ }
+ },
+ child: Text(
+ state.notificationStatus?.permission ==
+ 'not_requested'
+ ? l.enableNotifications
+ : l.notificationSettings,
),
+ )
+ : TextButton(
+ onPressed: state.refreshNotificationStatus,
+ child: Text(l.retry),
),
- ),
- SettingRow(
- title: l.largeFileNotifications,
- description:
- switch (state.notificationStatus?.permission) {
- 'allowed' => l.notificationsAllowed,
- 'not_requested' => l.notificationsNotRequested,
- 'denied' => l.notificationsDenied,
- 'unknown' => l.notificationsUnknown,
- _ => l.notificationsUnavailable,
- },
- child:
- state.notificationStatus?.supported == true &&
- !(Platform.isLinux &&
- state.notificationStatus?.permission ==
- 'unknown')
- ? TextButton(
- onPressed: () async {
- try {
- await state.requestNotifications();
- } catch (e) {
- if (context.mounted) {
- showToast(
- context,
- AppState.describeError(e),
- error: true,
- );
- }
- }
- },
- child: Text(
- state.notificationStatus?.permission ==
- 'not_requested'
- ? l.enableNotifications
- : l.notificationSettings,
- ),
- )
- : TextButton(
- onPressed: state.refreshNotificationStatus,
- child: Text(l.retry),
- ),
- ),
- SettingRow(
- title: l.autoApply,
- child: SmallSwitch(
- value: cfg.autoApplyToClipboard,
- onChanged: (v) =>
- _update(state, cfg..autoApplyToClipboard = v),
- ),
- ),
- ],
+ ),
+ SettingRow(
+ title: l.autoApply,
+ child: SmallSwitch(
+ value: cfg.autoApplyToClipboard,
+ onChanged: (v) =>
+ _update(state, cfg..autoApplyToClipboard = v),
),
),
- SendSection(
- config: cfg,
- onUpdate: (next) => _update(state, next),
+ ],
+ ),
+ ),
+ GroupSection(
+ title: l.whatToSync,
+ child: GroupBox(
+ children: [
+ _ToggleRow(
+ title: l.syncFiles,
+ value: cfg.syncFile,
+ onChanged: (v) => _update(state, cfg..syncFile = v),
),
- GroupSection(
- title: l.whatToSync,
- child: GroupBox(
- children: [
- _ToggleRow(
- title: l.syncFiles,
- value: cfg.syncFile,
- onChanged: (v) => _update(state, cfg..syncFile = v),
- ),
- _ToggleRow(
- title: l.syncText,
- value: cfg.syncText,
- onChanged: (v) => _update(state, cfg..syncText = v),
- ),
- _ToggleRow(
- title: l.syncRich,
- value: cfg.syncHtml,
- onChanged: (v) => _update(state, cfg..syncHtml = v),
- ),
- _ToggleRow(
- title: l.syncImages,
- value: cfg.syncImage,
- onChanged: (v) => _update(state, cfg..syncImage = v),
- ),
- ],
+ _ToggleRow(
+ title: l.syncText,
+ value: cfg.syncText,
+ onChanged: (v) => _update(state, cfg..syncText = v),
+ ),
+ _ToggleRow(
+ title: l.syncRich,
+ value: cfg.syncHtml,
+ onChanged: (v) => _update(state, cfg..syncHtml = v),
+ ),
+ _ToggleRow(
+ title: l.syncImages,
+ value: cfg.syncImage,
+ onChanged: (v) => _update(state, cfg..syncImage = v),
+ ),
+ ],
+ ),
+ ),
+ ],
+ _Category.quickPaste: [
+ QuickPasteSection(
+ config: cfg,
+ onUpdate: (next) => _update(state, next),
+ titled: false,
+ ),
+ ],
+ _Category.send: [
+ SendSection(
+ config: cfg,
+ onUpdate: (next) => _update(state, next),
+ titled: false,
+ ),
+ ],
+ _Category.storage: [
+ GroupSection(
+ title: '',
+ footnote: l.storageFootnote,
+ child: GroupBox(
+ children: [
+ SettingRow(
+ title: l.keepHistory,
+ child: _DurationSelector(
+ seconds: cfg.historyTtlSeconds.toInt(),
+ onChanged: (v) =>
+ _update(state, cfg..historyTtlSeconds = Int64(v)),
),
),
- GroupSection(
- title: l.storage,
- footnote: l.storageFootnote,
- child: GroupBox(
+ SettingRow(
+ title: l.keepCache,
+ description: l.keepCacheDesc,
+ child: _DurationSelector(
+ seconds: cfg.cacheTtlSeconds.toInt(),
+ onChanged: (v) =>
+ _update(state, cfg..cacheTtlSeconds = Int64(v)),
+ ),
+ ),
+ SettingRow(
+ title: l.cacheUsage,
+ child: Text(
+ humanBytes(state.status?.cacheBytesUsed.toInt() ?? 0),
+ style: context.text.bodyMedium?.copyWith(color: p.textDim),
+ ),
+ ),
+ // 硬链接、写时复制保存的副本实际占用更少,所以写「最多」
+ SettingRow(
+ title: l.favoritesUsage,
+ description: l.favoritesUsageDesc,
+ child: Text(
+ l.upToSize(humanBytes(state.favoritesBytes)),
+ style: context.text.bodyMedium?.copyWith(color: p.textDim),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ _Category.about: [
+ GroupSection(
+ title: '',
+ child: GroupBox(
+ children: [
+ SettingRow(
+ title: '${l.appName} ${state.status?.version ?? ''}',
+ description: appBuild.isEmpty
+ ? l.aboutDesc
+ : '${l.aboutDesc}\n${l.buildDetails(appVersion, state.status?.version ?? '…', appBuild)}',
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
children: [
- SettingRow(
- title: l.keepHistory,
- child: _DurationSelector(
- seconds: cfg.historyTtlSeconds.toInt(),
- onChanged: (v) =>
- _update(state, cfg..historyTtlSeconds = Int64(v)),
- ),
+ TextButton(
+ onPressed: () => _openUrl('https://pasteferry.cc/'),
+ child: Text(l.homepage),
),
- SettingRow(
- title: l.keepCache,
- description: l.keepCacheDesc,
- child: _DurationSelector(
- seconds: cfg.cacheTtlSeconds.toInt(),
- onChanged: (v) =>
- _update(state, cfg..cacheTtlSeconds = Int64(v)),
- ),
- ),
- SettingRow(
- title: l.cacheUsage,
- child: Text(
- humanBytes(state.status?.cacheBytesUsed.toInt() ?? 0),
- style: context.text.bodyMedium?.copyWith(
- color: p.textDim,
- ),
- ),
- ),
- // 硬链接、写时复制保存的副本实际占用更少,所以写「最多」
- SettingRow(
- title: l.favoritesUsage,
- description: l.favoritesUsageDesc,
- child: Text(
- l.upToSize(humanBytes(state.favoritesBytes)),
- style: context.text.bodyMedium?.copyWith(
- color: p.textDim,
- ),
- ),
+ TextButton(
+ onPressed: () => showFeedbackDialog(context),
+ child: Text(l.feedback),
),
],
),
),
- if (state.service.available)
- GroupSection(
- title: l.backgroundSync,
- child: GroupBox(
- children: [
- SettingRow(
- title: l.backgroundService,
- description: l.backgroundServiceDesc,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- OutlinedButton(
- onPressed: () => _serviceAction(
- state.restartService,
- l.restarted,
- ),
- child: Text(l.restart),
- ),
- const SizedBox(width: Insets.sm),
- OutlinedButton(
- onPressed: () => _confirmDisable(state),
- child: Text(l.disableEllipsis),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- GroupSection(
- title: l.about,
- child: GroupBox(
+ SettingRow(
+ title: l.updateAuto,
+ description: l.updateAutoDesc,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
children: [
- SettingRow(
- title: '${l.appName} ${state.status?.version ?? ''}',
- description: appBuild.isEmpty
- ? l.aboutDesc
- : '${l.aboutDesc}\n${l.buildDetails(appVersion, state.status?.version ?? '…', appBuild)}',
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- TextButton(
- onPressed: () => _open('https://pasteferry.cc/'),
- child: Text(l.homepage),
- ),
- TextButton(
- onPressed: () => showFeedbackDialog(context),
- child: Text(l.feedback),
- ),
- ],
- ),
+ TextButton(
+ onPressed: () => showUpdateDialog(context),
+ child: Text(l.updateCheckEllipsis),
),
- SettingRow(
- title: l.updateAuto,
- description: l.updateAutoDesc,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- TextButton(
- onPressed: () => showUpdateDialog(context),
- child: Text(l.updateCheckEllipsis),
- ),
- const SizedBox(width: Insets.sm),
- SmallSwitch(
- value: !cfg.updateCheckDisabled,
- onChanged: (v) =>
- _update(state, cfg..updateCheckDisabled = !v),
- ),
- ],
- ),
+ const SizedBox(width: Insets.sm),
+ SmallSwitch(
+ value: !cfg.updateCheckDisabled,
+ onChanged: (v) =>
+ _update(state, cfg..updateCheckDisabled = !v),
),
],
),
@@ -526,10 +521,50 @@ class _SettingsPageState extends State<SettingsPage> {
),
),
],
+ };
+
+ final category = _category;
+ if (category == null) {
+ return _CategoryList(
+ onOpen: _open,
+ connection: StatusDot(color: statusColor, label: statusLabel),
+ version: state.status?.version ?? '',
+ );
+ }
+ return CallbackShortcuts(
+ bindings: {
+ const SingleActivator(LogicalKeyboardKey.escape): () =>
+ setState(() => _category = null),
+ },
+ child: Focus(
+ autofocus: true,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ PageHeader(
+ title: category.title(l),
+ backLabel: l.navSettings,
+ onBack: () => setState(() => _category = null),
+ ),
+ Expanded(
+ child: ListView(
+ key: PageStorageKey(category),
+ padding: const EdgeInsets.fromLTRB(
+ Insets.xl,
+ 0,
+ Insets.xl,
+ Insets.xxl,
+ ),
+ children: groups[category]!,
+ ),
+ ),
+ ],
+ ),
+ ),
);
}
- static void _open(String url) => openUrl(url);
+ static void _openUrl(String url) => openUrl(url);
Future<void> _serviceAction(
Future<void> Function() action,
@@ -785,3 +820,171 @@ class _Dropdown<T> extends StatelessWidget {
);
}
}
+
+/// 设置的类别:首页列出来,点进去是各自的一页
+enum _Category {
+ general,
+ connection,
+ sync,
+ quickPaste,
+ send,
+ storage,
+ about;
+
+ static _Category? byName(String? name) =>
+ values.where((c) => c.name == name).firstOrNull;
+
+ String title(AppLocalizations l) => switch (this) {
+ general => l.general,
+ connection => l.settingsConnection,
+ sync => l.sync,
+ quickPaste => l.quickPaste,
+ send => l.navSend,
+ storage => l.storage,
+ about => l.about,
+ };
+
+ String summary(AppLocalizations l) => switch (this) {
+ general => l.settingsGeneralSummary,
+ connection => l.settingsConnectionSummary,
+ sync => l.settingsSyncSummary,
+ quickPaste => l.settingsQuickPasteSummary,
+ send => l.settingsSendSummary,
+ storage => l.settingsStorageSummary,
+ about => l.settingsAboutSummary,
+ };
+
+ IconData get icon => switch (this) {
+ general => AppIcons.gear,
+ connection => AppIcons.globe,
+ sync => AppIcons.sync,
+ quickPaste => AppIcons.keyboard,
+ send => AppIcons.send,
+ storage => AppIcons.archive,
+ about => AppIcons.info,
+ };
+}
+
+/// 设置首页:分组的类别列表,设置项再多也一屏看完
+class _CategoryList extends StatelessWidget {
+ const _CategoryList({
+ required this.onOpen,
+ required this.connection,
+ required this.version,
+ });
+
+ final ValueChanged<_Category> onOpen;
+ final Widget connection;
+ final String version;
+
+ static const _groups = [
+ [_Category.general, _Category.connection],
+ [_Category.sync, _Category.quickPaste, _Category.send],
+ [_Category.storage, _Category.about],
+ ];
+
+ @override
+ Widget build(BuildContext context) {
+ final l = context.l10n;
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ PageHeader(title: l.navSettings),
+ Expanded(
+ child: ListView(
+ padding: const EdgeInsets.fromLTRB(
+ Insets.xl,
+ 0,
+ Insets.xl,
+ Insets.xxl,
+ ),
+ children: [
+ for (final group in _groups)
+ Padding(
+ padding: const EdgeInsets.only(bottom: Insets.xl),
+ child: GroupBox(
+ dividerIndent: Insets.lg + 30,
+ children: [
+ for (final c in group)
+ _CategoryRow(
+ category: c,
+ trailing: switch (c) {
+ _Category.connection => connection,
+ _Category.about when version.isNotEmpty => Text(
+ version,
+ style: context.text.bodyMedium?.copyWith(
+ color: context.palette.textDim,
+ ),
+ ),
+ _ => null,
+ },
+ onTap: () => onOpen(c),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ );
+ }
+}
+
+class _CategoryRow extends StatelessWidget {
+ const _CategoryRow({
+ required this.category,
+ required this.onTap,
+ this.trailing,
+ });
+
+ final _Category category;
+ final VoidCallback onTap;
+ final Widget? trailing;
+
+ @override
+ Widget build(BuildContext context) {
+ final p = context.palette;
+ final l = context.l10n;
+ return Material(
+ type: MaterialType.transparency,
+ child: InkWell(
+ onTap: onTap,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: 52),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: Insets.lg,
+ vertical: 10,
+ ),
+ child: Row(
+ children: [
+ SizedBox(
+ width: 30,
+ child: Icon(category.icon, size: 18, color: p.textDim),
+ ),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(category.title(l), style: context.text.labelLarge),
+ const SizedBox(height: 2),
+ Text(category.summary(l), style: context.text.bodySmall),
+ ],
+ ),
+ ),
+ if (trailing != null) ...[
+ const SizedBox(width: Insets.md),
+ trailing!,
+ ],
+ const SizedBox(width: Insets.sm),
+ Icon(AppIcons.chevronRight, size: 13, color: p.textFaint),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/ui/lib/widgets/common.dart b/ui/lib/widgets/common.dart
index cd3c4fc..f4a02bd 100644
--- a/ui/lib/widgets/common.dart
+++ b/ui/lib/widgets/common.dart
@@ -12,17 +12,24 @@ class PageHeader extends StatelessWidget {
required this.title,
this.subtitle,
this.actions = const [],
+ this.backLabel,
+ this.onBack,
});
final String title;
final String? subtitle;
final List<Widget> actions;
+ /// 二级页:标题上方的「‹ 上一级」
+ final String? backLabel;
+ final VoidCallback? onBack;
+
@override
Widget build(BuildContext context) {
+ final back = onBack != null;
return Padding(
- // 顶部留出 macOS 红绿灯所在的标题栏高度
- padding: const EdgeInsets.fromLTRB(Insets.xl, 44, Insets.xl, Insets.lg),
+ // 顶部留出 macOS 红绿灯所在的标题栏高度;二级页的返回链接占掉其中一部分
+ padding: EdgeInsets.fromLTRB(Insets.xl, back ? 18 : 44, Insets.xl, Insets.lg),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
@@ -30,6 +37,7 @@ class PageHeader extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
+ if (back) _BackLink(label: backLabel ?? '', onTap: onBack!),
Text(title, style: context.text.headlineSmall),
if (subtitle != null) ...[
const SizedBox(height: 2),
@@ -45,6 +53,39 @@ class PageHeader extends StatelessWidget {
}
}
+class _BackLink extends StatelessWidget {
+ const _BackLink({required this.label, required this.onTap});
+
+ final String label;
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final color = context.palette.accent;
+ return Padding(
+ padding: const EdgeInsets.only(bottom: 4),
+ child: MouseRegion(
+ cursor: SystemMouseCursors.click,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: SizedBox(
+ height: 22,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(AppIcons.chevronLeft, size: 13, color: color),
+ const SizedBox(width: 2),
+ Text(label, style: context.text.bodyMedium?.copyWith(color: color)),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
/// 分组容器:白底、细边框,内部各行之间用缩进的细线分隔。
/// 与「系统设置」的分组列表同一种做法——用分隔线而不是一张张独立卡片。
class GroupBox extends StatelessWidget {
@@ -90,10 +131,11 @@ class GroupSection extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- Padding(
- padding: const EdgeInsets.only(left: 2, bottom: Insets.sm),
- child: Text(title, style: context.text.titleSmall),
- ),
+ if (title.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(left: 2, bottom: Insets.sm),
+ child: Text(title, style: context.text.titleSmall),
+ ),
child,
if (footnote != null)
Padding(
diff --git a/ui/lib/widgets/friends_dialog.dart b/ui/lib/widgets/friends_dialog.dart
index 505824d..f4ead6b 100644
--- a/ui/lib/widgets/friends_dialog.dart
+++ b/ui/lib/widgets/friends_dialog.dart
@@ -65,7 +65,7 @@ Future<void> showReachabilityHint(BuildContext context, Friend f) async {
],
),
);
- if (open == true && context.mounted) AppScope.read(context).requestPage('settings');
+ if (open == true && context.mounted) AppScope.read(context).requestPage('settings:connection');
}
// ─────────────────────────── 好友列表 ───────────────────────────
diff --git a/ui/test/i18n_test.dart b/ui/test/i18n_test.dart
index c0ff622..ce9ac1b 100644
--- a/ui/test/i18n_test.dart
+++ b/ui/test/i18n_test.dart
@@ -188,13 +188,25 @@ void main() {
expect(find.text(l.pairedDevices), findsOneWidget);
await tester.tap(find.text(l.navSettings).first);
await tester.pump();
- await tester.dragUntilVisible(find.text(l.language), find.byType(ListView), const Offset(0, -100));
- // 辅助功能授权只有 Mac 上有
- if (Platform.isMacOS) {
- await tester.dragUntilVisible(find.text(l.quickPasteAccessibility), find.byType(ListView), const Offset(0, -100));
+ // 设置首页列出各类,逐个点进去、拉到底,再回到首页
+ final pages = <String, String>{
+ l.general: l.language,
+ l.settingsConnection: l.lanDiscovery,
+ l.sync: l.syncImages,
+ // 辅助功能授权只有 Mac 上有
+ l.quickPaste: Platform.isMacOS ? l.quickPasteAccessibility : l.quickPasteWindow,
+ l.navSend: l.receiveNotify,
+ l.storage: l.favoritesUsage,
+ l.about: l.updateAuto,
+ };
+ for (final MapEntry(key: title, value: last) in pages.entries) {
+ await tester.dragUntilVisible(find.text(title).last, find.byType(ListView).last, const Offset(0, -100));
+ await tester.tap(find.text(title).last);
+ await tester.pump();
+ await tester.dragUntilVisible(find.text(last), find.byType(ListView).last, const Offset(0, -100));
+ await tester.tap(find.text(l.navSettings).last);
+ await tester.pump();
}
- await tester.dragUntilVisible(find.text(l.favoritesUsage), find.byType(ListView), const Offset(0, -100));
- await tester.dragUntilVisible(find.text(l.about), find.byType(ListView), const Offset(0, -200));
});
testWidgets('配对对话框', (tester) async {
diff --git a/ui/test/official_service_test.dart b/ui/test/official_service_test.dart
index f93a247..ee1d099 100644
--- a/ui/test/official_service_test.dart
+++ b/ui/test/official_service_test.dart
@@ -86,6 +86,8 @@ void main() {
await tester.pumpWidget(PasteFerryApp(state: state));
await tester.tap(find.text('设置').first);
await tester.pumpAndSettle();
+ await tester.tap(find.text('连接'));
+ await tester.pumpAndSettle();
final input = find.byType(TextField).first;
await tester.enterText(input, 'wss://my.example/signal');
expect(state.saves, 0);
diff --git a/ui/test/send_page_test.dart b/ui/test/send_page_test.dart
index 42945a2..4562396 100644
--- a/ui/test/send_page_test.dart
+++ b/ui/test/send_page_test.dart
@@ -145,6 +145,8 @@ void main() {
final l = AppLocalizations.of(tester.element(find.byType(Shell)));
await tester.tap(find.text(l.navSettings).first);
await tester.pump();
+ await tester.tap(find.text(l.navSend).last);
+ await tester.pump();
await tester.dragUntilVisible(find.text(l.receiveNotify), find.byType(ListView), const Offset(0, -100));
expect(find.text(l.receiveFiles), findsOneWidget);
expect(find.text(l.sendLayout), findsOneWidget);
diff --git a/ui/test/settings_page_test.dart b/ui/test/settings_page_test.dart
new file mode 100644
index 0000000..f0ba396
--- /dev/null
+++ b/ui/test/settings_page_test.dart
@@ -0,0 +1,48 @@
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:pasteferry_ui/app_state.dart';
+import 'package:pasteferry_ui/gen/pasteferry/v1/daemon.pb.dart';
+import 'package:pasteferry_ui/main.dart';
+
+AppState _state() => AppState()..debugSeed(status: Status(), config: Config(), self: Device(id: 'self'));
+
+void main() {
+ testWidgets('设置首页列出各类,点进去是二级页,能返回', (tester) async {
+ await tester.pumpWidget(PasteFerryApp(state: _state()));
+ await tester.tap(find.text('设置').first);
+ await tester.pumpAndSettle();
+ for (final title in ['通用', '连接', '同步', '快捷粘贴', '存储', '关于']) {
+ expect(find.text(title), findsOneWidget);
+ }
+ // 首页只有类别,没有具体的设置项
+ expect(find.text('在局域网中查找设备'), findsNothing);
+
+ await tester.tap(find.text('连接'));
+ await tester.pumpAndSettle();
+ expect(find.text('在局域网中查找设备'), findsOneWidget);
+ expect(find.text('通用'), findsNothing);
+
+ // 点「‹ 设置」回到首页
+ await tester.tap(find.text('设置').last);
+ await tester.pumpAndSettle();
+ expect(find.text('通用'), findsOneWidget);
+
+ // Esc 也能返回
+ await tester.tap(find.text('存储'));
+ await tester.pumpAndSettle();
+ expect(find.text('记录保留'), findsOneWidget);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pumpAndSettle();
+ expect(find.text('通用'), findsOneWidget);
+ });
+
+ testWidgets('好友连不上时「打开服务…」直接进到连接', (tester) async {
+ final state = _state();
+ await tester.pumpWidget(PasteFerryApp(state: state));
+ await tester.pumpAndSettle();
+ state.requestPage('settings:connection');
+ await tester.pumpAndSettle();
+ expect(find.text('使用服务'), findsOneWidget);
+ expect(find.text('在局域网中查找设备'), findsOneWidget);
+ });
+}
diff --git a/ui/test/sync_controls_test.dart b/ui/test/sync_controls_test.dart
index 91c47a1..0882db9 100644
--- a/ui/test/sync_controls_test.dart
+++ b/ui/test/sync_controls_test.dart
@@ -25,6 +25,8 @@ void main() {
await tester.pumpWidget(PasteFerryApp(state: state));
await tester.tap(find.text('设置').first);
await tester.pumpAndSettle();
+ await tester.tap(find.text('同步').last);
+ await tester.pumpAndSettle();
Future<void> toggle(String title) async {
await tester.scrollUntilVisible(
find.text(title),
diff --git a/ui/test/update_test.dart b/ui/test/update_test.dart
index 7bbf9a7..610c493 100644
--- a/ui/test/update_test.dart
+++ b/ui/test/update_test.dart
@@ -178,6 +178,8 @@ void main() {
await tester.pumpAndSettle();
await tester.tap(find.text('设置').first);
await tester.pumpAndSettle();
+ await tester.tap(find.text('关于'));
+ await tester.pumpAndSettle();
final page = find.byType(SettingsPage);
await tester.scrollUntilVisible(find.text('自动检查更新'), 200,
scrollable: find.descendant(of: page, matching: find.byType(Scrollable)).first);
diff --git a/ui/tool/screenshots/screenshots_test.dart b/ui/tool/screenshots/screenshots_test.dart
index 9c2717a..ea3ca25 100644
--- a/ui/tool/screenshots/screenshots_test.dart
+++ b/ui/tool/screenshots/screenshots_test.dart
@@ -705,7 +705,8 @@ void main() {
}
testWidgets('official-settings-dark', (tester) async {
- await _shoot(tester, 'official-settings-dark', state: officialDemo(),
+ // 服务器设置在「连接」这一类里
+ await _shoot(tester, 'official-settings-dark', state: officialDemo()..requestPage('settings:connection'),
section: Section.settings, brightness: Brightness.dark);
});
@@ -716,15 +717,17 @@ void main() {
// 网站「在局域网里部署服务器」:服务器地址填局域网 IP,已连接
testWidgets('settings-lan-dark', (tester) async {
+ // 服务器设置在「连接」这一类里
await _shoot(tester, 'settings-lan-dark',
- state: _demo(server: 'ws://192.168.1.20:8787/signal'),
+ state: _demo(server: 'ws://192.168.1.20:8787/signal')..requestPage('settings:connection'),
section: Section.settings, brightness: Brightness.dark);
});
// 网站「部署到公网服务器」:服务器地址填公网 IP(文档专用的示例地址段)
testWidgets('settings-cloud-dark', (tester) async {
+ // 服务器设置在「连接」这一类里
await _shoot(tester, 'settings-cloud-dark',
- state: _demo(server: 'ws://203.0.113.10:8787/signal'),
+ state: _demo(server: 'ws://203.0.113.10:8787/signal')..requestPage('settings:connection'),
section: Section.settings, brightness: Brightness.dark);
});