Skip to content

Commit 5a40ceb

Browse files
committed
Bug fixes
1 parent 205cbec commit 5a40ceb

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

app/src/foss/java/com/doubleangels/nextdnsmanagement/MainActivity.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,29 @@ private void setupSwipeToRefreshForActivity() {
627627
private void setupDownloadManagerForActivity() {
628628
webView.setDownloadListener((url, userAgent, contentDisposition, mimetype, contentLength) -> {
629629
try {
630+
if (url != null && url.startsWith("data:")) {
631+
String[] parts = url.split(",");
632+
if (parts.length > 1) {
633+
String dataString = parts[1];
634+
byte[] fileData;
635+
if (parts[0].contains(";base64")) {
636+
fileData = android.util.Base64.decode(dataString, android.util.Base64.DEFAULT);
637+
} else {
638+
fileData = java.net.URLDecoder.decode(dataString, "UTF-8").getBytes("UTF-8");
639+
}
640+
java.io.File downloadDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
641+
if (downloadDir != null) {
642+
java.io.File file = new java.io.File(downloadDir, "NextDNS-Configuration.mobileconfig");
643+
try (java.io.FileOutputStream fos = new java.io.FileOutputStream(file)) {
644+
fos.write(fileData);
645+
fos.flush();
646+
}
647+
Toast.makeText(getApplicationContext(), "Configuration saved to Downloads!", Toast.LENGTH_LONG).show();
648+
return;
649+
}
650+
}
651+
}
652+
630653
// Create a new download request
631654
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url.trim()));
632655
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

app/src/gms/java/com/doubleangels/nextdnsmanagement/MainActivity.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,29 @@ private void setupSwipeToRefreshForActivity() {
637637
private void setupDownloadManagerForActivity() {
638638
webView.setDownloadListener((url, userAgent, contentDisposition, mimetype, contentLength) -> {
639639
try {
640+
if (url != null && url.startsWith("data:")) {
641+
String[] parts = url.split(",");
642+
if (parts.length > 1) {
643+
String dataString = parts[1];
644+
byte[] fileData;
645+
if (parts[0].contains(";base64")) {
646+
fileData = android.util.Base64.decode(dataString, android.util.Base64.DEFAULT);
647+
} else {
648+
fileData = java.net.URLDecoder.decode(dataString, "UTF-8").getBytes("UTF-8");
649+
}
650+
java.io.File downloadDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
651+
if (downloadDir != null) {
652+
java.io.File file = new java.io.File(downloadDir, "NextDNS-Configuration.mobileconfig");
653+
try (java.io.FileOutputStream fos = new java.io.FileOutputStream(file)) {
654+
fos.write(fileData);
655+
fos.flush();
656+
}
657+
Toast.makeText(getApplicationContext(), "Configuration saved to Downloads!", Toast.LENGTH_LONG).show();
658+
return;
659+
}
660+
}
661+
}
662+
640663
// Create a new download request
641664
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url.trim()));
642665
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

app/src/main/java/com/doubleangels/nextdnsmanagement/protocol/VisualIndicator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public VisualIndicator(Context context) {
6969
throw new IOException("Proxy setup failed due to IllegalArgumentException", e);
7070
}
7171
})
72+
.retryOnConnectionFailure(true)
7273
.build();
7374
}
7475

@@ -213,6 +214,7 @@ public void checkInheritedDNS(Context context, AppCompatActivity activity) {
213214
.url("https://test.nextdns.io")
214215
.header("Accept", "application/json")
215216
.header("Cache-Control", "no-cache")
217+
.header("Connection", "close")
216218
.build();
217219

218220
// Execute the request asynchronously
@@ -308,7 +310,8 @@ private void catchNetworkErrors(@NonNull Exception e) {
308310
String msg = e.getMessage().toLowerCase();
309311
if (msg.contains("canceled") || msg.contains("cancel") ||
310312
msg.contains("port out of range") || msg.contains("exhausted all routes") ||
311-
msg.contains("failed to connect") || msg.contains("timeout")) {
313+
msg.contains("failed to connect") || msg.contains("timeout") ||
314+
msg.contains("unexpected end of stream")) {
312315
return;
313316
}
314317
}

0 commit comments

Comments
 (0)