flutter version allow hide cm

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-11-23 09:41:05 +08:00
parent c26e86288d
commit 8b4d50f3fb
37 changed files with 198 additions and 44 deletions

View File

@@ -4,6 +4,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/widgets/address_book.dart';
import 'package:flutter_hbb/consts.dart';
@@ -177,12 +178,15 @@ class _ConnectionPageState extends State<ConnectionPage>
children: [
Row(
children: [
Text(
translate('Control Remote Desktop'),
style: Theme.of(context)
.textTheme
.titleLarge
?.merge(TextStyle(height: 1)),
Expanded(
child: AutoSizeText(
translate('Control Remote Desktop'),
maxLines: 1,
style: Theme.of(context)
.textTheme
.titleLarge
?.merge(TextStyle(height: 1)),
),
),
],
).marginOnly(bottom: 15),

View File

@@ -658,13 +658,9 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
initialKey: modeInitialKey,
onChanged: (key) => model.setApproveMode(key),
).marginOnly(left: _kContentHMargin),
Offstage(
offstage: !usePassword,
child: radios[0],
),
Offstage(
offstage: !usePassword,
child: _SubLabeledWidget(
if (usePassword) radios[0],
if (usePassword)
_SubLabeledWidget(
'One-time password length',
Row(
children: [
@@ -672,20 +668,13 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
],
),
enabled: tmpEnabled && !locked),
),
Offstage(
offstage: !usePassword,
child: radios[1],
),
Offstage(
offstage: !usePassword,
child: _SubButton('Set permanent password', setPasswordDialog,
if (usePassword) radios[1],
if (usePassword)
_SubButton('Set permanent password', setPasswordDialog,
permEnabled && !locked),
),
Offstage(
offstage: !usePassword,
child: radios[2],
),
if (usePassword)
hide_cm(!locked).marginOnly(left: _kContentHSubMargin - 6),
if (usePassword) radios[2],
]);
})));
}
@@ -814,6 +803,46 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
).marginOnly(left: _kCheckBoxLeftMargin);
});
}
Widget hide_cm(bool enabled) {
return ChangeNotifierProvider.value(
value: gFFI.serverModel,
child: Consumer<ServerModel>(builder: (context, model, child) {
final enableHideCm = model.approveMode == 'password' &&
model.verificationMethod == kUsePermanentPassword;
onHideCmChanged(bool? b) {
if (b != null) {
bind.mainSetOption(
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', b));
}
}
return Tooltip(
message: enableHideCm ? "" : translate('hide_cm_tip'),
child: GestureDetector(
onTap:
enableHideCm ? () => onHideCmChanged(!model.hideCm) : null,
child: Row(
children: [
Checkbox(
value: model.hideCm,
onChanged: enabled && enableHideCm
? onHideCmChanged
: null)
.marginOnly(right: 5),
Expanded(
child: Text(
translate('Hide connection management window'),
style: TextStyle(
color: _disabledTextColor(
context, enabled && enableHideCm)),
),
),
],
),
));
}));
}
}
class _Network extends StatefulWidget {

View File

@@ -85,7 +85,7 @@ Future<void> main(List<String> args) async {
debugPrint("--cm started");
desktopType = DesktopType.cm;
await windowManager.ensureInitialized();
runConnectionManagerScreen();
runConnectionManagerScreen(args.contains('--hide'));
} else if (args.contains('--install')) {
runInstallPage();
} else {
@@ -185,16 +185,23 @@ void runMultiWindow(
}
}
void runConnectionManagerScreen() async {
void runConnectionManagerScreen(bool hide) async {
await initEnv(kAppTypeMain);
// initialize window
WindowOptions windowOptions =
getHiddenTitleBarWindowOptions(size: kConnectionManagerWindowSize);
_runApp(
'',
const DesktopServerPage(),
MyTheme.currentThemeMode(),
);
if (hide) {
hideCmWindow();
} else {
showCmWindow();
}
}
void showCmWindow() {
WindowOptions windowOptions =
getHiddenTitleBarWindowOptions(size: kConnectionManagerWindowSize);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await Future.wait([windowManager.focus(), windowManager.setOpacity(1)]);
@@ -204,6 +211,15 @@ void runConnectionManagerScreen() async {
});
}
void hideCmWindow() {
WindowOptions windowOptions =
getHiddenTitleBarWindowOptions(size: kConnectionManagerWindowSize);
windowManager.setOpacity(0);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.hide();
});
}
void _runApp(
String title,
Widget home,

View File

@@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/main.dart';
import 'package:flutter_hbb/models/platform_model.dart';
import 'package:get/get.dart';
import 'package:wakelock/wakelock.dart';
@@ -28,6 +29,7 @@ class ServerModel with ChangeNotifier {
bool _audioOk = false;
bool _fileOk = false;
bool _showElevation = true;
bool _hideCm = false;
int _connectStatus = 0; // Rendezvous Server status
String _verificationMethod = "";
String _temporaryPasswordLength = "";
@@ -56,6 +58,8 @@ class ServerModel with ChangeNotifier {
bool get showElevation => _showElevation;
bool get hideCm => _hideCm;
int get connectStatus => _connectStatus;
String get verificationMethod {
@@ -74,6 +78,10 @@ class ServerModel with ChangeNotifier {
setVerificationMethod(String method) async {
await bind.mainSetOption(key: "verification-method", value: method);
if (method != kUsePermanentPassword) {
await bind.mainSetOption(
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
}
}
String get temporaryPasswordLength {
@@ -90,6 +98,10 @@ class ServerModel with ChangeNotifier {
setApproveMode(String mode) async {
await bind.mainSetOption(key: 'approve-mode', value: mode);
if (mode != 'password') {
await bind.mainSetOption(
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
}
}
TextEditingController get serverId => _serverId;
@@ -125,7 +137,11 @@ class ServerModel with ChangeNotifier {
}
if (!isTest) {
Future.delayed(Duration.zero, timerCallback);
Future.delayed(Duration.zero, () async {
if (await bind.optionSynced()) {
await timerCallback();
}
});
Timer.periodic(Duration(milliseconds: 500), (timer) async {
await timerCallback();
});
@@ -166,6 +182,12 @@ class ServerModel with ChangeNotifier {
final temporaryPasswordLength =
await bind.mainGetOption(key: "temporary-password-length");
final approveMode = await bind.mainGetOption(key: 'approve-mode');
var hideCm = option2bool(
'allow-hide-cm', await bind.mainGetOption(key: 'allow-hide-cm'));
if (!(approveMode == 'password' &&
verificationMethod == kUsePermanentPassword)) {
hideCm = false;
}
if (_approveMode != approveMode) {
_approveMode = approveMode;
update = true;
@@ -190,6 +212,17 @@ class ServerModel with ChangeNotifier {
_temporaryPasswordLength = temporaryPasswordLength;
update = true;
}
if (_hideCm != hideCm) {
_hideCm = hideCm;
if (desktopType == DesktopType.cm) {
if (hideCm) {
hideCmWindow();
} else {
showCmWindow();
}
}
update = true;
}
if (update) {
notifyListeners();
}
@@ -436,11 +469,11 @@ class ServerModel with ChangeNotifier {
},
page: desktop.buildConnectionCard(client)));
Future.delayed(Duration.zero, () async {
window_on_top(null);
if (!hideCm) window_on_top(null);
});
if (client.authorized) {
cmHiddenTimer = Timer(const Duration(seconds: 3), () {
windowManager.minimize();
if (!hideCm) windowManager.minimize();
cmHiddenTimer = null;
});
}