From d319d51fcd6aa5f556fa92fde8e4c6727fb24235 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 26 Sep 2022 20:17:15 +1000 Subject: [PATCH] Refactor darwin app --- v2/internal/frontend/desktop/darwin/Application.h | 2 ++ v2/internal/frontend/desktop/darwin/Application.m | 8 ++++++++ v2/internal/frontend/desktop/darwin/frontend.go | 10 +++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/v2/internal/frontend/desktop/darwin/Application.h b/v2/internal/frontend/desktop/darwin/Application.h index 8a657051b..86138dda1 100644 --- a/v2/internal/frontend/desktop/darwin/Application.h +++ b/v2/internal/frontend/desktop/darwin/Application.h @@ -77,6 +77,8 @@ void SetAbout(void *inctx, const char* title, const char* description, void* ima void* AppendMenuItem(void* inctx, void* nsmenu, const char* label, const char* shortcutKey, int modifiers, int disabled, int checked, int menuItemID); void AppendSeparator(void* inMenu); void UpdateMenuItem(void* nsmenuitem, int checked); +void RunMainLoop(void); +void ReleaseContext(void *inctx); NSString* safeInit(const char* input); diff --git a/v2/internal/frontend/desktop/darwin/Application.m b/v2/internal/frontend/desktop/darwin/Application.m index 43ba0545d..9ee3144ab 100644 --- a/v2/internal/frontend/desktop/darwin/Application.m +++ b/v2/internal/frontend/desktop/darwin/Application.m @@ -462,6 +462,14 @@ void Run(void *inctx, const char* url, int activationPolicy) { [_url release]; [app setMainMenu:ctx.applicationMenu]; +} + +void RunMainLoop(void) { + NSApplication *app = [NSApplication sharedApplication]; [app run]; +} + +void ReleaseContext(void *inctx) { + WailsContext *ctx = (__bridge WailsContext*) inctx; [ctx release]; } diff --git a/v2/internal/frontend/desktop/darwin/frontend.go b/v2/internal/frontend/desktop/darwin/frontend.go index 0bcad23bd..8fce1967c 100644 --- a/v2/internal/frontend/desktop/darwin/frontend.go +++ b/v2/internal/frontend/desktop/darwin/frontend.go @@ -74,6 +74,14 @@ type Frontend struct { trayMenusBuffer []*menu.TrayMenu } +func (f *Frontend) RunMainLoop() { + C.RunMainLoop() +} + +func (f *Frontend) WindowClose() { + C.ReleaseContext(f.mainWindow.context) +} + func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend { result := &Frontend{ frontendOptions: appoptions, @@ -99,7 +107,7 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger. } else { appBindings.DB().UpdateObfuscatedCallMap() } - assets, err := assetserver.NewAssetServer(ctx, appoptions, bindings) + assets, err := assetserver.NewAssetServer(ctx, appoptions.Assets, appoptions.AssetsHandler, bindings) if err != nil { log.Fatal(err) }