Skip to content

Commit 0d6e030

Browse files
committed
Add Dart-side resolv.conf fallback using dart:io (#40)
The Kotlin writeResolv method channel silently fails in some cases. Added direct Dart file creation as fallback in both splash_screen and terminal_service (getProotShellConfig). Uses dart:io Directory and File APIs to create config/resolv.conf directly, bypassing the method channel entirely. Co-Authored-By: Mithun Gowda B <mithungowda.b7411@gmail.com>
1 parent 66efda7 commit 0d6e030

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

flutter_app/lib/screens/splash_screen.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:io';
12
import 'package:flutter/material.dart';
23
import 'package:google_fonts/google_fonts.dart';
34
import '../constants.dart';
@@ -51,6 +52,17 @@ class _SplashScreenState extends State<SplashScreen>
5152
try { await NativeBridge.setupDirs(); } catch (_) {}
5253
try { await NativeBridge.writeResolv(); } catch (_) {}
5354

55+
// Direct Dart fallback: create resolv.conf if native calls failed (#40).
56+
try {
57+
final filesDir = await NativeBridge.getFilesDir();
58+
final configDir = '$filesDir/config';
59+
final resolvFile = File('$configDir/resolv.conf');
60+
if (!resolvFile.existsSync()) {
61+
Directory(configDir).createSync(recursive: true);
62+
resolvFile.writeAsStringSync('nameserver 8.8.8.8\nnameserver 8.8.4.4\n');
63+
}
64+
} catch (_) {}
65+
5466
final prefs = PreferencesService();
5567
await prefs.init();
5668

flutter_app/lib/services/terminal_service.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:io';
12
import 'package:flutter/services.dart';
23
import '../constants.dart';
34
import 'native_bridge.dart';
@@ -33,6 +34,16 @@ class TerminalService {
3334
final prootPath = '$nativeLibDir/libproot.so';
3435
final libDir = '$filesDir/lib';
3536

37+
// Direct Dart fallback: create resolv.conf if it still doesn't exist
38+
// after the native method channel calls (#40).
39+
try {
40+
final resolvFile = File('$configDir/resolv.conf');
41+
if (!resolvFile.existsSync()) {
42+
Directory(configDir).createSync(recursive: true);
43+
resolvFile.writeAsStringSync('nameserver 8.8.8.8\nnameserver 8.8.4.4\n');
44+
}
45+
} catch (_) {}
46+
3647
final storageGranted = await NativeBridge.hasStoragePermission();
3748

3849
return {

0 commit comments

Comments
 (0)