fastercwtch #347

Merged
sarah merged 3 commits from fastercwtch into gherkin 2022-01-31 22:40:18 +00:00
3 changed files with 41 additions and 2 deletions
Showing only changes of commit e44599f33e - Show all commits

View File

@ -51,14 +51,21 @@ class Flwtch extends StatefulWidget {
}
}
class FlwtchState extends State<Flwtch> with WindowListener {
class FlwtchState extends State<Flwtch> with WindowListener, WidgetsBindingObserver {
final TextStyle biggerFont = const TextStyle(fontSize: 18);
late Cwtch cwtch;
late ProfileListState profs;
final MethodChannel notificationClickChannel = MethodChannel('im.cwtch.flwtch/notificationClickHandler');
final MethodChannel shutdownMethodChannel = MethodChannel('im.cwtch.flwtch/shutdownClickHandler');
final MethodChannel shutdownLinuxMethodChannel = MethodChannel('im.cwtch.linux.shutdown');
final GlobalKey<NavigatorState> navKey = GlobalKey<NavigatorState>();
Future<dynamic> shutdownDirect(MethodCall call) {
print(call);
cwtch.Shutdown();
return Future.value({});
}
@override
initState() {
print("initState: running...");
@ -69,6 +76,7 @@ class FlwtchState extends State<Flwtch> with WindowListener {
profs = ProfileListState();
notificationClickChannel.setMethodCallHandler(_externalNotificationClicked);
shutdownMethodChannel.setMethodCallHandler(modalShutdown);
shutdownLinuxMethodChannel.setMethodCallHandler(shutdownDirect);
print("initState: creating cwtchnotifier, ffi");
if (Platform.isAndroid) {
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState, globalServersList);
@ -178,6 +186,7 @@ class FlwtchState extends State<Flwtch> with WindowListener {
// coder beware: args["RemotePeer"] is actually a handle, and could be eg a groupID
Future<void> _externalNotificationClicked(MethodCall call) async {
var args = jsonDecode(call.arguments);
var profile = profs.getProfile(args["ProfileOnion"])!;
var convo = profile.contactList.getContact(args["Handle"])!;
Provider.of<AppState>(navKey.currentContext!, listen: false).initialScrollIndex = convo.unreadMessages;
@ -222,6 +231,7 @@ class FlwtchState extends State<Flwtch> with WindowListener {
globalAppState.focus = false;
}
@override
void dispose() {
cwtch.Shutdown();

View File

@ -21,6 +21,8 @@ struct _MyApplication {
char** dart_entrypoint_arguments;
};
FlMethodChannel* channel;
// Redefining from flutter/engine::shell/platform/linux/fl_dart_project.cc
// struct def required here to enable compiler to allow access to variables
struct _FlDartProject {
@ -35,6 +37,19 @@ struct _FlDartProject {
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
#include <dlfcn.h>
gboolean
on_shutdown(GtkWidget *widget, GdkEvent *event, gpointer data)
{
fl_method_channel_invoke_method(channel, "onWindowClose",
nullptr, nullptr, nullptr, nullptr);
return TRUE;
}
// Implements GApplication::activate.
static void my_application_activate(GApplication* application) {
MyApplication* self = MY_APPLICATION(application);
@ -72,6 +87,9 @@ static void my_application_activate(GApplication* application) {
gtk_window_set_default_size(window, 1280, 720);
gtk_widget_show(GTK_WIDGET(window));
g_signal_connect(G_OBJECT(window),
"destroy", G_CALLBACK(on_shutdown), NULL);
g_autoptr(FlDartProject) project = fl_dart_project_new();
// Check if assets folder is relative to the executable or if we can use a system copy
@ -113,11 +131,22 @@ static void my_application_activate(GApplication* application) {
gtk_widget_show(GTK_WIDGET(view));
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
// Create a specific channel for shutting down cwtch when the close button is triggered
// We have registered the "destroy" handle above for this reason
FlEngine *engine = fl_view_get_engine(view);
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
g_autoptr(FlBinaryMessenger) messenger = fl_engine_get_binary_messenger(engine);
channel =
fl_method_channel_new(messenger,
"im.cwtch.linux.shutdown", FL_METHOD_CODEC(codec));
gtk_widget_grab_focus(GTK_WIDGET(view));
}
// Implements GApplication::local_command_line.
static gboolean my_application_local_command_line(GApplication* application, gchar ***arguments, int *exit_status) {
MyApplication* self = MY_APPLICATION(application);