diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 3070833e4..8d432474e 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -11,6 +11,7 @@ final navigationBarKey = GlobalKey(); var isAndroid = false; var isIOS = false; var isWeb = false; +var isWebDesktop = false; var isDesktop = false; var version = ""; int androidVersion = 0; diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index a81a047b4..79e433d7f 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -1,4 +1,7 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; +import 'package:flutter_hbb/pages/desktop_home_page.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:provider/provider.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; @@ -16,7 +19,9 @@ Future main() async { await a; await b; refreshCurrentUser(); - toAndroidChannelInit(); + if (Platform.isAndroid) { + toAndroidChannelInit(); + } runApp(App()); } @@ -39,7 +44,11 @@ class App extends StatelessWidget { primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), - home: !isAndroid ? WebHomePage() : HomePage(), + home: isDesktop + ? DesktopHomePage() + : !isAndroid + ? WebHomePage() + : HomePage(), navigatorObservers: [ FirebaseAnalyticsObserver(analytics: analytics), FlutterSmartDialog.observer diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 313ab3fc1..72c960be7 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -282,7 +282,7 @@ class ImageModel with ChangeNotifier { void update(ui.Image? image) { if (_image == null && image != null) { - if (isDesktop) { + if (isWebDesktop) { FFI.canvasModel.updateViewStyle(); } else { final size = MediaQueryData.fromWindow(ui.window).size; @@ -394,7 +394,7 @@ class CanvasModel with ChangeNotifier { } void resetOffset() { - if (isDesktop) { + if (isWebDesktop) { updateViewStyle(); } else { _x = 0; @@ -783,7 +783,7 @@ class FFI { static void close() { chatModel.close(); - if (FFI.imageModel.image != null && !isDesktop) { + if (FFI.imageModel.image != null && !isWebDesktop) { savePreference(id, cursorModel.x, cursorModel.y, canvasModel.x, canvasModel.y, canvasModel.scale, ffiModel.pi.currentDisplay); } @@ -919,7 +919,7 @@ void savePreference(String id, double xCursor, double yCursor, double xCanvas, } Future?> getPreference(String id) async { - if (!isDesktop) return null; + if (!isWebDesktop) return null; SharedPreferences prefs = await SharedPreferences.getInstance(); var p = prefs.getString('peer' + id); if (p == null) return null; diff --git a/flutter/lib/models/native_model.dart b/flutter/lib/models/native_model.dart index f6824dda8..ffbe7a2f3 100644 --- a/flutter/lib/models/native_model.dart +++ b/flutter/lib/models/native_model.dart @@ -59,6 +59,11 @@ class PlatformFFI { static Future init() async { isIOS = Platform.isIOS; isAndroid = Platform.isAndroid; + isDesktop = Platform.isWindows || Platform.isMacOS || Platform.isLinux; + if (isDesktop) { + // TODO + return; + } final dylib = Platform.isAndroid ? DynamicLibrary.open('librustdesk.so') : DynamicLibrary.process(); diff --git a/flutter/lib/models/web_model.dart b/flutter/lib/models/web_model.dart index d9668272a..13b62998f 100644 --- a/flutter/lib/models/web_model.dart +++ b/flutter/lib/models/web_model.dart @@ -20,7 +20,7 @@ class PlatformFFI { static Future init() async { isWeb = true; - isDesktop = !context.callMethod('isMobile'); + isWebDesktop = !context.callMethod('isMobile'); context.callMethod('init'); version = getByName('version'); } diff --git a/flutter/lib/pages/connection_page.dart b/flutter/lib/pages/connection_page.dart index 1fe4dc6b0..1b5268586 100644 --- a/flutter/lib/pages/connection_page.dart +++ b/flutter/lib/pages/connection_page.dart @@ -211,8 +211,8 @@ class _ConnectionPageState extends State { width: width, child: Card( child: GestureDetector( - onTap: !isDesktop ? () => connect('${p.id}') : null, - onDoubleTap: isDesktop ? () => connect('${p.id}') : null, + onTap: !isWebDesktop ? () => connect('${p.id}') : null, + onDoubleTap: isWebDesktop ? () => connect('${p.id}') : null, onLongPressStart: (details) { final x = details.globalPosition.dx; final y = details.globalPosition.dy; diff --git a/flutter/lib/pages/remote_page.dart b/flutter/lib/pages/remote_page.dart index 50e645540..1d8c02709 100644 --- a/flutter/lib/pages/remote_page.dart +++ b/flutter/lib/pages/remote_page.dart @@ -28,7 +28,7 @@ class RemotePage extends StatefulWidget { class _RemotePageState extends State { Timer? _interval; Timer? _timer; - bool _showBar = !isDesktop; + bool _showBar = !isWebDesktop; double _bottom = 0; String _value = ''; double _scale = 1; @@ -256,7 +256,7 @@ class _RemotePageState extends State { OverlayEntry(builder: (context) { return Container( color: Colors.black, - child: isDesktop + child: isWebDesktop ? getBodyForDesktopWithListener(keyboard) : SafeArea( child: Container( @@ -397,7 +397,7 @@ class _RemotePageState extends State { }, ) ] + - (isDesktop + (isWebDesktop ? [] : FFI.ffiModel.isPeerAndroid ? [ @@ -641,7 +641,7 @@ class _RemotePageState extends State { ) ])), value: 'enter_os_password')); - if (!isDesktop) { + if (!isWebDesktop) { if (perms['keyboard'] != false && perms['clipboard'] != false) { more.add(PopupMenuItem( child: Text(translate('Paste')), value: 'paste'));