diff --git a/cyberwow/android/app/src/main/AndroidManifest.xml b/cyberwow/android/app/src/main/AndroidManifest.xml index 846544e..2227897 100644 --- a/cyberwow/android/app/src/main/AndroidManifest.xml +++ b/cyberwow/android/app/src/main/AndroidManifest.xml @@ -1,11 +1,6 @@ - - - - - + + + + + + + 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 + } + } } } diff --git a/cyberwow/lib/controller/process/run.dart b/cyberwow/lib/controller/process/run.dart index c0072bc..0733e55 100644 --- a/cyberwow/lib/controller/process/run.dart +++ b/cyberwow/lib/controller/process/run.dart @@ -37,6 +37,7 @@ Stream runBinary final String name, { final Stream input, final ShouldExit shouldExit, + final List userArgs = const [], } ) async* { final newPath = await getBinaryPath(name); @@ -61,7 +62,7 @@ Stream runBinary [ "--data-dir", binDir.path, - ] + extraArgs + config.c.extraArgs; + ] + extraArgs + config.c.extraArgs + userArgs; log.info('args: ' + args.toString()); diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index 08f36b4..a6a88fb 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -69,6 +69,7 @@ class CyberWOW_Page extends StatefulWidget { class _CyberWOW_PageState extends State 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 with WidgetsBindingObserv final StreamController inputStreamController = StreamController(); + Future 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 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 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);