Skip to content

Commit e2376fa

Browse files
committed
feat, update, win, macos
Signed-off-by: fufesou <linlong1266@gmail.com>
1 parent 62276b4 commit e2376fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2128
-69
lines changed

flutter/lib/common.dart

+38-12
Original file line numberDiff line numberDiff line change
@@ -1152,15 +1152,23 @@ Widget createDialogContent(String text) {
11521152

11531153
void msgBox(SessionID sessionId, String type, String title, String text,
11541154
String link, OverlayDialogManager dialogManager,
1155-
{bool? hasCancel, ReconnectHandle? reconnect, int? reconnectTimeout}) {
1155+
{bool? hasCancel,
1156+
ReconnectHandle? reconnect,
1157+
int? reconnectTimeout,
1158+
VoidCallback? onSubmit,
1159+
int? submitTimeout}) {
11561160
dialogManager.dismissAll();
11571161
List<Widget> buttons = [];
11581162
bool hasOk = false;
11591163
submit() {
11601164
dialogManager.dismissAll();
1161-
// https://github.com/rustdesk/rustdesk/blob/5e9a31340b899822090a3731769ae79c6bf5f3e5/src/ui/common.tis#L263
1162-
if (!type.contains("custom") && desktopType != DesktopType.portForward) {
1163-
closeConnection();
1165+
if (onSubmit != null) {
1166+
onSubmit.call();
1167+
} else {
1168+
// https://github.com/rustdesk/rustdesk/blob/5e9a31340b899822090a3731769ae79c6bf5f3e5/src/ui/common.tis#L263
1169+
if (!type.contains("custom") && desktopType != DesktopType.portForward) {
1170+
closeConnection();
1171+
}
11641172
}
11651173
}
11661174

@@ -1176,7 +1184,18 @@ void msgBox(SessionID sessionId, String type, String title, String text,
11761184

11771185
if (type != "connecting" && type != "success" && !type.contains("nook")) {
11781186
hasOk = true;
1179-
buttons.insert(0, dialogButton('OK', onPressed: submit));
1187+
late final Widget btn;
1188+
if (submitTimeout != null) {
1189+
btn = _CountDownButton(
1190+
text: 'OK',
1191+
second: submitTimeout,
1192+
onPressed: submit,
1193+
submitOnTimeout: true,
1194+
);
1195+
} else {
1196+
btn = dialogButton('OK', onPressed: submit);
1197+
}
1198+
buttons.insert(0, btn);
11801199
}
11811200
hasCancel ??= !type.contains("error") &&
11821201
!type.contains("nocancel") &&
@@ -1197,7 +1216,8 @@ void msgBox(SessionID sessionId, String type, String title, String text,
11971216
reconnectTimeout != null) {
11981217
// `enabled` is used to disable the dialog button once the button is clicked.
11991218
final enabled = true.obs;
1200-
final button = Obx(() => _ReconnectCountDownButton(
1219+
final button = Obx(() => _CountDownButton(
1220+
text: 'Reconnect',
12011221
second: reconnectTimeout,
12021222
onPressed: enabled.isTrue
12031223
? () {
@@ -3183,21 +3203,24 @@ parseParamScreenRect(Map<String, dynamic> params) {
31833203

31843204
get isInputSourceFlutter => stateGlobal.getInputSource() == "Input source 2";
31853205

3186-
class _ReconnectCountDownButton extends StatefulWidget {
3187-
_ReconnectCountDownButton({
3206+
class _CountDownButton extends StatefulWidget {
3207+
_CountDownButton({
31883208
Key? key,
3209+
required this.text,
31893210
required this.second,
31903211
required this.onPressed,
3212+
this.submitOnTimeout = false,
31913213
}) : super(key: key);
3214+
final String text;
31923215
final VoidCallback? onPressed;
31933216
final int second;
3217+
final bool submitOnTimeout;
31943218

31953219
@override
3196-
State<_ReconnectCountDownButton> createState() =>
3197-
_ReconnectCountDownButtonState();
3220+
State<_CountDownButton> createState() => _CountDownButtonState();
31983221
}
31993222

3200-
class _ReconnectCountDownButtonState extends State<_ReconnectCountDownButton> {
3223+
class _CountDownButtonState extends State<_CountDownButton> {
32013224
late int _countdownSeconds = widget.second;
32023225

32033226
Timer? _timer;
@@ -3218,6 +3241,9 @@ class _ReconnectCountDownButtonState extends State<_ReconnectCountDownButton> {
32183241
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
32193242
if (_countdownSeconds <= 0) {
32203243
timer.cancel();
3244+
if (widget.submitOnTimeout) {
3245+
widget.onPressed?.call();
3246+
}
32213247
} else {
32223248
setState(() {
32233249
_countdownSeconds--;
@@ -3229,7 +3255,7 @@ class _ReconnectCountDownButtonState extends State<_ReconnectCountDownButton> {
32293255
@override
32303256
Widget build(BuildContext context) {
32313257
return dialogButton(
3232-
'${translate('Reconnect')} (${_countdownSeconds}s)',
3258+
'${translate(widget.text)} (${_countdownSeconds}s)',
32333259
onPressed: widget.onPressed,
32343260
isOutline: true,
32353261
);

flutter/lib/consts.dart

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const String kOptionCurrentAbName = "current-ab-name";
139139
const String kOptionEnableConfirmClosingTabs = "enable-confirm-closing-tabs";
140140
const String kOptionAllowAlwaysSoftwareRender = "allow-always-software-render";
141141
const String kOptionEnableCheckUpdate = "enable-check-update";
142+
const String kOptionAllowAutoUpdate = "allow-auto-update";
142143
const String kOptionAllowLinuxHeadless = "allow-linux-headless";
143144
const String kOptionAllowRemoveWallpaper = "allow-remove-wallpaper";
144145
const String kOptionStopService = "stop-service";

flutter/lib/desktop/pages/desktop_home_page.dart

+15-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:flutter_hbb/consts.dart';
1212
import 'package:flutter_hbb/desktop/pages/connection_page.dart';
1313
import 'package:flutter_hbb/desktop/pages/desktop_setting_page.dart';
1414
import 'package:flutter_hbb/desktop/pages/desktop_tab_page.dart';
15+
import 'package:flutter_hbb/desktop/widgets/update_progress.dart';
1516
import 'package:flutter_hbb/models/platform_model.dart';
1617
import 'package:flutter_hbb/models/server_model.dart';
1718
import 'package:flutter_hbb/models/state_model.dart';
@@ -22,7 +23,6 @@ import 'package:provider/provider.dart';
2223
import 'package:url_launcher/url_launcher.dart';
2324
import 'package:window_manager/window_manager.dart';
2425
import 'package:window_size/window_size.dart' as window_size;
25-
2626
import '../widgets/button.dart';
2727

2828
class DesktopHomePage extends StatefulWidget {
@@ -433,13 +433,23 @@ class _DesktopHomePageState extends State<DesktopHomePage>
433433
updateUrl.isNotEmpty &&
434434
!isCardClosed &&
435435
bind.mainUriPrefixSync().contains('rustdesk')) {
436+
final isToUpdate = (isWindows || isMacOS) && bind.mainIsInstalled();
437+
String btnText = isToUpdate ? 'Click to update' : 'Click to download';
438+
GestureTapCallback onPressed = () async {
439+
final Uri url = Uri.parse('https://rustdesk.com/download');
440+
await launchUrl(url);
441+
};
442+
if (isToUpdate) {
443+
onPressed = () {
444+
handleUpdate(updateUrl);
445+
};
446+
}
436447
return buildInstallCard(
437448
"Status",
438449
"${translate("new-version-of-{${bind.mainGetAppNameSync()}}-tip")} (${bind.mainGetNewVersion()}).",
439-
"Click to download", () async {
440-
final Uri url = Uri.parse('https://rustdesk.com/download');
441-
await launchUrl(url);
442-
}, closeButton: true);
450+
btnText,
451+
onPressed,
452+
closeButton: true);
443453
}
444454
if (systemError.isNotEmpty) {
445455
return buildInstallCard("", systemError, "", () {});

flutter/lib/desktop/pages/desktop_setting_page.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ class _GeneralState extends State<_General> {
470470
}
471471

472472
Widget other() {
473+
final showAutoUpdate =
474+
isWindows && bind.mainIsInstalled() && !bind.isCustomClient();
473475
final children = <Widget>[
474476
if (!isWeb && !bind.isIncomingOnly())
475477
_OptionCheckBox(context, 'Confirm before closing multiple tabs',
@@ -523,12 +525,19 @@ class _GeneralState extends State<_General> {
523525
kOptionEnableCheckUpdate,
524526
isServer: false,
525527
),
528+
if (showAutoUpdate)
529+
_OptionCheckBox(
530+
context,
531+
'Auto update',
532+
kOptionAllowAutoUpdate,
533+
isServer: true,
534+
),
526535
if (isWindows && !bind.isOutgoingOnly())
527536
_OptionCheckBox(
528537
context,
529538
'Capture screen using DirectX',
530539
kOptionDirectxCapture,
531-
)
540+
),
532541
],
533542
];
534543
if (!isWeb && bind.mainShowOption(key: kOptionAllowLinuxHeadless)) {

0 commit comments

Comments
 (0)