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): run on Linux
baiyuzea51abd9ec102
diff --git a/proto/copysync/v1/daemon.proto b/proto/copysync/v1/daemon.protoindex 2a715cc..60875bf 100644--- a/proto/copysync/v1/daemon.proto+++ b/proto/copysync/v1/daemon.proto@@ -125,7 +125,7 @@ enum ConnectionKind {message Device {string id = 1;string name = 2;- string platform = 3; // darwin / windows+ string platform = 3; // darwin / windows / linuxbool online = 4;ConnectionKind connection = 5;string public_key_fingerprint = 6;@@ -224,7 +224,7 @@ message ConfirmPairingRequest {message NearbyDevice {string id = 1; // 对方这次启动的 mDNS 实例名,用来发起配对string name = 2;- string platform = 3; // darwin / windows+ string platform = 3; // darwin / windows / linuxbool paired = 4; // 已经与本机配对}diff --git a/proto/gen/copysync/v1/daemon.pb.go b/proto/gen/copysync/v1/daemon.pb.goindex 7affb1b..bd17084 100644--- a/proto/gen/copysync/v1/daemon.pb.go+++ b/proto/gen/copysync/v1/daemon.pb.go@@ -614,7 +614,7 @@ type Device struct {state protoimpl.MessageState `protogen:"open.v1"`Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`- Platform string `protobuf:"bytes,3,opt,name=platform,proto3" json:"platform,omitempty"` // darwin / windows+ Platform string `protobuf:"bytes,3,opt,name=platform,proto3" json:"platform,omitempty"` // darwin / windows / linuxOnline bool `protobuf:"varint,4,opt,name=online,proto3" json:"online,omitempty"`Connection ConnectionKind `protobuf:"varint,5,opt,name=connection,proto3,enum=copysync.v1.ConnectionKind" json:"connection,omitempty"`PublicKeyFingerprint string `protobuf:"bytes,6,opt,name=public_key_fingerprint,json=publicKeyFingerprint,proto3" json:"public_key_fingerprint,omitempty"`@@ -1406,7 +1406,7 @@ type NearbyDevice struct {state protoimpl.MessageState `protogen:"open.v1"`Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // 对方这次启动的 mDNS 实例名,用来发起配对Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`- Platform string `protobuf:"bytes,3,opt,name=platform,proto3" json:"platform,omitempty"` // darwin / windows+ Platform string `protobuf:"bytes,3,opt,name=platform,proto3" json:"platform,omitempty"` // darwin / windows / linuxPaired bool `protobuf:"varint,4,opt,name=paired,proto3" json:"paired,omitempty"` // 已经与本机配对unknownFields protoimpl.UnknownFieldssizeCache protoimpl.SizeCachediff --git a/ui/.metadata b/ui/.metadataindex 875bc02..cc64528 100644--- a/ui/.metadata+++ b/ui/.metadata@@ -21,6 +21,9 @@ migration:- platform: windowscreate_revision: 6b182d2c7585eba26d4edce0f97630effd256c33base_revision: 6b182d2c7585eba26d4edce0f97630effd256c33+ - platform: linux+ create_revision: 6b182d2c7585eba26d4edce0f97630effd256c33+ base_revision: 6b182d2c7585eba26d4edce0f97630effd256c33# User provided sectiondiff --git a/ui/lib/background_service.dart b/ui/lib/background_service.dartindex 37441df..57f7ff2 100644--- a/ui/lib/background_service.dart+++ b/ui/lib/background_service.dart@@ -1,5 +1,6 @@import 'dart:io';+import 'background_service_linux.dart';import 'background_service_windows.dart';import 'i18n.dart';@@ -14,7 +15,7 @@ enum ServiceState {/// 从一个随时会消失的位置运行,这时登记的自启项会指向不存在的路径:/// Mac 上是直接从 DMG 里打开、或被系统随机化路径(App Translocation);- /// Windows 上是直接在压缩包里双击打开(实际运行在临时目录)+ /// Windows 上是直接在压缩包里双击打开(实际运行在临时目录)。Linux 上没有这种情况mustMove,/// 尚未注册为登录项@@ -30,11 +31,14 @@ enum ServiceState {}/// 管理随 App 一起分发的后台服务(剪贴板监听与同步进程):开机自启、崩溃自动拉起,-/// 关掉窗口也照常同步。各平台的做法不同,见 [MacBackgroundService] 与-/// [WindowsBackgroundService]。+/// 关掉窗口也照常同步。各平台的做法不同,见 [MacBackgroundService]、+/// [WindowsBackgroundService] 与 [LinuxBackgroundService]。abstract class BackgroundService {- factory BackgroundService() =>- Platform.isWindows ? WindowsBackgroundService() : MacBackgroundService();+ factory BackgroundService() => Platform.isWindows+ ? WindowsBackgroundService()+ : Platform.isLinux+ ? LinuxBackgroundService()+ : MacBackgroundService();/// App 里是否带着后台服务(开发构建没有)bool get available;diff --git a/ui/lib/background_service_linux.dart b/ui/lib/background_service_linux.dartnew file mode 100644index 0000000..1a6b0ec--- /dev/null+++ b/ui/lib/background_service_linux.dart@@ -0,0 +1,130 @@+import 'dart:io';++import 'background_service.dart';+import 'i18n.dart';++/// Linux:后台服务 `copysyncd` 与界面程序放在同一个目录(.deb 装在 /opt/CopySync)。+///+/// 开机自启用 XDG 自启动项(`~/.config/autostart/` 下的 .desktop 文件),GNOME、KDE、Xfce 等桌面都认。+/// 它在登录后的图形会话里启动,带着 DISPLAY、XAUTHORITY 等环境变量,后台服务才连得上剪贴板。+/// 登记的命令是 `copysyncd -supervise`:守护进程拉起真正干活的子进程,崩溃就隔 10 秒再拉起,+/// 与 Windows 的做法相同。+///+/// 不用 systemd 的用户服务:它不一定拿得到图形会话的环境变量,各发行版的做法也不一致。+class LinuxBackgroundService implements BackgroundService {+ LinuxBackgroundService({String? executable, Map<String, String>? environment})+ : _executable = executable ?? Platform.resolvedExecutable,+ _env = environment ?? Platform.environment;++ static const _image = 'copysyncd';++ final String _executable;+ final Map<String, String> _env;++ String get daemonPath => '${File(_executable).parent.path}/$_image';++ String get _home => _env['HOME'] ?? '';++ /// XDG 目录:环境变量要是绝对路径才算数,否则用默认位置+ String _xdg(String name, String fallback) {+ final v = _env[name] ?? '';+ return v.startsWith('/') ? v : '$_home/$fallback';+ }++ String get autostartPath => '${_xdg('XDG_CONFIG_HOME', '.config')}/autostart/copysync-daemon.desktop';++ String get logPath => '${_xdg('XDG_DATA_HOME', '.local/share')}/copysync/logs/daemon.log';++ @override+ String get displayLogPath => _home.isEmpty ? logPath : logPath.replaceFirst(_home, '~');++ @override+ bool get available => Platform.isLinux && File(daemonPath).existsSync();++ /// 自启动项里的命令行+ String get _command => '${quoteExecArg(daemonPath)} -supervise';++ @override+ Future<ServiceState> state() async {+ if (!available) return ServiceState.unavailable;+ final file = File(autostartPath);+ if (!file.existsSync()) return ServiceState.notInstalled;+ final exec = execLine(await file.readAsString());+ if (exec == null || !exec.contains(quoteExecArg(daemonPath))) return ServiceState.stale;+ return await _running() ? ServiceState.running : ServiceState.stopped;+ }++ @override+ Future<void> install() async {+ try {+ final file = File(autostartPath);+ await file.parent.create(recursive: true);+ await file.writeAsString(desktopEntry(_command));+ } on FileSystemException catch (e) {+ throw ServiceException(appL10n.errAutostart(e.message));+ }+ await restart();+ }++ @override+ Future<void> restart() async {+ await _stop();+ // 脱离界面进程运行:关掉窗口后照常同步。环境变量随之传下去,后台服务才连得上剪贴板+ await Process.start(daemonPath, ['-supervise'], mode: ProcessStartMode.detached);+ }++ @override+ Future<void> uninstall() async {+ final file = File(autostartPath);+ if (file.existsSync()) await file.delete();+ await _stop();+ }++ /// 守护进程与后台服务一起结束:只结束后台服务的话,守护进程会把它重新拉起来+ Future<void> _stop() async {+ await Process.run('pkill', [..._ownedBy, '-x', _image]);+ for (var i = 0; i < 20 && await _running(); i++) {+ await Future<void>.delayed(const Duration(milliseconds: 250));+ }+ }++ Future<bool> _running() async {+ final r = await Process.run('pgrep', [..._ownedBy, '-x', _image]);+ return r.exitCode == 0;+ }++ /// 只管当前用户的进程:同一台电脑上别的用户也可能在运行 CopySync+ List<String> get _ownedBy {+ final user = _env['USER'] ?? '';+ return user.isEmpty ? const [] : ['-u', user];+ }+}++/// XDG 自启动项。NoDisplay:不出现在应用菜单里;它只是后台服务的开机启动入口。+String desktopEntry(String exec) => '''[Desktop Entry]+Type=Application+Name=CopySync+Comment=Keeps the clipboard in sync with your other devices+Exec=$exec+Icon=com.copysync.app+Terminal=false+NoDisplay=true+X-GNOME-Autostart-enabled=true+''';++/// 按 Desktop Entry 规范给 Exec 里的一个参数加引号:路径里可能有空格。+/// 引号里的 `"`、`` ` ``、`$`、`\` 要加反斜杠转义,而 .desktop 文件本身又把每个 `\` 转义一次:+/// 所以前三个写成两个反斜杠加原字符,反斜杠本身写成四个。+String quoteExecArg(String arg) {+ final escaped = arg.replaceAllMapped(+ RegExp(r'["`$\\]'), (m) => m[0] == r'\' ? r'\\\\' : r'\\' + m[0]!);+ return '"$escaped"';+}++/// 取出 .desktop 文件里 [Desktop Entry] 一节的 Exec 一行。+String? execLine(String content) {+ for (final line in content.split('\n')) {+ if (line.startsWith('Exec=')) return line.substring('Exec='.length).trim();+ }+ return null;+}diff --git a/ui/lib/daemon_client.dart b/ui/lib/daemon_client.dartindex 723d955..9e8ce6c 100644--- a/ui/lib/daemon_client.dart+++ b/ui/lib/daemon_client.dart@@ -47,8 +47,11 @@ class DaemonEndpoint {'';return '$base\\CopySync';}- final home = Platform.environment['HOME'] ?? '';- return '$home/.config/copysync';+ // Linux:按 XDG 放在 ~/.local/share 下,XDG_DATA_HOME 是绝对路径时以它为准+ final env = Platform.environment;+ final data = env['XDG_DATA_HOME'] ?? '';+ final base = data.startsWith('/') ? data : '${env['HOME'] ?? ''}/.local/share';+ return '$base/copysync';}static File endpointFile([String? dataDir]) =>diff --git a/ui/lib/icons.dart b/ui/lib/icons.dartindex 982a39c..88e3104 100644--- a/ui/lib/icons.dart+++ b/ui/lib/icons.dart@@ -4,9 +4,9 @@ import 'package:flutter/cupertino.dart';import 'package:fluentui_system_icons/fluentui_system_icons.dart';/// 界面用到的图标:Mac 上是 Cupertino 图标,Windows 上是微软的 Fluent 图标,-/// 各自与系统自带的应用一致。+/// 各自与系统自带的应用一致。Linux 上用 Fluent:线条风格与 GNOME、KDE 的图标接近。abstract final class AppIcons {- static final bool _win = Platform.isWindows;+ static final bool _win = !Platform.isMacOS;static IconData _pick(IconData mac, IconData windows) => _win ? windows : mac;diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arbindex 97e3fc7..142166e 100644--- a/ui/lib/l10n/app_en.arb+++ b/ui/lib/l10n/app_en.arb@@ -453,6 +453,7 @@"svcStoppedTitle": "The background service isn't running","svcStoppedBody": "It may have just quit; the system usually restarts it within seconds. If you stay on this page, restart it with the button below.","svcDevBodyWin": "This is a development build with no copysyncd.exe next to it. Run scripts\\build-windows.ps1 in the source folder to build a complete version.",+ "svcDevBodyLinux": "This is a development build with no copysyncd next to it. Run ./scripts/package-linux.sh in the source folder to build a complete version.","svcDevBodyMac": "This is a development build without the background service. Run ./scripts/install-macos.sh in the source folder to install it.","svcLogPath": "Log: {path}","@svcLogPath": {diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arbindex 70c34d5..9edd3af 100644--- a/ui/lib/l10n/app_ja.arb+++ b/ui/lib/l10n/app_ja.arb@@ -228,6 +228,7 @@"svcStoppedTitle": "バックグラウンドサービスが動いていません","svcStoppedBody": "終了した直後かもしれません。通常は数秒で再起動されます。この画面のままなら、下のボタンで再起動してください。","svcDevBodyWin": "開発ビルドのため copysyncd.exe がありません。ソースフォルダで scripts\\build-windows.ps1 を実行して完全版をビルドしてください。",+ "svcDevBodyLinux": "開発ビルドのため copysyncd がありません。ソースフォルダで ./scripts/package-linux.sh を実行して完全版をビルドしてください。","svcDevBodyMac": "開発ビルドのためバックグラウンドサービスが含まれていません。ソースフォルダで ./scripts/install-macos.sh を実行してインストールしてください。","svcLogPath": "ログ:{path}","svcCanDisable": "バックグラウンド同期は「設定」でいつでもオフにできます。"diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dartindex a87d47e..88609ef 100644--- a/ui/lib/l10n/app_localizations.dart+++ b/ui/lib/l10n/app_localizations.dart@@ -1468,6 +1468,12 @@ abstract class AppLocalizations {/// **'This is a development build with no copysyncd.exe next to it. Run scripts\\build-windows.ps1 in the source folder to build a complete version.'**String get svcDevBodyWin;+ /// No description provided for @svcDevBodyLinux.+ ///+ /// In en, this message translates to:+ /// **'This is a development build with no copysyncd next to it. Run ./scripts/package-linux.sh in the source folder to build a complete version.'**+ String get svcDevBodyLinux;+/// No description provided for @svcDevBodyMac.////// In en, this message translates to:diff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dartindex 1aede3f..a0a672e 100644--- a/ui/lib/l10n/app_localizations_en.dart+++ b/ui/lib/l10n/app_localizations_en.dart@@ -846,6 +846,10 @@ class AppLocalizationsEn extends AppLocalizations {String get svcDevBodyWin =>'This is a development build with no copysyncd.exe next to it. Run scripts\\build-windows.ps1 in the source folder to build a complete version.';+ @override+ String get svcDevBodyLinux =>+ 'This is a development build with no copysyncd next to it. Run ./scripts/package-linux.sh in the source folder to build a complete version.';+@overrideString get svcDevBodyMac =>'This is a development build without the background service. Run ./scripts/install-macos.sh in the source folder to install it.';diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dartindex 4e730f9..6372311 100644--- a/ui/lib/l10n/app_localizations_ja.dart+++ b/ui/lib/l10n/app_localizations_ja.dart@@ -775,6 +775,10 @@ class AppLocalizationsJa extends AppLocalizations {String get svcDevBodyWin =>'開発ビルドのため copysyncd.exe がありません。ソースフォルダで scripts\\build-windows.ps1 を実行して完全版をビルドしてください。';+ @override+ String get svcDevBodyLinux =>+ '開発ビルドのため copysyncd がありません。ソースフォルダで ./scripts/package-linux.sh を実行して完全版をビルドしてください。';+@overrideString get svcDevBodyMac =>'開発ビルドのためバックグラウンドサービスが含まれていません。ソースフォルダで ./scripts/install-macos.sh を実行してインストールしてください。';diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dartindex e5286e4..a5ac86f 100644--- a/ui/lib/l10n/app_localizations_zh.dart+++ b/ui/lib/l10n/app_localizations_zh.dart@@ -767,6 +767,10 @@ class AppLocalizationsZh extends AppLocalizations {String get svcDevBodyWin =>'这是开发构建,旁边没有 copysyncd.exe。在源码目录运行 scripts\\build-windows.ps1 构建完整的版本。';+ @override+ String get svcDevBodyLinux =>+ '这是开发构建,旁边没有 copysyncd。在源码目录运行 ./scripts/package-linux.sh 构建完整的版本。';+@overrideString get svcDevBodyMac =>'这是开发构建,App 里没有内置后台服务。在源码目录运行 ./scripts/install-macos.sh 安装它。';diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arbindex 781e9f9..edd7d5d 100644--- a/ui/lib/l10n/app_zh.arb+++ b/ui/lib/l10n/app_zh.arb@@ -228,6 +228,7 @@"svcStoppedTitle": "后台服务没有运行","svcStoppedBody": "它可能刚刚退出,系统通常会在几秒内把它重新拉起。如果一直停在这一页,点下面的按钮重新启动。","svcDevBodyWin": "这是开发构建,旁边没有 copysyncd.exe。在源码目录运行 scripts\\build-windows.ps1 构建完整的版本。",+ "svcDevBodyLinux": "这是开发构建,旁边没有 copysyncd。在源码目录运行 ./scripts/package-linux.sh 构建完整的版本。","svcDevBodyMac": "这是开发构建,App 里没有内置后台服务。在源码目录运行 ./scripts/install-macos.sh 安装它。","svcLogPath": "运行日志:{path}","svcCanDisable": "随时可以在「设置」中停用后台同步。"diff --git a/ui/lib/pages/devices_page.dart b/ui/lib/pages/devices_page.dartindex 66b51f8..0daf1cf 100644--- a/ui/lib/pages/devices_page.dart+++ b/ui/lib/pages/devices_page.dart@@ -158,7 +158,7 @@ String connectionLabel(Device d) => switch (d.connection) {};IconData platformIcon(String platform) => switch (platform) {- 'windows' => AppIcons.desktopComputer,+ 'windows' || 'linux' => AppIcons.desktopComputer,_ => AppIcons.deviceLaptop,};diff --git a/ui/lib/pages/service_page.dart b/ui/lib/pages/service_page.dartindex d2af325..274d93f 100644--- a/ui/lib/pages/service_page.dart+++ b/ui/lib/pages/service_page.dart@@ -41,7 +41,8 @@ class _ServicePageState extends State<ServicePage> {@overrideWidget build(BuildContext context) {final state = AppScope.of(context);- final windows = Platform.isWindows;+ // Linux 上的自启动与 Windows 一样是一个指向程序路径的条目,挪了位置的说法相同+ final windows = !Platform.isMacOS;final l = context.l10n;final (title, body, button) = switch (state.serviceState) {ServiceState.mustMove when windows => (l.svcExtractTitle, l.svcExtractBody, null),@@ -53,7 +54,15 @@ class _ServicePageState extends State<ServicePage> {l.svcReenable,),ServiceState.stopped => (l.svcStoppedTitle, l.svcStoppedBody, l.restart),- _ => (l.svcStoppedTitle, windows ? l.svcDevBodyWin : l.svcDevBodyMac, null),+ _ => (+ l.svcStoppedTitle,+ Platform.isLinux+ ? l.svcDevBodyLinux+ : windows+ ? l.svcDevBodyWin+ : l.svcDevBodyMac,+ null,+ ),};return Center(diff --git a/ui/lib/platform.dart b/ui/lib/platform.dartindex 8f0f2a1..8cf5e78 100644--- a/ui/lib/platform.dart+++ b/ui/lib/platform.dart@@ -2,9 +2,9 @@ import 'dart:io';import 'i18n.dart';-/// 随平台变化的叫法:Mac 上说「这台 Mac」,Windows 上说「这台电脑」。+/// 随平台变化的叫法:Mac 上说「这台 Mac」,Windows 与 Linux 上说「这台电脑」。abstract final class Wording {- static final bool _win = Platform.isWindows;+ static final bool _win = !Platform.isMacOS;/// 说到本机时的叫法,用作标题static String get thisDevice => _win ? appL10n.thisPcTitle : appL10n.thisMacTitle;@@ -12,7 +12,7 @@ abstract final class Wording {/// 用在句子中间。中日文里「Mac」后面紧跟汉字,文案里已带好空格static String get thisDeviceInText => _win ? appL10n.thisPcInText : appL10n.thisMacInText;- /// 说到配对双方时的叫法,用在句子中间:Windows 上对方可能是 Mac,也可能是另一台电脑+ /// 说到配对双方时的叫法,用在句子中间:Windows 与 Linux 上对方可能是 Mac,也可能是另一台电脑static String get bothDevicesInText => _win ? appL10n.bothDevices : appL10n.bothMacs;}@@ -21,6 +21,8 @@ void openUrl(String url) {if (Platform.isWindows) {// explorer 把网址交给默认浏览器;不经 cmd /c start,免得网址里的 & 被当成命令分隔符Process.run('explorer.exe', [url]);+ } else if (Platform.isLinux) {+ Process.run('xdg-open', [url]);} else {Process.run('open', [url]);}diff --git a/ui/lib/theme.dart b/ui/lib/theme.dartindex e0f71a2..e1d15d0 100644--- a/ui/lib/theme.dart+++ b/ui/lib/theme.dart@@ -138,8 +138,13 @@ extension PaletteAccess on BuildContext {}/// 等宽字体:配对码、指纹、服务器地址这类需要逐字符核对的内容。-/// Windows 没有 Menlo,找不到时会退回 Segoe UI,数字就不等宽了。-final monoFamily = Platform.isWindows ? 'Consolas' : 'Menlo';+/// Windows 没有 Menlo,找不到时会退回 Segoe UI,数字就不等宽了。Linux 上交给 fontconfig 的 monospace 别名,+/// 各发行版会解析成自己的等宽字体(DejaVu Sans Mono 等)。+final monoFamily = Platform.isWindows+ ? 'Consolas'+ : Platform.isLinux+ ? 'monospace'+ : 'Menlo';/// Windows 上汉字用哪些字体,按界面语言 [language] 排先后。///@@ -150,13 +155,24 @@ List<String> windowsFontFallback(String language) => language == 'ja'? const ['Yu Gothic UI', 'Meiryo UI', 'Microsoft YaHei UI']: const ['Microsoft YaHei UI', 'Microsoft YaHei', 'Yu Gothic UI'];+/// Linux 上汉字用哪些字体,按界面语言 [language] 排先后。主字体跟随系统(fontconfig 默认的无衬线字体),+/// 汉字指定字体,理由与 [windowsFontFallback] 相同。列的都是各发行版常见的开源字体,没装的会被跳过。+List<String> linuxFontFallback(String language) => language == 'ja'+ ? const ['Noto Sans CJK JP', 'Source Han Sans JP', 'IPAexGothic', 'Noto Sans CJK SC']+ : const ['Noto Sans CJK SC', 'Source Han Sans SC', 'WenQuanYi Micro Hei', 'Droid Sans Fallback'];+/// [fontFamily] 只给截图渲染用:App 本身不指定。Mac 上跟随系统字体(SF Pro 与苹方),-/// Windows 上用 Segoe UI,汉字按 [language] 用 [windowsFontFallback] 里的字体。+/// Windows 上用 Segoe UI,汉字按 [language] 用 [windowsFontFallback] 里的字体;+/// Linux 上主字体跟随系统,汉字用 [linuxFontFallback] 里的字体。ThemeData buildTheme(Brightness brightness,{String? fontFamily, List<String>? fontFamilyFallback, String language = 'zh'}) {- if (fontFamily == null && Platform.isWindows) {- fontFamily = 'Segoe UI';- fontFamilyFallback = windowsFontFallback(language);+ if (fontFamily == null && fontFamilyFallback == null) {+ if (Platform.isWindows) {+ fontFamily = 'Segoe UI';+ fontFamilyFallback = windowsFontFallback(language);+ } else if (Platform.isLinux) {+ fontFamilyFallback = linuxFontFallback(language);+ }}final dark = brightness == Brightness.dark;final p = dark ? AppPalette.dark : AppPalette.light;@@ -185,7 +201,7 @@ ThemeData buildTheme(Brightness brightness,labelMedium: TextStyle(fontSize: 12, fontWeight: FontWeight.w500, color: p.textDim),labelSmall: TextStyle(fontSize: 11, fontWeight: FontWeight.w500, color: p.textDim),);- if (fontFamily != null) {+ if (fontFamily != null || fontFamilyFallback != null) {textTheme = textTheme.apply(fontFamily: fontFamily, fontFamilyFallback: fontFamilyFallback);}diff --git a/ui/lib/widgets/nearby_dialog.dart b/ui/lib/widgets/nearby_dialog.dartindex d77fb00..b7f66f5 100644--- a/ui/lib/widgets/nearby_dialog.dart+++ b/ui/lib/widgets/nearby_dialog.dart@@ -234,7 +234,7 @@ class _NearbyDialogState extends State<NearbyDialog> with SingleTickerProviderStWidget _radar(BuildContext context, AppState state) {final p = context.palette;- final selfPlatform = state.self?.platform ?? (Platform.isWindows ? 'windows' : 'darwin');+ final selfPlatform = state.self?.platform ?? Platform.operatingSystem.replaceFirst('macos', 'darwin');return LayoutBuilder(builder: (context, box) {final center = box.biggest.center(Offset.zero);diff --git a/ui/linux/.gitignore b/ui/linux/.gitignorenew file mode 100644index 0000000..d3896c9--- /dev/null+++ b/ui/linux/.gitignore@@ -0,0 +1 @@+flutter/ephemeraldiff --git a/ui/linux/CMakeLists.txt b/ui/linux/CMakeLists.txtnew file mode 100644index 0000000..16573c9--- /dev/null+++ b/ui/linux/CMakeLists.txt@@ -0,0 +1,129 @@+# Project-level configuration.+cmake_minimum_required(VERSION 3.13)+project(runner LANGUAGES CXX)++# The name of the executable created for the application. Change this to change+# the on-disk name of your application.+set(BINARY_NAME "copysync")+# The unique GTK application identifier for this application. See:+# https://wiki.gnome.org/HowDoI/ChooseApplicationID+# 与 Mac 的包名一致。桌面据此把运行中的窗口与 com.copysync.app.desktop 对应起来(Dock 里的图标、名字)+set(APPLICATION_ID "com.copysync.app")++# Explicitly opt in to modern CMake behaviors to avoid warnings with recent+# versions of CMake.+cmake_policy(SET CMP0063 NEW)++# Load bundled libraries from the lib/ directory relative to the binary.+set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")++# Root filesystem for cross-building.+if(FLUTTER_TARGET_PLATFORM_SYSROOT)+ set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})+ set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)+ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)+ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)+ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)+endif()++# Define build configuration options.+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)+ set(CMAKE_BUILD_TYPE "Debug" CACHE+ STRING "Flutter build mode" FORCE)+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS+ "Debug" "Profile" "Release")+endif()++# Compilation settings that should be applied to most targets.+#+# Be cautious about adding new options here, as plugins use this function by+# default. In most cases, you should add new options to specific targets instead+# of modifying this function.+function(APPLY_STANDARD_SETTINGS TARGET)+ target_compile_features(${TARGET} PUBLIC cxx_std_14)+ target_compile_options(${TARGET} PRIVATE -Wall -Werror)+ target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")+ target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")+endfunction()++# Flutter library and tool build rules.+set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")+add_subdirectory(${FLUTTER_MANAGED_DIR})++# System-level dependencies.+find_package(PkgConfig REQUIRED)+pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)++# Application build; see runner/CMakeLists.txt.+add_subdirectory("runner")++# Run the Flutter tool portions of the build. This must not be removed.+add_dependencies(${BINARY_NAME} flutter_assemble)++# Only the install-generated bundle's copy of the executable will launch+# correctly, since the resources must in the right relative locations. To avoid+# people trying to run the unbundled copy, put it in a subdirectory instead of+# the default top-level location.+set_target_properties(${BINARY_NAME}+ PROPERTIES+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"+)+++# Generated plugin build rules, which manage building the plugins and adding+# them to the application.+include(flutter/generated_plugins.cmake)+++# === Installation ===+# By default, "installing" just makes a relocatable bundle in the build+# directory.+set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)+ set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)+endif()++# Start with a clean build bundle directory every time.+install(CODE "+ file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")+ " COMPONENT Runtime)++set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")+set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")++install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"+ COMPONENT Runtime)++install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"+ COMPONENT Runtime)++install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"+ COMPONENT Runtime)++foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})+ install(FILES "${bundled_library}"+ DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"+ COMPONENT Runtime)+endforeach(bundled_library)++# Copy the native assets provided by the build.dart from all packages.+set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")+install(DIRECTORY "${NATIVE_ASSETS_DIR}"+ DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"+ COMPONENT Runtime)++# Fully re-copy the assets directory on each build to avoid having stale files+# from a previous install.+set(FLUTTER_ASSET_DIR_NAME "flutter_assets")+install(CODE "+ file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")+ " COMPONENT Runtime)+install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"+ DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)++# Install the AOT library on non-Debug builds only.+if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")+ install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"+ COMPONENT Runtime)+endif()diff --git a/ui/linux/flutter/CMakeLists.txt b/ui/linux/flutter/CMakeLists.txtnew file mode 100644index 0000000..d5bd016--- /dev/null+++ b/ui/linux/flutter/CMakeLists.txt@@ -0,0 +1,88 @@+# This file controls Flutter-level build steps. It should not be edited.+cmake_minimum_required(VERSION 3.10)++set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")++# Configuration provided via flutter tool.+include(${EPHEMERAL_DIR}/generated_config.cmake)++# TODO: Move the rest of this into files in ephemeral. See+# https://github.com/flutter/flutter/issues/57146.++# Serves the same purpose as list(TRANSFORM ... PREPEND ...),+# which isn't available in 3.10.+function(list_prepend LIST_NAME PREFIX)+ set(NEW_LIST "")+ foreach(element ${${LIST_NAME}})+ list(APPEND NEW_LIST "${PREFIX}${element}")+ endforeach(element)+ set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)+endfunction()++# === Flutter Library ===+# System-level dependencies.+find_package(PkgConfig REQUIRED)+pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)+pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)+pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)++set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")++# Published to parent scope for install step.+set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)+set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)+set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)+set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)++list(APPEND FLUTTER_LIBRARY_HEADERS+ "fl_basic_message_channel.h"+ "fl_binary_codec.h"+ "fl_binary_messenger.h"+ "fl_dart_project.h"+ "fl_engine.h"+ "fl_json_message_codec.h"+ "fl_json_method_codec.h"+ "fl_message_codec.h"+ "fl_method_call.h"+ "fl_method_channel.h"+ "fl_method_codec.h"+ "fl_method_response.h"+ "fl_plugin_registrar.h"+ "fl_plugin_registry.h"+ "fl_standard_message_codec.h"+ "fl_standard_method_codec.h"+ "fl_string_codec.h"+ "fl_value.h"+ "fl_view.h"+ "flutter_linux.h"+)+list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")+add_library(flutter INTERFACE)+target_include_directories(flutter INTERFACE+ "${EPHEMERAL_DIR}"+)+target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")+target_link_libraries(flutter INTERFACE+ PkgConfig::GTK+ PkgConfig::GLIB+ PkgConfig::GIO+)+add_dependencies(flutter flutter_assemble)++# === Flutter tool backend ===+# _phony_ is a non-existent file to force this command to run every time,+# since currently there's no way to get a full input/output list from the+# flutter tool.+add_custom_command(+ OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}+ ${CMAKE_CURRENT_BINARY_DIR}/_phony_+ COMMAND ${CMAKE_COMMAND} -E env+ ${FLUTTER_TOOL_ENVIRONMENT}+ "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"+ ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}+ VERBATIM+)+add_custom_target(flutter_assemble DEPENDS+ "${FLUTTER_LIBRARY}"+ ${FLUTTER_LIBRARY_HEADERS}+)diff --git a/ui/linux/flutter/generated_plugin_registrant.cc b/ui/linux/flutter/generated_plugin_registrant.ccnew file mode 100644index 0000000..e71a16d--- /dev/null+++ b/ui/linux/flutter/generated_plugin_registrant.cc@@ -0,0 +1,11 @@+//+// Generated file. Do not edit.+//++// clang-format off++#include "generated_plugin_registrant.h"+++void fl_register_plugins(FlPluginRegistry* registry) {+}diff --git a/ui/linux/flutter/generated_plugin_registrant.h b/ui/linux/flutter/generated_plugin_registrant.hnew file mode 100644index 0000000..e0f0a47--- /dev/null+++ b/ui/linux/flutter/generated_plugin_registrant.h@@ -0,0 +1,15 @@+//+// Generated file. Do not edit.+//++// clang-format off++#ifndef GENERATED_PLUGIN_REGISTRANT_+#define GENERATED_PLUGIN_REGISTRANT_++#include <flutter_linux/flutter_linux.h>++// Registers Flutter plugins.+void fl_register_plugins(FlPluginRegistry* registry);++#endif // GENERATED_PLUGIN_REGISTRANT_diff --git a/ui/linux/flutter/generated_plugins.cmake b/ui/linux/flutter/generated_plugins.cmakenew file mode 100644index 0000000..2e1de87--- /dev/null+++ b/ui/linux/flutter/generated_plugins.cmake@@ -0,0 +1,23 @@+#+# Generated file, do not edit.+#++list(APPEND FLUTTER_PLUGIN_LIST+)++list(APPEND FLUTTER_FFI_PLUGIN_LIST+)++set(PLUGIN_BUNDLED_LIBRARIES)++foreach(plugin ${FLUTTER_PLUGIN_LIST})+ add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})+ target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)+ list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)+ list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})+endforeach(plugin)++foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})+ add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})+ list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})+endforeach(ffi_plugin)diff --git a/ui/linux/runner/CMakeLists.txt b/ui/linux/runner/CMakeLists.txtnew file mode 100644index 0000000..e97dabc--- /dev/null+++ b/ui/linux/runner/CMakeLists.txt@@ -0,0 +1,26 @@+cmake_minimum_required(VERSION 3.13)+project(runner LANGUAGES CXX)++# Define the application target. To change its name, change BINARY_NAME in the+# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer+# work.+#+# Any new source files that you add to the application should be added here.+add_executable(${BINARY_NAME}+ "main.cc"+ "my_application.cc"+ "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"+)++# Apply the standard set of build settings. This can be removed for applications+# that need different build settings.+apply_standard_settings(${BINARY_NAME})++# Add preprocessor definitions for the application ID.+add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")++# Add dependency libraries. Add any application-specific dependencies here.+target_link_libraries(${BINARY_NAME} PRIVATE flutter)+target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)++target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")diff --git a/ui/linux/runner/main.cc b/ui/linux/runner/main.ccnew file mode 100644index 0000000..e7c5c54--- /dev/null+++ b/ui/linux/runner/main.cc@@ -0,0 +1,6 @@+#include "my_application.h"++int main(int argc, char** argv) {+ g_autoptr(MyApplication) app = my_application_new();+ return g_application_run(G_APPLICATION(app), argc, argv);+}diff --git a/ui/linux/runner/my_application.cc b/ui/linux/runner/my_application.ccnew file mode 100644index 0000000..c89aeac--- /dev/null+++ b/ui/linux/runner/my_application.cc@@ -0,0 +1,179 @@+#include "my_application.h"++#include <flutter_linux/flutter_linux.h>+#ifdef GDK_WINDOWING_X11+#include <gdk/gdkx.h>+#endif++#include "flutter/generated_plugin_registrant.h"++struct _MyApplication {+ GtkApplication parent_instance;+ char** dart_entrypoint_arguments;+ GtkWindow* window; // 已经打开的窗口:再次启动时把它调到前面,而不是再开一个+};++// 与 macOS、Windows 一致:默认 960×640,最小 760×520+static const int kDefaultWidth = 960;+static const int kDefaultHeight = 640;+static const int kMinWidth = 760;+static const int kMinHeight = 520;++// set_window_icon 用随程序一起发布的图标。装了 .deb(或运行过 install.sh)时,+// 桌面会按应用 ID 找到系统里的图标;直接解压运行时靠这一份。+static void set_window_icon(GtkWindow* window) {+ gtk_window_set_icon_name(window, APPLICATION_ID);+ g_autofree gchar* exe = g_file_read_link("/proc/self/exe", nullptr);+ if (exe == nullptr) {+ return;+ }+ g_autofree gchar* dir = g_path_get_dirname(exe);+ g_autofree gchar* icon = g_build_filename(dir, "data", "flutter_assets", "assets", "app_icon.png", nullptr);+ gtk_window_set_icon_from_file(window, icon, nullptr);+}++G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)++// Called when first Flutter frame received.+static void first_frame_cb(MyApplication* self, FlView* view) {+ gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view)));+}++// Implements GApplication::activate.+static void my_application_activate(GApplication* application) {+ MyApplication* self = MY_APPLICATION(application);+ if (self->window != nullptr) {+ gtk_window_present(self->window);+ return;+ }+ GtkWindow* window =+ GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));+ self->window = window;+ g_object_add_weak_pointer(G_OBJECT(window), reinterpret_cast<gpointer*>(&self->window));++ // Use a header bar when running in GNOME as this is the common style used+ // by applications and is the setup most users will be using (e.g. Ubuntu+ // desktop).+ // If running on X and not using GNOME then just use a traditional title bar+ // in case the window manager does more exotic layout, e.g. tiling.+ // If running on Wayland assume the header bar will work (may need changing+ // if future cases occur).+ gboolean use_header_bar = TRUE;+#ifdef GDK_WINDOWING_X11+ GdkScreen* screen = gtk_window_get_screen(window);+ if (GDK_IS_X11_SCREEN(screen)) {+ const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);+ if (g_strcmp0(wm_name, "GNOME Shell") != 0) {+ use_header_bar = FALSE;+ }+ }+#endif+ if (use_header_bar) {+ GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());+ gtk_widget_show(GTK_WIDGET(header_bar));+ gtk_header_bar_set_title(header_bar, "CopySync");+ gtk_header_bar_set_show_close_button(header_bar, TRUE);+ gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));+ } else {+ gtk_window_set_title(window, "CopySync");+ }+ gtk_window_set_title(window, "CopySync");+ set_window_icon(window);++ gtk_window_set_default_size(window, kDefaultWidth, kDefaultHeight);+ gtk_window_set_position(window, GTK_WIN_POS_CENTER);++ g_autoptr(FlDartProject) project = fl_dart_project_new();+ fl_dart_project_set_dart_entrypoint_arguments(+ project, self->dart_entrypoint_arguments);++ FlView* view = fl_view_new(project);+ gtk_widget_set_size_request(GTK_WIDGET(view), kMinWidth, kMinHeight);+ GdkRGBA background_color;+ // Background defaults to black, override it here if necessary, e.g. #00000000+ // for transparent.+ gdk_rgba_parse(&background_color, "#000000");+ fl_view_set_background_color(view, &background_color);+ gtk_widget_show(GTK_WIDGET(view));+ gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));++ // Show the window when Flutter renders.+ // Requires the view to be realized so we can start rendering.+ g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb),+ self);+ gtk_widget_realize(GTK_WIDGET(view));++ fl_register_plugins(FL_PLUGIN_REGISTRY(view));++ gtk_widget_grab_focus(GTK_WIDGET(view));+}++// Implements GApplication::local_command_line.+static gboolean my_application_local_command_line(GApplication* application,+ gchar*** arguments,+ int* exit_status) {+ MyApplication* self = MY_APPLICATION(application);+ // Strip out the first argument as it is the binary name.+ self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);++ g_autoptr(GError) error = nullptr;+ if (!g_application_register(application, nullptr, &error)) {+ g_warning("Failed to register: %s", error->message);+ *exit_status = 1;+ return TRUE;+ }++ g_application_activate(application);+ *exit_status = 0;++ return TRUE;+}++// Implements GApplication::startup.+static void my_application_startup(GApplication* application) {+ // MyApplication* self = MY_APPLICATION(object);++ // Perform any actions required at application startup.++ G_APPLICATION_CLASS(my_application_parent_class)->startup(application);+}++// Implements GApplication::shutdown.+static void my_application_shutdown(GApplication* application) {+ // MyApplication* self = MY_APPLICATION(object);++ // Perform any actions required at application shutdown.++ G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);+}++// Implements GObject::dispose.+static void my_application_dispose(GObject* object) {+ MyApplication* self = MY_APPLICATION(object);+ g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);+ G_OBJECT_CLASS(my_application_parent_class)->dispose(object);+}++static void my_application_class_init(MyApplicationClass* klass) {+ G_APPLICATION_CLASS(klass)->activate = my_application_activate;+ G_APPLICATION_CLASS(klass)->local_command_line =+ my_application_local_command_line;+ G_APPLICATION_CLASS(klass)->startup = my_application_startup;+ G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;+ G_OBJECT_CLASS(klass)->dispose = my_application_dispose;+}++static void my_application_init(MyApplication* self) {}++MyApplication* my_application_new() {+ // Set the program name to the application ID, which helps various systems+ // like GTK and desktop environments map this running application to its+ // corresponding .desktop file. This ensures better integration by allowing+ // the application to be recognized beyond its binary name.+ g_set_prgname(APPLICATION_ID);++ // 不加 G_APPLICATION_NON_UNIQUE:同一个用户只运行一个界面,再次启动只会激活已有的窗口+ return MY_APPLICATION(g_object_new(my_application_get_type(),+ "application-id", APPLICATION_ID, "flags",+ static_cast<GApplicationFlags>(0), nullptr));+}diff --git a/ui/linux/runner/my_application.h b/ui/linux/runner/my_application.hnew file mode 100644index 0000000..db16367--- /dev/null+++ b/ui/linux/runner/my_application.h@@ -0,0 +1,21 @@+#ifndef FLUTTER_MY_APPLICATION_H_+#define FLUTTER_MY_APPLICATION_H_++#include <gtk/gtk.h>++G_DECLARE_FINAL_TYPE(MyApplication,+ my_application,+ MY,+ APPLICATION,+ GtkApplication)++/**+ * my_application_new:+ *+ * Creates a new Flutter-based application.+ *+ * Returns: a new #MyApplication.+ */+MyApplication* my_application_new();++#endif // FLUTTER_MY_APPLICATION_H_diff --git a/ui/test/background_service_linux_test.dart b/ui/test/background_service_linux_test.dartnew file mode 100644index 0000000..ed03b40--- /dev/null+++ b/ui/test/background_service_linux_test.dart@@ -0,0 +1,21 @@+import 'package:copysync_ui/background_service_linux.dart';+import 'package:flutter_test/flutter_test.dart';++void main() {+ test('自启动项里的路径按 Desktop Entry 规范加引号', () {+ expect(quoteExecArg('/opt/CopySync/copysyncd'), '"/opt/CopySync/copysyncd"');+ // 路径里有空格时整体放在引号里+ expect(quoteExecArg('/home/a/下载/CopySync 1/copysyncd'), '"/home/a/下载/CopySync 1/copysyncd"');+ // 引号里的特殊字符要转义,.desktop 文件本身又把反斜杠转义一次+ expect(quoteExecArg(r'/x/$a"b`c\d'), r'"/x/\\$a\\"b\\`c\\\\d"');+ });++ test('能从写出去的自启动项里读回同一条命令', () {+ final exec = '${quoteExecArg('/opt/CopySync/copysyncd')} -supervise';+ final entry = desktopEntry(exec);+ expect(entry, startsWith('[Desktop Entry]\n'));+ expect(entry, contains('NoDisplay=true'));+ expect(execLine(entry), exec);+ expect(execLine('[Desktop Entry]\nName=x\n'), isNull);+ });+}diff --git a/ui/test/widget_test.dart b/ui/test/widget_test.dartindex e7f85c5..bd29f84 100644--- a/ui/test/widget_test.dart+++ b/ui/test/widget_test.dart@@ -1,3 +1,5 @@+import 'dart:io';+import 'package:fixnum/fixnum.dart';import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';@@ -126,7 +128,8 @@ void main() {test('数据目录路径与 Go 侧 config.DefaultPaths 保持一致', () {final dir = DaemonEndpoint.defaultDataDir();// 路径不一致会导致 UI 根本找不到 daemon,这里锁住约定- expect(dir, contains('CopySync'));+ // Linux 按 XDG 的习惯用小写目录名,见 config.DefaultPaths+ expect(dir, Platform.isLinux ? endsWith('/copysync') : contains('CopySync'));expect(DaemonEndpoint.endpointFile(dir).path, endsWith('daemon.json'));});diff --git a/ui/tool/l10n/strings.py b/ui/tool/l10n/strings.pyindex ac1c6b4..790952b 100644--- a/ui/tool/l10n/strings.py+++ b/ui/tool/l10n/strings.py@@ -263,6 +263,7 @@ S = [("svcStoppedTitle", "The background service isn't running", "后台服务没有运行", "バックグラウンドサービスが動いていません"),("svcStoppedBody", "It may have just quit; the system usually restarts it within seconds. If you stay on this page, restart it with the button below.", "它可能刚刚退出,系统通常会在几秒内把它重新拉起。如果一直停在这一页,点下面的按钮重新启动。", "終了した直後かもしれません。通常は数秒で再起動されます。この画面のままなら、下のボタンで再起動してください。"),("svcDevBodyWin", "This is a development build with no copysyncd.exe next to it. Run scripts\\build-windows.ps1 in the source folder to build a complete version.", "这是开发构建,旁边没有 copysyncd.exe。在源码目录运行 scripts\\build-windows.ps1 构建完整的版本。", "開発ビルドのため copysyncd.exe がありません。ソースフォルダで scripts\\build-windows.ps1 を実行して完全版をビルドしてください。"),+ ("svcDevBodyLinux", "This is a development build with no copysyncd next to it. Run ./scripts/package-linux.sh in the source folder to build a complete version.", "这是开发构建,旁边没有 copysyncd。在源码目录运行 ./scripts/package-linux.sh 构建完整的版本。", "開発ビルドのため copysyncd がありません。ソースフォルダで ./scripts/package-linux.sh を実行して完全版をビルドしてください。"),("svcDevBodyMac", "This is a development build without the background service. Run ./scripts/install-macos.sh in the source folder to install it.", "这是开发构建,App 里没有内置后台服务。在源码目录运行 ./scripts/install-macos.sh 安装它。", "開発ビルドのためバックグラウンドサービスが含まれていません。ソースフォルダで ./scripts/install-macos.sh を実行してインストールしてください。"),("svcLogPath", "Log: {path}", "运行日志:{path}", "ログ:{path}"),("svcCanDisable", "You can turn background sync off anytime in Settings.", "随时可以在「设置」中停用后台同步。", "バックグラウンド同期は「設定」でいつでもオフにできます。"),