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(android): confirm the picked files and sign with a fixed key

baiyuze356ed5c70507
diff --git a/.gitignore b/.gitignore
index 5e3419c..e1e27b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,10 @@ ui/tool/screenshots/out/
# Python site generator cache
__pycache__/
*.pyc
+
+# Android 发版签名(密钥不進仓库)
+ui/android/key.properties
+*.jks
+*.keystore
+ui/android/build/
+ui/build/
diff --git a/scripts/build-android.sh b/scripts/build-android.sh
index 4745032..33e324e 100755
--- a/scripts/build-android.sh
+++ b/scripts/build-android.sh
@@ -86,4 +86,19 @@ $aar_only && exit 0
echo "▶ APK"
(cd ui && flutter build apk --release --target-platform android-arm64)
-ls -lh ui/build/app/outputs/flutter-apk/app-release.apk
+apk=ui/build/app/outputs/flutter-apk/app-release.apk
+
+# 发版签名:密钥固定在 ~/.pasteferry-android/pasteferry-release.jks,密码在登录钥匙串
+# (服务名 pasteferry-android-keystore)。这张密钥不能换:换了,已装的用户没法覆盖升级。
+# 没有密钥时留着 gradle 打的调试签名,只能内测。
+KEYSTORE="$HOME/.pasteferry-android/pasteferry-release.jks"
+if [[ -f "$KEYSTORE" ]] && ks_pw=$(security find-generic-password -s pasteferry-android-keystore -a pasteferry -w 2>/dev/null); then
+ apksigner="$(ls -d "$ANDROID_HOME"/build-tools/*/apksigner 2>/dev/null | sort -V | tail -1)"
+ "$apksigner" sign --ks "$KEYSTORE" --ks-key-alias pasteferry \
+ --ks-pass "pass:$ks_pw" --key-pass "pass:$ks_pw" "$apk"
+ unset ks_pw
+ echo " · 签名:PasteFerry Android release key"
+else
+ echo " · 签名:调试密钥(没有发版密钥,只能内测)"
+fi
+ls -lh "$apk"
diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arb
index c21fb5a..9d100d8 100644
--- a/ui/lib/l10n/app_en.arb
+++ b/ui/lib/l10n/app_en.arb
@@ -1659,6 +1659,7 @@
"mSendHint": "Type or paste text",
"mPaste": "Paste",
"mPhotosFiles": "Photos or files",
+ "mSendConfirmTitle": "Send {n} file(s)?",
"mFilesSent": "{n, plural, =1{1 file sent to your computer} other{{n} files sent to your computer}}",
"mClipboardNoText": "The clipboard has no text",
"mSendAction": "Send",
@@ -1673,7 +1674,7 @@
"mNoOnlineDevices": "No devices online nearby",
"mNoPairedDevices": "Pair with a computer first",
"mSent": "Sent",
- "mSendFootnote": "The text goes into the computer’s history and onto its clipboard, as if you had copied it there. Text you copy on this phone isn’t sent automatically: paste it here and tap Send.",
+ "mSendFootnote": "Text and files go into the records on the computer and, by its setting, into its clipboard. What you copy on the phone is not sent by itself.",
"mSendFailed": "Couldn’t send: {detail}",
"@mSendFailed": {
"placeholders": {
diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arb
index 70ba161..72176dd 100644
--- a/ui/lib/l10n/app_ja.arb
+++ b/ui/lib/l10n/app_ja.arb
@@ -647,6 +647,7 @@
"mSendHint": "テキストを入力または貼り付け",
"mPaste": "貼り付け",
"mPhotosFiles": "写真またはファイル",
+ "mSendConfirmTitle": "{n} 件のファイルを送りますか?",
"mFilesSent": "{n} 件のファイルをコンピュータに送りました",
"mClipboardNoText": "クリップボードにテキストがありません",
"mSendAction": "送信",
@@ -654,7 +655,7 @@
"mNoOnlineDevices": "近くにオンラインのデバイスがありません",
"mNoPairedDevices": "先にパソコンとペアリングしてください",
"mSent": "送信しました",
- "mSendFootnote": "テキストはパソコンの履歴に入り、パソコンの設定どおりクリップボードにも入ります。パソコンでコピーしたのと同じです。スマホでコピーした内容は自動では送られないので、ここに貼り付けて送信してください。",
+ "mSendFootnote": "テキストとファイルはパソコンの履歴に入り、設定に従ってクリップボードにも入ります。スマホでコピーした内容は自動では送られません。",
"mSendFailed": "送信できませんでした:{detail}",
"mCopy": "コピー",
"mCopied": "スマホのクリップボードにコピーしました",
diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dart
index dd38723..0fceb68 100644
--- a/ui/lib/l10n/app_localizations.dart
+++ b/ui/lib/l10n/app_localizations.dart
@@ -3992,6 +3992,12 @@ abstract class AppLocalizations {
/// **'Photos or files'**
String get mPhotosFiles;
+ /// No description provided for @mSendConfirmTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Send {n} file(s)?'**
+ String mSendConfirmTitle(Object n);
+
/// No description provided for @mFilesSent.
///
/// In en, this message translates to:
@@ -4037,7 +4043,7 @@ abstract class AppLocalizations {
/// No description provided for @mSendFootnote.
///
/// In en, this message translates to:
- /// **'The text goes into the computer’s history and onto its clipboard, as if you had copied it there. Text you copy on this phone isn’t sent automatically: paste it here and tap Send.'**
+ /// **'Text and files go into the records on the computer and, by its setting, into its clipboard. What you copy on the phone is not sent by itself.'**
String get mSendFootnote;
/// No description provided for @mSendFailed.
diff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dart
index 6c5cbde..d9d4b0d 100644
--- a/ui/lib/l10n/app_localizations_en.dart
+++ b/ui/lib/l10n/app_localizations_en.dart
@@ -2438,6 +2438,11 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get mPhotosFiles => 'Photos or files';
+ @override
+ String mSendConfirmTitle(Object n) {
+ return 'Send $n file(s)?';
+ }
+
@override
String mFilesSent(num n) {
String _temp0 = intl.Intl.pluralLogic(
@@ -2471,7 +2476,7 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get mSendFootnote =>
- 'The text goes into the computer’s history and onto its clipboard, as if you had copied it there. Text you copy on this phone isn’t sent automatically: paste it here and tap Send.';
+ 'Text and files go into the records on the computer and, by its setting, into its clipboard. What you copy on the phone is not sent by itself.';
@override
String mSendFailed(String detail) {
diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dart
index 212405a..a552577 100644
--- a/ui/lib/l10n/app_localizations_ja.dart
+++ b/ui/lib/l10n/app_localizations_ja.dart
@@ -2265,6 +2265,11 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get mPhotosFiles => '写真またはファイル';
+ @override
+ String mSendConfirmTitle(Object n) {
+ return '$n 件のファイルを送りますか?';
+ }
+
@override
String mFilesSent(num n) {
return '$n 件のファイルをコンピュータに送りました';
@@ -2292,7 +2297,7 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get mSendFootnote =>
- 'テキストはパソコンの履歴に入り、パソコンの設定どおりクリップボードにも入ります。パソコンでコピーしたのと同じです。スマホでコピーした内容は自動では送られないので、ここに貼り付けて送信してください。';
+ 'テキストとファイルはパソコンの履歴に入り、設定に従ってクリップボードにも入ります。スマホでコピーした内容は自動では送られません。';
@override
String mSendFailed(String detail) {
diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dart
index 5fecea5..bb5186f 100644
--- a/ui/lib/l10n/app_localizations_zh.dart
+++ b/ui/lib/l10n/app_localizations_zh.dart
@@ -2239,6 +2239,11 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get mPhotosFiles => '照片或文件';
+ @override
+ String mSendConfirmTitle(Object n) {
+ return '确认发送 $n 个文件?';
+ }
+
@override
String mFilesSent(num n) {
return '$n 个文件已发到电脑';
@@ -2266,7 +2271,7 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get mSendFootnote =>
- '文字会进入电脑的复制记录,并按电脑的设置写入剪贴板,就像在电脑上复制了一样。手机上复制的内容不会自动发出,要粘贴到这里再发送。';
+ '文字和文件会进电脑的复制记录,并按电脑的设置写入剪贴板。手机上复制的内容不会自动发出,粘贴到这里再发送。';
@override
String mSendFailed(String detail) {
@@ -4603,6 +4608,11 @@ class AppLocalizationsZhHantHk extends AppLocalizationsZh {
@override
String get mPhotosFiles => '照片或檔案';
+ @override
+ String mSendConfirmTitle(Object n) {
+ return '確認傳送 $n 個檔案?';
+ }
+
@override
String mFilesSent(num n) {
return '$n 個檔案已傳到電腦';
@@ -4630,7 +4640,7 @@ class AppLocalizationsZhHantHk extends AppLocalizationsZh {
@override
String get mSendFootnote =>
- '文字會進入電腦的複製記錄,並按電腦的設定寫入剪貼簿,就像在電腦上複製了一樣。手機上複製的內容不會自動送出,要貼到這裡再傳送。';
+ '文字和檔案會進電腦的複製記錄,並按電腦的設定寫入剪貼簿。手機上複製的內容不會自動發出,貼到這裏再傳送。';
@override
String mSendFailed(String detail) {
@@ -6967,6 +6977,11 @@ class AppLocalizationsZhHantTw extends AppLocalizationsZh {
@override
String get mPhotosFiles => '照片或檔案';
+ @override
+ String mSendConfirmTitle(Object n) {
+ return '確認傳送 $n 個檔案?';
+ }
+
@override
String mFilesSent(num n) {
return '$n 個檔案已傳到電腦';
@@ -6994,7 +7009,7 @@ class AppLocalizationsZhHantTw extends AppLocalizationsZh {
@override
String get mSendFootnote =>
- '文字會進入電腦的複製記錄,並依電腦的設定寫入剪貼簿,就像在電腦上複製了一樣。手機上複製的內容不會自動送出,要貼到這裡再傳送。';
+ '文字和檔案會進電腦的複製記錄,並按電腦的設定寫入剪貼簿。手機上複製的內容不會自動發出,貼到這裡再傳送。';
@override
String mSendFailed(String detail) {
diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arb
index 343fa7d..06297f6 100644
--- a/ui/lib/l10n/app_zh.arb
+++ b/ui/lib/l10n/app_zh.arb
@@ -647,6 +647,7 @@
"mSendHint": "输入或粘贴文字",
"mPaste": "粘贴",
"mPhotosFiles": "照片或文件",
+ "mSendConfirmTitle": "确认发送 {n} 个文件?",
"mFilesSent": "{n} 个文件已发到电脑",
"mClipboardNoText": "剪贴板里没有文字",
"mSendAction": "发送",
@@ -654,7 +655,7 @@
"mNoOnlineDevices": "附近没有在线的设备",
"mNoPairedDevices": "先和电脑配对",
"mSent": "已发送",
- "mSendFootnote": "文字会进入电脑的复制记录,并按电脑的设置写入剪贴板,就像在电脑上复制了一样。手机上复制的内容不会自动发出,要粘贴到这里再发送。",
+ "mSendFootnote": "文字和文件会进电脑的复制记录,并按电脑的设置写入剪贴板。手机上复制的内容不会自动发出,粘贴到这里再发送。",
"mSendFailed": "发送失败:{detail}",
"mCopy": "复制",
"mCopied": "已复制到手机剪贴板",
diff --git a/ui/lib/l10n/app_zh_Hant_HK.arb b/ui/lib/l10n/app_zh_Hant_HK.arb
index e7af0eb..925d1ab 100644
--- a/ui/lib/l10n/app_zh_Hant_HK.arb
+++ b/ui/lib/l10n/app_zh_Hant_HK.arb
@@ -647,6 +647,7 @@
"mSendHint": "輸入或貼上文字",
"mPaste": "貼上",
"mPhotosFiles": "照片或檔案",
+ "mSendConfirmTitle": "確認傳送 {n} 個檔案?",
"mFilesSent": "{n} 個檔案已傳到電腦",
"mClipboardNoText": "剪貼簿裡沒有文字",
"mSendAction": "傳送",
@@ -654,7 +655,7 @@
"mNoOnlineDevices": "附近沒有在線的裝置",
"mNoPairedDevices": "先和電腦配對",
"mSent": "已傳送",
- "mSendFootnote": "文字會進入電腦的複製記錄,並按電腦的設定寫入剪貼簿,就像在電腦上複製了一樣。手機上複製的內容不會自動送出,要貼到這裡再傳送。",
+ "mSendFootnote": "文字和檔案會進電腦的複製記錄,並按電腦的設定寫入剪貼簿。手機上複製的內容不會自動發出,貼到這裏再傳送。",
"mSendFailed": "傳送失敗:{detail}",
"mCopy": "複製",
"mCopied": "已複製到手機剪貼簿",
diff --git a/ui/lib/l10n/app_zh_Hant_TW.arb b/ui/lib/l10n/app_zh_Hant_TW.arb
index fe41a8d..e3ea124 100644
--- a/ui/lib/l10n/app_zh_Hant_TW.arb
+++ b/ui/lib/l10n/app_zh_Hant_TW.arb
@@ -647,6 +647,7 @@
"mSendHint": "輸入或貼上文字",
"mPaste": "貼上",
"mPhotosFiles": "照片或檔案",
+ "mSendConfirmTitle": "確認傳送 {n} 個檔案?",
"mFilesSent": "{n} 個檔案已傳到電腦",
"mClipboardNoText": "剪貼簿裡沒有文字",
"mSendAction": "傳送",
@@ -654,7 +655,7 @@
"mNoOnlineDevices": "附近沒有在線的裝置",
"mNoPairedDevices": "先和電腦配對",
"mSent": "已傳送",
- "mSendFootnote": "文字會進入電腦的複製記錄,並依電腦的設定寫入剪貼簿,就像在電腦上複製了一樣。手機上複製的內容不會自動送出,要貼到這裡再傳送。",
+ "mSendFootnote": "文字和檔案會進電腦的複製記錄,並按電腦的設定寫入剪貼簿。手機上複製的內容不會自動發出,貼到這裡再傳送。",
"mSendFailed": "傳送失敗:{detail}",
"mCopy": "複製",
"mCopied": "已複製到手機剪貼簿",
diff --git a/ui/lib/mobile/send_tab.dart b/ui/lib/mobile/send_tab.dart
index dfce8a3..c86f8fc 100644
--- a/ui/lib/mobile/send_tab.dart
+++ b/ui/lib/mobile/send_tab.dart
@@ -74,8 +74,7 @@ class _SendTabState extends State<SendTab> with WidgetsBindingObserver {
);
}
- /// 选照片或文件发到电脑。file_selector 在 Android 上会把选中的内容拷到应用缓存,
- /// 后台服务和 App 在同一个进程里,直接读得到这些路径。
+ /// 选照片或文件:先让用户看清会发哪些,确认了才发(支持多选)。
Future<void> _pickFiles() async {
final l = context.l10n;
if (_picking) return;
@@ -83,9 +82,19 @@ class _SendTabState extends State<SendTab> with WidgetsBindingObserver {
try {
final files = await openFiles();
if (files.isEmpty || !mounted) return;
- final paths = [for (final f in files) f.path];
- await AppScope.read(context).submitFiles(paths);
- if (mounted) showToast(context, l.mFilesSent(paths.length));
+ final picked = <(String, String, int)>[];
+ for (final f in files) {
+ var size = 0;
+ try {
+ size = await f.length();
+ } catch (_) {}
+ picked.add((f.path, f.name, size));
+ }
+ if (!mounted) return;
+ final ok = await showFileConfirmSheet(context, picked);
+ if (ok != true || !mounted) return;
+ await AppScope.read(context).submitFiles([for (final p in picked) p.$1]);
+ if (mounted) showToast(context, l.mFilesSent(picked.length));
} catch (e) {
if (mounted) showToast(context, l.mSendFailed(AppState.describeError(e)), error: true);
} finally {
@@ -228,3 +237,89 @@ class _SendTabState extends State<SendTab> with WidgetsBindingObserver {
);
}
}
+
+/// 文件大小的简短写法,和网页、桌面一致。
+String _sizeLabel(int n) {
+ if (n < 1024) return '$n B';
+ const units = ['KB', 'MB', 'GB'];
+ var v = n.toDouble();
+ for (final u in units) {
+ v /= 1024;
+ if (v < 1024 || u == 'GB') return v < 10 ? '${v.toStringAsFixed(1)} $u' : '${v.round()} $u';
+ }
+ return '$n B';
+}
+
+/// 选完照片或文件后的确认弹层:先看清发什么、多大,再决定发不发。
+Future<bool?> showFileConfirmSheet(BuildContext context, List<(String, String, int)> files) {
+ final l = context.l10n;
+ final p = context.palette;
+ return showModalBottomSheet<bool>(
+ context: context,
+ isScrollControlled: true,
+ useSafeArea: true,
+ builder: (_) => ConstrainedBox(
+ constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(context).height * 0.7),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(Insets.lg, 0, Insets.lg, Insets.lg),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Text(
+ l.mSendConfirmTitle(files.length),
+ style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
+ textAlign: TextAlign.center,
+ ),
+ const SizedBox(height: Insets.md),
+ Flexible(
+ child: SingleChildScrollView(
+ child: Column(
+ children: [
+ for (final f in files)
+ Padding(
+ padding: const EdgeInsets.only(bottom: Insets.md),
+ child: Row(
+ children: [
+ Icon(AppIcons.folder, size: 20, color: p.textDim),
+ const SizedBox(width: Insets.md),
+ Expanded(
+ child: Text(f.$2,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: const TextStyle(fontSize: 15)),
+ ),
+ const SizedBox(width: Insets.md),
+ Text(_sizeLabel(f.$3), style: TextStyle(fontSize: 13, color: p.textDim)),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ const SizedBox(height: Insets.md),
+ Row(
+ children: [
+ Expanded(
+ child: FilledButton(
+ style: secondaryButtonStyle(context),
+ onPressed: () => Navigator.pop(context, false),
+ child: Text(l.cancel),
+ ),
+ ),
+ const SizedBox(width: Insets.md),
+ Expanded(
+ child: FilledButton(
+ onPressed: () => Navigator.pop(context, true),
+ child: Text(l.mSendAction),
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+}