Merge pull request #5404 from 21pages/ab
fix ab ui not updating immediately
This commit is contained in:
commit
1141b99cf4
@ -48,13 +48,14 @@ class _AddressBookState extends State<AddressBook> {
|
||||
return Column(
|
||||
children: [
|
||||
_buildNotEmptyLoading(),
|
||||
_buildRetryProgress(),
|
||||
_buildErrorBanner(
|
||||
err: gFFI.abModel.pullError,
|
||||
retry: null,
|
||||
close: () => gFFI.abModel.pullError.value = ''),
|
||||
_buildErrorBanner(
|
||||
err: gFFI.abModel.pushError,
|
||||
retry: () => gFFI.abModel.pushAb(),
|
||||
retry: () => gFFI.abModel.pushAb(isRetry: true),
|
||||
close: () => gFFI.abModel.pushError.value = ''),
|
||||
Expanded(
|
||||
child: isDesktop
|
||||
@ -136,6 +137,13 @@ class _AddressBookState extends State<AddressBook> {
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildRetryProgress() {
|
||||
return Obx(() => Offstage(
|
||||
offstage: !gFFI.abModel.retrying.value,
|
||||
child: LinearProgressIndicator(),
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildAddressBookDesktop() {
|
||||
return Row(
|
||||
children: [
|
||||
@ -339,7 +347,7 @@ class _AddressBookState extends State<AddressBook> {
|
||||
return;
|
||||
}
|
||||
gFFI.abModel.addId(id, aliasController.text.trim(), selectedTag);
|
||||
await gFFI.abModel.pushAb();
|
||||
gFFI.abModel.pushAb();
|
||||
this.setState(() {});
|
||||
// final currentPeers
|
||||
}
|
||||
@ -448,7 +456,7 @@ class _AddressBookState extends State<AddressBook> {
|
||||
for (final tag in tags) {
|
||||
gFFI.abModel.addTag(tag);
|
||||
}
|
||||
await gFFI.abModel.pushAb();
|
||||
gFFI.abModel.pushAb();
|
||||
// final currentPeers
|
||||
}
|
||||
close();
|
||||
|
@ -1,9 +1,11 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/common/widgets/dialog.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/models/ab_model.dart';
|
||||
import 'package:flutter_hbb/models/peer_tab_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -582,6 +584,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
),
|
||||
proc: () {
|
||||
bind.mainCreateShortcut(id: id);
|
||||
showToast(translate('Successful'));
|
||||
},
|
||||
padding: menuPadding,
|
||||
dismissOnClicked: true,
|
||||
@ -597,6 +600,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
setter: (bool v) async {
|
||||
await bind.mainSetPeerOption(
|
||||
id: id, key: key, value: bool2option(key, v));
|
||||
showToast(translate('Successful'));
|
||||
},
|
||||
padding: menuPadding,
|
||||
dismissOnClicked: true,
|
||||
@ -633,6 +637,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
id: id,
|
||||
key: kOptionForceAlwaysRelay,
|
||||
value: bool2option(kOptionForceAlwaysRelay, v));
|
||||
showToast(translate('Successful'));
|
||||
},
|
||||
padding: menuPadding,
|
||||
dismissOnClicked: true,
|
||||
@ -657,6 +662,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
gFFI.abModel.pushAb();
|
||||
} else {
|
||||
await bind.mainSetPeerAlias(id: id, alias: newName);
|
||||
showToast(translate('Successful'));
|
||||
_update();
|
||||
}
|
||||
}
|
||||
@ -706,11 +712,25 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
break;
|
||||
case PeerTabIndex.ab:
|
||||
gFFI.abModel.deletePeer(id);
|
||||
await gFFI.abModel.pushAb();
|
||||
final future = gFFI.abModel.pushAb();
|
||||
if (shouldSyncAb() && await bind.mainPeerExists(id: peer.id)) {
|
||||
Future.delayed(Duration.zero, () async {
|
||||
final succ = await future;
|
||||
if (succ) {
|
||||
await Future.delayed(Duration(seconds: 2)); // success msg
|
||||
BotToast.showText(
|
||||
contentColor: Colors.lightBlue,
|
||||
text: translate('synced_peer_readded_tip'));
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case PeerTabIndex.group:
|
||||
break;
|
||||
}
|
||||
if (tab != PeerTabIndex.ab) {
|
||||
showToast(translate('Successful'));
|
||||
}
|
||||
}
|
||||
|
||||
deletePeerConfirmDialog(onSubmit,
|
||||
@ -730,6 +750,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
),
|
||||
proc: () {
|
||||
bind.mainForgetPassword(id: id);
|
||||
showToast(translate('Successful'));
|
||||
},
|
||||
padding: menuPadding,
|
||||
dismissOnClicked: true,
|
||||
@ -762,6 +783,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
favs.add(id);
|
||||
await bind.mainStoreFav(favs: favs);
|
||||
}
|
||||
showToast(translate('Successful'));
|
||||
}();
|
||||
},
|
||||
padding: menuPadding,
|
||||
@ -796,6 +818,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
await bind.mainStoreFav(favs: favs);
|
||||
await reloadFunc();
|
||||
}
|
||||
showToast(translate('Successful'));
|
||||
}();
|
||||
},
|
||||
padding: menuPadding,
|
||||
@ -817,7 +840,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
}
|
||||
if (!gFFI.abModel.idContainBy(peer.id)) {
|
||||
gFFI.abModel.addPeer(peer);
|
||||
await gFFI.abModel.pushAb();
|
||||
gFFI.abModel.pushAb();
|
||||
}
|
||||
}();
|
||||
},
|
||||
@ -1049,7 +1072,7 @@ class AddressBookPeerCard extends BasePeerCard {
|
||||
proc: () {
|
||||
editAbTagDialog(gFFI.abModel.getPeerTags(id), (selectedTag) async {
|
||||
gFFI.abModel.changeTagForPeer(id, selectedTag);
|
||||
await gFFI.abModel.pushAb();
|
||||
gFFI.abModel.pushAb();
|
||||
});
|
||||
},
|
||||
padding: super.menuPadding,
|
||||
@ -1121,6 +1144,7 @@ void _rdpDialog(String id) async {
|
||||
id: id, key: 'rdp_username', value: username);
|
||||
await bind.mainSetPeerOption(
|
||||
id: id, key: 'rdp_password', value: password);
|
||||
showToast(translate('Successful'));
|
||||
close();
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/common/widgets/address_book.dart';
|
||||
import 'package:flutter_hbb/common/widgets/dialog.dart';
|
||||
@ -7,6 +8,7 @@ import 'package:flutter_hbb/common/widgets/peer_card.dart';
|
||||
import 'package:flutter_hbb/common/widgets/animated_rotation_widget.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/desktop/widgets/popup_menu.dart';
|
||||
import 'package:flutter_hbb/models/ab_model.dart';
|
||||
|
||||
import 'package:flutter_hbb/models/peer_tab_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
@ -122,12 +124,11 @@ class _PeerTabPageState extends State<PeerTabPage>
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
borderRadius: BorderRadius.circular(6)),
|
||||
child: Tooltip(
|
||||
message: translate('Toggle Tags'),
|
||||
child: Icon(
|
||||
Icons.tag_rounded,
|
||||
size: 18,
|
||||
))
|
||||
)),
|
||||
message: translate('Toggle Tags'),
|
||||
child: Icon(
|
||||
Icons.tag_rounded,
|
||||
size: 18,
|
||||
)))),
|
||||
onTap: () async {
|
||||
await bind.mainSetLocalOption(
|
||||
key: "hideAbTagsPanel",
|
||||
@ -221,13 +222,12 @@ class _PeerTabPageState extends State<PeerTabPage>
|
||||
child: RotatedBox(
|
||||
quarterTurns: 2,
|
||||
child: Tooltip(
|
||||
message: translate('Refresh'),
|
||||
child: Icon(
|
||||
Icons.refresh,
|
||||
size: 18,
|
||||
color: textColor,
|
||||
))
|
||||
)),
|
||||
message: translate('Refresh'),
|
||||
child: Icon(
|
||||
Icons.refresh,
|
||||
size: 18,
|
||||
color: textColor,
|
||||
)))),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -243,29 +243,28 @@ class _PeerTabPageState extends State<PeerTabPage>
|
||||
|
||||
return Obx(
|
||||
() => Container(
|
||||
padding: EdgeInsets.all(4.0),
|
||||
decoration: hover.value ? deco : null,
|
||||
child: InkWell(
|
||||
onHover: (value) => hover.value = value,
|
||||
onTap: () async {
|
||||
final type = types.elementAt(
|
||||
peerCardUiType.value == types.elementAt(0) ? 1 : 0);
|
||||
await bind.setLocalFlutterOption(
|
||||
k: 'peer-card-ui-type', v: type.index.toString());
|
||||
peerCardUiType.value = type;
|
||||
},
|
||||
child: Tooltip(
|
||||
message: peerCardUiType.value == PeerUiType.grid
|
||||
? translate('List View')
|
||||
: translate('Grid View'),
|
||||
child: Icon(
|
||||
peerCardUiType.value == PeerUiType.grid
|
||||
? Icons.view_list_rounded
|
||||
: Icons.grid_view_rounded,
|
||||
size: 18,
|
||||
color: textColor,
|
||||
))
|
||||
)),
|
||||
padding: EdgeInsets.all(4.0),
|
||||
decoration: hover.value ? deco : null,
|
||||
child: InkWell(
|
||||
onHover: (value) => hover.value = value,
|
||||
onTap: () async {
|
||||
final type = types.elementAt(
|
||||
peerCardUiType.value == types.elementAt(0) ? 1 : 0);
|
||||
await bind.setLocalFlutterOption(
|
||||
k: 'peer-card-ui-type', v: type.index.toString());
|
||||
peerCardUiType.value = type;
|
||||
},
|
||||
child: Tooltip(
|
||||
message: peerCardUiType.value == PeerUiType.grid
|
||||
? translate('List View')
|
||||
: translate('Grid View'),
|
||||
child: Icon(
|
||||
peerCardUiType.value == PeerUiType.grid
|
||||
? Icons.view_list_rounded
|
||||
: Icons.grid_view_rounded,
|
||||
size: 18,
|
||||
color: textColor,
|
||||
)))),
|
||||
);
|
||||
}
|
||||
|
||||
@ -280,12 +279,12 @@ class _PeerTabPageState extends State<PeerTabPage>
|
||||
model.setMultiSelectionMode(true);
|
||||
},
|
||||
child: Tooltip(
|
||||
message: translate('Select'),
|
||||
child: Icon(
|
||||
IconFont.checkbox,
|
||||
size: 18,
|
||||
color: textColor,
|
||||
)),
|
||||
message: translate('Select'),
|
||||
child: Icon(
|
||||
IconFont.checkbox,
|
||||
size: 18,
|
||||
color: textColor,
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -334,14 +333,36 @@ class _PeerTabPageState extends State<PeerTabPage>
|
||||
await bind.mainLoadLanPeers();
|
||||
break;
|
||||
case 3:
|
||||
gFFI.abModel.deletePeers(peers.map((p) => p.id).toList());
|
||||
await gFFI.abModel.pushAb();
|
||||
{
|
||||
bool hasSynced = false;
|
||||
if (shouldSyncAb()) {
|
||||
for (var p in peers) {
|
||||
if (await bind.mainPeerExists(id: p.id)) {
|
||||
hasSynced = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
gFFI.abModel.deletePeers(peers.map((p) => p.id).toList());
|
||||
final future = gFFI.abModel.pushAb();
|
||||
if (hasSynced) {
|
||||
Future.delayed(Duration.zero, () async {
|
||||
final succ = await future;
|
||||
if (succ) {
|
||||
await Future.delayed(
|
||||
Duration(seconds: 2)); // success msg
|
||||
BotToast.showText(
|
||||
contentColor: Colors.lightBlue,
|
||||
text: translate('synced_peer_readded_tip'));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
gFFI.peerTabModel.setMultiSelectionMode(false);
|
||||
showToast(translate('Successful'));
|
||||
if (model.currentTab != 3) showToast(translate('Successful'));
|
||||
}
|
||||
|
||||
deletePeerConfirmDialog(onSubmit, translate('Delete'));
|
||||
@ -384,11 +405,18 @@ class _PeerTabPageState extends State<PeerTabPage>
|
||||
!gFFI.userModel.isLogin || model.currentTab == PeerTabIndex.ab.index,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (gFFI.abModel.isFull(true)) {
|
||||
return;
|
||||
}
|
||||
final peers = model.selectedPeers;
|
||||
gFFI.abModel.addPeers(peers);
|
||||
gFFI.abModel.pushAb();
|
||||
final future = gFFI.abModel.pushAb();
|
||||
model.setMultiSelectionMode(false);
|
||||
showToast(translate('Successful'));
|
||||
Future.delayed(Duration.zero, () async {
|
||||
await future;
|
||||
await Future.delayed(Duration(seconds: 2)); // toast
|
||||
gFFI.abModel.isFull(true);
|
||||
});
|
||||
},
|
||||
child: Tooltip(
|
||||
message: translate('Add to Address Book'),
|
||||
@ -483,8 +511,7 @@ class _PeerSearchBarState extends State<PeerSearchBar> {
|
||||
child: Icon(
|
||||
Icons.search_rounded,
|
||||
color: Theme.of(context).hintColor,
|
||||
))
|
||||
);
|
||||
)));
|
||||
}
|
||||
|
||||
Widget _buildSearchBar() {
|
||||
@ -543,22 +570,21 @@ class _PeerSearchBarState extends State<PeerSearchBar> {
|
||||
),
|
||||
// Icon(Icons.close),
|
||||
IconButton(
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 2),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
peerSearchTextController.clear();
|
||||
peerSearchText.value = "";
|
||||
drawer = false;
|
||||
});
|
||||
},
|
||||
icon: Tooltip(
|
||||
message: translate('Close'),
|
||||
child:
|
||||
Icon(
|
||||
Icons.close,
|
||||
color: Theme.of(context).hintColor,
|
||||
)),
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 2),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
peerSearchTextController.clear();
|
||||
peerSearchText.value = "";
|
||||
drawer = false;
|
||||
});
|
||||
},
|
||||
icon: Tooltip(
|
||||
message: translate('Close'),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
color: Theme.of(context).hintColor,
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -628,7 +654,7 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
|
||||
child: Icon(
|
||||
Icons.sort_rounded,
|
||||
size: 18,
|
||||
)),
|
||||
)),
|
||||
onTapDown: (details) {
|
||||
final x = details.globalPosition.dx;
|
||||
final y = details.globalPosition.dy;
|
||||
|
@ -30,6 +30,7 @@ class AbModel {
|
||||
final tags = [].obs;
|
||||
final peers = List<Peer>.empty(growable: true).obs;
|
||||
final sortTags = shouldSortTags().obs;
|
||||
final retrying = false.obs;
|
||||
bool get emtpy => peers.isEmpty && tags.isEmpty;
|
||||
|
||||
final selectedTags = List<String>.empty(growable: true).obs;
|
||||
@ -55,10 +56,11 @@ class AbModel {
|
||||
if (gFFI.userModel.userName.isEmpty) return;
|
||||
if (abLoading.value) return;
|
||||
if (!force && initialized) return;
|
||||
DateTime startTime = DateTime.now();
|
||||
if (pushError.isNotEmpty) {
|
||||
try {
|
||||
// push to retry
|
||||
pushAb(toast: false);
|
||||
pushAb(toastIfFail: false, toastIfSucc: false);
|
||||
} catch (_) {}
|
||||
}
|
||||
if (!quiet) {
|
||||
@ -112,14 +114,14 @@ class AbModel {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (initialized) {
|
||||
// make loading effect obvious
|
||||
Future.delayed(Duration(milliseconds: 300), () {
|
||||
abLoading.value = false;
|
||||
});
|
||||
} else {
|
||||
var ms =
|
||||
(Duration(milliseconds: 300) - DateTime.now().difference(startTime))
|
||||
.inMilliseconds;
|
||||
ms = ms > 0 ? ms : 0;
|
||||
Future.delayed(Duration(milliseconds: ms), () {
|
||||
abLoading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
initialized = true;
|
||||
_syncAllFromRecent = true;
|
||||
_timerCounter = 0;
|
||||
@ -161,10 +163,16 @@ class AbModel {
|
||||
}
|
||||
}
|
||||
|
||||
void addPeers(List<Peer> ps) {
|
||||
bool addPeers(List<Peer> ps) {
|
||||
bool allAdded = true;
|
||||
for (var p in ps) {
|
||||
addPeer(p);
|
||||
if (!isFull(false)) {
|
||||
addPeer(p);
|
||||
} else {
|
||||
allAdded = false;
|
||||
}
|
||||
}
|
||||
return allAdded;
|
||||
}
|
||||
|
||||
void addTag(String tag) async {
|
||||
@ -198,13 +206,22 @@ class AbModel {
|
||||
it.first.alias = alias;
|
||||
}
|
||||
|
||||
Future<void> pushAb({bool toast = true}) async {
|
||||
debugPrint("pushAb");
|
||||
Future<bool> pushAb(
|
||||
{bool toastIfFail = true,
|
||||
bool toastIfSucc = true,
|
||||
bool isRetry = false}) async {
|
||||
debugPrint(
|
||||
"pushAb: toastIfFail:$toastIfFail, toastIfSucc:$toastIfSucc, isRetry:$isRetry");
|
||||
pushError.value = '';
|
||||
if (isRetry) retrying.value = true;
|
||||
DateTime startTime = DateTime.now();
|
||||
bool ret = false;
|
||||
try {
|
||||
// avoid double pushes in a row
|
||||
_syncAllFromRecent = true;
|
||||
syncFromRecent(push: false);
|
||||
await syncFromRecent(push: false);
|
||||
//https: //stackoverflow.com/questions/68249333/flutter-getx-updating-item-in-children-list-is-not-reactive
|
||||
peers.refresh();
|
||||
final api = "${await bind.mainGetApiServer()}/api/ab";
|
||||
var authHeaders = getHttpHeaders();
|
||||
authHeaders['Content-Type'] = "application/json";
|
||||
@ -224,12 +241,14 @@ class AbModel {
|
||||
}
|
||||
if (resp.statusCode == 200 &&
|
||||
(resp.body.isEmpty || resp.body.toLowerCase() == 'null')) {
|
||||
ret = true;
|
||||
_saveCache();
|
||||
} else {
|
||||
Map<String, dynamic> json = _jsonDecode(resp.body, resp.statusCode);
|
||||
if (json.containsKey('error')) {
|
||||
throw json['error'];
|
||||
} else if (resp.statusCode == 200) {
|
||||
ret = true;
|
||||
_saveCache();
|
||||
} else {
|
||||
throw 'HTTP ${resp.statusCode}';
|
||||
@ -238,12 +257,25 @@ class AbModel {
|
||||
} catch (e) {
|
||||
pushError.value =
|
||||
'${translate('push_ab_failed_tip')}: ${translate(e.toString())}';
|
||||
if (toast && gFFI.peerTabModel.currentTab != PeerTabIndex.ab.index) {
|
||||
BotToast.showText(contentColor: Colors.red, text: pushError.value);
|
||||
}
|
||||
} finally {
|
||||
_syncAllFromRecent = true;
|
||||
}
|
||||
_syncAllFromRecent = true;
|
||||
if (isRetry) {
|
||||
var ms =
|
||||
(Duration(milliseconds: 200) - DateTime.now().difference(startTime))
|
||||
.inMilliseconds;
|
||||
ms = ms > 0 ? ms : 0;
|
||||
Future.delayed(Duration(milliseconds: ms), () {
|
||||
retrying.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
if (!ret && toastIfFail) {
|
||||
BotToast.showText(contentColor: Colors.red, text: pushError.value);
|
||||
}
|
||||
if (ret && toastIfSucc) {
|
||||
showToast(translate('Successful'));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Peer? find(String id) {
|
||||
@ -333,42 +365,37 @@ class AbModel {
|
||||
rdpUsername: r.rdpUsername);
|
||||
}
|
||||
|
||||
void syncFromRecent({bool push = true}) async {
|
||||
Future<void> syncFromRecent({bool push = true}) async {
|
||||
if (!_syncFromRecentLock) {
|
||||
_syncFromRecentLock = true;
|
||||
_syncFromRecentWithoutLock(push: push);
|
||||
await _syncFromRecentWithoutLock(push: push);
|
||||
_syncFromRecentLock = false;
|
||||
}
|
||||
}
|
||||
|
||||
void _syncFromRecentWithoutLock({bool push = true}) async {
|
||||
bool shouldSync(Peer a, Peer b) {
|
||||
return a.hash != b.hash ||
|
||||
a.username != b.username ||
|
||||
a.platform != b.platform ||
|
||||
a.hostname != b.hostname ||
|
||||
a.alias != b.alias;
|
||||
Future<void> _syncFromRecentWithoutLock({bool push = true}) async {
|
||||
bool shouldSync(Peer r, Peer p) {
|
||||
return r.hash != p.hash ||
|
||||
r.username != p.username ||
|
||||
r.platform != p.platform ||
|
||||
r.hostname != p.hostname ||
|
||||
(p.alias.isEmpty && r.alias.isNotEmpty);
|
||||
}
|
||||
|
||||
Future<List<Peer>> getRecentPeers() async {
|
||||
try {
|
||||
if (peers.isEmpty) [];
|
||||
List<String> filteredPeerIDs;
|
||||
if (_syncAllFromRecent) {
|
||||
_syncAllFromRecent = false;
|
||||
filteredPeerIDs = peers.map((e) => e.id).toList();
|
||||
filteredPeerIDs = [];
|
||||
} else {
|
||||
final new_stored_str = await bind.mainGetNewStoredPeers();
|
||||
if (new_stored_str.isEmpty) return [];
|
||||
List<String> new_stores =
|
||||
(jsonDecode(new_stored_str) as List<dynamic>)
|
||||
.map((e) => e.toString())
|
||||
.toList();
|
||||
final abPeerIds = peers.map((e) => e.id).toList();
|
||||
filteredPeerIDs =
|
||||
new_stores.where((e) => abPeerIds.contains(e)).toList();
|
||||
filteredPeerIDs = (jsonDecode(new_stored_str) as List<dynamic>)
|
||||
.map((e) => e.toString())
|
||||
.toList();
|
||||
if (filteredPeerIDs.isEmpty) return [];
|
||||
}
|
||||
if (filteredPeerIDs.isEmpty) return [];
|
||||
final loadStr = await bind.mainLoadRecentPeersForAb(
|
||||
filter: jsonEncode(filteredPeerIDs));
|
||||
if (loadStr.isEmpty) {
|
||||
@ -390,28 +417,34 @@ class AbModel {
|
||||
|
||||
try {
|
||||
if (!shouldSyncAb()) return;
|
||||
final oldPeers = peers.toList();
|
||||
final recents = await getRecentPeers();
|
||||
if (recents.isEmpty) return;
|
||||
for (var i = 0; i < peers.length; i++) {
|
||||
var p = peers[i];
|
||||
var r = recents.firstWhereOrNull((r) => p.id == r.id);
|
||||
if (r != null) {
|
||||
peers[i] = merge(r, p);
|
||||
}
|
||||
}
|
||||
bool changed = false;
|
||||
for (var i = 0; i < peers.length; i++) {
|
||||
final o = oldPeers[i];
|
||||
final p = peers[i];
|
||||
if (shouldSync(o, p)) {
|
||||
changed = true;
|
||||
break;
|
||||
bool syncChanged = false;
|
||||
bool uiChanged = false;
|
||||
for (var i = 0; i < recents.length; i++) {
|
||||
var r = recents[i];
|
||||
var index = peers.indexWhere((e) => e.id == r.id);
|
||||
if (index < 0) {
|
||||
if (!isFull(false)) {
|
||||
peers.add(r);
|
||||
syncChanged = true;
|
||||
uiChanged = true;
|
||||
}
|
||||
} else {
|
||||
if (!r.equal(peers[index])) {
|
||||
uiChanged = true;
|
||||
}
|
||||
if (shouldSync(r, peers[index])) {
|
||||
syncChanged = true;
|
||||
}
|
||||
peers[index] = merge(r, peers[index]);
|
||||
}
|
||||
}
|
||||
// Be careful with loop calls
|
||||
if (changed && push) {
|
||||
pushAb();
|
||||
if (syncChanged && push) {
|
||||
pushAb(toastIfSucc: false);
|
||||
} else if (uiChanged) {
|
||||
peers.refresh();
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('syncFromRecent:$e');
|
||||
|
@ -1,6 +1,8 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'platform_model.dart';
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class Peer {
|
||||
final String id;
|
||||
@ -87,6 +89,18 @@ class Peer {
|
||||
rdpPort: '',
|
||||
rdpUsername: '',
|
||||
);
|
||||
bool equal(Peer other) {
|
||||
return id == other.id &&
|
||||
hash == other.hash &&
|
||||
username == other.username &&
|
||||
hostname == other.hostname &&
|
||||
platform == other.platform &&
|
||||
alias == other.alias &&
|
||||
tags.equals(other.tags) &&
|
||||
forceAlwaysRelay == other.forceAlwaysRelay &&
|
||||
rdpPort == other.rdpPort &&
|
||||
rdpUsername == other.rdpUsername;
|
||||
}
|
||||
}
|
||||
|
||||
enum UpdateEvent { online, load }
|
||||
|
@ -1079,6 +1079,10 @@ impl PeerConfig {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn exists(id: &str) -> bool {
|
||||
Self::path(id).exists()
|
||||
}
|
||||
|
||||
serde_field_string!(
|
||||
default_view_style,
|
||||
deserialize_view_style,
|
||||
|
@ -841,6 +841,10 @@ pub fn main_peer_has_password(id: String) -> bool {
|
||||
peer_has_password(id)
|
||||
}
|
||||
|
||||
pub fn main_peer_exists(id: String) -> bool {
|
||||
peer_exists(&id)
|
||||
}
|
||||
|
||||
pub fn main_load_recent_peers() {
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers(None)
|
||||
@ -883,8 +887,13 @@ pub fn main_load_recent_peers_sync() -> SyncReturn<String> {
|
||||
|
||||
pub fn main_load_recent_peers_for_ab(filter: String) -> String {
|
||||
let id_filters = serde_json::from_str::<Vec<String>>(&filter).unwrap_or_default();
|
||||
let id_filters = if id_filters.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(id_filters)
|
||||
};
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers(Some(id_filters))
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers(id_filters)
|
||||
.drain(..)
|
||||
.map(|(id, _, p)| peer_to_map_ab(id, p))
|
||||
.collect();
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", "未成功获取地址簿"),
|
||||
("push_ab_failed_tip", "未成功上传地址簿"),
|
||||
("synced_peer_readded_tip", "最近会话中存在的设备将会被重新添加到地址簿。"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", "Tags umschalten"),
|
||||
("pull_ab_failed_tip", "Aktualisierung des Adressbuchs fehlgeschlagen"),
|
||||
("push_ab_failed_tip", "Synchronisierung des Adressbuchs mit dem Server fehlgeschlagen"),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -76,5 +76,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("exceed_max_devices", "You have reached the maximum number of managed devices."),
|
||||
("pull_ab_failed_tip", "Failed to refresh address book"),
|
||||
("push_ab_failed_tip", "Failed to sync address book to server"),
|
||||
("synced_peer_readded_tip", "The devices present in the recent sessions will be re-added to the address book."),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", "Alternar Etiquetas"),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", "Attiva/disattiva tag"),
|
||||
("pull_ab_failed_tip", "Impossibile aggiornare la rubrica"),
|
||||
("push_ab_failed_tip", "Impossibile sincronizzare la rubrica con il server"),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", "Переключить метки"),
|
||||
("pull_ab_failed_tip", "Невозможно обновить адресную книгу"),
|
||||
("push_ab_failed_tip", "Невозможно синхронизировать адресную книгу с сервером"),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", "未成功獲取地址簿"),
|
||||
("push_ab_failed_tip", "未成功上傳地址簿"),
|
||||
("synced_peer_readded_tip", "最近會話中存在的設備將會被重新添加到地址簿。"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -537,5 +537,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Toggle Tags", ""),
|
||||
("pull_ab_failed_tip", ""),
|
||||
("push_ab_failed_tip", ""),
|
||||
("synced_peer_readded_tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -648,6 +648,11 @@ pub fn peer_to_map_ab(id: String, p: PeerConfig) -> HashMap<&'static str, String
|
||||
m
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter")]
|
||||
pub fn peer_exists(id: &str) -> bool {
|
||||
PeerConfig::exists(id)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_lan_peers() -> Vec<HashMap<&'static str, String>> {
|
||||
config::LanPeers::load()
|
||||
|
Loading…
x
Reference in New Issue
Block a user