});
}
- Future<List<PveAccessDomainModel?>?> _tryGetAccessDomains(
- Uri uri, bool showConnectionError) async {
+ Future<List<PveAccessDomainModel?>?> _loadAccessDomains(Uri uri) async {
final settings = await ProxmoxGeneralSettingsModel.fromLocalStorage();
List<PveAccessDomainModel?>? response;
try {
exception: e,
),
);
- } catch (e, trace) {
- print(e);
- print(trace);
- if (e.runtimeType == HandshakeException) {
- showDialog(
- context: context,
- builder: (context) => ProxmoxCertificateErrorDialog(),
- );
- } else {
- if (showConnectionError) {
- showDialog(
- context: context,
- builder: (context) => ConnectionErrorDialog(
- exception: e,
- ));
- } else {
- throw e;
- }
- }
+ } on HandshakeException {
+ showDialog(
+ context: context,
+ builder: (context) => ProxmoxCertificateErrorDialog(),
+ );
+ }
+ return response;
+ }
+
+ Future<List<PveAccessDomainModel?>?> _tryLoadAccessDomains(Uri uri) async {
+ List<PveAccessDomainModel?>? response;
+ try {
+ response = await _loadAccessDomains(uri);
+ } catch (e) {
+ showDialog(
+ context: context,
+ builder: (context) => ConnectionErrorDialog(
+ exception: e,
+ ),
+ );
}
return response;
}
RegExp portRE = new RegExp(r":\d{1,5}$");
- bool hasPort = true;
- if (!portRE.hasMatch(host)) {
- hasPort = false;
- apiBaseUrl = apiBaseUrl.replace(port: 8006);
- }
-
List<PveAccessDomainModel?>? response;
- try {
- response = await _tryGetAccessDomains(apiBaseUrl, hasPort);
- if (!hasPort) {
- _originController.text = '$host:8006';
- }
- } catch (e) {
- if (!hasPort) {
+ if (portRE.hasMatch(host)) {
+ response = await _tryLoadAccessDomains(apiBaseUrl);
+ } else {
+ // try to guess the port, 8006 first, and then 443
+ apiBaseUrl = apiBaseUrl.replace(port: 8006);
+ try {
+ response = await _loadAccessDomains(apiBaseUrl);
+ if (response != null) {
+ _originController.text = '$host:8006';
+ }
+ } catch (e) {
// we were no port given, and we couldn't reach on port 8006, retry with 443
apiBaseUrl = apiBaseUrl.replace(port: 443);
- response = await _tryGetAccessDomains(apiBaseUrl, true);
+ response = await _tryLoadAccessDomains(apiBaseUrl);
if (response != null) {
_originController.text = '$host:443';
}