move showMsgBox,fix fileModel value init

This commit is contained in:
csf 2022-03-28 17:24:52 +08:00
parent 0ae338524c
commit 7957efee5e
5 changed files with 42 additions and 73 deletions

View File

@ -12,6 +12,7 @@ import 'package:flutter/material.dart';
import 'package:tuple/tuple.dart';
import 'dart:async';
import '../common.dart';
import '../widgets/dialog.dart';
import 'native_model.dart' if (dart.library.html) 'web_model.dart';
typedef HandleMsgBox = void Function(Map<String, dynamic> evt, String id);
@ -26,6 +27,8 @@ class FfiModel with ChangeNotifier {
final _permissions = Map<String, bool>();
bool? _secure;
bool? _direct;
Timer? _timer;
var _reconnects = 1;
get permissions => _permissions;
@ -78,6 +81,8 @@ class FfiModel with ChangeNotifier {
_secure = null;
_direct = null;
_inputBlocked = false;
_timer?.cancel();
_timer = null;
clearPermissions();
}
@ -107,7 +112,7 @@ class FfiModel with ChangeNotifier {
_permissions.clear();
}
void update(String peerId, HandleMsgBox handleMsgBox) {
void update(String peerId) {
var pos;
for (;;) {
var evt = FFI.popEvent();
@ -193,6 +198,35 @@ class FfiModel with ChangeNotifier {
notifyListeners();
}
void handleMsgBox(Map<String, dynamic> evt, String id) {
var type = evt['type'];
var title = evt['title'];
var text = evt['text'];
if (type == 're-input-password') {
wrongPasswordDialog(id);
} else if (type == 'input-password') {
enterPasswordDialog(id);
} else {
var hasRetry = evt['hasRetry'] == 'true';
print(evt);
showMsgBox(type, title, text, hasRetry);
}
}
void showMsgBox(String type, String title, String text, bool hasRetry) {
msgBox(type, title, text);
if (hasRetry) {
_timer?.cancel();
_timer = Timer(Duration(seconds: _reconnects), () {
FFI.reconnect();
showLoading(translate('Connecting...'));
});
_reconnects *= 2;
} else {
_reconnects = 1;
}
}
void handlePeerInfo(Map<String, dynamic> evt) {
EasyLoading.dismiss();
DialogManager.reset();

View File

@ -13,8 +13,8 @@ class ServerModel with ChangeNotifier {
bool _isStart = false;
bool _mediaOk = false;
bool _inputOk = false;
late bool _audioOk;
late bool _fileOk;
bool _audioOk = false;
bool _fileOk = false;
final _serverId = TextEditingController(text: _emptyIdShow);
final _serverPasswd = TextEditingController(text: "");
@ -48,6 +48,7 @@ class ServerModel with ChangeNotifier {
..["name"] = "enable-keyboard"
..["value"] = 'N';
FFI.setByName('option', jsonEncode(res)); // input false by default
notifyListeners();
}();
}
@ -110,7 +111,7 @@ class ServerModel with ChangeNotifier {
notifyListeners();
FFI.setByName("ensure_init_event_queue");
_interval = Timer.periodic(Duration(milliseconds: 30), (timer) {
FFI.ffiModel.update("", (_, __) {});
FFI.ffiModel.update("");
});
await FFI.invokeMethod("init_service");
FFI.setByName("start_service");

View File

@ -21,8 +21,6 @@ class _FileManagerPageState extends State<FileManagerPage> {
final model = FFI.fileModel;
final _selectedItems = SelectedItems();
Timer? _interval;
Timer? _timer;
var _reconnects = 1;
final _breadCrumbScroller = ScrollController();
@override
@ -30,9 +28,8 @@ class _FileManagerPageState extends State<FileManagerPage> {
super.initState();
showLoading(translate('Connecting...'));
FFI.connect(widget.id, isFileTransfer: true);
_interval = Timer.periodic(Duration(milliseconds: 30),
(timer) => FFI.ffiModel.update(widget.id, handleMsgBox));
_interval = Timer.periodic(
Duration(milliseconds: 30), (timer) => FFI.ffiModel.update(widget.id));
}
@override
@ -193,35 +190,6 @@ class _FileManagerPageState extends State<FileManagerPage> {
model.goToParentDirectory();
}
void handleMsgBox(Map<String, dynamic> evt, String id) {
var type = evt['type'];
var title = evt['title'];
var text = evt['text'];
if (type == 're-input-password') {
wrongPasswordDialog(id);
} else if (type == 'input-password') {
enterPasswordDialog(id);
} else {
var hasRetry = evt['hasRetry'] == 'true';
print(evt);
showMsgBox(type, title, text, hasRetry);
}
}
void showMsgBox(String type, String title, String text, bool hasRetry) {
msgBox(type, title, text);
if (hasRetry) {
_timer?.cancel();
_timer = Timer(Duration(seconds: _reconnects), () {
FFI.reconnect();
showLoading(translate('Connecting...'));
});
_reconnects *= 2;
} else {
_reconnects = 1;
}
}
breadCrumbScrollToEnd() {
Future.delayed(Duration(milliseconds: 200), () {
_breadCrumbScroller.animateTo(

View File

@ -35,7 +35,6 @@ class _RemotePageState extends State<RemotePage> {
var _fn = false;
final FocusNode _focusNode = FocusNode();
var _showEdit = false;
var _reconnects = 1;
var _touchMode = false;
@override
@ -86,7 +85,7 @@ class _RemotePageState extends State<RemotePage> {
}
});
}
FFI.ffiModel.update(widget.id, handleMsgBox);
FFI.ffiModel.update(widget.id);
}
void interval() {
@ -95,35 +94,6 @@ class _RemotePageState extends State<RemotePage> {
} catch (e) {}
}
void handleMsgBox(Map<String, dynamic> evt, String id) {
var type = evt['type'];
var title = evt['title'];
var text = evt['text'];
if (type == 're-input-password') {
wrongPasswordDialog(id);
} else if (type == 'input-password') {
enterPasswordDialog(id);
} else {
var hasRetry = evt['hasRetry'] == 'true';
print(evt);
showMsgBox(type, title, text, hasRetry);
}
}
void showMsgBox(String type, String title, String text, bool hasRetry) {
msgBox(type, title, text);
if (hasRetry) {
_timer?.cancel();
_timer = Timer(Duration(seconds: _reconnects), () {
FFI.reconnect();
showLoading(translate('Connecting...'));
});
_reconnects *= 2;
} else {
_reconnects = 1;
}
}
void handleInput(String newValue) {
var oldValue = _value;
_value = newValue;

View File

@ -33,10 +33,6 @@ dependencies:
external_path: ^1.0.1
provider: ^5.0.0
flutter_easyloading: ^3.0.3
# flutter_easyloading: # not Null safety 2.2.0
# git:
# url: git://github.com/open-trade/flutter_easyloading
# #path: flutter_easyloading
tuple: ^2.0.0
wakelock: ^0.5.2
device_info: ^2.0.2