add splashview (whoops) and gomobile impl for getting appbus events (proof of concepty still)

This commit is contained in:
Dan Ballard 2021-01-20 12:07:22 -08:00
parent 215e77fe63
commit afd8844b8b
5 changed files with 65 additions and 6 deletions

View File

@ -62,4 +62,6 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation project(':cwtch')
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2"
}

View File

@ -1,31 +1,45 @@
package com.example.flutter_app
import io.flutter.embedding.android.FlutterActivity
import androidx.annotation.NonNull
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Looper
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import android.content.pm.PackageManager
import android.util.Log
import cwtch.Cwtch
import io.flutter.plugin.common.EventChannel
import kotlin.concurrent.thread
class MainActivity: FlutterActivity() {
// Channel to get app info
private val CHANNEL_APP_INFO = "test.flutter.dev/applicationInfo"
private val CALL_APP_INFO = "getNativeLibDir"
// Channel to get cwtch api calls on
private val CHANNEL_CWTCH = "cwtch"
// Channel to send eventbus events on
private val CWTCH_EVENTBUS = "test.flutter.dev/eventBus"
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
// Note: this method is invoked on the main thread.
// Note: this methods are invoked on the main thread.
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL_APP_INFO).setMethodCallHandler { call, result -> handleAppInfo(call, result) }
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL_CWTCH).setMethodCallHandler { call, result -> handleCwtch(call, result) }
}
private fun handleAppInfo(@NonNull call: MethodCall, @NonNull result: Result) {
@ -51,6 +65,21 @@ class MainActivity: FlutterActivity() {
val torPath = (call.argument("torPath") as? String) ?: "tor";
Log.i("MainActivity.kt", " appDir: '" + appDir + "' torPath: '" + torPath + "'")
Cwtch.startCwtch(appDir, torPath)
// seperate coroutine to poll event bus and send to dart
val eventbus_chan = MethodChannel(flutterEngine?.dartExecutor?.binaryMessenger, CWTCH_EVENTBUS)
Log.i("MainActivity.kt", "got event chan: " + eventbus_chan + " launching corouting...")
GlobalScope.launch(Dispatchers.IO) {
while(true) {
val jsonEvent = Cwtch.getAppBusEvent()
Log.i("MainActivity.kt", "got appbusEvent: " + jsonEvent)
launch(Dispatchers.Main) {
eventbus_chan.invokeMethod("AppbusEvent", jsonEvent)
}
}
}
}
"SelectProfile" -> {
val onion = (call.argument("profile") as? String) ?: "";

Binary file not shown.

View File

@ -22,6 +22,8 @@ class CwtchGomobile implements Cwtch {
static const appInfoPlatform = const MethodChannel('test.flutter.dev/applicationInfo');
static const cwtchPlatform = const MethodChannel('cwtch');
final appbusEventChannelName = 'test.flutter.dev/eventBus';
Future<String> androidLibraryDir;
Future<Directory> androidHomeDirectory;
@ -29,6 +31,9 @@ class CwtchGomobile implements Cwtch {
print("gomobile.dart: CwtchGomobile()");
androidHomeDirectory = getApplicationDocumentsDirectory();
androidLibraryDir = appInfoPlatform.invokeMethod('getNativeLibDir');
final appbusEventChannel = MethodChannel(appbusEventChannelName);
appbusEventChannel.setMethodCallHandler(this._handleAppbusEvent);
}
Future<void> Start() async {
@ -39,6 +44,11 @@ class CwtchGomobile implements Cwtch {
cwtchPlatform.invokeMethod("Start", {"appDir": cwtchDir, "torPath": torPath});
}
Future<void> _handleAppbusEvent(MethodCall call) async {
final String json = call.arguments;
print("appbus event: ${call.method} $json");
}
void SelectProfile(String onion) {
cwtchPlatform.invokeMethod("SelectProfile", {"profile" : onion});
}

18
lib/views/splashView.dart Normal file
View File

@ -0,0 +1,18 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SplashView extends StatelessWidget {
@override
Widget build(BuildContext context) {
print("SplashView build()");
return Scaffold(
appBar: AppBar( title: Text("Cwtch")),
body: Center(
child: Column(
children: <Widget>[
Text("Loading Cwtch...")
])
),
);
}
}