diff --git a/lib/models/model.dart b/lib/models/model.dart index 4f775f23f..bb6fefe25 100644 --- a/lib/models/model.dart +++ b/lib/models/model.dart @@ -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 evt, String id); @@ -26,6 +27,8 @@ class FfiModel with ChangeNotifier { final _permissions = Map(); 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 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 evt) { EasyLoading.dismiss(); DialogManager.reset(); diff --git a/lib/models/server_model.dart b/lib/models/server_model.dart index e406b1e4a..a7efd25bc 100644 --- a/lib/models/server_model.dart +++ b/lib/models/server_model.dart @@ -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"); diff --git a/lib/pages/file_manager_page.dart b/lib/pages/file_manager_page.dart index 71bf5088a..e93c72c10 100644 --- a/lib/pages/file_manager_page.dart +++ b/lib/pages/file_manager_page.dart @@ -21,8 +21,6 @@ class _FileManagerPageState extends State { 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 { 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 { model.goToParentDirectory(); } - void handleMsgBox(Map 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( diff --git a/lib/pages/remote_page.dart b/lib/pages/remote_page.dart index fd7d578e8..9a8ede370 100644 --- a/lib/pages/remote_page.dart +++ b/lib/pages/remote_page.dart @@ -35,7 +35,6 @@ class _RemotePageState extends State { 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 { } }); } - FFI.ffiModel.update(widget.id, handleMsgBox); + FFI.ffiModel.update(widget.id); } void interval() { @@ -95,35 +94,6 @@ class _RemotePageState extends State { } catch (e) {} } - void handleMsgBox(Map 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; diff --git a/pubspec.yaml b/pubspec.yaml index d5f869d76..cdab37490 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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