mirror of
https://github.com/DefinedNet/mobile_nebula.git
synced 2025-09-07 19:46:06 +00:00
Compare commits
2 commits
c0b856e611
...
4a3e286ae3
Author | SHA1 | Date | |
---|---|---|---|
|
4a3e286ae3 | ||
|
3cea52a15f |
2 changed files with 23 additions and 8 deletions
|
@ -189,7 +189,10 @@ class MainActivity: FlutterActivity() {
|
||||||
return result.error("unhandled_error", err.message, null)
|
return result.error("unhandled_error", err.message, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateOrDeleteSite(siteDir)) {
|
val validationResult = validateOrDeleteSite(siteDir);
|
||||||
|
if (validationResult is ValidationResult.FailureReason) {
|
||||||
|
return result.error("failure", validationResult.value, null)
|
||||||
|
} else if (validationResult is ValidationResult.BooleanResult && !validationResult.value) {
|
||||||
return result.error("failure", "Enrollment failed due to invalid config", null)
|
return result.error("failure", "Enrollment failed due to invalid config", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +228,10 @@ class MainActivity: FlutterActivity() {
|
||||||
return result.error("failure", err.toString(), null)
|
return result.error("failure", err.toString(), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateOrDeleteSite(siteDir)) {
|
val validationResult = validateOrDeleteSite(siteDir);
|
||||||
|
if (validationResult is ValidationResult.FailureReason) {
|
||||||
|
return result.error("failure", validationResult.value, null)
|
||||||
|
} else if (validationResult is ValidationResult.BooleanResult && !validationResult.value) {
|
||||||
return result.error("failure", "Site config was incomplete, please review and try again", null)
|
return result.error("failure", "Site config was incomplete, please review and try again", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,19 +240,28 @@ class MainActivity: FlutterActivity() {
|
||||||
result.success(null)
|
result.success(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateOrDeleteSite(siteDir: File): Boolean {
|
sealed class ValidationResult {
|
||||||
|
data class FailureReason(val value: String) : ValidationResult()
|
||||||
|
data class BooleanResult(val value: Boolean) : ValidationResult()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validateOrDeleteSite(siteDir: File): ValidationResult {
|
||||||
try {
|
try {
|
||||||
// Try to render a full site, if this fails the config was bad somehow
|
// Try to render a full site, if this fails the config was bad somehow
|
||||||
Site(context, siteDir)
|
val site = Site(context, siteDir);
|
||||||
|
if (site.errors.isNotEmpty()) {
|
||||||
|
// Return the first error, so the user can at least know one thing to solve
|
||||||
|
return ValidationResult.FailureReason(site.errors[0])
|
||||||
|
}
|
||||||
} catch(err: java.io.FileNotFoundException) {
|
} catch(err: java.io.FileNotFoundException) {
|
||||||
Log.e(TAG, "Site not found at $siteDir")
|
Log.e(TAG, "Site not found at $siteDir")
|
||||||
return false
|
return ValidationResult.BooleanResult(false)
|
||||||
} catch(err: Exception) {
|
} catch(err: Exception) {
|
||||||
Log.e(TAG, "Deleting site at $siteDir due to error: $err")
|
Log.e(TAG, "Deleting site at $siteDir due to error: $err")
|
||||||
siteDir.deleteRecursively()
|
siteDir.deleteRecursively()
|
||||||
return false
|
return ValidationResult.BooleanResult(false)
|
||||||
}
|
}
|
||||||
return true
|
return ValidationResult.BooleanResult(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startSite(call: MethodCall, result: MethodChannel.Result) {
|
private fun startSite(call: MethodCall, result: MethodChannel.Result) {
|
||||||
|
|
|
@ -156,7 +156,7 @@ class _SiteConfigScreenState extends State<SiteConfigScreen> {
|
||||||
final certError = site.certInfo == null || site.certInfo!.validity == null || !site.certInfo!.validity!.valid;
|
final certError = site.certInfo == null || site.certInfo!.validity == null || !site.certInfo!.validity!.valid;
|
||||||
var caError = false;
|
var caError = false;
|
||||||
if (!site.managed) {
|
if (!site.managed) {
|
||||||
var caError = site.ca.length == 0;
|
caError = site.ca.length == 0;
|
||||||
if (!caError) {
|
if (!caError) {
|
||||||
site.ca.forEach((ca) {
|
site.ca.forEach((ca) {
|
||||||
if (ca.validity == null || !ca.validity!.valid) {
|
if (ca.validity == null || !ca.validity!.valid) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue