From 29ffeaa9f39f13afec5b9a8be1b5db2d0a40dffa Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Thu, 14 Jan 2021 13:55:20 +1100 Subject: [PATCH] Misc tidy up --- v2/internal/app/desktop.go | 20 +++++------ v2/internal/ffenestri/ffenestri_darwin.c | 16 +++++---- v2/internal/runtime/system.go | 1 + v2/internal/subsystem/runtime.go | 45 ++++++++++++++++++++---- 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/v2/internal/app/desktop.go b/v2/internal/app/desktop.go index 6b2337596..35c7f6b2f 100644 --- a/v2/internal/app/desktop.go +++ b/v2/internal/app/desktop.go @@ -45,8 +45,8 @@ type App struct { appconfigStore *runtime.Store // Startup/Shutdown - startup func(*runtime.Runtime) - shutdown func() + startupCallback func(*runtime.Runtime) + shutdownCallback func() } // Create App @@ -80,13 +80,13 @@ func CreateApp(appoptions *options.App) (*App, error) { window := ffenestri.NewApplicationWithConfig(appoptions, myLogger, menuManager) result := &App{ - window: window, - servicebus: servicebus.New(myLogger), - logger: myLogger, - bindings: binding.NewBindings(myLogger), - menuManager: menuManager, - startup: appoptions.Startup, - shutdown: appoptions.Shutdown, + window: window, + servicebus: servicebus.New(myLogger), + logger: myLogger, + bindings: binding.NewBindings(myLogger), + menuManager: menuManager, + startupCallback: appoptions.Startup, + shutdownCallback: appoptions.Shutdown, } result.options = appoptions @@ -118,7 +118,7 @@ func (a *App) Run() error { return err } - runtimesubsystem, err := subsystem.NewRuntime(a.servicebus, a.logger) + runtimesubsystem, err := subsystem.NewRuntime(a.servicebus, a.logger, a.startupCallback, a.shutdownCallback) if err != nil { return err } diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 5367032ec..dc2e9e3cd 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -21,10 +21,6 @@ int debug; // A cache for all our dialog icons struct hashmap_s dialogIconCache; -// Context menu data is given by the frontend when clicking a context menu. -// We send this to the backend when an item is selected; -const char *contextMenuData; - // Dispatch Method typedef void (^dispatchMethod)(void); @@ -255,6 +251,10 @@ void messageHandler(id self, SEL cmd, id contentController, id message) { // TODO: Check this actually does reduce flicker msg(app->config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str("suppressesIncrementalRendering")); + + // Notify backend we are ready (system startup) + app->sendMessageToBackend("SS"); + } else if( strcmp(name, "windowDrag") == 0 ) { // Guard against null events if( app->mouseEvent != NULL ) { @@ -633,6 +633,8 @@ extern void MessageDialog(struct Application *app, char *callbackID, char *type, dialogIcon = icon; } + // TODO: move dialog icons + methods to own file + // Determine what dialog icon we are looking for id dialogImage = NULL; // Look for `name-theme2x` first @@ -1501,6 +1503,9 @@ void Run(struct Application *app, int argc, char **argv) { makeWindowBackgroundTranslucent(app); } + // We set it to be invisible by default. It will become visible when everything has initialised + msg(app->mainWindow, s("setIsVisible:"), NO); + // Setup webview id config = msg(c("WKWebViewConfiguration"), s("new")); msg(config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 1), str("suppressesIncrementalRendering")); @@ -1651,9 +1656,6 @@ void Run(struct Application *app, int argc, char **argv) { // Process dialog icons processUserDialogIcons(app); - // We set it to be invisible by default. It will become visible when everything has initialised - msg(app->mainWindow, s("setIsVisible:"), NO); - // Finally call run Debug(app, "Run called"); msg(app->application, s("run")); diff --git a/v2/internal/runtime/system.go b/v2/internal/runtime/system.go index 3bb97dc33..681e0472b 100644 --- a/v2/internal/runtime/system.go +++ b/v2/internal/runtime/system.go @@ -44,6 +44,7 @@ func (r *system) IsDarkMode() bool { systemResponseChannel, err := r.bus.Subscribe(responseTopic) if err != nil { fmt.Printf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error()) + return false } message := "system:isdarkmode:" + uniqueCallback diff --git a/v2/internal/subsystem/runtime.go b/v2/internal/subsystem/runtime.go index 1d9907283..bd55021d0 100644 --- a/v2/internal/subsystem/runtime.go +++ b/v2/internal/subsystem/runtime.go @@ -14,7 +14,13 @@ import ( type Runtime struct { quitChannel <-chan *servicebus.Message runtimeChannel <-chan *servicebus.Message - running bool + + // The hooks channel allows us to hook into frontend startup + hooksChannel <-chan *servicebus.Message + startupCallback func(*runtime.Runtime) + shutdownCallback func() + + running bool logger logger.CustomLogger @@ -23,7 +29,7 @@ type Runtime struct { } // NewRuntime creates a new runtime subsystem -func NewRuntime(bus *servicebus.ServiceBus, logger *logger.Logger) (*Runtime, error) { +func NewRuntime(bus *servicebus.ServiceBus, logger *logger.Logger, startupCallback func(*runtime.Runtime), shutdownCallback func()) (*Runtime, error) { // Register quit channel quitChannel, err := bus.Subscribe("quit") @@ -37,11 +43,20 @@ func NewRuntime(bus *servicebus.ServiceBus, logger *logger.Logger) (*Runtime, er return nil, err } + // Subscribe to log messages + hooksChannel, err := bus.Subscribe("hooks:") + if err != nil { + return nil, err + } + result := &Runtime{ - quitChannel: quitChannel, - runtimeChannel: runtimeChannel, - logger: logger.CustomLogger("Runtime Subsystem"), - runtime: runtime.New(bus), + quitChannel: quitChannel, + runtimeChannel: runtimeChannel, + hooksChannel: hooksChannel, + logger: logger.CustomLogger("Runtime Subsystem"), + runtime: runtime.New(bus), + startupCallback: startupCallback, + shutdownCallback: shutdownCallback, } return result, nil @@ -59,6 +74,21 @@ func (r *Runtime) Start() error { case <-r.quitChannel: r.running = false break + case hooksMessage := <-r.hooksChannel: + r.logger.Trace(fmt.Sprintf("Received hooksmessage: %+v", hooksMessage)) + messageSlice := strings.Split(hooksMessage.Topic(), ":") + hook := messageSlice[1] + switch hook { + case "startup": + if r.startupCallback != nil { + go r.startupCallback(r.runtime) + } else { + r.logger.Error("no startup callback registered!") + } + default: + r.logger.Error("unknown hook message: %+v", hooksMessage) + continue + } case runtimeMessage := <-r.runtimeChannel: r.logger.Trace(fmt.Sprintf("Received message: %+v", runtimeMessage)) // Topics have the format: "runtime:category:call" @@ -99,6 +129,9 @@ func (r *Runtime) GoRuntime() *runtime.Runtime { } func (r *Runtime) shutdown() { + if r.shutdownCallback != nil { + go r.shutdownCallback() + } r.logger.Trace("Shutdown") }