fix desktop init file / input permission bug

This commit is contained in:
csf 2022-08-09 20:36:52 +08:00
parent 26ed41ed32
commit cb88a3abb6
4 changed files with 71 additions and 95 deletions

View File

@ -8,11 +8,9 @@ import 'package:flutter_hbb/desktop/widgets/peer_widget.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';
import '../../common.dart';
import '../../mobile/pages/home_page.dart';
import '../../mobile/pages/scan_page.dart';
import '../../mobile/pages/settings_page.dart';
import '../../models/model.dart';
@ -21,18 +19,9 @@ import '../../models/platform_model.dart';
// enum RemoteType { recently, favorite, discovered, addressBook }
/// Connection page for connecting to a remote peer.
class ConnectionPage extends StatefulWidget implements PageShape {
class ConnectionPage extends StatefulWidget {
ConnectionPage({Key? key}) : super(key: key);
@override
final icon = Icon(Icons.connected_tv);
@override
final title = translate("Connection");
@override
final appBarActions = !isAndroid ? <Widget>[WebMenu()] : <Widget>[];
@override
_ConnectionPageState createState() => _ConnectionPageState();
}
@ -174,8 +163,8 @@ class _ConnectionPageState extends State<ConnectionPage> {
: InkWell(
onTap: () async {
final url = _updateUrl + '.apk';
if (await canLaunch(url)) {
await launch(url);
if (await canLaunchUrlString(url)) {
await launchUrlString(url);
}
},
child: Container(

View File

@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart' hide MenuItem;
import 'package:flutter/services.dart';
import 'package:flutter_hbb/common.dart';
@ -27,8 +26,8 @@ class DesktopHomePage extends StatefulWidget {
const borderColor = Color(0xFF2F65BA);
class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, WindowListener {
class _DesktopHomePageState extends State<DesktopHomePage>
with TrayListener, WindowListener {
@override
void onWindowClose() async {
super.onWindowClose();
@ -132,18 +131,7 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, Wi
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
),
FutureBuilder<Widget>(
future: buildPopupMenu(context),
builder: (context, snapshot) {
if (snapshot.hasError) {
print("${snapshot.error}");
}
if (snapshot.hasData) {
return snapshot.data!;
} else {
return Offstage();
}
})
buildPopupMenu(context)
],
),
GestureDetector(
@ -165,7 +153,7 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, Wi
);
}
Future<Widget> buildPopupMenu(BuildContext context) async {
Widget buildPopupMenu(BuildContext context) {
var position;
return GestureDetector(
onTapDown: (detail) {
@ -178,19 +166,19 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, Wi
final enabledInput = await bind.mainGetOption(key: 'enable-audio');
final defaultInput = await gFFI.getDefaultAudioInput();
var menu = <PopupMenuEntry>[
genEnablePopupMenuItem(
await genEnablePopupMenuItem(
translate("Enable Keyboard/Mouse"),
'enable-keyboard',
),
genEnablePopupMenuItem(
await genEnablePopupMenuItem(
translate("Enable Clipboard"),
'enable-clipboard',
),
genEnablePopupMenuItem(
await genEnablePopupMenuItem(
translate("Enable File Transfer"),
'enable-file-transfer',
),
genEnablePopupMenuItem(
await genEnablePopupMenuItem(
translate("Enable TCP Tunneling"),
'enable-tunnel',
),
@ -209,16 +197,16 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, Wi
value: 'socks5-proxy',
),
PopupMenuDivider(),
genEnablePopupMenuItem(
await genEnablePopupMenuItem(
translate("Enable Service"),
'stop-service',
),
// TODO: direct server
genEnablePopupMenuItem(
await genEnablePopupMenuItem(
translate("Always connected via relay"),
'allow-always-relay',
),
genEnablePopupMenuItem(
await genEnablePopupMenuItem(
translate("Start ID/relay service"),
'stop-rendezvous-service',
),
@ -237,7 +225,7 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, Wi
value: 'change-id',
),
PopupMenuDivider(),
genEnablePopupMenuItem(
await genEnablePopupMenuItem(
translate("Dark Theme"),
'allow-darktheme',
),
@ -522,30 +510,22 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, Wi
}
}
PopupMenuItem<String> genEnablePopupMenuItem(String label, String key) {
Future<bool> getOptionEnable(String key) async {
final v = await bind.mainGetOption(key: key);
return key.startsWith('enable-') ? v != "N" : v == "Y";
}
Future<PopupMenuItem<String>> genEnablePopupMenuItem(
String label, String key) async {
final v = await bind.mainGetOption(key: key);
bool enable = v != "N";
return PopupMenuItem(
child: FutureBuilder<bool>(
future: getOptionEnable(key),
builder: (context, snapshot) {
var enable = false;
if (snapshot.hasData && snapshot.data!) {
enable = true;
}
return Row(
children: [
Offstage(offstage: !enable, child: Icon(Icons.check)),
Text(
label,
style: genTextStyle(enable),
),
],
);
}),
child: Row(
children: [
Icon(Icons.check,
color: enable ? null : MyTheme.accent.withAlpha(00)),
Text(
label,
style: genTextStyle(enable),
),
],
),
value: key,
);
}

View File

@ -8,7 +8,7 @@ import '../../models/platform_model.dart';
import '../../models/server_model.dart';
import 'home_page.dart';
class ServerPage extends StatelessWidget implements PageShape {
class ServerPage extends StatefulWidget implements PageShape {
@override
final title = translate("Share Screen");
@ -102,6 +102,17 @@ class ServerPage extends StatelessWidget implements PageShape {
})
];
@override
State<StatefulWidget> createState() => _ServerPageState();
}
class _ServerPageState extends State<ServerPage> {
@override
void initState() {
super.initState();
gFFI.serverModel.checkAndroidPermission();
}
@override
Widget build(BuildContext context) {
checkService();

View File

@ -85,40 +85,8 @@ class ServerModel with ChangeNotifier {
WeakReference<FFI> parent;
ServerModel(this.parent) {
() async {
_emptyIdShow = translate("Generating ...");
_serverId = TextEditingController(text: this._emptyIdShow);
/**
* 1. check android permission
* 2. check config
* audio true by default (if permission on) (false default < Android 10)
* file true by default (if permission on)
*/
await Future.delayed(Duration(seconds: 1));
// audio
if (androidVersion < 30 || !await PermissionManager.check("audio")) {
_audioOk = false;
bind.mainSetOption(key: "enable-audio", value: "N");
} else {
final audioOption = await bind.mainGetOption(key: 'enable-audio');
_audioOk = audioOption.isEmpty;
}
// file
if (!await PermissionManager.check("file")) {
_fileOk = false;
bind.mainSetOption(key: "enable-file-transfer", value: "N");
} else {
final fileOption =
await bind.mainGetOption(key: 'enable-file-transfer');
_fileOk = fileOption.isEmpty;
}
// input (mouse control) false by default
bind.mainSetOption(key: "enable-keyboard", value: "N");
notifyListeners();
}();
_emptyIdShow = translate("Generating ...");
_serverId = TextEditingController(text: this._emptyIdShow);
Timer.periodic(Duration(seconds: 1), (timer) async {
var status = await bind.mainGetOnlineStatue();
@ -139,6 +107,34 @@ class ServerModel with ChangeNotifier {
});
}
/// 1. check android permission
/// 2. check config
/// audio true by default (if permission on) (false default < Android 10)
/// file true by default (if permission on)
checkAndroidPermission() async {
// audio
if (androidVersion < 30 || !await PermissionManager.check("audio")) {
_audioOk = false;
bind.mainSetOption(key: "enable-audio", value: "N");
} else {
final audioOption = await bind.mainGetOption(key: 'enable-audio');
_audioOk = audioOption.isEmpty;
}
// file
if (!await PermissionManager.check("file")) {
_fileOk = false;
bind.mainSetOption(key: "enable-file-transfer", value: "N");
} else {
final fileOption = await bind.mainGetOption(key: 'enable-file-transfer');
_fileOk = fileOption.isEmpty;
}
// input (mouse control) false by default
bind.mainSetOption(key: "enable-keyboard", value: "N");
notifyListeners();
}
updatePasswordModel() async {
var update = false;
final temporaryPassword = await bind.mainGetTemporaryPassword();