From 18e7f5cccd0e2d490d115ae4b0adfeddb0f8899e Mon Sep 17 00:00:00 2001 From: erinn Date: Tue, 23 Mar 2021 15:42:10 -0700 Subject: [PATCH] fixing warnings --- lib/cwtch/cwtch.dart | 14 ++++++++++ lib/cwtch/cwtchNotifier.dart | 3 --- lib/cwtch/ffi.dart | 27 +++++++++++++++----- lib/cwtch/gomobile.dart | 16 +++++++++++- lib/main.dart | 8 +++++- lib/model.dart | 6 +++++ lib/views/globalsettingsview.dart | 1 - lib/views/messageview.dart | 8 +++--- lib/views/peersettingsview.dart | 3 --- linux/flutter/generated_plugin_registrant.cc | 2 ++ linux/flutter/generated_plugin_registrant.h | 2 ++ 11 files changed, 72 insertions(+), 18 deletions(-) diff --git a/lib/cwtch/cwtch.dart b/lib/cwtch/cwtch.dart index d5ab130..3bcb2e6 100644 --- a/lib/cwtch/cwtch.dart +++ b/lib/cwtch/cwtch.dart @@ -1,18 +1,32 @@ abstract class Cwtch { + // ignore: non_constant_identifier_names Future Start(); + // ignore: non_constant_identifier_names void SelectProfile(String onion); + // ignore: non_constant_identifier_names void CreateProfile(String nick, String pass); + // ignore: non_constant_identifier_names void LoadProfiles(String pass); + // ignore: non_constant_identifier_names void SendProfileEvent(String onion, String jsonEvent); + // ignore: non_constant_identifier_names void SendAppEvent(String jsonEvent); + // ignore: non_constant_identifier_names Future ACNEvents(); + // ignore: non_constant_identifier_names Future ContactEvents(); + // ignore: non_constant_identifier_names Future GetProfiles(); + // ignore: non_constant_identifier_names Future NumMessages(String profile, String handle); + // ignore: non_constant_identifier_names Future GetMessage(String profile, String handle, int index); + // ignore: non_constant_identifier_names Future GetMessages(String profile, String handle, int start, int end); + + void dispose(); } diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 9291733..47b5ad0 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -1,8 +1,5 @@ import 'dart:convert'; -import 'package:provider/provider.dart'; -import 'package:provider/provider.dart'; - import '../model.dart'; import '../settings.dart'; diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 374499f..66380d8 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -2,14 +2,12 @@ import 'dart:convert'; import 'dart:ffi'; import 'dart:io'; import 'dart:isolate'; -import 'package:flutter/rendering.dart'; import 'package:flutter_app/cwtch/cwtchNotifier.dart'; import 'package:path/path.dart' as path; import 'package:ffi/ffi.dart'; import 'package:flutter_app/cwtch/cwtch.dart'; -import '../model.dart'; ///////////////////// /// Cwtch API /// @@ -55,12 +53,14 @@ class CwtchFfi implements Cwtch { DynamicLibrary library; CwtchNotifier cwtchNotifier; Isolate cwtchIsolate; + ReceivePort rp; CwtchFfi(CwtchNotifier _cwtchNotifier) { library = DynamicLibrary.open("libCwtch.so"); cwtchNotifier = _cwtchNotifier; } + // ignore: non_constant_identifier_names Future Start() async { String home = ""; Map envVars = Platform.environment; @@ -80,9 +80,10 @@ class CwtchFfi implements Cwtch { StartCwtch(ut8CwtchDir, ut8CwtchDir.length, "".toNativeUtf8(), 0); // Spawn an isolate to listen to events from libcwtch-go and then dispatch them when received on main thread to cwtchNotifier - var _receivePort = ReceivePort(); - cwtchIsolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort); - _receivePort.listen((message) { + //var _receivePort = ReceivePort(); + rp = ReceivePort(); + cwtchIsolate = await Isolate.spawn(_checkAppbusEvents, rp.sendPort);//_receivePort.sendPort); + /*_receivePort*/rp.listen((message) { var env = jsonDecode(message); cwtchNotifier.handleMessage(env["EventType"], env["Data"]); }); @@ -91,8 +92,12 @@ class CwtchFfi implements Cwtch { // Called on object being disposed to (presumably on app close) to close the isolate that's listening to libcwtch-go events @override void dispose() { + if (rp != null) { + rp.close(); + } + if (cwtchIsolate != null) { - cwtchIsolate.kill(); + cwtchIsolate.kill(priority: Isolate.immediate); } } @@ -100,6 +105,7 @@ class CwtchFfi implements Cwtch { static void _checkAppbusEvents(SendPort sendPort) async { var stream = pollAppbusEvents(); await for (var value in stream) { + print("_checkAppbusEvent: " + value); sendPort.send(value); } } @@ -108,6 +114,7 @@ class CwtchFfi implements Cwtch { static Stream pollAppbusEvents() async* { var library = DynamicLibrary.open("libCwtch.so"); var getAppbusEventC = library.lookup>("c_GetAppBusEvent"); + // ignore: non_constant_identifier_names final GetAppbusEvent = getAppbusEventC.asFunction(); while (true) { @@ -145,6 +152,7 @@ class CwtchFfi implements Cwtch { LoadProfiles(ut8pass, ut8pass.length); } + // ignore: non_constant_identifier_names Future ACNEvents() async { var acnEventsC = library.lookup>("c_ACNEvents"); // ignore: non_constant_identifier_names @@ -155,6 +163,7 @@ class CwtchFfi implements Cwtch { return event; } + // ignore: non_constant_identifier_names Future ContactEvents() async { var acnEventsC = library.lookup>("c_ContactEvents"); // ignore: non_constant_identifier_names @@ -165,6 +174,7 @@ class CwtchFfi implements Cwtch { return event; } + // ignore: non_constant_identifier_names Future GetProfiles() async { var getProfilesC = library.lookup>("c_GetProfiles"); // ignore: non_constant_identifier_names @@ -175,6 +185,7 @@ class CwtchFfi implements Cwtch { return jsonProfiles; } + // ignore: non_constant_identifier_names Future NumMessages(String profile, String handle) async { var numMessagesC = library.lookup>("c_NumMessages"); // ignore: non_constant_identifier_names @@ -185,6 +196,7 @@ class CwtchFfi implements Cwtch { return num; } + // ignore: non_constant_identifier_names Future GetMessage(String profile, String handle, int index) async { var getMessageC = library.lookup>("c_GetMessage"); // ignore: non_constant_identifier_names @@ -196,6 +208,7 @@ class CwtchFfi implements Cwtch { return jsonMessage; } + // ignore: non_constant_identifier_names Future GetMessages(String profile, String handle, int start, int end) async { var getMessagesC = library.lookup>("c_GetMessages"); // ignore: non_constant_identifier_names @@ -208,6 +221,7 @@ class CwtchFfi implements Cwtch { } @override + // ignore: non_constant_identifier_names void SendProfileEvent(String onion, String json) { var sendAppBusEvent = library.lookup>("c_SendProfileEvent"); // ignore: non_constant_identifier_names @@ -218,6 +232,7 @@ class CwtchFfi implements Cwtch { } @override + // ignore: non_constant_identifier_names void SendAppEvent(String json) { var sendAppBusEvent = library.lookup>("c_SendAppEvent"); // ignore: non_constant_identifier_names diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index 5403a47..ed7b616 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -2,7 +2,6 @@ import 'dart:convert'; import 'dart:io'; import 'package:flutter/services.dart'; -import 'package:flutter_app/model.dart'; import 'package:path_provider/path_provider.dart'; import 'dart:async'; import 'package:path/path.dart' as path; @@ -42,6 +41,7 @@ class CwtchGomobile implements Cwtch { appbusEventChannel.setMethodCallHandler(this._handleAppbusEvent); } + // ignore: non_constant_identifier_names Future Start() async { print("gomobile.dart: Start()..."); var cwtchDir = path.join((await androidHomeDirectory).path, ".cwtch/dev/"); @@ -57,51 +57,65 @@ class CwtchGomobile implements Cwtch { cwtchNotifier.handleMessage(call.method, obj); } + // ignore: non_constant_identifier_names void SelectProfile(String onion) { cwtchPlatform.invokeMethod("SelectProfile", {"profile": onion}); } + // ignore: non_constant_identifier_names void CreateProfile(String nick, String pass) { cwtchPlatform.invokeMethod("CreateProfile", {"nick": nick, "pass": pass}); } + // ignore: non_constant_identifier_names void LoadProfiles(String pass) { cwtchPlatform.invokeMethod("LoadProfiles", {"pass": pass}); } + // ignore: non_constant_identifier_names Future ACNEvents() { return cwtchPlatform.invokeMethod("ACNEvents"); } + // ignore: non_constant_identifier_names Future ContactEvents() { return cwtchPlatform.invokeMethod("ContactEvents"); } + // ignore: non_constant_identifier_names Future GetProfiles() { print("gomobile.dart: GetProfiles()"); return cwtchPlatform.invokeMethod("GetProfiles"); } + // ignore: non_constant_identifier_names Future NumMessages(String profile, String handle) { return cwtchPlatform.invokeMethod("NumMessages", {"profile": profile, "contact": handle}); } + // ignore: non_constant_identifier_names Future GetMessage(String profile, String handle, int index) { print("gomobile.dart GetMessage " + index.toString()); return cwtchPlatform.invokeMethod("GetMessage", {"profile": profile, "contact": handle, "index": index}); } + // ignore: non_constant_identifier_names Future GetMessages(String profile, String handle, int start, int end) { return cwtchPlatform.invokeMethod("GetMessage", {"profile": profile, "contact": handle, "start": start, "end": end}); } @override + // ignore: non_constant_identifier_names void SendProfileEvent(String onion, String jsonEvent) { cwtchPlatform.invokeMethod("SendProfileEvent", {"onion": onion, "jsonEvent": jsonEvent}); } @override + // ignore: non_constant_identifier_names void SendAppEvent(String jsonEvent) { cwtchPlatform.invokeMethod("SendAppEvent", {"jsonEvent": jsonEvent}); } + + @override + void dispose() => {}; } diff --git a/lib/main.dart b/lib/main.dart index 05d2bfd..f47fdd3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -69,7 +69,7 @@ class FlwtchState extends State { @override Widget build(BuildContext context) { - appStatus = AppModel(cwtch: cwtch); + //appStatus = AppModel(cwtch: cwtch); return MultiProvider( providers: [getFlwtchStateProvider(), getProfileListProvider(), getSettingsProvider()], @@ -127,4 +127,10 @@ class FlwtchState extends State { }, ); } + + @override + void dispose() { + cwtch.dispose(); + super.dispose(); + } } diff --git a/lib/model.dart b/lib/model.dart index a5c54a6..71c7fd4 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -217,6 +217,12 @@ class ContactInfoState extends ChangeNotifier { notifyListeners(); } + get isGroup => this._isGroup; + set isGroup(bool newVal) { + this._isGroup = newVal; + notifyListeners(); + } + get isBlocked => this._isBlocked; set isBlocked(bool newVal) { this._isBlocked = newVal; diff --git a/lib/views/globalsettingsview.dart b/lib/views/globalsettingsview.dart index 6fdcfe5..0a22d1c 100644 --- a/lib/views/globalsettingsview.dart +++ b/lib/views/globalsettingsview.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:io'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:flutter/material.dart'; import 'package:flutter_app/opaque.dart'; diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index f1de90b..66a879d 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -57,7 +57,7 @@ class _MessageViewState extends State { } void _sendMessage() { - ChatMessage cm = new ChatMessage(o: 1, d: ctrlrCompose.value.text); + //ChatMessage cm = new ChatMessage(o: 1, d: ctrlrCompose.value.text); //todo: merge: Provider.of(context).cwtch.SendMessage(widget.profile.onion, widget.conversationHandle, jsonEncode(cm)); ctrlrCompose.clear(); } @@ -81,8 +81,8 @@ class _MessageViewState extends State { onPressed: _sendMessage, ), Row(children: [ - SizedBox(width: 45, child: ElevatedButton(child: Icon(Icons.emoji_emotions_outlined, color: Opaque.current().mainTextColor()))), - SizedBox(width: 45, child: ElevatedButton(child: Icon(Icons.attach_file, color: Opaque.current().mainTextColor()))), + SizedBox(width: 45, child: ElevatedButton(child: Icon(Icons.emoji_emotions_outlined, color: Opaque.current().mainTextColor()), onPressed: placeHolder,)), + SizedBox(width: 45, child: ElevatedButton(child: Icon(Icons.attach_file, color: Opaque.current().mainTextColor()), onPressed: placeHolder,)), ]) ]), ), @@ -90,4 +90,6 @@ class _MessageViewState extends State { ), ); } + + void placeHolder() => {}; } diff --git a/lib/views/peersettingsview.dart b/lib/views/peersettingsview.dart index bc34fb1..9ad5543 100644 --- a/lib/views/peersettingsview.dart +++ b/lib/views/peersettingsview.dart @@ -1,12 +1,9 @@ import 'dart:convert'; -import 'dart:io'; import 'package:flutter/services.dart'; import 'package:flutter_app/model.dart'; import 'package:flutter_app/widgets/buttontextfield.dart'; import 'package:flutter_app/widgets/cwtchlabel.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_app/opaque.dart'; import 'package:flutter_app/settings.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index d38195a..e71a16d 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #include "generated_plugin_registrant.h" diff --git a/linux/flutter/generated_plugin_registrant.h b/linux/flutter/generated_plugin_registrant.h index 9bf7478..e0f0a47 100644 --- a/linux/flutter/generated_plugin_registrant.h +++ b/linux/flutter/generated_plugin_registrant.h @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #ifndef GENERATED_PLUGIN_REGISTRANT_ #define GENERATED_PLUGIN_REGISTRANT_