Skip to content

Commit c3a49b5

Browse files
committed
[ver1.3.1] bug fix.
1 parent 559d047 commit c3a49b5

File tree

3 files changed

+75
-66
lines changed

3 files changed

+75
-66
lines changed

lib/models/backup_data_model.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class BackupData {
77
final List<Credential> credentials;
88
final List<ConnectionInfo> recentConnections;
99
final AppSettings settings;
10+
final List<ArchiveGroup> archiveGroups;
1011
final DateTime backupTime;
1112
final String version;
1213

@@ -15,6 +16,7 @@ class BackupData {
1516
required this.credentials,
1617
required this.recentConnections,
1718
required this.settings,
19+
required this.archiveGroups,
1820
required this.backupTime,
1921
required this.version,
2022
});
@@ -26,7 +28,8 @@ class BackupData {
2628
'connections': connections.map((c) => c.toJson()).toList(),
2729
'credentials': credentials.map((c) => c.toJson()).toList(),
2830
'recentConnections': recentConnections.map((c) => c.toJson()).toList(),
29-
'settings': settings.toMap(), // 改为使用 toMap()
31+
'settings': settings.toMap(),
32+
'archiveGroups': archiveGroups.map((g) => g.toJson()).toList(),
3033
};
3134
}
3235

@@ -43,7 +46,11 @@ class BackupData {
4346
recentConnections: (json['recentConnections'] as List)
4447
.map((c) => ConnectionInfo.fromJson(c))
4548
.toList(),
46-
settings: AppSettings.fromMap(json['settings']), // 改为使用 fromMap()
49+
settings: AppSettings.fromMap(json['settings']),
50+
archiveGroups: (json['archiveGroups'] as List?)
51+
?.map((g) => ArchiveGroup.fromJson(g))
52+
.toList() ??
53+
[],
4754
);
4855
}
4956
}

