mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 05:30:52 +08:00
Mac support
This commit is contained in:
parent
547e30f025
commit
276a1a22a5
@ -10,6 +10,8 @@ package application
|
||||
#include "application_darwin.h"
|
||||
#include "application_darwin_delegate.h"
|
||||
#include "webview_window_darwin.h"
|
||||
#include "custom_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
extern void registerListener(unsigned int event);
|
||||
@ -177,6 +179,8 @@ import (
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
)
|
||||
|
||||
var openUrlBuffer = make(chan string, 100)
|
||||
|
||||
type macosApp struct {
|
||||
applicationMenu unsafe.Pointer
|
||||
parent *App
|
||||
@ -229,6 +233,9 @@ func (m *macosApp) setApplicationMenu(menu *Menu) {
|
||||
}
|
||||
|
||||
func (m *macosApp) run() error {
|
||||
|
||||
C.StartCustomProtocolHandler()
|
||||
|
||||
if m.parent.options.SingleInstance != nil {
|
||||
cUniqueID := C.CString(m.parent.options.SingleInstance.UniqueID)
|
||||
defer C.free(unsafe.Pointer(cUniqueID))
|
||||
@ -262,9 +269,25 @@ func (m *macosApp) GetFlags(options Options) map[string]any {
|
||||
|
||||
func newPlatformApp(app *App) *macosApp {
|
||||
C.init()
|
||||
return &macosApp{
|
||||
result := &macosApp{
|
||||
parent: app,
|
||||
}
|
||||
go result.startUrlOpenProcessor()
|
||||
return result
|
||||
}
|
||||
|
||||
func (m *macosApp) startUrlOpenProcessor() {
|
||||
for url := range openUrlBuffer {
|
||||
if m.parent.options.Mac.OnUrlOpen != nil {
|
||||
m.parent.options.Mac.OnUrlOpen(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//export HandleCustomProtocol
|
||||
func HandleCustomProtocol(url *C.char) {
|
||||
goUrl := C.GoString(url)
|
||||
openUrlBuffer <- goUrl
|
||||
}
|
||||
|
||||
//export processApplicationEvent
|
||||
|
14
v3/pkg/application/custom_protocol.h
Normal file
14
v3/pkg/application/custom_protocol.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef CustomProtocol_h
|
||||
#define CustomProtocol_h
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
extern void HandleCustomProtocol(char*);
|
||||
|
||||
@interface CustomProtocolSchemeHandler : NSObject
|
||||
+ (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
|
||||
@end
|
||||
|
||||
void StartCustomProtocolHandler(void);
|
||||
|
||||
#endif /* CustomProtocol_h */
|
20
v3/pkg/application/custom_protocol.m
Normal file
20
v3/pkg/application/custom_protocol.m
Normal file
@ -0,0 +1,20 @@
|
||||
#include "CustomProtocol.h"
|
||||
|
||||
@implementation CustomProtocolSchemeHandler
|
||||
+ (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
|
||||
[event paramDescriptorForKeyword:keyDirectObject];
|
||||
|
||||
NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
|
||||
|
||||
HandleCustomProtocol((char*)[[[event paramDescriptorForKeyword:keyDirectObject] stringValue] UTF8String]);
|
||||
}
|
||||
@end
|
||||
|
||||
void StartCustomProtocolHandler(void) {
|
||||
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
|
||||
|
||||
[appleEventManager setEventHandler:[CustomProtocolSchemeHandler class]
|
||||
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
|
||||
forEventClass:kInternetEventClass
|
||||
andEventID: kAEGetURL];
|
||||
}
|
Loading…
Reference in New Issue
Block a user