diff --git a/Plugins/Mac/.gitignore b/Plugins/Mac/.gitignore new file mode 100644 index 00000000..04d6d043 --- /dev/null +++ b/Plugins/Mac/.gitignore @@ -0,0 +1,3 @@ +DerivedData +WebView.xcodeproj/project.xcworkspace/xcuserdata/ +WebView.xcodeproj/xcuserdata/ diff --git a/Plugins/Mac/Resources/Info-WebViewSeparated.plist b/Plugins/Mac/Resources/Info-WebViewSeparated.plist new file mode 100644 index 00000000..e89822fe --- /dev/null +++ b/Plugins/Mac/Resources/Info-WebViewSeparated.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + NSPrincipalClass + + + diff --git a/Plugins/Mac/Resources/Info.plist b/Plugins/Mac/Resources/Info.plist new file mode 100644 index 00000000..e89822fe --- /dev/null +++ b/Plugins/Mac/Resources/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + NSPrincipalClass + + + diff --git a/Plugins/Mac/Resources/InfoPlist.strings b/Plugins/Mac/Resources/InfoPlist.strings new file mode 100644 index 00000000..477b28ff --- /dev/null +++ b/Plugins/Mac/Resources/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/Plugins/Mac/Resources/Prefix.pch b/Plugins/Mac/Resources/Prefix.pch new file mode 100644 index 00000000..aabef477 --- /dev/null +++ b/Plugins/Mac/Resources/Prefix.pch @@ -0,0 +1,3 @@ +#ifdef __OBJC__ + #import +#endif diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac/WebView.mm b/Plugins/Mac/Sources/WebView.mm similarity index 86% rename from src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac/WebView.mm rename to Plugins/Mac/Sources/WebView.mm index 1d7f4503..2f5950f7 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac/WebView.mm +++ b/Plugins/Mac/Sources/WebView.mm @@ -19,20 +19,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#if canImport(UIKit) -#import -#else #import -#endif - #import -#if canImport(UIKit) -// NOTE: we need extern without "C" before unity 4.5 -//extern UIViewController *UnityGetGLViewController(); -extern "C" UIViewController *UnityGetGLViewController(); -extern "C" void UnitySendMessage(const char *, const char *, const char *); -#endif extern "C" typedef void (*DelegateCallbackFunction)(const char * key, const char * message); DelegateCallbackFunction delegateCallback = NULL; @@ -84,10 +73,10 @@ - (void)load:(NSURLRequest *)request NSURL *url = [request URL]; if ([url.absoluteString hasPrefix:@"file:"]) { // LoadFileURL is not loading the JS content due to thinking it's out of the sandbox - // NSURL *top = [NSURL URLWithString:[[url absoluteString] stringByDeletingLastPathComponent]]; - // [webView loadFileURL:url allowingReadAccessToURL:top]; - NSString *htmlContent = [NSString stringWithContentsOfFile:url.path encoding:NSUTF8StringEncoding error:nil]; - [webView loadHTMLString:htmlContent baseURL:url]; + NSURL *top = [NSURL URLWithString:[[url absoluteString] stringByDeletingLastPathComponent]]; + [webView loadFileURL:url allowingReadAccessToURL:top]; + // NSString *htmlContent = [NSString stringWithContentsOfFile:url.path encoding:NSUTF8StringEncoding error:nil]; + // [webView loadHTMLString:htmlContent baseURL:url]; } else { [webView loadRequest:request]; } @@ -97,7 +86,8 @@ - (void)load:(NSURLRequest *)request @interface CWebViewPlugin : NSObject { WKWebView *webView; -} + NSWindow *window; + NSWindowController *windowController;} @end @implementation CWebViewPlugin @@ -110,7 +100,7 @@ - (id)initWithUa:(const char *)ua { self = [super init]; - // UIView *view = UnityGetGLViewController().view; + CGRect frame = CGRectMake(0, 0, 500, 400); if (_sharedProcessPool == NULL) { _sharedProcessPool = [[WKProcessPool alloc] init]; @@ -132,15 +122,14 @@ - (id)initWithUa:(const char *)ua "; WKUserScript *script - = [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]; + = [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]; [controller addUserScript:script]; configuration.userContentController = controller; - configuration.allowsInlineMediaPlayback = true; configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; configuration.websiteDataStore = [WKWebsiteDataStore defaultDataStore]; configuration.processPool = _sharedProcessPool; - WKWebView *wkwebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]; + WKWebView *wkwebView = [[WKWebView alloc] initWithFrame:frame configuration:configuration]; #if UNITYWEBVIEW_DEVELOPMENT // enable Safari debugging if exists if ([wkwebView respondsToSelector:@selector(setInspectable:)]) { @@ -155,23 +144,17 @@ - (id)initWithUa:(const char *)ua ((WKWebView *)webView).customUserAgent = [[NSString alloc] initWithUTF8String:ua]; } - webView.opaque = NO; - webView.hidden = YES; + // webView.hidden = YES; -#if canImport(UIKit) - // cf. https://rick38yip.medium.com/wkwebview-weird-spacing-issue-in-ios-13-54a4fc686f72 - // cf. https://stackoverflow.com/questions/44390971/automaticallyadjustsscrollviewinsets-was-deprecated-in-ios-11-0 - ((WKWebView *)webView).scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; - - webView.backgroundColor = [UIColor clearColor]; - webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - - UIView *view = UnityGetGLViewController().view; - [view addSubview:webView]; -#else [webView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)]; -#endif - + window = [[NSWindow alloc] initWithContentRect:frame + styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskResizable + backing:NSBackingStoreBuffered + defer:NO]; + [window setContentView:webView]; + [window orderFront:NSApp]; +// [window setDelegate:self]; + windowController = [[NSWindowController alloc] initWithWindow:window]; return self; } @@ -292,11 +275,7 @@ - (void)webView:(WKWebView *)wkWebView decidePolicyForNavigationAction:(WKNaviga NSString *url = [nsurl absoluteString]; if ([url rangeOfString:@"//itunes.apple.com/"].location != NSNotFound) { -#if canImport(UIKit) - [[UIApplication sharedApplication] openURL:nsurl]; -#else [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]]; -#endif decisionHandler(WKNavigationActionPolicyCancel); return; } else if ([url hasPrefix:@"unity:"]) { @@ -307,13 +286,8 @@ - (void)webView:(WKWebView *)wkWebView decidePolicyForNavigationAction:(WKNaviga && ![url hasPrefix:@"file:"] && ![url hasPrefix:@"http:"] && ![url hasPrefix:@"https:"]) { -#if canImport(UIKit) - if([[UIApplication sharedApplication] canOpenURL:nsurl]) { - [[UIApplication sharedApplication] openURL:nsurl]; - } -#else + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]]; -#endif decisionHandler(WKNavigationActionPolicyCancel); return; } else if (navigationAction.navigationType == WKNavigationTypeLinkActivated @@ -352,7 +326,7 @@ - (void)loadURL:(const char *)url { if (webView == nil) return; - + WKWebView *_webView = (WKWebView *)webView; NSString *urlStr = [NSString stringWithUTF8String:url]; NSURL *nsurl = [NSURL URLWithString:urlStr]; @@ -370,11 +344,11 @@ - (void)evaluateJS:(const char *)js @end extern "C" { - void *_CWebViewPlugin_Init(const char *ua); - void _CWebViewPlugin_Destroy(void *instance); - void _CWebViewPlugin_LoadURL(void *instance, const char *url); - void _CWebViewPlugin_EvaluateJS(void *instance, const char *url); - void _CWebViewPlugin_SetDelegate(DelegateCallbackFunction callback); +void *_CWebViewPlugin_Init(const char *ua); +void _CWebViewPlugin_Destroy(void *instance); +void _CWebViewPlugin_LoadURL(void *instance, const char *url); +void _CWebViewPlugin_EvaluateJS(void *instance, const char *url); +void _CWebViewPlugin_SetDelegate(DelegateCallbackFunction callback); } void _CWebViewPlugin_SetDelegate(DelegateCallbackFunction callback) { diff --git a/Plugins/Mac/WebView.xcodeproj/project.pbxproj b/Plugins/Mac/WebView.xcodeproj/project.pbxproj new file mode 100644 index 00000000..6a1393d3 --- /dev/null +++ b/Plugins/Mac/WebView.xcodeproj/project.pbxproj @@ -0,0 +1,347 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 48; + objects = { + +/* Begin PBXBuildFile section */ + 8102525814C569D80022296D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8102525514C569D80022296D /* InfoPlist.strings */; }; + 81B8C535151078DB000C56DC /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81B8C534151078DB000C56DC /* WebKit.framework */; }; + 81B8C53815108B89000C56DC /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81B8C53715108B89000C56DC /* Carbon.framework */; }; + 81E2C20C14C5684A004CE5C2 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81E2C20B14C5684A004CE5C2 /* Cocoa.framework */; }; + 81F4B4D914C6888B001B4465 /* WebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 81F4B4D814C6888B001B4465 /* WebView.mm */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 18E976051EA4873F00083D49 /* Info-WebViewSeparated.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = "Info-WebViewSeparated.plist"; path = "Resources/Info-WebViewSeparated.plist"; sourceTree = ""; }; + 8102525414C569D80022296D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Resources/Info.plist; sourceTree = SOURCE_ROOT; }; + 8102525514C569D80022296D /* InfoPlist.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = InfoPlist.strings; path = Resources/InfoPlist.strings; sourceTree = SOURCE_ROOT; }; + 8102525614C569D80022296D /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Prefix.pch; path = Resources/Prefix.pch; sourceTree = SOURCE_ROOT; }; + 81B8C534151078DB000C56DC /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; + 81B8C53715108B89000C56DC /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; }; + 81E2C20814C5684A004CE5C2 /* WebView.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WebView.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; + 81E2C20B14C5684A004CE5C2 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; + 81E2C20E14C5684A004CE5C2 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; + 81E2C21014C5684A004CE5C2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 81F4B4D814C6888B001B4465 /* WebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebView.mm; path = Sources/WebView.mm; sourceTree = ""; }; + 81F81AEC14D76D2400845D4C /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 81E2C20514C5684A004CE5C2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 81B8C53815108B89000C56DC /* Carbon.framework in Frameworks */, + 81B8C535151078DB000C56DC /* WebKit.framework in Frameworks */, + 81E2C20C14C5684A004CE5C2 /* Cocoa.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 8102525914C573EB0022296D /* Sources */ = { + isa = PBXGroup; + children = ( + 81F4B4D814C6888B001B4465 /* WebView.mm */, + ); + name = Sources; + sourceTree = ""; + }; + 81E2C1FD14C5684A004CE5C2 = { + isa = PBXGroup; + children = ( + 8102525914C573EB0022296D /* Sources */, + 81E2C21114C5684A004CE5C2 /* Resources */, + 81E2C20A14C5684A004CE5C2 /* Frameworks */, + 81E2C20914C5684A004CE5C2 /* Products */, + ); + sourceTree = ""; + }; + 81E2C20914C5684A004CE5C2 /* Products */ = { + isa = PBXGroup; + children = ( + 81E2C20814C5684A004CE5C2 /* WebView.bundle */, + ); + name = Products; + sourceTree = ""; + }; + 81E2C20A14C5684A004CE5C2 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 81B8C53715108B89000C56DC /* Carbon.framework */, + 81F81AEC14D76D2400845D4C /* OpenGL.framework */, + 81E2C20E14C5684A004CE5C2 /* AppKit.framework */, + 81E2C21014C5684A004CE5C2 /* Foundation.framework */, + 81E2C20B14C5684A004CE5C2 /* Cocoa.framework */, + 81B8C534151078DB000C56DC /* WebKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 81E2C21114C5684A004CE5C2 /* Resources */ = { + isa = PBXGroup; + children = ( + 8102525414C569D80022296D /* Info.plist */, + 18E976051EA4873F00083D49 /* Info-WebViewSeparated.plist */, + 8102525514C569D80022296D /* InfoPlist.strings */, + 8102525614C569D80022296D /* Prefix.pch */, + ); + name = Resources; + path = WebView; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 81E2C20714C5684A004CE5C2 /* WebView */ = { + isa = PBXNativeTarget; + buildConfigurationList = 81E2C21A14C5684A004CE5C2 /* Build configuration list for PBXNativeTarget "WebView" */; + buildPhases = ( + 81E2C20414C5684A004CE5C2 /* Sources */, + 81E2C20514C5684A004CE5C2 /* Frameworks */, + 81E2C20614C5684A004CE5C2 /* Resources */, + 81F4B4F514C696C4001B4465 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = WebView; + productName = WebView; + productReference = 81E2C20814C5684A004CE5C2 /* WebView.bundle */; + productType = "com.apple.product-type.bundle"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 81E2C1FF14C5684A004CE5C2 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1200; + }; + buildConfigurationList = 81E2C20214C5684A004CE5C2 /* Build configuration list for PBXProject "WebView" */; + compatibilityVersion = "Xcode 8.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 81E2C1FD14C5684A004CE5C2; + productRefGroup = 81E2C20914C5684A004CE5C2 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 81E2C20714C5684A004CE5C2 /* WebView */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 81E2C20614C5684A004CE5C2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8102525814C569D80022296D /* InfoPlist.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 81F4B4F514C696C4001B4465 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = ""; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 81E2C20414C5684A004CE5C2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 81F4B4D914C6888B001B4465 /* WebView.mm in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 81E2C21814C5684A004CE5C2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ""; + MACOSX_DEPLOYMENT_TARGET = 10.13; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ""; + SDKROOT = macosx; + USE_HEADERMAP = YES; + }; + name = Debug; + }; + 81E2C21914C5684A004CE5C2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ""; + MACOSX_DEPLOYMENT_TARGET = 10.13; + OTHER_LDFLAGS = ""; + SDKROOT = macosx; + USE_HEADERMAP = YES; + }; + name = Release; + }; + 81E2C21B14C5684A004CE5C2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_WEAK = YES; + GCC_C_LANGUAGE_STANDARD = "compiler-default"; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = Resources/Prefix.pch; + INFOPLIST_FILE = Resources/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; + LD_RUNPATH_SEARCH_PATHS = ""; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + PRODUCT_BUNDLE_IDENTIFIER = "net.gree.unitywebview.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + USE_HEADERMAP = YES; + WRAPPER_EXTENSION = bundle; + }; + name = Debug; + }; + 81E2C21C14C5684A004CE5C2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_WEAK = YES; + GCC_C_LANGUAGE_STANDARD = "compiler-default"; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = Resources/Prefix.pch; + INFOPLIST_FILE = Resources/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; + LD_RUNPATH_SEARCH_PATHS = ""; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + PRODUCT_BUNDLE_IDENTIFIER = "net.gree.unitywebview.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + USE_HEADERMAP = YES; + WRAPPER_EXTENSION = bundle; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 81E2C20214C5684A004CE5C2 /* Build configuration list for PBXProject "WebView" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 81E2C21814C5684A004CE5C2 /* Debug */, + 81E2C21914C5684A004CE5C2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 81E2C21A14C5684A004CE5C2 /* Build configuration list for PBXNativeTarget "WebView" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 81E2C21B14C5684A004CE5C2 /* Debug */, + 81E2C21C14C5684A004CE5C2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 81E2C1FF14C5684A004CE5C2 /* Project object */; +} diff --git a/Plugins/Mac/WebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Plugins/Mac/WebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/Plugins/Mac/WebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Plugins/Mac/WebView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Plugins/Mac/WebView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Plugins/Mac/WebView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Plugins/Mac/install.sh b/Plugins/Mac/install.sh new file mode 100755 index 00000000..50a08342 --- /dev/null +++ b/Plugins/Mac/install.sh @@ -0,0 +1,10 @@ +#!/bin/bash +DSTDIR="./" +rm -rf DerivedData +# xcodebuild -target WebView -configuration Release -arch x86_64 -arch arm64 build CONFIGURATION_BUILD_DIR='DerivedData' | xcbeautify +xcodebuild -target WebView -configuration Debug -arch x86_64 -arch arm64 build CONFIGURATION_BUILD_DIR='DerivedData' | xcbeautify +mkdir -p $DSTDIR + +cp -r DerivedData/WebView.bundle $DSTDIR +rm -rf DerivedData +cp *.bundle.meta $DSTDIR diff --git a/sample/.vscode/settings.json b/sample/.vscode/settings.json index e232cd65..3c1ea9e8 100644 --- a/sample/.vscode/settings.json +++ b/sample/.vscode/settings.json @@ -1,55 +1,55 @@ -{ - "files.exclude": - { - "**/.DS_Store":true, - "**/.git":true, - "**/.gitmodules":true, - "**/*.booproj":true, - "**/*.pidb":true, - "**/*.suo":true, - "**/*.user":true, - "**/*.userprefs":true, - "**/*.unityproj":true, - "**/*.dll":true, - "**/*.exe":true, - "**/*.pdf":true, - "**/*.mid":true, - "**/*.midi":true, - "**/*.wav":true, - "**/*.gif":true, - "**/*.ico":true, - "**/*.jpg":true, - "**/*.jpeg":true, - "**/*.png":true, - "**/*.psd":true, - "**/*.tga":true, - "**/*.tif":true, - "**/*.tiff":true, - "**/*.3ds":true, - "**/*.3DS":true, - "**/*.fbx":true, - "**/*.FBX":true, - "**/*.lxo":true, - "**/*.LXO":true, - "**/*.ma":true, - "**/*.MA":true, - "**/*.obj":true, - "**/*.OBJ":true, - "**/*.asset":true, - "**/*.cubemap":true, - "**/*.flare":true, - "**/*.mat":true, - "**/*.meta":true, - "**/*.prefab":true, - "**/*.unity":true, - "build/":true, - "Build/":true, - "Library/":true, - "library/":true, - "obj/":true, - "Obj/":true, - "ProjectSettings/":true, - "temp/":true, - "Temp/":true - } +{ + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.gitmodules": true, + "**/*.booproj": true, + "**/*.pidb": true, + "**/*.suo": true, + "**/*.user": true, + "**/*.userprefs": true, + "**/*.unityproj": true, + "**/*.dll": true, + "**/*.exe": true, + "**/*.pdf": true, + "**/*.mid": true, + "**/*.midi": true, + "**/*.wav": true, + "**/*.gif": true, + "**/*.ico": true, + "**/*.jpg": true, + "**/*.jpeg": true, + "**/*.png": true, + "**/*.psd": true, + "**/*.tga": true, + "**/*.tif": true, + "**/*.tiff": true, + "**/*.3ds": true, + "**/*.3DS": true, + "**/*.fbx": true, + "**/*.FBX": true, + "**/*.lxo": true, + "**/*.LXO": true, + "**/*.ma": true, + "**/*.MA": true, + "**/*.obj": true, + "**/*.OBJ": true, + "**/*.asset": true, + "**/*.cubemap": true, + "**/*.flare": true, + "**/*.mat": true, + "**/*.meta": true, + "**/*.prefab": true, + "**/*.unity": true, + "build/": true, + "Build/": true, + "Library/": true, + "library/": true, + "obj/": true, + "Obj/": true, + "ProjectSettings/": true, + "temp/": true, + "Temp/": true + }, + "dotnet.defaultSolution": "sample.sln" } \ No newline at end of file diff --git a/sample/Assets/Scenes/AuthenticatedScene.unity b/sample/Assets/Scenes/AuthenticatedScene.unity index 7eb9a91f..0ede739b 100644 --- a/sample/Assets/Scenes/AuthenticatedScene.unity +++ b/sample/Assets/Scenes/AuthenticatedScene.unity @@ -8691,8 +8691,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1335469792} m_HandleRect: {fileID: 1335469791} m_Direction: 2 - m_Value: 1 - m_Size: 0.99999994 + m_Value: 0 + m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: diff --git a/sample/Packages/manifest.json b/sample/Packages/manifest.json index 29b6ef9a..c1cb3f71 100644 --- a/sample/Packages/manifest.json +++ b/sample/Packages/manifest.json @@ -1,7 +1,7 @@ { "dependencies": { "com.immutable.passport": "file:../../src/Packages/Passport", - "com.unity.ide.visualstudio": "2.0.18", + "com.unity.ide.visualstudio": "2.0.21", "com.unity.ide.vscode": "1.2.5", "com.unity.test-framework": "2.0.1-exp.1", "com.unity.visualscripting": "1.8.0", diff --git a/sample/Packages/packages-lock.json b/sample/Packages/packages-lock.json index c663e869..e2322c1e 100644 --- a/sample/Packages/packages-lock.json +++ b/sample/Packages/packages-lock.json @@ -14,7 +14,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.18", + "version": "2.0.21", "depth": 0, "source": "registry", "dependencies": { diff --git a/sample/ProjectSettings/ProjectSettings.asset b/sample/ProjectSettings/ProjectSettings.asset index 92bfb447..dd564465 100644 --- a/sample/ProjectSettings/ProjectSettings.asset +++ b/sample/ProjectSettings/ProjectSettings.asset @@ -75,7 +75,7 @@ PlayerSettings: androidMinimumWindowHeight: 300 androidFullscreenMode: 1 defaultIsNativeResolution: 1 - macRetinaSupport: 1 + macRetinaSupport: 0 runInBackground: 0 captureSingleScreen: 0 muteOtherAudioSources: 0 @@ -88,7 +88,7 @@ PlayerSettings: bakeCollisionMeshes: 0 forceSingleInstance: 0 useFlipModelSwapchain: 1 - resizableWindow: 0 + resizableWindow: 1 useMacAppStoreValidation: 0 macAppStoreCategory: public.app-category.games gpuSkinning: 0 @@ -99,7 +99,7 @@ PlayerSettings: xboxEnableFitness: 0 visibleInBackground: 1 allowFullscreenSwitch: 1 - fullscreenMode: 3 + fullscreenMode: 2 xboxSpeechDB: 0 xboxEnableHeadOrientation: 0 xboxEnableGuest: 0 diff --git a/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs b/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs index dc2d65af..88a9188a 100644 --- a/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs +++ b/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs @@ -34,14 +34,16 @@ private Passport() { #if UNITY_EDITOR_WIN Application.quitting += OnQuit; -#elif UNITY_IPHONE || UNITY_ANDROID || UNITY_STANDALONE_OSX +#elif UNITY_IPHONE || UNITY_ANDROID || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX Application.deepLinkActivated += onDeepLinkActivated; if (!string.IsNullOrEmpty(Application.absoluteURL)) { // Cold start and Application.absoluteURL not null so process Deep Link. onDeepLinkActivated(Application.absoluteURL); } + Debug.Log($"{TAG} Deeplink setup"); #endif + Debug.Log($"{TAG} init done"); } /// @@ -76,11 +78,14 @@ public static UniTask Init( { if (readySignalReceived == true) { + Debug.Log($"{TAG} Triggering init"); await Instance.GetPassportImpl().Init(clientId, environment, redirectUri, deeplink); + Debug.Log($"{TAG} finished init"); return Instance; } else { + Debug.Log($"{TAG} Failed to initialise Passport"); throw new PassportException("Failed to initiliase Passport", PassportErrorType.INITALISATION_ERROR); } }); @@ -107,11 +112,12 @@ int engineStartupTimeoutMs #endif passportImpl = new PassportImpl(communicationsManager); } - catch (Exception) + catch (Exception ex) { // Reset values readySignalReceived = false; Instance = null; + throw ex; } } @@ -148,7 +154,7 @@ public async UniTask Connect(long? timeoutMs = null) await GetPassportImpl().Connect(timeoutMs); } -#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX +#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX /// /// Connects the user into Passport via PKCE auth and sets up the IMX provider. /// diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/GreeBrowserClient.cs b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/GreeBrowserClient.cs index 15a95bcc..031e9486 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/GreeBrowserClient.cs +++ b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/GreeBrowserClient.cs @@ -8,6 +8,7 @@ public class GreeBrowserClient : IWebBrowserClient { private const string TAG = "[GreeBrowserClient]"; private const string ANDROID_DATA_DIRECTORY = "android_asset"; + private const string MAC_DATA_DIRECTORY = "/Resources/Data"; private readonly WebViewObject webViewObject; public event OnUnityPostMessageDelegate OnUnityPostMessage; @@ -27,6 +28,8 @@ public GreeBrowserClient() ); #if UNITY_ANDROID string filePath = Constants.SCHEME_FILE + ANDROID_DATA_DIRECTORY + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME; +#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX + string filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + MAC_DATA_DIRECTORY + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME; #else string filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME; #endif diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac.meta b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac.meta deleted file mode 100644 index 33307131..00000000 --- a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 539832580c6c84e639c556d779b4b84b -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac/WebView.mm.meta b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle.meta similarity index 77% rename from src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac/WebView.mm.meta rename to src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle.meta index fac23d4c..1165b4f0 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/Mac/WebView.mm.meta +++ b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 096af82eb4f3a4f6f92cfee1a45b463b +guid: 5390f3f89134c467fb0bf687e714c2d6 PluginImporter: externalObjects: {} serializedVersion: 2 @@ -19,19 +19,15 @@ PluginImporter: - first: Editor: Editor second: - enabled: 0 + enabled: 1 settings: DefaultValueInitialized: true - first: - iPhone: iOS - second: - enabled: 1 - settings: {} - - first: - tvOS: tvOS + Standalone: OSXUniversal second: enabled: 1 - settings: {} + settings: + CPU: AnyCPU userData: assetBundleName: assetBundleVariant: diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/Info.plist b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/Info.plist new file mode 100644 index 00000000..82e68462 --- /dev/null +++ b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/Info.plist @@ -0,0 +1,48 @@ + + + + + BuildMachineOSBuild + 22G90 + CFBundleDevelopmentRegion + English + CFBundleExecutable + WebView + CFBundleIdentifier + net.gree.unitywebview.WebView + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + WebView + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 1 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + + DTPlatformName + macosx + DTPlatformVersion + 13.3 + DTSDKBuild + 22E245 + DTSDKName + macosx13.3 + DTXcode + 1431 + DTXcodeBuild + 14E300c + LSMinimumSystemVersion + 10.13 + + diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/MacOS/WebView b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/MacOS/WebView new file mode 100755 index 00000000..3a263eaa Binary files /dev/null and b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/MacOS/WebView differ diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/Resources/InfoPlist.strings b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/Resources/InfoPlist.strings new file mode 100644 index 00000000..5e45963c Binary files /dev/null and b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/Resources/InfoPlist.strings differ diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/_CodeSignature/CodeResources b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/_CodeSignature/CodeResources new file mode 100644 index 00000000..f4d2e431 --- /dev/null +++ b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/Contents/_CodeSignature/CodeResources @@ -0,0 +1,128 @@ + + + + + files + + Resources/InfoPlist.strings + + MiLKDDnrUKr4EmuvhS5VQwxHGK8= + + + files2 + + Resources/InfoPlist.strings + + hash2 + + Oc8u4Ht7Mz58F50L9NeYpbcq9qTlhPUeZCcDu/pPyCg= + + + + rules + + ^Resources/ + + ^Resources/.*\.lproj/ + + optional + + weight + 1000 + + ^Resources/.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Resources/Base\.lproj/ + + weight + 1010 + + ^version.plist$ + + + rules2 + + .*\.dSYM($|/) + + weight + 11 + + ^(.*/)?\.DS_Store$ + + omit + + weight + 2000 + + ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ + + nested + + weight + 10 + + ^.* + + ^Info\.plist$ + + omit + + weight + 20 + + ^PkgInfo$ + + omit + + weight + 20 + + ^Resources/ + + weight + 20 + + ^Resources/.*\.lproj/ + + optional + + weight + 1000 + + ^Resources/.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Resources/Base\.lproj/ + + weight + 1010 + + ^[^/]+$ + + nested + + weight + 10 + + ^embedded\.provisionprofile$ + + weight + 20 + + ^version\.plist$ + + weight + 20 + + + + diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebViewObject.cs b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebViewObject.cs index 2f3b43bd..10d3abc3 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebViewObject.cs +++ b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebViewObject.cs @@ -27,7 +27,7 @@ #if UNITY_2018_4_OR_NEWER using UnityEngine.Networking; #endif -#if UNITY_STANDALONE_OSX +#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX using System.IO; using System.Text.RegularExpressions; using UnityEngine.Rendering; @@ -35,13 +35,13 @@ #if UNITY_ANDROID using UnityEngine.Android; #endif -#if UNITY_IPHONE || UNITY_STANDALONE_OSX +#if UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX using AOT; #endif using Callback = System.Action; -#if UNITY_IPHONE || UNITY_STANDALONE_OSX +#if UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX public class Singleton { private static Singleton _instance; @@ -89,7 +89,7 @@ public void call(String message) { IntPtr webView; #endif -#if UNITY_IPHONE || UNITY_STANDALONE_OSX +#if UNITY_IPHONE [DllImport("__Internal")] private static extern IntPtr _CWebViewPlugin_Init(string ua); [DllImport("__Internal")] @@ -102,7 +102,31 @@ private static extern void _CWebViewPlugin_EvaluateJS( IntPtr instance, string url); [DllImport("__Internal")] private static extern void _CWebViewPlugin_SetDelegate(DelegateMessage callback); +#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX + [DllImport("WebView")] + private static extern IntPtr _CWebViewPlugin_Init(string ua); + [DllImport("WebView")] + private static extern int _CWebViewPlugin_Destroy(IntPtr instance); + [DllImport("WebView")] + private static extern void _CWebViewPlugin_LoadURL( + IntPtr instance, string url); + [DllImport("WebView")] + private static extern void _CWebViewPlugin_EvaluateJS( + IntPtr instance, string url); + [DllImport("WebView")] + private static extern void _CWebViewPlugin_SetDelegate(DelegateMessage callback); +#elif UNITY_WEBGL + [DllImport("__Internal")] + private static extern void _gree_unity_webview_init(); + [DllImport("__Internal")] + private static extern void _gree_unity_webview_loadURL(string url); + [DllImport("__Internal")] + private static extern void _gree_unity_webview_evaluateJS(string js); + [DllImport("__Internal")] + private static extern void _gree_unity_webview_destroy(); +#endif +#if UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX private delegate void DelegateMessage(string key, string message); [MonoPInvokeCallback(typeof(DelegateMessage))] @@ -133,15 +157,6 @@ private static void delegateMessageReceived(string key, string message) { Debug.Log($"{TAG} delegateMessageReceived unsupported key " + key); } -#elif UNITY_WEBGL - [DllImport("__Internal")] - private static extern void _gree_unity_webview_init(); - [DllImport("__Internal")] - private static extern void _gree_unity_webview_loadURL(string url); - [DllImport("__Internal")] - private static extern void _gree_unity_webview_evaluateJS(string js); - [DllImport("__Internal")] - private static extern void _gree_unity_webview_destroy(); #endif public void handleMessage(string message) @@ -184,7 +199,7 @@ public void Init( #elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX //TODO: UNSUPPORTED Debug.LogError("Webview is not supported on this platform."); -#elif UNITY_IPHONE || UNITY_STANDALONE_OSX +#elif UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX webView = _CWebViewPlugin_Init(ua); Singleton.Instance.onJS = ((message) => CallFromJS(message)); Singleton.Instance.onError = ((message) => CallOnError(message)); @@ -211,7 +226,7 @@ public void LoadURL(string url) Application.ExternalCall("unityWebView.loadURL", url); #elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX //TODO: UNSUPPORTED -#elif UNITY_STANDALONE_OSX || UNITY_IPHONE +#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_IPHONE if (webView == IntPtr.Zero) return; _CWebViewPlugin_LoadURL(webView, url); @@ -232,7 +247,7 @@ public void EvaluateJS(string js) Application.ExternalCall("unityWebView.evaluateJS", js); #elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX //TODO: UNSUPPORTED -#elif UNITY_STANDALONE_OSX || UNITY_IPHONE +#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_IPHONE if (webView == IntPtr.Zero) return; _CWebViewPlugin_EvaluateJS(webView, js); diff --git a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/iOS/WebView.mm b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/iOS/WebView.mm index 1d7f4503..4a2d394f 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/iOS/WebView.mm +++ b/src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/iOS/WebView.mm @@ -19,7 +19,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#if canImport(UIKit) +#if TARGET_OS_IOS #import #else #import @@ -27,7 +27,7 @@ #import -#if canImport(UIKit) +#if TARGET_OS_IOS // NOTE: we need extern without "C" before unity 4.5 //extern UIViewController *UnityGetGLViewController(); extern "C" UIViewController *UnityGetGLViewController(); @@ -97,6 +97,10 @@ - (void)load:(NSURLRequest *)request @interface CWebViewPlugin : NSObject { WKWebView *webView; +#if !TARGET_OS_IOS + NSWindow *window; + NSWindowController *windowController; +#endif } @end @@ -135,7 +139,6 @@ - (id)initWithUa:(const char *)ua = [[WKUserScript alloc] initWithSource:str injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]; [controller addUserScript:script]; configuration.userContentController = controller; - configuration.allowsInlineMediaPlayback = true; configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; configuration.websiteDataStore = [WKWebsiteDataStore defaultDataStore]; configuration.processPool = _sharedProcessPool; @@ -155,10 +158,9 @@ - (id)initWithUa:(const char *)ua ((WKWebView *)webView).customUserAgent = [[NSString alloc] initWithUTF8String:ua]; } - webView.opaque = NO; webView.hidden = YES; -#if canImport(UIKit) +#if TARGET_OS_IOS // cf. https://rick38yip.medium.com/wkwebview-weird-spacing-issue-in-ios-13-54a4fc686f72 // cf. https://stackoverflow.com/questions/44390971/automaticallyadjustsscrollviewinsets-was-deprecated-in-ios-11-0 ((WKWebView *)webView).scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; @@ -170,6 +172,14 @@ - (id)initWithUa:(const char *)ua [view addSubview:webView]; #else [webView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)]; + window = [[NSWindow alloc] initWithContentRect:frame + styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskResizable + backing:NSBackingStoreBuffered + defer:NO]; + [window setContentView:webView]; + [window orderFront:NSApp]; + // [window setDelegate:self]; + windowController = [[NSWindowController alloc] initWithWindow:window]; #endif return self; @@ -292,7 +302,7 @@ - (void)webView:(WKWebView *)wkWebView decidePolicyForNavigationAction:(WKNaviga NSString *url = [nsurl absoluteString]; if ([url rangeOfString:@"//itunes.apple.com/"].location != NSNotFound) { -#if canImport(UIKit) +#if TARGET_OS_IOS [[UIApplication sharedApplication] openURL:nsurl]; #else [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]]; @@ -307,7 +317,7 @@ - (void)webView:(WKWebView *)wkWebView decidePolicyForNavigationAction:(WKNaviga && ![url hasPrefix:@"file:"] && ![url hasPrefix:@"http:"] && ![url hasPrefix:@"https:"]) { -#if canImport(UIKit) +#if TARGET_OS_IOS if([[UIApplication sharedApplication] canOpenURL:nsurl]) { [[UIApplication sharedApplication] openURL:nsurl]; }