diff --git a/v2/internal/frontend/desktop/darwin/Application.h b/v2/internal/frontend/desktop/darwin/Application.h index 705ef98f5..880b25910 100644 --- a/v2/internal/frontend/desktop/darwin/Application.h +++ b/v2/internal/frontend/desktop/darwin/Application.h @@ -28,4 +28,6 @@ void UnFullscreen(WailsContext *ctx); void Minimise(WailsContext *ctx); void UnMinimise(WailsContext *ctx); +void Quit(void*); + #endif /* Application_h */ diff --git a/v2/internal/frontend/desktop/darwin/Application.m b/v2/internal/frontend/desktop/darwin/Application.m index d2dd7d9bc..0f581ed4a 100644 --- a/v2/internal/frontend/desktop/darwin/Application.m +++ b/v2/internal/frontend/desktop/darwin/Application.m @@ -1,17 +1,15 @@ -//// -//// Window.m -//// test -//// -//// Created by Lea Anthony on 10/10/21. -//// // +// Application.m +// +// Created by Lea Anthony on 10/10/21. +// + #import #import #import "WailsContext.h" #import "Application.h" #import "AppDelegate.h" -// -// + WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent) { WailsContext *result = [WailsContext new]; @@ -86,8 +84,14 @@ void UnMinimise(WailsContext *ctx) { ); } +void Quit(void *inctx) { + WailsContext *ctx = (__bridge WailsContext*) inctx; + [NSApp stop:ctx]; +} + + void Run(void *inctx) { - WailsContext *ctx = (WailsContext*) inctx; + WailsContext *ctx = (__bridge WailsContext*) inctx; [NSApplication sharedApplication]; AppDelegate* delegate = [AppDelegate new]; [NSApp setDelegate:(id)delegate]; @@ -98,4 +102,3 @@ void Run(void *inctx) { [ctx release]; NSLog(@"Here"); } -// diff --git a/v2/internal/frontend/desktop/darwin/WindowDelegate.m b/v2/internal/frontend/desktop/darwin/WindowDelegate.m index 3ccd0a327..549413e45 100644 --- a/v2/internal/frontend/desktop/darwin/WindowDelegate.m +++ b/v2/internal/frontend/desktop/darwin/WindowDelegate.m @@ -8,13 +8,14 @@ #import #import #import "WindowDelegate.h" +#import "message.h" @implementation WindowDelegate - (BOOL)windowShouldClose:(NSWindow *)sender { [sender orderOut:nil]; if( self.hideOnClose == false ) { - NSLog(@"send message: WC"); + processMessage("Q"); } return !self.hideOnClose; } diff --git a/v2/internal/frontend/desktop/darwin/frontend.go b/v2/internal/frontend/desktop/darwin/frontend.go index 63d1f5c76..e71af5052 100644 --- a/v2/internal/frontend/desktop/darwin/frontend.go +++ b/v2/internal/frontend/desktop/darwin/frontend.go @@ -3,6 +3,7 @@ package darwin +import "C" import ( "context" "encoding/json" @@ -17,6 +18,8 @@ import ( "github.com/wailsapp/wails/v2/pkg/options" ) +var messageBuffer = make(chan string) + type Frontend struct { // Context @@ -70,9 +73,17 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger. } result.assets = assets + go result.startMessageProcessor(ctx) + return result } +func (f *Frontend) startMessageProcessor(ctx context.Context) { + for message := range messageBuffer { + f.processMessage(message) + } +} + func (f *Frontend) WindowReload() { f.ExecJS("runtime.WindowReload();") } @@ -239,7 +250,7 @@ func (f *Frontend) WindowSetRGBA(col *options.RGBA) { } func (f *Frontend) Quit() { - //winc.Exit() + f.mainWindow.Quit() } /* @@ -421,3 +432,10 @@ func (f *Frontend) ExecJS(js string) { // f.mainWindow.Show() // //} + +//export processMessage +func processMessage(message *C.char) { + goMessage := C.GoString(message) + messageBuffer <- goMessage + println("Message in Go:", goMessage) +} diff --git a/v2/internal/frontend/desktop/darwin/message.h b/v2/internal/frontend/desktop/darwin/message.h new file mode 100644 index 000000000..c98c0e0c7 --- /dev/null +++ b/v2/internal/frontend/desktop/darwin/message.h @@ -0,0 +1,24 @@ +// +// message.h +// test +// +// Created by Lea Anthony on 14/10/21. +// + +#ifndef export_h +#define export_h + + +#ifdef __cplusplus +extern "C" +{ +#endif + +void processMessage(const char *); + +#ifdef __cplusplus +} +#endif + + +#endif /* export_h */ diff --git a/v2/internal/frontend/desktop/darwin/window.go b/v2/internal/frontend/desktop/darwin/window.go index 5252c636a..df9c8dc47 100644 --- a/v2/internal/frontend/desktop/darwin/window.go +++ b/v2/internal/frontend/desktop/darwin/window.go @@ -82,3 +82,7 @@ func (w *Window) Run() { C.Run(w.context) println("I exited!") } + +func (w *Window) Quit() { + C.Quit(w.context) +}