@@ -1152,15 +1152,23 @@ Widget createDialogContent(String text) {
1152
1152
1153
1153
void msgBox (SessionID sessionId, String type, String title, String text,
1154
1154
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}) {
1156
1160
dialogManager.dismissAll ();
1157
1161
List <Widget > buttons = [];
1158
1162
bool hasOk = false ;
1159
1163
submit () {
1160
1164
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
+ }
1164
1172
}
1165
1173
}
1166
1174
@@ -1176,7 +1184,18 @@ void msgBox(SessionID sessionId, String type, String title, String text,
1176
1184
1177
1185
if (type != "connecting" && type != "success" && ! type.contains ("nook" )) {
1178
1186
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);
1180
1199
}
1181
1200
hasCancel ?? = ! type.contains ("error" ) &&
1182
1201
! type.contains ("nocancel" ) &&
@@ -1197,7 +1216,8 @@ void msgBox(SessionID sessionId, String type, String title, String text,
1197
1216
reconnectTimeout != null ) {
1198
1217
// `enabled` is used to disable the dialog button once the button is clicked.
1199
1218
final enabled = true .obs;
1200
- final button = Obx (() => _ReconnectCountDownButton (
1219
+ final button = Obx (() => _CountDownButton (
1220
+ text: 'Reconnect' ,
1201
1221
second: reconnectTimeout,
1202
1222
onPressed: enabled.isTrue
1203
1223
? () {
@@ -3183,21 +3203,24 @@ parseParamScreenRect(Map<String, dynamic> params) {
3183
3203
3184
3204
get isInputSourceFlutter => stateGlobal.getInputSource () == "Input source 2" ;
3185
3205
3186
- class _ReconnectCountDownButton extends StatefulWidget {
3187
- _ReconnectCountDownButton ({
3206
+ class _CountDownButton extends StatefulWidget {
3207
+ _CountDownButton ({
3188
3208
Key ? key,
3209
+ required this .text,
3189
3210
required this .second,
3190
3211
required this .onPressed,
3212
+ this .submitOnTimeout = false ,
3191
3213
}) : super (key: key);
3214
+ final String text;
3192
3215
final VoidCallback ? onPressed;
3193
3216
final int second;
3217
+ final bool submitOnTimeout;
3194
3218
3195
3219
@override
3196
- State <_ReconnectCountDownButton > createState () =>
3197
- _ReconnectCountDownButtonState ();
3220
+ State <_CountDownButton > createState () => _CountDownButtonState ();
3198
3221
}
3199
3222
3200
- class _ReconnectCountDownButtonState extends State <_ReconnectCountDownButton > {
3223
+ class _CountDownButtonState extends State <_CountDownButton > {
3201
3224
late int _countdownSeconds = widget.second;
3202
3225
3203
3226
Timer ? _timer;
@@ -3218,6 +3241,9 @@ class _ReconnectCountDownButtonState extends State<_ReconnectCountDownButton> {
3218
3241
_timer = Timer .periodic (Duration (seconds: 1 ), (timer) {
3219
3242
if (_countdownSeconds <= 0 ) {
3220
3243
timer.cancel ();
3244
+ if (widget.submitOnTimeout) {
3245
+ widget.onPressed? .call ();
3246
+ }
3221
3247
} else {
3222
3248
setState (() {
3223
3249
_countdownSeconds-- ;
@@ -3229,7 +3255,7 @@ class _ReconnectCountDownButtonState extends State<_ReconnectCountDownButton> {
3229
3255
@override
3230
3256
Widget build (BuildContext context) {
3231
3257
return dialogButton (
3232
- '${translate ('Reconnect' )} (${_countdownSeconds }s)' ,
3258
+ '${translate (widget . text )} (${_countdownSeconds }s)' ,
3233
3259
onPressed: widget.onPressed,
3234
3260
isOutline: true ,
3235
3261
);
0 commit comments