feat(devices): 设备默认名「平台简写·主机名」+ 支持重命名(1.0.13)
ci-pangolin / Lint — shellcheck (push) Successful in 7s
ci-pangolin / OpenAPI Sync Check (push) Successful in 17s
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (push) Successful in 6s
ci-pangolin / Flutter — analyze + test (push) Failing after 14s
ci-pangolin / Portable SQL — 可移植性 (mysql/sqlite) (push) Successful in 5s
ci-pangolin / Codegen Drift — token 生成物未漂移 (push) Successful in 6s
ci-pangolin / Go — build + test (push) Successful in 11s
ci-pangolin / E2E Smoke — L4 进程级端到端 (push) Successful in 14s
ci-pangolin / Go — integration (mysql/redis testcontainers) (push) Failing after 4m3s
ci-pangolin / Golden — 视觉回归 (components + auth) (push) Successful in 14s
ci-pangolin / Lint — shellcheck (push) Successful in 7s
ci-pangolin / OpenAPI Sync Check (push) Successful in 17s
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (push) Successful in 6s
ci-pangolin / Flutter — analyze + test (push) Failing after 14s
ci-pangolin / Portable SQL — 可移植性 (mysql/sqlite) (push) Successful in 5s
ci-pangolin / Codegen Drift — token 生成物未漂移 (push) Successful in 6s
ci-pangolin / Go — build + test (push) Successful in 11s
ci-pangolin / E2E Smoke — L4 进程级端到端 (push) Successful in 14s
ci-pangolin / Go — integration (mysql/redis testcontainers) (push) Failing after 4m3s
ci-pangolin / Golden — 视觉回归 (components + auth) (push) Successful in 14s
① 默认名:DeviceIdentity 改「平台简写(Win/Mac/Linux/iOS/Andr)·主机名」,主机名截
到 8、总长≈12(替代裸主机名,更短)。
② 重命名:新端点 POST /v1/me/devices/{uuid}/rename(Service.RenameDevice 校验归属+
截 64);store.UpdateName;客户端 account_api.renameDevice + provider.rename +
「我的设备」⋯ 菜单加「重命名」+ 输入弹窗;l10n(zh/en)。
③ 版本 1.0.13。
测试:server RenameDevice(归属/空名/404)+ 客户端 rename widget;全量 go/flutter 绿。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -95,6 +95,9 @@ abstract class AppText {
|
||||
String get devNeverLogin;
|
||||
String get devForceLogout;
|
||||
String get devClearLogin;
|
||||
String get devRename;
|
||||
String get devRenameHint;
|
||||
String get devSave;
|
||||
String get devForceLogoutConfirm; // 弹窗正文(含设备名占位 %s)
|
||||
String get devClearLoginConfirm;
|
||||
String get devCancel;
|
||||
|
||||
@@ -140,6 +140,12 @@ class StringsEn extends AppText {
|
||||
@override
|
||||
String get devClearLogin => 'Clear login info';
|
||||
@override
|
||||
String get devRename => 'Rename';
|
||||
@override
|
||||
String get devRenameHint => 'Device name';
|
||||
@override
|
||||
String get devSave => 'Save';
|
||||
@override
|
||||
String get devForceLogoutConfirm => 'This revokes the device\'s login session — it will be kicked offline and must sign in again. The device stays in the list.';
|
||||
@override
|
||||
String get devClearLoginConfirm => 'This removes the device from the list entirely and revokes its login session and data-plane credential. The device must sign in again to be used.';
|
||||
|
||||
@@ -139,6 +139,12 @@ class StringsZh extends AppText {
|
||||
@override
|
||||
String get devClearLogin => '清除登录信息';
|
||||
@override
|
||||
String get devRename => '重命名';
|
||||
@override
|
||||
String get devRenameHint => '设备名称';
|
||||
@override
|
||||
String get devSave => '保存';
|
||||
@override
|
||||
String get devForceLogoutConfirm => '将吊销该设备的登录会话,它会被踢下线、需重新登录。设备仍保留在列表中。';
|
||||
@override
|
||||
String get devClearLoginConfirm => '将从设备列表彻底移除此设备,并吊销其登录会话与数据面凭证。该设备需重新登录才能再次使用。';
|
||||
|
||||
@@ -64,6 +64,11 @@ class AccountApi {
|
||||
await _c.postJson('/v1/me/devices/$uuid/logout');
|
||||
}
|
||||
|
||||
/// POST /v1/me/devices/{uuid}/rename — 重命名设备。
|
||||
Future<void> renameDevice(String uuid, String name) async {
|
||||
await _c.postJson('/v1/me/devices/$uuid/rename', {'name': name});
|
||||
}
|
||||
|
||||
/// GET /v1/usage?days=N&tz_offset=M — 最近 N 天用量(默认 7,后端范围 [1,90])。
|
||||
/// 带本机时区偏移(分钟,如 UTC+8=480),服务端按「本地日」聚合 → 「今天」与本地日历一致
|
||||
/// (修「29 号却显示 28 号数据」的时区 bug)。
|
||||
|
||||
@@ -103,21 +103,37 @@ class DeviceIdentity {
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/// 平台简写(默认名前缀,保持短)。
|
||||
static String _shortPlatform(String p) => switch (p) {
|
||||
'windows' => 'Win',
|
||||
'macos' => 'Mac',
|
||||
'linux' => 'Linux',
|
||||
'ios' => 'iOS',
|
||||
'android' => 'Andr',
|
||||
_ => p,
|
||||
};
|
||||
|
||||
// 默认名 = 平台简写·主机名(桌面用主机名,移动用机型);主机名截到 8、总长≈12,尽量短。
|
||||
// 用户可在「我的设备」改名覆盖。
|
||||
Future<String> _name() async {
|
||||
var host = '';
|
||||
try {
|
||||
if (Platform.isIOS) {
|
||||
final i = await DeviceInfoPlugin().iosInfo;
|
||||
return i.name.isNotEmpty ? i.name : i.utsname.machine;
|
||||
}
|
||||
if (Platform.isAndroid) {
|
||||
host = i.name.isNotEmpty ? i.name : i.utsname.machine;
|
||||
} else if (Platform.isAndroid) {
|
||||
final a = await DeviceInfoPlugin().androidInfo;
|
||||
return '${a.manufacturer} ${a.model}'.trim();
|
||||
host = a.model;
|
||||
} else {
|
||||
host = Platform.localHostname;
|
||||
}
|
||||
// 桌面:主机名最有意义(MacBook-Pro / DESKTOP-XXXX)。
|
||||
return Platform.localHostname;
|
||||
} catch (_) {
|
||||
return currentPlatform();
|
||||
host = '';
|
||||
}
|
||||
host = host.trim();
|
||||
if (host.length > 8) host = host.substring(0, 8);
|
||||
final short = _shortPlatform(currentPlatform());
|
||||
return host.isEmpty ? short : '$short·$host';
|
||||
}
|
||||
|
||||
Future<String> _clientVersion() async {
|
||||
|
||||
@@ -95,6 +95,13 @@ class DevicesNotifier extends AsyncNotifier<List<Device>> {
|
||||
ref.invalidateSelf();
|
||||
await future;
|
||||
}
|
||||
|
||||
/// 重命名设备后刷新列表。
|
||||
Future<void> rename(String uuid, String name) async {
|
||||
await ref.read(accountApiProvider).renameDevice(uuid, name);
|
||||
ref.invalidateSelf();
|
||||
await future;
|
||||
}
|
||||
}
|
||||
|
||||
final devicesProvider =
|
||||
|
||||
@@ -219,6 +219,10 @@ class DevicesScreen extends ConsumerWidget {
|
||||
color: c.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(PangolinRadius.md), side: BorderSide(color: c.border)),
|
||||
itemBuilder: (_) => [
|
||||
PopupMenuItem(value: 'rename', child: Row(children: [
|
||||
Icon(PangolinIcons.edit, size: 16, color: c.fg2), const SizedBox(width: 10),
|
||||
Text(t.devRename, style: PangolinText.sm.copyWith(color: c.fg1)),
|
||||
])),
|
||||
PopupMenuItem(value: 'logout', child: Row(children: [
|
||||
Icon(PangolinIcons.logOut, size: 16, color: c.fg2), const SizedBox(width: 10),
|
||||
Text(t.devForceLogout, style: PangolinText.sm.copyWith(color: c.fg1)),
|
||||
@@ -229,6 +233,13 @@ class DevicesScreen extends ConsumerWidget {
|
||||
])),
|
||||
],
|
||||
onSelected: (v) async {
|
||||
if (v == 'rename') {
|
||||
final newName = await _renameDialog(context, c, d);
|
||||
if (newName != null && newName.trim().isNotEmpty) {
|
||||
await ref.read(devicesProvider.notifier).rename(d.uuid, newName.trim());
|
||||
}
|
||||
return;
|
||||
}
|
||||
final isClear = v == 'clear';
|
||||
final label = isClear ? t.devClearLogin : t.devForceLogout;
|
||||
final shown = d.name.isNotEmpty ? d.name : d.platformKind.label;
|
||||
@@ -271,6 +282,37 @@ class DevicesScreen extends ConsumerWidget {
|
||||
);
|
||||
return ok ?? false;
|
||||
}
|
||||
|
||||
// 重命名弹窗:预填当前名,返回新名(取消返回 null)。
|
||||
Future<String?> _renameDialog(BuildContext context, PangolinScheme c, Device d) {
|
||||
final ctl = TextEditingController(text: d.name);
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: c.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(PangolinRadius.xl)),
|
||||
title: Text(t.devRename, style: PangolinText.body.copyWith(color: c.fg1, fontWeight: FontWeight.w700)),
|
||||
content: TextField(
|
||||
controller: ctl,
|
||||
autofocus: true,
|
||||
maxLength: 64,
|
||||
style: PangolinText.sm.copyWith(color: c.fg1),
|
||||
decoration: InputDecoration(
|
||||
hintText: t.devRenameHint,
|
||||
counterText: '',
|
||||
hintStyle: PangolinText.sm.copyWith(color: c.fg3),
|
||||
),
|
||||
onSubmitted: (v) => Navigator.pop(ctx, v),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx),
|
||||
child: Text(t.devCancel, style: PangolinText.sm.copyWith(color: c.fg2, fontWeight: FontWeight.w600))),
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, ctl.text),
|
||||
child: Text(t.devSave, style: PangolinText.sm.copyWith(color: c.accent, fontWeight: FontWeight.w700))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// ── 兑换 & 购买 ── (兑换码走 POST /v1/redeem,成功后刷新账户)
|
||||
|
||||
@@ -58,6 +58,7 @@ class PangolinIcons {
|
||||
static const moreVertical = LucideIcons.moreVertical;
|
||||
static const trash = LucideIcons.trash2;
|
||||
static const alertTriangle= LucideIcons.alertTriangle;
|
||||
static const edit = LucideIcons.pencil;
|
||||
|
||||
static IconData? byName(String name) => _byName[name];
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
name: pangolin_vpn
|
||||
description: 穿山甲 · Pangolin — 极简、稳定、跨平台网络加速客户端。
|
||||
publish_to: "none"
|
||||
version: 1.0.12+13
|
||||
version: 1.0.13+14
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.0
|
||||
|
||||
@@ -124,4 +124,18 @@ void main() {
|
||||
expect(recorded.any((r) => r == 'DELETE /v1/me/devices/phone-uuid'), isTrue,
|
||||
reason: '应调清除接口: $recorded');
|
||||
});
|
||||
|
||||
testWidgets('重命名 → 输入新名 → 保存 → 调 rename 接口', (tester) async {
|
||||
await pump(tester);
|
||||
await tester.tap(find.byType(PopupMenuButton<String>));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(t.devRename));
|
||||
await tester.pumpAndSettle();
|
||||
// 弹窗里输入新名。
|
||||
await tester.enterText(find.byType(TextField).last, '我的手机');
|
||||
await tester.tap(find.widgetWithText(TextButton, t.devSave));
|
||||
await tester.pumpAndSettle();
|
||||
expect(recorded.any((r) => r == 'POST /v1/me/devices/phone-uuid/rename'), isTrue,
|
||||
reason: '应调重命名接口: $recorded');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
; 前置: 先在 client/ 跑 `flutter build windows`(Release),产物在
|
||||
; ..\..\build\windows\x64\runner\Release
|
||||
#define MyAppName "穿山甲 Pangolin"
|
||||
#define MyAppVersion "1.0.12"
|
||||
#define MyAppVersion "1.0.13"
|
||||
#define MyAppPublisher "Pangolin"
|
||||
#define MyAppExeName "pangolin_vpn.exe"
|
||||
#define BuildDir "..\..\build\windows\x64\runner\Release"
|
||||
|
||||
Reference in New Issue
Block a user