add support of custom start up args

pull/5/head
fuwa 4 years ago
parent 465ada7c11
commit 2876d88397

@ -1,11 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.wownero.cyberwow">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="CyberWOW"
@ -17,17 +12,16 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<!-- <meta-data -->
<!-- android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" -->
<!-- android:value="true" /> -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<meta-data

@ -1,12 +1,64 @@
package org.wownero.cyberwow
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugin.common.ActivityLifecycleListener
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import android.content.Intent
import android.os.Bundle
import android.util.Log
class MainActivity: FlutterActivity() {
private val CHANNEL = "send-intent"
private var initialIntentText:String = ""
private var initialIntentSet = false
private var _channel: MethodChannel? = null;
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
val channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL);
_channel = channel;
channel.setMethodCallHandler{
call, result ->
if (call.method == "getInitialIntent") {
result.success(initialIntentText)
} else {
result.notImplemented()
}
}
val intent = getIntent()
checkIntent(intent)
initialIntentSet = true
}
internal fun handleSendText(intent:Intent) {
val text:String = intent.getStringExtra(Intent.EXTRA_TEXT)
if (initialIntentSet == false) {
initialIntentText = text
}
}
internal fun checkIntent(intent: Intent) {
val _action = intent.getAction()
// Log.i("Main", "action: " + action)
if (Intent.ACTION_SEND.equals(_action)) {
val _type = intent.getType()
// Log.i("Main", "type: " + type)
if (_type == "text/plain") {
handleSendText(intent) // Handle text being sent
}
}
}
}

@ -37,6 +37,7 @@ Stream<String> runBinary
final String name,
{ final Stream<String> input,
final ShouldExit shouldExit,
final List<String> userArgs = const [],
}
) async* {
final newPath = await getBinaryPath(name);
@ -61,7 +62,7 @@ Stream<String> runBinary
[
"--data-dir",
binDir.path,
] + extraArgs + config.c.extraArgs;
] + extraArgs + config.c.extraArgs + userArgs;
log.info('args: ' + args.toString());

@ -69,6 +69,7 @@ class CyberWOW_Page extends StatefulWidget {
class _CyberWOW_PageState extends State<CyberWOW_Page> with WidgetsBindingObserver
{
// AppState _state = LoadingState("init...");
static const _channel = const MethodChannel('send-intent');
state.AppState _state;
AppLifecycleState _notification = AppLifecycleState.resumed;
@ -77,6 +78,12 @@ class _CyberWOW_PageState extends State<CyberWOW_Page> with WidgetsBindingObserv
final StreamController<String> inputStreamController = StreamController();
Future<String> getInitialIntent() async {
final text = await _channel.invokeMethod('getInitialIntent');
log.fine('getInitialIntent: ${text}');
return text;
}
@override
void didChangeAppLifecycleState(final AppLifecycleState state) {
log.fine('app cycle: ${state}');
@ -112,6 +119,7 @@ class _CyberWOW_PageState extends State<CyberWOW_Page> with WidgetsBindingObserv
final loadingText = config.c.splash;
state.LoadingState _loadingState = await _blankState.next(loadingText);
final binName = config.c.outputBin;
final resourcePath = 'native/output/' + describeEnum(config.arch) + '/' + binName;
final bundle = DefaultAssetBundle.of(context);
@ -119,8 +127,25 @@ class _CyberWOW_PageState extends State<CyberWOW_Page> with WidgetsBindingObserv
state.SyncingState _syncingState = await _loadingState.next(loading);
final _initialIntent = await getInitialIntent();
final _userArgs = _initialIntent
.trim()
.split(RegExp(r"\s+"))
.where((x) => !x.isEmpty)
.toList();
if (!_userArgs.isEmpty) {
log.info('user args: ${_userArgs}');
}
final syncing = process
.runBinary(binName, input: inputStreamController.stream, shouldExit: _isExiting)
.runBinary
(
binName,
input: inputStreamController.stream,
shouldExit: _isExiting,
userArgs: _userArgs,
)
.asBroadcastStream();
await _syncingState.next(inputStreamController.sink, syncing);