mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Refactor: extract server cert dialogs
This commit is contained in:
parent
0b766723d8
commit
9bf3e0e7ff
2 changed files with 64 additions and 41 deletions
|
@ -18,6 +18,7 @@ import 'package:nc_photos/platform/features.dart' as features;
|
||||||
import 'package:nc_photos/snack_bar_manager.dart';
|
import 'package:nc_photos/snack_bar_manager.dart';
|
||||||
import 'package:nc_photos/url_launcher_util.dart';
|
import 'package:nc_photos/url_launcher_util.dart';
|
||||||
import 'package:nc_photos/use_case/ls_single_file.dart';
|
import 'package:nc_photos/use_case/ls_single_file.dart';
|
||||||
|
import 'package:nc_photos/widget/server_cert_error_dialog.dart';
|
||||||
import 'package:np_codegen/np_codegen.dart';
|
import 'package:np_codegen/np_codegen.dart';
|
||||||
import 'package:np_string/np_string.dart';
|
import 'package:np_string/np_string.dart';
|
||||||
|
|
||||||
|
@ -132,58 +133,22 @@ class _ConnectState extends State<Connect> {
|
||||||
void _onSelfSignedCert(BuildContext context) {
|
void _onSelfSignedCert(BuildContext context) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (_) => const ServerCertErrorDialog(),
|
||||||
title: Text(L10n.global().serverCertErrorDialogTitle),
|
|
||||||
content: Text(L10n.global().serverCertErrorDialogContent),
|
|
||||||
actions: <Widget>[
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop(true);
|
|
||||||
},
|
|
||||||
child: Text(L10n.global().advancedButtonLabel),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != true) {
|
if (value != true) {
|
||||||
Navigator.of(context).pop(null);
|
Navigator.of(context).pop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => const WhitelistLastBadCertDialog(),
|
||||||
title: Text(L10n.global().whitelistCertDialogTitle),
|
|
||||||
content: Text(L10n.global().whitelistCertDialogContent(
|
|
||||||
SelfSignedCertManager().getLastBadCertHost(),
|
|
||||||
SelfSignedCertManager().getLastBadCertFingerprint())),
|
|
||||||
actions: <Widget>[
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop(true);
|
|
||||||
},
|
|
||||||
child: Text(L10n.global().whitelistCertButtonLabel),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != true) {
|
if (value != true) {
|
||||||
Navigator.of(context).pop(null);
|
Navigator.of(context).pop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SelfSignedCertManager().whitelistLastBadCert().then((value) {
|
SelfSignedCertManager().whitelistLastBadCert().then((value) {
|
||||||
Navigator.of(context).pop(null);
|
Navigator.of(context).pop();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
58
app/lib/widget/server_cert_error_dialog.dart
Normal file
58
app/lib/widget/server_cert_error_dialog.dart
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:nc_photos/app_localizations.dart';
|
||||||
|
import 'package:nc_photos/mobile/self_signed_cert_manager.dart';
|
||||||
|
|
||||||
|
class ServerCertErrorDialog extends StatelessWidget {
|
||||||
|
const ServerCertErrorDialog({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(L10n.global().serverCertErrorDialogTitle),
|
||||||
|
content: Text(L10n.global().serverCertErrorDialogContent),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(true);
|
||||||
|
},
|
||||||
|
child: Text(L10n.global().advancedButtonLabel),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WhitelistLastBadCertDialog extends StatelessWidget {
|
||||||
|
const WhitelistLastBadCertDialog({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(L10n.global().whitelistCertDialogTitle),
|
||||||
|
content: Text(L10n.global().whitelistCertDialogContent(
|
||||||
|
SelfSignedCertManager().getLastBadCertHost(),
|
||||||
|
SelfSignedCertManager().getLastBadCertFingerprint(),
|
||||||
|
)),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(true);
|
||||||
|
},
|
||||||
|
child: Text(L10n.global().whitelistCertButtonLabel),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue