mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 06:20:48 +08:00
[mac] message passing, quit
This commit is contained in:
parent
84622b829c
commit
450eb2e7ae
@ -28,4 +28,6 @@ void UnFullscreen(WailsContext *ctx);
|
||||
void Minimise(WailsContext *ctx);
|
||||
void UnMinimise(WailsContext *ctx);
|
||||
|
||||
void Quit(void*);
|
||||
|
||||
#endif /* Application_h */
|
||||
|
@ -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 <Foundation/Foundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#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");
|
||||
}
|
||||
//
|
||||
|
@ -8,13 +8,14 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#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;
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
24
v2/internal/frontend/desktop/darwin/message.h
Normal file
24
v2/internal/frontend/desktop/darwin/message.h
Normal file
@ -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 */
|
@ -82,3 +82,7 @@ func (w *Window) Run() {
|
||||
C.Run(w.context)
|
||||
println("I exited!")
|
||||
}
|
||||
|
||||
func (w *Window) Quit() {
|
||||
C.Quit(w.context)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user