diff --git a/v2/internal/app/desktop.go b/v2/internal/app/desktop.go index 380c9f52..0e76efec 100644 --- a/v2/internal/app/desktop.go +++ b/v2/internal/app/desktop.go @@ -118,7 +118,7 @@ func (a *App) Run() error { ctx, cancel := context.WithCancel(parentContext) // Setup signal handler - signalsubsystem, err := signal.NewManager(ctx, cancel, a.servicebus, a.logger, a.shutdownCallback) + signalsubsystem, err := signal.NewManager(ctx, cancel, a.servicebus, a.logger) if err != nil { return err } @@ -132,7 +132,7 @@ func (a *App) Run() error { return err } - runtimesubsystem, err := subsystem.NewRuntime(ctx, a.servicebus, a.logger, a.startupCallback, a.shutdownCallback) + runtimesubsystem, err := subsystem.NewRuntime(ctx, a.servicebus, a.logger, a.startupCallback) if err != nil { return err } @@ -231,5 +231,10 @@ func (a *App) Run() error { return err } + // Shutdown callback + if a.shutdownCallback != nil { + a.shutdownCallback() + } + return nil } diff --git a/v2/internal/app/dev.go b/v2/internal/app/dev.go index aed58109..48aaf32e 100644 --- a/v2/internal/app/dev.go +++ b/v2/internal/app/dev.go @@ -119,7 +119,7 @@ func (a *App) Run() error { ctx, cancel := context.WithCancel(parentContext) // Setup signal handler - signalsubsystem, err := signal.NewManager(ctx, cancel, a.servicebus, a.logger, a.shutdownCallback) + signalsubsystem, err := signal.NewManager(ctx, cancel, a.servicebus, a.logger) if err != nil { return err } @@ -133,7 +133,7 @@ func (a *App) Run() error { return err } - runtimesubsystem, err := subsystem.NewRuntime(ctx, a.servicebus, a.logger, a.startupCallback, a.shutdownCallback) + runtimesubsystem, err := subsystem.NewRuntime(ctx, a.servicebus, a.logger, a.startupCallback) if err != nil { return err } @@ -235,6 +235,10 @@ func (a *App) Run() error { return err } + // Shutdown callback + if a.shutdownCallback != nil { + a.shutdownCallback() + } return nil } diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index a99109a7..3193ab55 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -1817,10 +1817,9 @@ void Run(struct Application *app, int argc, char **argv) { void Quit(struct Application *app) { Debug(app, "Quit Called"); msg(app->application, s("stop:"), NULL); - ON_MAIN_THREAD ( - // Terminate app by triggering a UI event - SetSize(app, 0, 0); - ); + SetSize(app, 0, 0); + Show(app); + Hide(app); } void* NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen, int startHidden, int logLevel, int hideWindowOnClose) { diff --git a/v2/internal/runtime/runtime.go b/v2/internal/runtime/runtime.go index 9a4b46fa..3330366e 100644 --- a/v2/internal/runtime/runtime.go +++ b/v2/internal/runtime/runtime.go @@ -6,20 +6,19 @@ import ( // Runtime is a means for the user to interact with the application at runtime type Runtime struct { - Browser Browser - Events Events - Window Window - Dialog Dialog - System System - Menu Menu - Store *StoreProvider - Log Log - bus *servicebus.ServiceBus - shutdownCallback func() + Browser Browser + Events Events + Window Window + Dialog Dialog + System System + Menu Menu + Store *StoreProvider + Log Log + bus *servicebus.ServiceBus } // New creates a new runtime -func New(serviceBus *servicebus.ServiceBus, shutdownCallback func()) *Runtime { +func New(serviceBus *servicebus.ServiceBus) *Runtime { result := &Runtime{ Browser: newBrowser(), Events: newEvents(serviceBus), @@ -36,11 +35,6 @@ func New(serviceBus *servicebus.ServiceBus, shutdownCallback func()) *Runtime { // Quit the application func (r *Runtime) Quit() { - // Call back to user's shutdown method if defined - if r.shutdownCallback != nil { - r.shutdownCallback() - } - // Start shutdown of Wails r.bus.Publish("quit", "runtime.Quit()") } diff --git a/v2/internal/signal/signal.go b/v2/internal/signal/signal.go index aa13598a..6d38d89c 100644 --- a/v2/internal/signal/signal.go +++ b/v2/internal/signal/signal.go @@ -26,25 +26,20 @@ type Manager struct { ctx context.Context cancel context.CancelFunc - // The shutdown callback to notify the user's app that a shutdown - // has started - shutdownCallback func() - // Parent waitgroup wg *sync.WaitGroup } // NewManager creates a new signal manager -func NewManager(ctx context.Context, cancel context.CancelFunc, bus *servicebus.ServiceBus, logger *logger.Logger, shutdownCallback func()) (*Manager, error) { +func NewManager(ctx context.Context, cancel context.CancelFunc, bus *servicebus.ServiceBus, logger *logger.Logger) (*Manager, error) { result := &Manager{ - bus: bus, - logger: logger.CustomLogger("Event Manager"), - signalchannel: make(chan os.Signal, 2), - ctx: ctx, - cancel: cancel, - shutdownCallback: shutdownCallback, - wg: ctx.Value("waitgroup").(*sync.WaitGroup), + bus: bus, + logger: logger.CustomLogger("Event Manager"), + signalchannel: make(chan os.Signal, 2), + ctx: ctx, + cancel: cancel, + wg: ctx.Value("waitgroup").(*sync.WaitGroup), } return result, nil @@ -67,11 +62,6 @@ func (m *Manager) Start() { m.logger.Trace("Ctrl+C detected. Shutting down...") m.bus.Publish("quit", "ctrl-c pressed") - // Shutdown app first - if m.shutdownCallback != nil { - m.shutdownCallback() - } - // Start shutdown of Wails m.cancel() diff --git a/v2/internal/subsystem/runtime.go b/v2/internal/subsystem/runtime.go index c42bf5ff..7b44ddb7 100644 --- a/v2/internal/subsystem/runtime.go +++ b/v2/internal/subsystem/runtime.go @@ -37,7 +37,7 @@ type Runtime struct { } // NewRuntime creates a new runtime subsystem -func NewRuntime(ctx context.Context, bus *servicebus.ServiceBus, logger *logger.Logger, startupCallback func(*runtime.Runtime), shutdownCallback func()) (*Runtime, error) { +func NewRuntime(ctx context.Context, bus *servicebus.ServiceBus, logger *logger.Logger, startupCallback func(*runtime.Runtime)) (*Runtime, error) { // Subscribe to log messages runtimeChannel, err := bus.Subscribe("runtime:") @@ -52,13 +52,12 @@ func NewRuntime(ctx context.Context, bus *servicebus.ServiceBus, logger *logger. } result := &Runtime{ - runtimeChannel: runtimeChannel, - hooksChannel: hooksChannel, - logger: logger.CustomLogger("Runtime Subsystem"), - runtime: runtime.New(bus, shutdownCallback), - startupCallback: startupCallback, - shutdownCallback: shutdownCallback, - ctx: ctx, + runtimeChannel: runtimeChannel, + hooksChannel: hooksChannel, + logger: logger.CustomLogger("Runtime Subsystem"), + runtime: runtime.New(bus), + startupCallback: startupCallback, + ctx: ctx, } return result, nil