diff --git a/android/app/build.gradle b/android/app/build.gradle index e75ebbb..b08b16a 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -102,7 +102,7 @@ dependencies { implementation "com.android.billingclient:billing:$billing_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.google.android.gms:play-services-base:17.2.0' + implementation 'com.google.android.gms:play-services-base:17.6.0' //Duplicate Classes Issue https://stackoverflow.com/a/60492942 implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' @@ -110,7 +110,7 @@ dependencies { debugImplementation 'com.jeppeman.locallydynamic:locallydynamic-debug:0.3' releaseImplementation 'com.jeppeman.locallydynamic:locallydynamic:0.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + // testImplementation 'junit:junit:4.12' + // androidTestImplementation 'androidx.test:runner:1.2.0' + // androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } diff --git a/android/app/src/main/kotlin/in/canews/zeronetmobile/MainActivity.kt b/android/app/src/main/kotlin/in/canews/zeronetmobile/MainActivity.kt index 4c2bb1b..0fe4ecb 100644 --- a/android/app/src/main/kotlin/in/canews/zeronetmobile/MainActivity.kt +++ b/android/app/src/main/kotlin/in/canews/zeronetmobile/MainActivity.kt @@ -56,7 +56,7 @@ class MainActivity : FlutterActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if(intent.getStringExtra("LAUNCH_SHORTCUT_URL") != null) { - mLaunchShortcutUrl = intent.getStringExtra("LAUNCH_SHORTCUT_URL") + mLaunchShortcutUrl = intent.getStringExtra("LAUNCH_SHORTCUT_URL")!! } } @@ -237,7 +237,7 @@ class MainActivity : FlutterActivity() { success(msg) }.onFailure { if (it is IllegalStateException) { - Log.e("MainActivity>resultSuc>", it.message) + Log.e("MainActivity>resultSuc>", it.message!!) } } } @@ -370,7 +370,7 @@ class MainActivity : FlutterActivity() { private fun isGooglePlayServicesAvailable(activity: Activity?): Boolean { val googleApiAvailability: GoogleApiAvailability = GoogleApiAvailability.getInstance() - val status: Int = googleApiAvailability.isGooglePlayServicesAvailable(activity) + val status: Int = googleApiAvailability.isGooglePlayServicesAvailable(applicationContext) if (status != ConnectionResult.SUCCESS) { // if (googleApiAvailability.isUserResolvableError(status)) { // googleApiAvailability.getErrorDialog(activity, status, 2404).show() diff --git a/android/arm64/src/main/assets/site_packages_arm64.zip b/android/arm64/src/main/assets/site_packages_arm64.zip index f921c9e..63cdc3b 100644 Binary files a/android/arm64/src/main/assets/site_packages_arm64.zip and b/android/arm64/src/main/assets/site_packages_arm64.zip differ diff --git a/android/build.gradle b/android/build.gradle index daa3f6f..71f0077 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,9 +1,8 @@ buildscript { - ext.kotlin_version = '1.3.61' + ext.kotlin_version = '1.5.21' ext.gradle_version = '4.2.0' repositories { google() - jcenter() maven { url "https://plugins.gradle.org/m2" } @@ -19,7 +18,6 @@ buildscript { allprojects { repositories { google() - jcenter() } } diff --git a/lib/core/content/content_db.dart b/lib/core/content/content_db.dart new file mode 100644 index 0000000..e8554d9 --- /dev/null +++ b/lib/core/content/content_db.dart @@ -0,0 +1,32 @@ +class ContentDb { + bool foreignKeys = false; + Map schema = {}; + + ContentDb(String path) { + // Db({"db_name": "ContentDb", "tables": {}}, path); + foreignKeys = true; + } + + getSchema() { + Map scehma = {}; + scehma['db_name'] = 'ContentDb'; + schema["version"] = 3; + schema["tables"] = {}; + } +} + +Map content_db = {}; + +getContentDb({String path}) { + if (path == null) { + path = "../content.db"; + } + + var result = content_db.keys.where((element) => path == element).toList(); + + if (result.isEmpty) { + content_db[path] = ContentDb(path); + content_db[path].init(); + return content_db[path]; + } +} diff --git a/lib/main.dart b/lib/main.dart index a127756..69b6019 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -44,6 +44,7 @@ class MyApp extends StatelessWidget { makeExecHelper().then( (value) => isExecPermitted = value, ); + if (zeroNetNativeDir.isNotEmpty) saveDataFile(); // createTorDataDir(); firstTime = false; } diff --git a/lib/models/enums.dart b/lib/models/enums.dart index 3714507..cc62412 100644 --- a/lib/models/enums.dart +++ b/lib/models/enums.dart @@ -1,3 +1,5 @@ +import 'package:zeronet/others/zeronet_isolate.dart'; + import '../imports.dart'; enum ZeroNetStatus { @@ -52,7 +54,11 @@ extension ZeroNetStatusExt on ZeroNetStatus { void onAction() { switch (this) { case ZeroNetStatus.NOT_RUNNING: - runZeroNetService(autoStart: true); + printOut('onAction()'); + printOut('ZeroNetStatus.NOT_RUNNING'); + var autoStart = + (varStore.settings[autoStartZeroNet] as ToggleSetting).value; + runZeroNetService(autoStart: autoStart); break; case ZeroNetStatus.RUNNING: case ZeroNetStatus.RUNNING_WITH_TOR: diff --git a/lib/others/common.dart b/lib/others/common.dart index a31a9f6..fb16700 100644 --- a/lib/others/common.dart +++ b/lib/others/common.dart @@ -2,6 +2,7 @@ import 'package:get/get.dart'; import 'package:purchases_flutter/purchases_flutter.dart'; import '../imports.dart'; +import 'zeronet_isolate.dart'; Directory appPrivDir; Directory tempDir; @@ -93,9 +94,7 @@ init() async { varStore.isZeroNetInstalled(isZeroNetInstalledm); checkForAppUpdates(); if (enableZeroNetAddTrackers) await downloadTrackerFiles(); - runZeroNetService( - autoStart: (varStore.settings[autoStartZeroNet] as ToggleSetting).value, - ); + ZeroNetStatus.NOT_RUNNING.onAction(); } if (!tempDir.existsSync()) tempDir.createSync(recursive: true); Purchases.setup("ShCpAJsKdJrAAQawcMQSswqTyPWFMwXb"); @@ -158,7 +157,7 @@ saveDataFile() { loadDataFile() { File f = File(dataDir + '/data.json'); Map m = json.decode(f.readAsStringSync()); - print(m); + printOut(m); zeroNetNativeDir = m['zeroNetNativeDir']; } diff --git a/lib/others/donation_const.dart b/lib/others/donation_const.dart index 04a2cbe..09a5793 100644 --- a/lib/others/donation_const.dart +++ b/lib/others/donation_const.dart @@ -3,11 +3,34 @@ import 'package:purchases_flutter/purchases_flutter.dart'; import '../imports.dart'; -const Map donationsAddressMap = { - "BTC(Preferred)": "1eVStCWqLM7hFB1enaoGzAt7T3tsAB41z", - "ETH": "0xa81a32dcce8e5bcb9792daa19ae7f964699ee536", - "UPI(Indian Users)": "pramukesh@upi", - "Liberapay": "https://liberapay.com/canews.in/donate", +var enableExternalDonations = false; +var btcAddress = '1eVStCWqLM7hFB1enaoGzAt7T3tsAB41z'; +var ethAddress = '0xa81a32dcce8e5bcb9792daa19ae7f964699ee536'; +var upiAddress = 'pramukesh@upi'; +var liberaPayAddress = 'https://liberapay.com/canews.in/donate'; + +void getDonationSettings() { + var dir = Utils.urlZeroNetMob.zeroNetDataPath; + if (Directory(dir).existsSync()) { + var file = File(dir + '/native.decent'); + if (file.existsSync()) { + var decode = json.decode(file.readAsStringSync()); + var settingsMap = (decode as Map)['settings']; + var donations = settingsMap['donations']; + enableExternalDonations = donations['enableExternalDonations']; + btcAddress = donations['btcAddress']; + ethAddress = donations['ethAddress']; + upiAddress = donations['upiAddress']; + liberaPayAddress = donations['liberapayAddress']; + } + } +} + +Map donationsAddressMap = { + "BTC(Preferred)": btcAddress, + "ETH": ethAddress, + "UPI(Indian Users)": upiAddress, + "Liberapay": liberaPayAddress, }; const Set kGooglePlayPurchaseOneTimeIds = { @@ -64,7 +87,7 @@ void purchasePackage(Package package) async { if (isPro) { // Unlock that great "pro" content } - print(purchaserInfo); + printOut(purchaserInfo); } on PlatformException catch (e) { var errorCode = PurchasesErrorHelper.getErrorCode(e); if (errorCode != PurchasesErrorCode.purchaseCancelledError) { @@ -111,7 +134,7 @@ void listenToPurchaseUpdated(List purchaseDetailsList) { } _verifyPurchase(PurchaseDetails purchaseDetails) { - print(purchaseDetails.verificationData.localVerificationData); + printOut(purchaseDetails.verificationData.localVerificationData); return Future.value(true); } diff --git a/lib/others/extensions.dart b/lib/others/extensions.dart index 0fcc1af..2374c5d 100644 --- a/lib/others/extensions.dart +++ b/lib/others/extensions.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'package:zeronet/imports.dart'; extension FileSystemExtension on FileSystemEntity { String get name => this.path.replaceFirst(this.parent.path + '/', ''); @@ -9,6 +10,7 @@ extension CapExtension on String { String get allInCaps => this.toUpperCase(); String get capitalizeFirstofEach => this.split(" ").map((str) => str.inCaps).join(" "); + String get zeroNetDataPath => getZeroNetDataDir().path + '/' + this + '/'; } extension DynamicExt on dynamic { diff --git a/lib/others/utils.dart b/lib/others/utils.dart index 24fa779..eb613ef 100644 --- a/lib/others/utils.dart +++ b/lib/others/utils.dart @@ -7,7 +7,7 @@ import '../imports.dart'; debugTime(Function func) { var start = DateTime.now(); func(); - print(DateTime.now().difference(start).inMilliseconds); + printOut(DateTime.now().difference(start).inMilliseconds); } printOut(Object object, {int lineBreaks = 0, bool isNative = false}) { diff --git a/lib/others/zeronet_isolate.dart b/lib/others/zeronet_isolate.dart new file mode 100644 index 0000000..97e8e4c --- /dev/null +++ b/lib/others/zeronet_isolate.dart @@ -0,0 +1,309 @@ +import '../imports.dart'; + +void runTorEngine() { + service = FlutterBackgroundService(); + final tor = zeroNetNativeDir + '/libtor.so'; + if (File(tor).existsSync()) { + service.sendData({'console': 'Running Tor Engine..'}); + Process.start('$tor', [], environment: { + "LD_LIBRARY_PATH": "$libDir:$libDir64:/system/lib64", + }).then((proc) { + zero = proc; + if (enableTorLogConsole) { + zero.stderr.listen((onData) { + service.sendData({'console': utf8.decode(onData)}); + }); + zero.stdout.listen((onData) { + service.sendData({'console': utf8.decode(onData)}); + }); + } + }).catchError((e) { + if (e is ProcessException) { + printOut(e.toString()); + } + }); + } else { + //TODO: Improve Error Trace here + service.sendData({'console': 'Tor Binary Not Found'}); + uiStore.setZeroNetStatus(ZeroNetStatus.RUNNING); + } +} + +void runZeroNet() { + printOut('runZeroNet()'); + printOut('zeroNetStatus : ${uiStore.zeroNetStatus.value}'); + // if (zeroNetNativeDir.isEmpty) { + // printOut('zeroNetNativeDir.isEmpty : ${zeroNetNativeDir.isEmpty}'); + // getNativeDir().then((nativeDir) { + // zeroNetNativeDir = nativeDir; + // runZeroNet(); + // }); + // } else { + if (uiStore.zeroNetStatus.value == ZeroNetStatus.NOT_RUNNING || + uiStore.zeroNetStatus.value == ZeroNetStatus.ERROR) { + uiStore.setZeroNetStatus(ZeroNetStatus.INITIALISING); + service.sendData({'ZeroNetStatus': 'INITIALISING'}); + runTorEngine(); + log = ''; + service.sendData({'console': logRunning}); + service.sendData({'console': startZeroNetLog + '\n'}); + var python = zeroNetNativeDir + '/libpython3.8.so'; + var openssl = zeroNetNativeDir + '/libopenssl.so'; + var trackerFile = trackersDir.path + '/${trackerFileNames[7]}'; + printOut('python file : $python'); + printOut('openssl file : $openssl'); + if (File(python).existsSync()) { + Process.start('$python', [ + zeronet, + if (debugZeroNetCode) '--debug', + "--start_dir", + zeroNetDir, + "--openssl_bin_file", + openssl, + if (enableZeroNetAddTrackers) '--trackers_file', + if (enableZeroNetAddTrackers) trackerFile, + ], environment: { + "LD_LIBRARY_PATH": "$libDir:$libDir64:/system/lib64", + 'PYTHONHOME': '$dataDir/usr', + 'PYTHONPATH': '$python', + }).then((proc) { + zero = proc; + zero.stderr.listen((onData) { + service.sendData({'console': utf8.decode(onData)}); + }); + zero.stdout.listen((onData) { + service.sendData({'console': utf8.decode(onData)}); + }); + }).catchError((e) { + if (e is ProcessException) { + printOut(e.toString()); + } + uiStore.setZeroNetStatus(ZeroNetStatus.ERROR); + service.sendData({'ZeroNetStatus': 'ERROR'}); + service.sendData({'console': e.toString()}); + }); + // service.sendData({'ZeroNetStatus': 'RUNNING'}); + } else { + //TODO: Improve Error Trace here + service.sendData({'console': 'Python Binary Not Found'}); + uiStore.setZeroNetStatus(ZeroNetStatus.ERROR); + service.sendData({'ZeroNetStatus': 'ERROR'}); + service.sendData({'console': 'zeroNetNativeDir : $zeroNetNativeDir'}); + if (zeroNetNativeDir.isNotEmpty) { + var contents = Directory(zeroNetNativeDir).listSync(recursive: true); + for (var item in contents) { + service.sendData({'console': item.name}); + service.sendData({'console': item.path}); + } + } else { + service.sendData({'console': 'Initialising ZeroNet'}); + } + } + } else { + shutDownZeronet(); + } +} + +void runZeroNetService({bool autoStart = false}) async { + printOut('runZeroNetService()'); + bool autoStartService = autoStart + ? true + : (varStore.settings[autoStartZeroNetonBoot] as ToggleSetting).value; + bool filtersEnabled = + (varStore.settings[enableZeroNetFilters] as ToggleSetting).value ?? true; + if (filtersEnabled) await activateFilters(); + printToConsole(startZeroNetLog); + //TODO?: Check for Bugs Here. + var serviceRunning = await FlutterBackgroundService().isServiceRunning(); + printOut('serviceRunning : $serviceRunning'); + if (!serviceRunning) { + uiStore.setZeroNetStatus(ZeroNetStatus.NOT_RUNNING); + service = FlutterBackgroundService(); + } + + FlutterBackgroundService.initialize( + runBgIsolate, + autoStart: autoStartService, + ).then((value) { + printOut('FlutterBackgroundService.initialize() : $value'); + if (value) { + service = FlutterBackgroundService(); + service.onDataReceived.listen(onBgServiceDataReceived); + if (zeroNetNativeDir.isNotEmpty) saveDataFile(); + uiStore.setZeroNetStatus(ZeroNetStatus.INITIALISING); + // if (autoStart) + service.sendData({'cmd': 'runZeroNet'}); + } + }); +} + +void runBgIsolate() { + WidgetsFlutterBinding.ensureInitialized(); + service = FlutterBackgroundService(); + service.onDataReceived.listen(onBgServiceDataReceivedForIsolate); + service.sendData({'status': 'Started Background Service Successfully'}); + Timer(Duration(milliseconds: 0), () { + if (zeroNetStartedFromBoot || zeroNetNativeDir.isEmpty) { + setBgServiceRunningNotification(); + if (zeroNetNativeDir.isEmpty || zeroNetNativeDir == null) { + loadSettings(); + loadDataFile(); + debugZeroNetCode = + (varStore.settings[debugZeroNet] as ToggleSetting).value; + enableTorLogConsole = + (varStore.settings[enableTorLog] as ToggleSetting).value; + enableZeroNetAddTrackers = + (varStore.settings[enableAdditionalTrackers] as ToggleSetting) + .value; + vibrateonZeroNetStart = + (varStore.settings[vibrateOnZeroNetStart] as ToggleSetting).value; + printOut('runBgIsolate() > runZeroNet()'); + runZeroNet(); + setZeroNetRunningNotification(); + } + } + }); +} + +void onBgServiceDataReceivedForIsolate(Map data) { + if (data.keys.first == 'cmd') { + switch (data.values.first) { + case 'runZeroNet': + printOut('onBgServiceDataReceivedForIsolate() > runZeroNet()'); + runZeroNet(); + break; + case 'shutDownZeronet': + service.stopBackgroundService(); + uiStore.setZeroNetStatus(ZeroNetStatus.NOT_RUNNING); + break; + default: + } + } else if (data.keys.first == 'init') { + Map initMap = data['init']; + zeroNetNativeDir = initMap['zeroNetNativeDir']; + debugZeroNetCode = initMap['debugZeroNetCode']; + enableTorLogConsole = initMap['enableTorLog']; + zeroNetStartedFromBoot = initMap['zeroNetStartedFromBoot']; + vibrateonZeroNetStart = initMap['vibrateOnZeroNetStart']; + enableZeroNetAddTrackers = initMap['enableAdditionalTrackers']; + setBgServiceRunningNotification(); + } else if (data.keys.first == 'notification') { + if (data.values.first == 'ZeroNetStatus.RUNNING') { + setZeroNetRunningNotification(); + } else if (data.values.first == 'BgService.RUNNING') { + setBgServiceRunningNotification(); + } + } +} + +void setZeroNetRunningNotification() { + service.setNotificationInfo( + title: "ZeroNet Mobile is Running", + content: "Click Here on this Notification to open app", + ); +} + +void setBgServiceRunningNotification() { + service.setNotificationInfo( + title: "ZeroNet Mobile is Not Running", + content: "Open ZeroNet Mobile App and click start to run ZeroNet", + ); +} + +void onBgServiceDataReceived(Map data) { + if (data.keys.first == 'status') { + service.sendData({'notification': 'BgService.RUNNING'}); + service.sendData({ + 'init': { + 'zeroNetNativeDir': zeroNetNativeDir, + 'zeroNetStartedFromBoot': false, + 'debugZeroNetCode': + (varStore.settings[debugZeroNet] as ToggleSetting).value, + 'enableTorLog': + (varStore.settings[enableTorLog] as ToggleSetting).value, + 'vibrateOnZeroNetStart': + (varStore.settings[vibrateOnZeroNetStart] as ToggleSetting).value, + 'enableAdditionalTrackers': + (varStore.settings[enableAdditionalTrackers] as ToggleSetting) + .value, + } + }); + if (zeroNetNativeDir.isEmpty || zeroNetNativeDir == null) { + printToConsole('zeroNetNativeDir is Empty'); + } else if ((varStore.settings[autoStartZeroNet] as ToggleSetting).value == + true) { + service.sendData({'cmd': 'runZeroNet'}); + } + } else if (data.keys.first == 'ZeroNetStatus') { + switch (data.values.first) { + case 'INITIALISING': + uiStore.setZeroNetStatus(ZeroNetStatus.INITIALISING); + break; + case 'RUNNING': + uiStore.setZeroNetStatus(ZeroNetStatus.RUNNING); + runZeroNetWs(); + break; + case 'ERROR': + uiStore.setZeroNetStatus(ZeroNetStatus.ERROR); + break; + default: + } + } else if (data.keys.first == 'console') { + printToConsole(data.values.first); + } +} + +void runZeroNetWs({String address}) { + var zeroNetUrlL = zeroNetUrl.isNotEmpty ? zeroNetUrl : defZeroNetUrl; + zeroNetUrl = zeroNetUrlL; + if (varStore.zeroNetWrapperKey.isEmpty) { + try { + ZeroNet.instance + .getWrapperKey( + zeroNetUrl + Utils.urlHello, + override: true, + ) + .then((value) { + if (value != null) { + // ZeroNet.wrapperKey = value; + varStore.zeroNetWrapperKey = value; + browserUrl = zeroNetUrl; + ZeroNet.instance.connect( + // zeroNetIPwithPort(defZeroNetUrl), + address ?? Utils.urlHello, + override: true, + ); + } + }); + } catch (e) { + // printToConsole(e); + } + } else { + // ZeroNet.wrapperKey = varStore.zeroNetWrapperKey; + browserUrl = zeroNetUrl; + } +} + +void restartZeroNet() { + ZeroNet.instance.shutDown(); + service.sendData({'cmd': 'runZeroNet'}); +} + +void shutDownZeronet() { + if (uiStore.zeroNetStatus.value == ZeroNetStatus.RUNNING) { + service.sendData({'cmd': 'shutDownZeronet'}); + runZeroNetWs(); + if (ZeroNet.isInitialised) + ZeroNet.instance.shutDown(); + else { + runZeroNetWs(address: Utils.urlHello); + try { + ZeroNet.instance.shutDown(); + } catch (e) { + printOut(e); + } + } + zeroNetUrl = ''; + uiStore.setZeroNetStatus(ZeroNetStatus.NOT_RUNNING); + } +} diff --git a/lib/others/zeronet_utils.dart b/lib/others/zeronet_utils.dart index 127e0da..ffae5a5 100644 --- a/lib/others/zeronet_utils.dart +++ b/lib/others/zeronet_utils.dart @@ -82,290 +82,6 @@ setZeroBrowserThemeValues() { zeroBrowserTheme = usersAvailable.first.settings.theme ?? 'light'; } -runTorEngine() { - service = FlutterBackgroundService(); - final tor = zeroNetNativeDir + '/libtor.so'; - if (File(tor).existsSync()) { - service.sendData({'console': 'Running Tor Engine..'}); - Process.start('$tor', [], environment: { - "LD_LIBRARY_PATH": "$libDir:$libDir64:/system/lib64", - }).then((proc) { - zero = proc; - if (enableTorLogConsole) { - zero.stderr.listen((onData) { - service.sendData({'console': utf8.decode(onData)}); - }); - zero.stdout.listen((onData) { - service.sendData({'console': utf8.decode(onData)}); - }); - } - }).catchError((e) { - if (e is ProcessException) { - printOut(e.toString()); - } - }); - } else { - //TODO: Improve Error Trace here - service.sendData({'console': 'Tor Binary Not Found'}); - uiStore.setZeroNetStatus(ZeroNetStatus.RUNNING); - } -} - -runZeroNet() { - if (uiStore.zeroNetStatus.value == ZeroNetStatus.NOT_RUNNING || - uiStore.zeroNetStatus.value == ZeroNetStatus.ERROR) { - uiStore.setZeroNetStatus(ZeroNetStatus.INITIALISING); - service.sendData({'ZeroNetStatus': 'INITIALISING'}); - runTorEngine(); - log = ''; - service.sendData({'console': logRunning}); - service.sendData({'console': startZeroNetLog + '\n'}); - var python = zeroNetNativeDir + '/libpython3.8.so'; - var openssl = zeroNetNativeDir + '/libopenssl.so'; - var trackerFile = trackersDir.path + '/${trackerFileNames[7]}'; - - if (File(python).existsSync()) { - Process.start('$python', [ - zeronet, - if (debugZeroNetCode) '--debug', - "--start_dir", - zeroNetDir, - "--openssl_bin_file", - openssl, - if (enableZeroNetAddTrackers) '--trackers_file', - if (enableZeroNetAddTrackers) trackerFile, - ], environment: { - "LD_LIBRARY_PATH": "$libDir:$libDir64:/system/lib64", - 'PYTHONHOME': '$dataDir/usr', - 'PYTHONPATH': '$python', - }).then((proc) { - zero = proc; - zero.stderr.listen((onData) { - service.sendData({'console': utf8.decode(onData)}); - }); - zero.stdout.listen((onData) { - service.sendData({'console': utf8.decode(onData)}); - }); - }).catchError((e) { - if (e is ProcessException) { - printOut(e.toString()); - } - uiStore.setZeroNetStatus(ZeroNetStatus.ERROR); - service.sendData({'ZeroNetStatus': 'ERROR'}); - service.sendData({'console': e.toString()}); - }); - service.sendData({'ZeroNetStatus': 'RUNNING'}); - } else { - //TODO: Improve Error Trace here - service.sendData({'console': 'Python Binary Not Found'}); - uiStore.setZeroNetStatus(ZeroNetStatus.ERROR); - service.sendData({'ZeroNetStatus': 'ERROR'}); - service.sendData({'console': 'zeroNetNativeDir : $zeroNetNativeDir'}); - var contents = Directory(zeroNetNativeDir).listSync(recursive: true); - for (var item in contents) { - service.sendData({'console': item.name}); - service.sendData({'console': item.path}); - } - } - } else { - shutDownZeronet(); - } -} - -void runZeroNetService({bool autoStart = false}) async { - bool autoStartService = autoStart - ? true - : (varStore.settings[autoStartZeroNetonBoot] as ToggleSetting).value; - bool filtersEnabled = - (varStore.settings[enableZeroNetFilters] as ToggleSetting).value ?? true; - if (filtersEnabled) await activateFilters(); - printToConsole(startZeroNetLog); - //TODO?: Check for Bugs Here. - var serviceRunning = await FlutterBackgroundService().isServiceRunning(); - if (!serviceRunning) { - uiStore.setZeroNetStatus(ZeroNetStatus.NOT_RUNNING); - service = FlutterBackgroundService(); - } - - FlutterBackgroundService.initialize( - runBgIsolate, - autoStart: autoStartService, - ).then((value) { - if (value) { - service = FlutterBackgroundService(); - service.onDataReceived.listen(onBgServiceDataReceived); - if (zeroNetNativeDir.isNotEmpty) saveDataFile(); - uiStore.setZeroNetStatus(ZeroNetStatus.INITIALISING); - if (autoStart) service.sendData({'cmd': 'runZeroNet'}); - } - }); -} - -void runBgIsolate() { - WidgetsFlutterBinding.ensureInitialized(); - service = FlutterBackgroundService(); - service.onDataReceived.listen(onBgServiceDataReceivedForIsolate); - service.sendData({'status': 'Started Background Service Successfully'}); - Timer(Duration(milliseconds: 500), () { - if (zeroNetStartedFromBoot) { - setBgServiceRunningNotification(); - if (zeroNetNativeDir.isEmpty || zeroNetNativeDir == null) { - loadSettings(); - loadDataFile(); - debugZeroNetCode = - (varStore.settings[debugZeroNet] as ToggleSetting).value; - enableTorLogConsole = - (varStore.settings[enableTorLog] as ToggleSetting).value; - enableZeroNetAddTrackers = - (varStore.settings[enableAdditionalTrackers] as ToggleSetting) - .value; - vibrateonZeroNetStart = - (varStore.settings[vibrateOnZeroNetStart] as ToggleSetting).value; - runZeroNet(); - setZeroNetRunningNotification(); - } - } - }); -} - -void onBgServiceDataReceivedForIsolate(Map data) { - if (data.keys.first == 'cmd') { - switch (data.values.first) { - case 'runZeroNet': - runZeroNet(); - break; - case 'shutDownZeronet': - service.stopBackgroundService(); - uiStore.setZeroNetStatus(ZeroNetStatus.NOT_RUNNING); - break; - default: - } - } else if (data.keys.first == 'init') { - Map initMap = data['init']; - zeroNetNativeDir = initMap['zeroNetNativeDir']; - debugZeroNetCode = initMap['debugZeroNetCode']; - enableTorLogConsole = initMap['enableTorLog']; - zeroNetStartedFromBoot = initMap['zeroNetStartedFromBoot']; - vibrateonZeroNetStart = initMap['vibrateOnZeroNetStart']; - enableZeroNetAddTrackers = initMap['enableAdditionalTrackers']; - setBgServiceRunningNotification(); - } else if (data.keys.first == 'notification') { - if (data.values.first == 'ZeroNetStatus.RUNNING') { - setZeroNetRunningNotification(); - } else if (data.values.first == 'BgService.RUNNING') { - setBgServiceRunningNotification(); - } - } -} - -setZeroNetRunningNotification() { - service.setNotificationInfo( - title: "ZeroNet Mobile is Running", - content: "Click Here on this Notification to open app", - ); -} - -setBgServiceRunningNotification() { - service.setNotificationInfo( - title: "ZeroNet Mobile is Not Running", - content: "Open ZeroNet Mobile App and click start to run ZeroNet", - ); -} - -void onBgServiceDataReceived(Map data) { - if (data.keys.first == 'status') { - service.sendData({'notification': 'BgService.RUNNING'}); - service.sendData({ - 'init': { - 'zeroNetNativeDir': zeroNetNativeDir, - 'zeroNetStartedFromBoot': false, - 'debugZeroNetCode': - (varStore.settings[debugZeroNet] as ToggleSetting).value, - 'enableTorLog': - (varStore.settings[enableTorLog] as ToggleSetting).value, - 'vibrateOnZeroNetStart': - (varStore.settings[vibrateOnZeroNetStart] as ToggleSetting).value, - 'enableAdditionalTrackers': - (varStore.settings[enableAdditionalTrackers] as ToggleSetting) - .value, - } - }); - if (zeroNetNativeDir.isEmpty || zeroNetNativeDir == null) { - printToConsole('zeroNetNativeDir is Empty'); - } else if ((varStore.settings[autoStartZeroNet] as ToggleSetting).value == - true) { - service.sendData({'cmd': 'runZeroNet'}); - } - } else if (data.keys.first == 'ZeroNetStatus') { - switch (data.values.first) { - case 'INITIALISING': - uiStore.setZeroNetStatus(ZeroNetStatus.INITIALISING); - break; - case 'RUNNING': - uiStore.setZeroNetStatus(ZeroNetStatus.RUNNING); - runZeroNetWs(); - break; - case 'ERROR': - uiStore.setZeroNetStatus(ZeroNetStatus.ERROR); - break; - default: - } - } else if (data.keys.first == 'console') { - printToConsole(data.values.first); - } -} - -shutDownZeronet() { - if (uiStore.zeroNetStatus.value == ZeroNetStatus.RUNNING) { - service.sendData({'cmd': 'shutDownZeronet'}); - runZeroNetWs(); - if (ZeroNet.isInitialised) - ZeroNet.instance.shutDown(); - else { - runZeroNetWs(address: Utils.urlHello); - try { - ZeroNet.instance.shutDown(); - } catch (e) { - printOut(e); - } - } - zeroNetUrl = ''; - uiStore.setZeroNetStatus(ZeroNetStatus.NOT_RUNNING); - } -} - -runZeroNetWs({String address}) { - var zeroNetUrlL = zeroNetUrl.isNotEmpty ? zeroNetUrl : defZeroNetUrl; - zeroNetUrl = zeroNetUrlL; - if (varStore.zeroNetWrapperKey.isEmpty) { - ZeroNet.instance - .getWrapperKey( - zeroNetUrl + Utils.urlHello, - override: true, - ) - .then((value) { - if (value != null) { - // ZeroNet.wrapperKey = value; - varStore.zeroNetWrapperKey = value; - browserUrl = zeroNetUrl; - ZeroNet.instance.connect( - // zeroNetIPwithPort(defZeroNetUrl), - address ?? Utils.urlHello, - override: true, - ); - } - }); - } else { - // ZeroNet.wrapperKey = varStore.zeroNetWrapperKey; - browserUrl = zeroNetUrl; - } -} - -restartZeroNet() { - ZeroNet.instance.shutDown(); - service.sendData({'cmd': 'runZeroNet'}); -} - writeZeroNetConf(String str) { File f = File(zeroNetDir + '/zeronet.conf'); if (f.existsSync()) { diff --git a/lib/widgets/about_page.dart b/lib/widgets/about_page.dart index e04225b..58db49e 100644 --- a/lib/widgets/about_page.dart +++ b/lib/widgets/about_page.dart @@ -140,39 +140,44 @@ class DonationWidget extends StatelessWidget { builder: (ctx, cons) { List children = []; for (var crypto in donationsAddressMap.keys) { - children.add( - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - crypto, - style: GoogleFonts.roboto( - fontSize: 16.0, + var enabled = true; + if (crypto == 'Liberapay') { + if (!enableExternalDonations) enabled = false; + } + if (enabled) + children.add( + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + crypto, + style: GoogleFonts.roboto( + fontSize: 16.0, + ), ), - ), - ClickableTextWidget( - text: donationsAddressMap[crypto], - textStyle: GoogleFonts.roboto( - fontSize: 15.0, - fontWeight: FontWeight.w500, - height: 1.5, - color: Color(0xFF8663FF), - decoration: TextDecoration.underline, + ClickableTextWidget( + text: donationsAddressMap[crypto], + textStyle: GoogleFonts.roboto( + fontSize: 15.0, + fontWeight: FontWeight.w500, + height: 1.5, + color: Color(0xFF8663FF), + decoration: TextDecoration.underline, + ), + onClick: () { + FlutterClipboard.copy(donationsAddressMap[crypto]); + Get.showSnackbar(GetBar( + message: + '$crypto Donation Address Copied to Clipboard', + )); + }, ), - onClick: () { - FlutterClipboard.copy(donationsAddressMap[crypto]); - Get.showSnackbar(GetBar( - message: - '$crypto Donation Address Copied to Clipboard', - )); - }, - ), - Padding( - padding: const EdgeInsets.all(6.0), - ) - ], - ), - ); + Padding( + padding: const EdgeInsets.all(6.0), + ) + ], + ), + ); } return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/widgets/settings_page.dart b/lib/widgets/settings_page.dart index 3bb2689..abab506 100644 --- a/lib/widgets/settings_page.dart +++ b/lib/widgets/settings_page.dart @@ -175,7 +175,7 @@ class SettingsCard extends StatelessWidget { if (setting is MapSetting) Obx(() { var i = uiStore.reload.value; - printOut(i); + printOut(i.toString()); List children = []; var settingL = setting as MapSetting; settingL.options.forEach((element) { diff --git a/version.properties b/version.properties index 55411fd..ec7e46e 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ -flutter.versionName=v 0.8.1 - beta 2 -flutter.versionCode=51 +flutter.versionName=v 0.8.1 - beta 3 +flutter.versionCode=53