diff --git a/v3/pkg/application/application_darwin.go b/v3/pkg/application/application_darwin.go index 4a5e28b016c..a698160dde9 100644 --- a/v3/pkg/application/application_darwin.go +++ b/v3/pkg/application/application_darwin.go @@ -141,12 +141,27 @@ static void show(void) { [NSApp unhide:nil]; } +static const char* serializationNSDictionary(void *dict) { + NSDictionary *nsDict = (__bridge NSDictionary *)dict; + + if ([NSJSONSerialization isValidJSONObject:nsDict]) { + NSError *error; + NSData *data = [NSJSONSerialization dataWithJSONObject:nsDict options:kNilOptions error:&error]; + NSString *resultStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; + + return [resultStr UTF8String]; + } + + return nil; +} */ import "C" import ( - "github.com/wailsapp/wails/v3/internal/operatingsystem" + "encoding/json" "unsafe" + "github.com/wailsapp/wails/v3/internal/operatingsystem" + "github.com/wailsapp/wails/v3/internal/assetserver/webview" "github.com/wailsapp/wails/v3/pkg/events" ) @@ -237,8 +252,24 @@ func newPlatformApp(app *App) *macosApp { } //export processApplicationEvent -func processApplicationEvent(eventID C.uint, _ unsafe.Pointer) { +func processApplicationEvent(eventID C.uint, data unsafe.Pointer) { event := newApplicationEvent(int(eventID)) + + if data != nil { + dataCStrJSON := C.serializationNSDictionary(data) + if dataCStrJSON != nil { + dataJSON := C.GoString(dataCStrJSON) + var result map[string]any + err := json.Unmarshal([]byte(dataJSON), &result) + + if err != nil { + panic(err) + } + + event.Context().setData(result) + } + } + switch event.Id { case uint(events.Mac.ApplicationDidChangeTheme): isDark := globalApplication.IsDarkMode() diff --git a/v3/pkg/application/application_darwin_delegate.m b/v3/pkg/application/application_darwin_delegate.m index 4f71dc7916a..e12858e3590 100644 --- a/v3/pkg/application/application_darwin_delegate.m +++ b/v3/pkg/application/application_darwin_delegate.m @@ -20,7 +20,7 @@ - (void)themeChanged:(NSNotification *)notification { - (BOOL)applicationShouldHandleReopen:(NSNotification *)notification hasVisibleWindows:(BOOL)flag { if( hasListeners(EventApplicationShouldHandleReopen) ) { - processApplicationEvent(EventApplicationShouldHandleReopen, NULL); + processApplicationEvent(EventApplicationShouldHandleReopen, @{@"hasVisibleWindows": @(flag)}); } return TRUE; diff --git a/v3/pkg/application/context_application_event.go b/v3/pkg/application/context_application_event.go index 27d539d0b1f..2cd1ca2c0a0 100644 --- a/v3/pkg/application/context_application_event.go +++ b/v3/pkg/application/context_application_event.go @@ -31,8 +31,8 @@ func (c ApplicationEventContext) setIsDarkMode(mode bool) { c.data["isDarkMode"] = mode } -func (c ApplicationEventContext) IsDarkMode() bool { - mode, ok := c.data["isDarkMode"] +func (c ApplicationEventContext) getBool(key string) bool { + mode, ok := c.data[key] if !ok { return false } @@ -43,6 +43,18 @@ func (c ApplicationEventContext) IsDarkMode() bool { return result } +func (c ApplicationEventContext) IsDarkMode() bool { + return c.getBool("isDarkMode") +} + +func (c ApplicationEventContext) HasVisibleWindows() bool { + return c.getBool("hasVisibleWindows") +} + +func (c ApplicationEventContext) setData(data map[string]any) { + c.data = data +} + func newApplicationEventContext() *ApplicationEventContext { return &ApplicationEventContext{ data: make(map[string]any),