lib/pages/manage_connections.dart

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -489,78 +489,78 @@ class _ManageConnectionsPageState extends State<ManageConnectionsPage> {
489489
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
490490
child: Column(
491491
children: [
492-
Container(
493-
height: 56,
494-
decoration: BoxDecoration(
495-
color: Colors.transparent,
496-
borderRadius: BorderRadius.circular(12),
497-
),
498-
child: Padding(
499-
padding: const EdgeInsets.symmetric(horizontal: 16),
500-
child: Row(
501-
children: [
502-
Container(
503-
width: 40,
504-
height: 40,
505-
decoration: BoxDecoration(
506-
color: Colors.grey.withOpacity(0.1),
507-
shape: BoxShape.circle,
508-
),
509-
child: IconButton(
510-
icon: Icon(
492+
GestureDetector(
493+
onTap: () => _toggleGroupExpanded(group),
494+
child: Container(
495+
height: 56,
496+
decoration: BoxDecoration(
497+
color: Colors.transparent,
498+
borderRadius: BorderRadius.circular(12),
499+
),
500+
child: Padding(
501+
padding: const EdgeInsets.symmetric(horizontal: 16),
502+
child: Row(
503+
children: [
504+
Container(
505+
width: 40,
506+
height: 40,
507+
decoration: BoxDecoration(
508+
color: Colors.grey.withOpacity(0.1),
509+
shape: BoxShape.circle,
510+
),
511+
child: Icon(
511512
group.isExpanded
512513
? Icons.expand_less
513514
: Icons.expand_more,
514515
size: 20,
515516
color: Theme.of(context).colorScheme.primary,
516517
),
517-
onPressed: () => _toggleGroupExpanded(group),
518-
padding: EdgeInsets.zero,
519518
),
520-
),
521-
const SizedBox(width: 16),
522-
Expanded(
523-
child: Column(
524-
mainAxisAlignment: MainAxisAlignment.center,
525-
crossAxisAlignment: CrossAxisAlignment.start,
519+
const SizedBox(width: 16),
520+
Expanded(
521+
child: Column(
522+
mainAxisAlignment: MainAxisAlignment.center,
523+
crossAxisAlignment: CrossAxisAlignment.start,
524+
children: [
525+
Text(
526+
group.name,
527+
style: const TextStyle(
528+
fontWeight: FontWeight.bold,
529+
fontSize: 16,
530+
),
531+
),
532+
Text(
533+
'${connections.length} 个连接',
534+
style: TextStyle(
535+
color: Colors.grey[600],
536+
fontSize: 12,
537+
),
538+
),
539+
],
540+
),
541+
),
542+
Row(
543+
mainAxisSize: MainAxisSize.min,
526544
children: [
527-
Text(
528-
group.name,
529-
style: const TextStyle(
530-
fontWeight: FontWeight.bold,
531-
fontSize: 16,
545+
GestureDetector(
546+
onTap: () => _editArchiveGroup(group),
547+
child: Container(
548+
padding: const EdgeInsets.all(8),
549+
child: const Icon(Icons.edit, size: 20),
532550
),
533551
),
534-
Text(
535-
'${connections.length} 个连接',
536-
style: TextStyle(
537-
color: Colors.grey[600],
538-
fontSize: 12,
552+
const SizedBox(width: 8),
553+
GestureDetector(
554+
onTap: () => _deleteArchiveGroup(group),
555+
child: Container(
556+
padding: const EdgeInsets.all(8),
557+
child: const Icon(Icons.delete, size: 20),
539558
),
540559
),
541560
],
542561
),
543-
),
544-
Row(
545-
mainAxisSize: MainAxisSize.min,
546-
children: [
547-
IconButton(
548-
icon: const Icon(Icons.edit, size: 20),
549-
onPressed: () => _editArchiveGroup(group),
550-
padding: const EdgeInsets.all(4),
551-
constraints: const BoxConstraints(),
552-
tooltip: '编辑分组',
553-
),
554-
IconButton(
555-
icon: const Icon(Icons.delete, size: 20),
556-
onPressed: () => _deleteArchiveGroup(group),
557-
padding: const EdgeInsets.all(4),
558-
constraints: const BoxConstraints(),
559-
tooltip: '删除分组',
560-
),
561-
],
562-
),
563-
],
562+
],
563+
),
564564
),
565565
),
566566
),

lib/services/backup_service.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ class BackupService {
2121
}) : _storageService = storageService,
2222
_settingsService = settingsService;
2323

24-
// 生成加密密钥
2524
encrypt_package.Key _generateKey(String password) {
2625
final hash = crypto.sha256.convert(utf8.encode(password));
2726
return encrypt_package.Key(Uint8List.fromList(hash.bytes));
2827
}
2928

30-
// 生成固定IV
3129
encrypt_package.IV _generateIV(String password) {
3230
final hash = crypto.sha1.convert(utf8.encode(password));
3331
return encrypt_package.IV(Uint8List.fromList(hash.bytes.sublist(0, 16)));
@@ -38,14 +36,16 @@ class BackupService {
3836
final credentials = await _storageService.getCredentials();
3937
final recentConnections = await _storageService.getRecentConnections();
4038
final settings = await _settingsService.getSettings();
39+
final archiveGroups = await _storageService.getArchiveGroups();
4140

4241
return BackupData(
4342
connections: connections,
4443
credentials: credentials,
4544
recentConnections: recentConnections,
4645
settings: settings,
46+
archiveGroups: archiveGroups,
4747
backupTime: DateTime.now(),
48-
version: '1.3.0',
48+
version: '1.3.1',
4949
);
5050
}
5151

@@ -261,18 +261,20 @@ class BackupService {
261261
await prefs.remove('saved_connections');
262262
await prefs.remove('saved_credentials');
263263
await prefs.remove('recent_connections');
264+
await prefs.remove('archive_groups'); // 清空现有分组
265+
266+
for (final group in backupData.archiveGroups) {
267+
await _storageService.saveArchiveGroup(group);
268+
}
264269

265-
// 恢复连接
266270
for (final connection in backupData.connections) {
267271
await _storageService.saveConnection(connection);
268272
}
269273

270-
// 恢复凭证
271274
for (final credential in backupData.credentials) {
272275
await _storageService.saveCredential(credential);
273276
}
274277

275-
// 恢复最近连接
276278
final recentConnectionsJson = json.encode(
277279
backupData.recentConnections.map((c) => c.toJson()).toList(),
278280
);

0 commit comments

Comments
 (0)