fix: FFI id assignment && keep Remote Page state for multi tabs

Signed-off-by: Kingtous <kingtous@qq.com>
This commit is contained in:
Kingtous 2022-06-17 22:21:49 +08:00
parent ed434fa90e
commit 330a2ce5a5
4 changed files with 35 additions and 29 deletions

View File

@ -77,7 +77,7 @@ fn gen_flutter_rust_bridge() {
..Default::default() ..Default::default()
}; };
// run fbr_codegen // run fbr_codegen
lib_flutter_rust_bridge_codegen::frb_codegen(opts).unwrap(); // lib_flutter_rust_bridge_codegen::frb_codegen(opts).unwrap();
} }
fn main() { fn main() {

View File

@ -31,7 +31,8 @@ class RemotePage extends StatefulWidget {
_RemotePageState createState() => _RemotePageState(); _RemotePageState createState() => _RemotePageState();
} }
class _RemotePageState extends State<RemotePage> with WindowListener { class _RemotePageState extends State<RemotePage>
with WindowListener, AutomaticKeepAliveClientMixin {
Timer? _interval; Timer? _interval;
Timer? _timer; Timer? _timer;
bool _showBar = !isWebDesktop; bool _showBar = !isWebDesktop;
@ -234,13 +235,14 @@ class _RemotePageState extends State<RemotePage> with WindowListener {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context);
final pi = Provider.of<FfiModel>(context).pi; final pi = Provider.of<FfiModel>(context).pi;
final hideKeyboard = isKeyboardShown() && _showEdit; final hideKeyboard = isKeyboardShown() && _showEdit;
final showActionButton = !_showBar || hideKeyboard; final showActionButton = !_showBar || hideKeyboard;
final keyboard = _ffi.ffiModel.permissions['keyboard'] != false; final keyboard = _ffi.ffiModel.permissions['keyboard'] != false;
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
clientClose(); clientClose();
return false; return false;
}, },
@ -254,28 +256,28 @@ class _RemotePageState extends State<RemotePage> with WindowListener {
child: getRawPointerAndKeyBody( child: getRawPointerAndKeyBody(
keyboard, keyboard,
Scaffold( Scaffold(
// resizeToAvoidBottomInset: true, // resizeToAvoidBottomInset: true,
floatingActionButton: !showActionButton floatingActionButton: !showActionButton
? null ? null
: FloatingActionButton( : FloatingActionButton(
mini: !hideKeyboard, mini: !hideKeyboard,
child: Icon(hideKeyboard child: Icon(hideKeyboard
? Icons.expand_more ? Icons.expand_more
: Icons.expand_less), : Icons.expand_less),
backgroundColor: MyTheme.accent, backgroundColor: MyTheme.accent,
onPressed: () { onPressed: () {
setState(() { setState(() {
if (hideKeyboard) { if (hideKeyboard) {
_showEdit = false; _showEdit = false;
_ffi.invokeMethod( _ffi.invokeMethod(
"enable_soft_keyboard", false); "enable_soft_keyboard", false);
_mobileFocusNode.unfocus(); _mobileFocusNode.unfocus();
_physicalFocusNode.requestFocus(); _physicalFocusNode.requestFocus();
} else { } else {
_showBar = !_showBar; _showBar = !_showBar;
} }
}); });
}), }),
bottomNavigationBar: _showBar && pi.displays.length > 0 bottomNavigationBar: _showBar && pi.displays.length > 0
? getBottomAppBar(keyboard) ? getBottomAppBar(keyboard)
: null, : null,
@ -287,11 +289,11 @@ class _RemotePageState extends State<RemotePage> with WindowListener {
child: isWebDesktop child: isWebDesktop
? getBodyForDesktopWithListener(keyboard) ? getBodyForDesktopWithListener(keyboard)
: SafeArea( : SafeArea(
child: Container( child: Container(
color: MyTheme.canvasColor, color: MyTheme.canvasColor,
child: _isPhysicalMouse child: _isPhysicalMouse
? getBodyForMobile() ? getBodyForMobile()
: getBodyForMobileWithGesture()))); : getBodyForMobileWithGesture())));
}) })
], ],
))), ))),
@ -916,6 +918,9 @@ class _RemotePageState extends State<RemotePage> with WindowListener {
break; break;
} }
} }
@override
bool get wantKeepAlive => true;
} }
class ImagePaint extends StatelessWidget { class ImagePaint extends StatelessWidget {

View File

@ -22,7 +22,7 @@ Future<Null> main(List<String> args) async {
// global FFI, use this **ONLY** for global configuration // global FFI, use this **ONLY** for global configuration
// for convenience, use global FFI on mobile platform // for convenience, use global FFI on mobile platform
// focus on multi-ffi on desktop first // focus on multi-ffi on desktop first
initGlobalFFI(); await initGlobalFFI();
// await Firebase.initializeApp(); // await Firebase.initializeApp();
if (isAndroid) { if (isAndroid) {
toAndroidChannelInit(); toAndroidChannelInit();

View File

@ -913,7 +913,7 @@ class FFI {
}(); }();
// every instance will bind a stream // every instance will bind a stream
} }
id = id; this.id = id;
} }
/// Login with [password], choose if the client should [remember] it. /// Login with [password], choose if the client should [remember] it.
@ -935,6 +935,7 @@ class FFI {
ffiModel.clear(); ffiModel.clear();
canvasModel.clear(); canvasModel.clear();
resetModifiers(); resetModifiers();
print("model closed");
} }
/// Send **get** command to the Rust core based on [name] and [arg]. /// Send **get** command to the Rust core based on [name] and [arg].