From f738f1e24678daba41f19e9752f6081f5ef3e14a Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 8 Jun 2024 15:16:33 +1000 Subject: [PATCH] Add more macOS version checks --- v3/pkg/application/dialogs_darwin.go | 6 ++++-- v3/pkg/application/screen_darwin.go | 3 ++- v3/pkg/application/webview_window_darwin.go | 15 +++++++++++---- v3/pkg/application/webview_window_darwin_dev.go | 12 ++++++------ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/v3/pkg/application/dialogs_darwin.go b/v3/pkg/application/dialogs_darwin.go index 256db19be..6f83f5a85 100644 --- a/v3/pkg/application/dialogs_darwin.go +++ b/v3/pkg/application/dialogs_darwin.go @@ -172,6 +172,7 @@ static void showOpenFileDialog(unsigned int dialogID, delegate.allowedExtensions = [filterPatternsString componentsSeparatedByString:@";"]; // Use UTType if macOS 11 or higher to add file filters +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000 if (@available(macOS 11, *)) { NSMutableArray *filterTypes = [NSMutableArray array]; // Iterate the filtertypes, create uti's that are limited to the file extensions then add @@ -179,9 +180,10 @@ static void showOpenFileDialog(unsigned int dialogID, [filterTypes addObject:[UTType typeWithFilenameExtension:filterType]]; } [panel setAllowedContentTypes:filterTypes]; - } else { - [panel setAllowedFileTypes:delegate.allowedExtensions]; } +#else + [panel setAllowedFileTypes:delegate.allowedExtensions]; +#endif // Free the memory free(filterPatterns); diff --git a/v3/pkg/application/screen_darwin.go b/v3/pkg/application/screen_darwin.go index d35cf4611..661c45446 100644 --- a/v3/pkg/application/screen_darwin.go +++ b/v3/pkg/application/screen_darwin.go @@ -68,10 +68,11 @@ Screen processScreen(NSScreen* screen){ double rotation = CGDisplayRotation(displayID); returnScreen.rotation = rotation; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 if( @available(macOS 10.15, *) ){ returnScreen.name = [screen.localizedName UTF8String]; } - +#endif return returnScreen; } diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 06a272f26..7163c31ff 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -62,11 +62,13 @@ void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWa config.preferences.tabFocusesLinks = *preferences.TabFocusesLinks; } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110300 if (@available(macOS 11.3, *)) { if (preferences.TextInteractionEnabled != NULL) { config.preferences.textInteractionEnabled = *preferences.TextInteractionEnabled; } } +#endif #if MAC_OS_X_VERSION_MAX_ALLOWED >= 120300 if (@available(macOS 12.3, *)) { @@ -79,9 +81,12 @@ void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWa config.suppressesIncrementalRendering = true; config.applicationNameForUserAgent = @"wails.io"; [config setURLSchemeHandler:delegate forURLScheme:@"wails"]; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 if (@available(macOS 10.15, *)) { config.preferences.fraudulentWebsiteWarningEnabled = fraudulentWebsiteWarningEnabled; } +#endif // Setup user content controller WKUserContentController* userContentController = [WKUserContentController new]; @@ -457,8 +462,8 @@ void windowSetUseToolbar(void* nsWindow, bool useToolbar) { // Set window toolbar style void windowSetToolbarStyle(void* nsWindow, int style) { WebviewWindow* window = (WebviewWindow*)nsWindow; - // use @available to check if the function is available - // if not, return + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000 if (@available(macOS 11.0, *)) { NSToolbar* toolbar = [window toolbar]; if ( toolbar == nil ) { @@ -466,8 +471,9 @@ void windowSetToolbarStyle(void* nsWindow, int style) { } [window setToolbarStyle:style]; } -} +#endif +} // Set Hide Toolbar Separator void windowSetHideToolbarSeparator(void* nsWindow, bool hideSeparator) { NSToolbar* toolbar = [(WebviewWindow*)nsWindow toolbar]; @@ -712,7 +718,7 @@ static void startDrag(void *window) { // Credit: https://stackoverflow.com/q/33319295 static void windowPrint(void *window) { - +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000 // Check if macOS 11.0 or newer if (@available(macOS 11.0, *)) { WebviewWindow* nsWindow = (WebviewWindow*)window; @@ -744,6 +750,7 @@ static void windowPrint(void *window) { // [printOperation runOperation] DOES NOT WORK WITH WKWEBVIEW, use [po runOperationModalForWindow:window delegate:windowDelegate didRunSelector:nil contextInfo:nil]; } +#endif } void setWindowEnabled(void *window, bool enabled) { diff --git a/v3/pkg/application/webview_window_darwin_dev.go b/v3/pkg/application/webview_window_darwin_dev.go index c16746239..6ae5fa998 100644 --- a/v3/pkg/application/webview_window_darwin_dev.go +++ b/v3/pkg/application/webview_window_darwin_dev.go @@ -21,8 +21,8 @@ package application void openDevTools(void *window) { #if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000 - dispatch_async(dispatch_get_main_queue(), ^{ - if (@available(macOS 12.0, *)) { + if (@available(macOS 12.0, *)) { + dispatch_async(dispatch_get_main_queue(), ^{ WebviewWindow* nsWindow = (WebviewWindow*)window; @try { @@ -31,10 +31,10 @@ void openDevTools(void *window) { NSLog(@"Opening the inspector failed: %@", exception.reason); return; } - } else { - NSLog(@"Opening the inspector needs at least MacOS 12"); - } - }); + }); + } +#else + NSLog(@"Opening the inspector needs at least MacOS 12"); #endif }