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

@ -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;
});
}