fix web and multi platform adaptation
This commit is contained in:
parent
98d8689d7b
commit
8736d37605
@ -9,6 +9,7 @@ var isIOS = false;
|
|||||||
var isWeb = false;
|
var isWeb = false;
|
||||||
var isDesktop = false;
|
var isDesktop = false;
|
||||||
var version = "";
|
var version = "";
|
||||||
|
int androidVersion = 0;
|
||||||
|
|
||||||
typedef F = String Function(String);
|
typedef F = String Function(String);
|
||||||
typedef FMethod = String Function(String, dynamic);
|
typedef FMethod = String Function(String, dynamic);
|
||||||
|
@ -18,20 +18,26 @@ Future<Null> main() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class App extends StatelessWidget {
|
class App extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final analytics = FirebaseAnalytics();
|
final analytics = FirebaseAnalytics();
|
||||||
return MultiProvider(
|
final providers = [
|
||||||
providers: [
|
|
||||||
ChangeNotifierProvider.value(value: FFI.ffiModel),
|
ChangeNotifierProvider.value(value: FFI.ffiModel),
|
||||||
ChangeNotifierProvider.value(value: FFI.imageModel),
|
ChangeNotifierProvider.value(value: FFI.imageModel),
|
||||||
ChangeNotifierProvider.value(value: FFI.cursorModel),
|
ChangeNotifierProvider.value(value: FFI.cursorModel),
|
||||||
ChangeNotifierProvider.value(value: FFI.canvasModel),
|
ChangeNotifierProvider.value(value: FFI.canvasModel),
|
||||||
ChangeNotifierProvider.value(value: FFI.serverModel),
|
];
|
||||||
|
if (!isWeb) {
|
||||||
|
providers.addAll([
|
||||||
ChangeNotifierProvider.value(value: FFI.chatModel),
|
ChangeNotifierProvider.value(value: FFI.chatModel),
|
||||||
ChangeNotifierProvider.value(value: FFI.fileModel),
|
ChangeNotifierProvider.value(value: FFI.fileModel),
|
||||||
],
|
]);
|
||||||
|
if (isAndroid) {
|
||||||
|
providers.add(ChangeNotifierProvider.value(value: FFI.serverModel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MultiProvider(
|
||||||
|
providers: providers,
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
navigatorKey: globalKey,
|
navigatorKey: globalKey,
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
@ -40,7 +46,7 @@ class App extends StatelessWidget {
|
|||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||||
),
|
),
|
||||||
home: HomePage(),
|
home: isWeb ? WebHomePage() : HomePage(),
|
||||||
navigatorObservers: [
|
navigatorObservers: [
|
||||||
FirebaseAnalyticsObserver(analytics: analytics),
|
FirebaseAnalyticsObserver(analytics: analytics),
|
||||||
],
|
],
|
||||||
|
@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_hbb/pages/chat_page.dart';
|
import 'package:flutter_hbb/pages/chat_page.dart';
|
||||||
|
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
import 'native_model.dart';
|
|
||||||
|
|
||||||
class ChatModel with ChangeNotifier {
|
class ChatModel with ChangeNotifier {
|
||||||
// -1作为客户端模式的id,客户端模式下此id唯一
|
// -1作为客户端模式的id,客户端模式下此id唯一
|
||||||
@ -51,12 +50,12 @@ class ChatModel with ChangeNotifier {
|
|||||||
if (message.text != null && message.text!.isNotEmpty) {
|
if (message.text != null && message.text!.isNotEmpty) {
|
||||||
_messages[_currentID]?.add(message);
|
_messages[_currentID]?.add(message);
|
||||||
if (_currentID == clientModeID) {
|
if (_currentID == clientModeID) {
|
||||||
PlatformFFI.setByName("chat_client_mode", message.text!);
|
FFI.setByName("chat_client_mode", message.text!);
|
||||||
} else {
|
} else {
|
||||||
final msg = Map()
|
final msg = Map()
|
||||||
..["id"] = _currentID
|
..["id"] = _currentID
|
||||||
..["text"] = message.text!;
|
..["text"] = message.text!;
|
||||||
PlatformFFI.setByName("chat_server_mode", jsonEncode(msg));
|
FFI.setByName("chat_server_mode", jsonEncode(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -24,7 +24,6 @@ class PlatformFFI {
|
|||||||
static Pointer<RgbaFrame>? _lastRgbaFrame;
|
static Pointer<RgbaFrame>? _lastRgbaFrame;
|
||||||
static String _dir = '';
|
static String _dir = '';
|
||||||
static String _homeDir = '';
|
static String _homeDir = '';
|
||||||
static int? _androidVersion;
|
|
||||||
static F2? _getByName;
|
static F2? _getByName;
|
||||||
static F3? _setByName;
|
static F3? _setByName;
|
||||||
static F4? _freeRgba;
|
static F4? _freeRgba;
|
||||||
@ -49,8 +48,6 @@ class PlatformFFI {
|
|||||||
return packageInfo.version;
|
return packageInfo.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int? get androidVersion => _androidVersion;
|
|
||||||
|
|
||||||
static String getByName(String name, [String arg = '']) {
|
static String getByName(String name, [String arg = '']) {
|
||||||
if (_getByName == null) return '';
|
if (_getByName == null) return '';
|
||||||
var a = name.toNativeUtf8();
|
var a = name.toNativeUtf8();
|
||||||
@ -97,7 +94,7 @@ class PlatformFFI {
|
|||||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||||
name = '${androidInfo.brand}-${androidInfo.model}';
|
name = '${androidInfo.brand}-${androidInfo.model}';
|
||||||
id = androidInfo.id.hashCode.toString();
|
id = androidInfo.id.hashCode.toString();
|
||||||
_androidVersion = androidInfo.version.sdkInt;
|
androidVersion = androidInfo.version.sdkInt;
|
||||||
} else {
|
} else {
|
||||||
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
|
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
|
||||||
name = iosInfo.utsname.machine;
|
name = iosInfo.utsname.machine;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/models/native_model.dart';
|
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../pages/server_page.dart';
|
import '../pages/server_page.dart';
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
@ -71,7 +70,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
|
|
||||||
toggleInput(){
|
toggleInput(){
|
||||||
if(_inputOk){
|
if(_inputOk){
|
||||||
PlatformFFI.invokeMethod("stop_input");
|
FFI.invokeMethod("stop_input");
|
||||||
}else{
|
}else{
|
||||||
showInputWarnAlert();
|
showInputWarnAlert();
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,20 @@ class HomePage extends StatefulWidget {
|
|||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
class _HomePageState extends State<HomePage> {
|
||||||
var _selectedIndex = 0;
|
var _selectedIndex = 0;
|
||||||
final List<PageShape> _pages = [
|
final List<PageShape> _pages = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_pages.addAll([
|
||||||
ConnectionPage(),
|
ConnectionPage(),
|
||||||
chatPage,
|
chatPage,
|
||||||
ServerPage(),
|
]);
|
||||||
SettingsPage()
|
if(isAndroid){
|
||||||
];
|
_pages.add(ServerPage());
|
||||||
|
}
|
||||||
|
_pages.add(SettingsPage());
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -69,3 +77,20 @@ class _HomePageState extends State<HomePage> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WebHomePage extends StatelessWidget {
|
||||||
|
final connectionPage = ConnectionPage();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: MyTheme.grayBg,
|
||||||
|
appBar: AppBar(
|
||||||
|
centerTitle: true,
|
||||||
|
title: Text("RustDesk"),
|
||||||
|
actions: connectionPage.appBarActions,
|
||||||
|
),
|
||||||
|
body: connectionPage,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,7 +3,6 @@ import 'package:flutter_hbb/models/model.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../models/native_model.dart';
|
|
||||||
import '../models/server_model.dart';
|
import '../models/server_model.dart';
|
||||||
import 'home_page.dart';
|
import 'home_page.dart';
|
||||||
import '../models/model.dart';
|
import '../models/model.dart';
|
||||||
@ -156,7 +155,6 @@ class _PermissionCheckerState extends State<PermissionChecker> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final serverModel = Provider.of<ServerModel>(context);
|
final serverModel = Provider.of<ServerModel>(context);
|
||||||
final androidVersion = PlatformFFI.androidVersion ?? 0;
|
|
||||||
final hasAudioPermission = androidVersion>=30;
|
final hasAudioPermission = androidVersion>=30;
|
||||||
return PaddingCard(
|
return PaddingCard(
|
||||||
title: translate("Configuration Permissions"),
|
title: translate("Configuration Permissions"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user