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(android): check for updates against the version list
baiyuzec5cd084b0073
diff --git a/ui/android/app/src/main/kotlin/com/pasteferry/app/MainActivity.kt b/ui/android/app/src/main/kotlin/com/pasteferry/app/MainActivity.ktindex 320e7c9..ed29825 100644--- a/ui/android/app/src/main/kotlin/com/pasteferry/app/MainActivity.kt+++ b/ui/android/app/src/main/kotlin/com/pasteferry/app/MainActivity.kt@@ -83,6 +83,19 @@ class MainActivity : FlutterActivity() {result.success(null)}"onLan" -> result.success(onLan())+ "openUrl" -> {+ val url = call.argument<String>("url") ?: ""+ if (url.isEmpty()) {+ result.success(false)+ } else {+ try {+ startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))+ result.success(true)+ } catch (e: Exception) {+ result.success(false)+ }+ }+ }else -> result.notImplemented()}}diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arbindex 0984ec2..271ba1d 100644--- a/ui/lib/l10n/app_en.arb+++ b/ui/lib/l10n/app_en.arb@@ -1678,6 +1678,11 @@"mSentRecords": "Sent","mViewAll": "View all","mClearCache": "Clear",+ "mCheckUpdate": "Check for updates",+ "mUpdateFailed": "Could not check for updates",+ "mUpToDate": "You are up to date",+ "mNewVersion": "Version {v} is available",+ "mDownloadInstall": "Download the new version","mSendFailed": "Couldn’t send: {detail}","@mSendFailed": {"placeholders": {diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arbindex 5cf7fde..b8e0152 100644--- a/ui/lib/l10n/app_ja.arb+++ b/ui/lib/l10n/app_ja.arb@@ -659,6 +659,11 @@"mSentRecords": "送信履歴","mViewAll": "すべて見る","mClearCache": "キャッシュを消去",+ "mCheckUpdate": "アップデートを確認",+ "mUpdateFailed": "確認できませんでした",+ "mUpToDate": "最新版です",+ "mNewVersion": "新しいバージョン {v} があります",+ "mDownloadInstall": "新しいバージョンをダウンロード","mSendFailed": "送信できませんでした:{detail}","mCopy": "コピー","mCopied": "スマホのクリップボードにコピーしました",diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dartindex aa3504e..ba6e8bd 100644--- a/ui/lib/l10n/app_localizations.dart+++ b/ui/lib/l10n/app_localizations.dart@@ -4064,6 +4064,36 @@ abstract class AppLocalizations {/// **'Clear'**String get mClearCache;+ /// No description provided for @mCheckUpdate.+ ///+ /// In en, this message translates to:+ /// **'Check for updates'**+ String get mCheckUpdate;++ /// No description provided for @mUpdateFailed.+ ///+ /// In en, this message translates to:+ /// **'Could not check for updates'**+ String get mUpdateFailed;++ /// No description provided for @mUpToDate.+ ///+ /// In en, this message translates to:+ /// **'You are up to date'**+ String get mUpToDate;++ /// No description provided for @mNewVersion.+ ///+ /// In en, this message translates to:+ /// **'Version {v} is available'**+ String mNewVersion(Object v);++ /// No description provided for @mDownloadInstall.+ ///+ /// In en, this message translates to:+ /// **'Download the new version'**+ String get mDownloadInstall;+/// No description provided for @mSendFailed.////// In en, this message translates to:diff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dartindex 0878ac3..c548194 100644--- a/ui/lib/l10n/app_localizations_en.dart+++ b/ui/lib/l10n/app_localizations_en.dart@@ -2487,6 +2487,23 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get mClearCache => 'Clear';+ @override+ String get mCheckUpdate => 'Check for updates';++ @override+ String get mUpdateFailed => 'Could not check for updates';++ @override+ String get mUpToDate => 'You are up to date';++ @override+ String mNewVersion(Object v) {+ return 'Version $v is available';+ }++ @override+ String get mDownloadInstall => 'Download the new version';+@overrideString mSendFailed(String detail) {return 'Couldn’t send: $detail';diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dartindex 112e584..2498ef6 100644--- a/ui/lib/l10n/app_localizations_ja.dart+++ b/ui/lib/l10n/app_localizations_ja.dart@@ -2308,6 +2308,23 @@ class AppLocalizationsJa extends AppLocalizations {@overrideString get mClearCache => 'キャッシュを消去';+ @override+ String get mCheckUpdate => 'アップデートを確認';++ @override+ String get mUpdateFailed => '確認できませんでした';++ @override+ String get mUpToDate => '最新版です';++ @override+ String mNewVersion(Object v) {+ return '新しいバージョン $v があります';+ }++ @override+ String get mDownloadInstall => '新しいバージョンをダウンロード';+@overrideString mSendFailed(String detail) {return '送信できませんでした:$detail';diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dartindex ed45435..52dc360 100644--- a/ui/lib/l10n/app_localizations_zh.dart+++ b/ui/lib/l10n/app_localizations_zh.dart@@ -2282,6 +2282,23 @@ class AppLocalizationsZh extends AppLocalizations {@overrideString get mClearCache => '清除缓存';+ @override+ String get mCheckUpdate => '检查更新';++ @override+ String get mUpdateFailed => '检查更新失败,请稍后再试';++ @override+ String get mUpToDate => '已是最新版本';++ @override+ String mNewVersion(Object v) {+ return '有新版本 $v';+ }++ @override+ String get mDownloadInstall => '下载新版本';+@overrideString mSendFailed(String detail) {return '发送失败:$detail';@@ -4660,6 +4677,23 @@ class AppLocalizationsZhHantHk extends AppLocalizationsZh {@overrideString get mClearCache => '清除快取';+ @override+ String get mCheckUpdate => '檢查更新';++ @override+ String get mUpdateFailed => '檢查更新失敗,請稍後再試';++ @override+ String get mUpToDate => '已是最新版本';++ @override+ String mNewVersion(Object v) {+ return '有新版本 $v';+ }++ @override+ String get mDownloadInstall => '下載新版本';+@overrideString mSendFailed(String detail) {return '傳送失敗:$detail';@@ -7038,6 +7072,23 @@ class AppLocalizationsZhHantTw extends AppLocalizationsZh {@overrideString get mClearCache => '清除快取';+ @override+ String get mCheckUpdate => '檢查更新';++ @override+ String get mUpdateFailed => '檢查更新失敗,請稍後再試';++ @override+ String get mUpToDate => '已是最新版本';++ @override+ String mNewVersion(Object v) {+ return '有新版本 $v';+ }++ @override+ String get mDownloadInstall => '下載新版本';+@overrideString mSendFailed(String detail) {return '傳送失敗:$detail';diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arbindex c093ba3..109310e 100644--- a/ui/lib/l10n/app_zh.arb+++ b/ui/lib/l10n/app_zh.arb@@ -659,6 +659,11 @@"mSentRecords": "发送记录","mViewAll": "查看全部","mClearCache": "清除缓存",+ "mCheckUpdate": "检查更新",+ "mUpdateFailed": "检查更新失败,请稍后再试",+ "mUpToDate": "已是最新版本",+ "mNewVersion": "有新版本 {v}",+ "mDownloadInstall": "下载新版本","mSendFailed": "发送失败:{detail}","mCopy": "复制","mCopied": "已复制到手机剪贴板",diff --git a/ui/lib/l10n/app_zh_Hant_HK.arb b/ui/lib/l10n/app_zh_Hant_HK.arbindex 93c565c..bf290dd 100644--- a/ui/lib/l10n/app_zh_Hant_HK.arb+++ b/ui/lib/l10n/app_zh_Hant_HK.arb@@ -659,6 +659,11 @@"mSentRecords": "傳送記錄","mViewAll": "查看全部","mClearCache": "清除快取",+ "mCheckUpdate": "檢查更新",+ "mUpdateFailed": "檢查更新失敗,請稍後再試",+ "mUpToDate": "已是最新版本",+ "mNewVersion": "有新版本 {v}",+ "mDownloadInstall": "下載新版本","mSendFailed": "傳送失敗:{detail}","mCopy": "複製","mCopied": "已複製到手機剪貼簿",diff --git a/ui/lib/l10n/app_zh_Hant_TW.arb b/ui/lib/l10n/app_zh_Hant_TW.arbindex 02a104f..87aaabe 100644--- a/ui/lib/l10n/app_zh_Hant_TW.arb+++ b/ui/lib/l10n/app_zh_Hant_TW.arb@@ -659,6 +659,11 @@"mSentRecords": "傳送記錄","mViewAll": "查看全部","mClearCache": "清除快取",+ "mCheckUpdate": "檢查更新",+ "mUpdateFailed": "檢查更新失敗,請稍後再試",+ "mUpToDate": "已是最新版本",+ "mNewVersion": "有新版本 {v}",+ "mDownloadInstall": "下載新版本","mSendFailed": "傳送失敗:{detail}","mCopy": "複製","mCopied": "已複製到手機剪貼簿",diff --git a/ui/lib/mobile/host.dart b/ui/lib/mobile/host.dartindex 47aa58e..dc0ee4c 100644--- a/ui/lib/mobile/host.dart+++ b/ui/lib/mobile/host.dart@@ -35,6 +35,10 @@ abstract final class Host {static Future<void> requestBatteryUnrestricted() => _channel.invokeMethod('requestBatteryUnrestricted');+ /// 用系统浏览器打开链接(检查更新时下载 APK)+ static Future<bool> openUrl(String url) async =>+ await _channel.invokeMethod<bool>('openUrl', {'url': url}) ?? false;+/// 当前网络是 Wi-Fi 或有线网static Future<bool> onLan() async => await _channel.invokeMethod<bool>('onLan') ?? true;}diff --git a/ui/lib/mobile/settings_tab.dart b/ui/lib/mobile/settings_tab.dartindex 3fe3363..47fe4cc 100644--- a/ui/lib/mobile/settings_tab.dart+++ b/ui/lib/mobile/settings_tab.dart@@ -8,6 +8,7 @@ import '../main.dart' show AppScope;import '../theme.dart';import '../widgets/common.dart';import 'host.dart';+import 'update_check.dart';import 'ui.dart';/// 设置页:本机名称、收到文字后写不写剪贴板、后台保持连接与相关的系统权限、版本。@@ -181,6 +182,8 @@ class _SettingsTabState extends State<SettingsTab> with WidgetsBindingObserver {const SizedBox(height: Insets.sm),Text(l.appName, style: context.text.titleSmall),Text(l.mVersion(state.status?.version ?? ''), style: context.text.bodySmall),+ const SizedBox(height: Insets.md),+ _UpdateTile(current: state.status?.version ?? ''),Text(l.aboutDesc, style: context.text.bodySmall),],),@@ -190,3 +193,73 @@ class _SettingsTabState extends State<SettingsTab> with WidgetsBindingObserver {);}}++/// 检查更新:版本号从更新清单里读(地址固定),有新版就在浏览器里下 APK。+class _UpdateTile extends StatefulWidget {+ const _UpdateTile({required this.current});++ final String current;++ @override+ State<_UpdateTile> createState() => _UpdateTileState();+}++class _UpdateTileState extends State<_UpdateTile> {+ bool _busy = false;+ String? _latest;+ String? _error;++ Future<void> _check() async {+ final l = context.l10n;+ setState(() {+ _busy = true;+ _error = null;+ _latest = null;+ });+ final v = await UpdateCheck.latest();+ if (!mounted) return;+ setState(() {+ _busy = false;+ if (v == null) {+ _error = l.mUpdateFailed;+ } else if (UpdateCheck.isNewer(v, widget.current)) {+ _latest = v;+ } else {+ _latest = '';+ }+ });+ }++ @override+ Widget build(BuildContext context) {+ final l = context.l10n;+ final p = context.palette;+ return Column(+ children: [+ OutlinedButton(+ onPressed: _busy ? null : _check,+ child: _busy+ ? const SizedBox.square(dimension: 16, child: CircularProgressIndicator(strokeWidth: 2))+ : Text(l.mCheckUpdate),+ ),+ if (_error != null) ...[+ const SizedBox(height: Insets.xs),+ Text(_error!, style: TextStyle(fontSize: 12, color: p.danger)),+ ],+ if (_latest != null && _latest!.isEmpty) ...[+ const SizedBox(height: Insets.xs),+ Text(l.mUpToDate, style: TextStyle(fontSize: 12, color: p.textDim)),+ ],+ if (_latest != null && _latest!.isNotEmpty) ...[+ const SizedBox(height: Insets.xs),+ Text(l.mNewVersion(_latest!), style: TextStyle(fontSize: 12, color: p.accent)),+ const SizedBox(height: Insets.xs),+ FilledButton(+ onPressed: () => Host.openUrl(UpdateCheck.apkUrl),+ child: Text(l.mDownloadInstall),+ ),+ ],+ ],+ );+ }+}diff --git a/ui/lib/mobile/update_check.dart b/ui/lib/mobile/update_check.dartnew file mode 100644index 0000000..44d177c--- /dev/null+++ b/ui/lib/mobile/update_check.dart@@ -0,0 +1,60 @@+import 'dart:convert';+import 'dart:io';++/// 检查更新(手机上)。+///+/// 更新清单固定在 pasteferry.cc 与 Gitee 两个地址,里面只有「最新版本号」;+/// 安装包文件名不带版本号,所以下载地址也是固定的,直接打开浏览器下载即可。+/// 不依赖桌面端那套按平台解析安装包的逻辑。+class UpdateCheck {+ static const manifestUrls = [+ 'https://pasteferry.cc/updates/latest.json',+ 'https://gitee.com/baiyuze/pasteferry/raw/main/updates/latest.json',+ ];++ /// 安装包地址:文件名固定,永远指向最新版+ static const apkUrl =+ 'https://github.com/baiyuze/pasteferry/releases/latest/download/PasteFerry-android-arm64.apk';++ /// 返回最新版本号;全都取不到时返回 null+ static Future<String?> latest() async {+ for (final url in manifestUrls) {+ final v = await _read(url);+ if (v != null) return v;+ }+ return null;+ }++ static Future<String?> _read(String url) async {+ final client = HttpClient()..connectionTimeout = const Duration(seconds: 8);+ try {+ final req = await client.getUrl(Uri.parse(url));+ final res = await req.close().timeout(const Duration(seconds: 8));+ if (res.statusCode != 200) return null;+ final body = await res.transform(utf8.decoder).join();+ final json = jsonDecode(body);+ final latest = json is Map ? json['latest'] : null;+ return latest is String && latest.isNotEmpty ? latest : null;+ } catch (_) {+ return null;+ } finally {+ client.close(force: true);+ }+ }++ /// a 是否比 b 新。只比较数字段,忽略 -dev 之类的后缀。+ static bool isNewer(String a, String b) {+ List<int> parts(String s) => s+ .split(RegExp(r'[^0-9]+'))+ .where((x) => x.isNotEmpty)+ .map((x) => int.tryParse(x) ?? 0)+ .toList();+ final x = parts(a), y = parts(b);+ for (var i = 0; i < 3; i++) {+ final xi = i < x.length ? x[i] : 0;+ final yi = i < y.length ? y[i] : 0;+ if (xi != yi) return xi > yi;+ }+ return false;+ }+}