From 651a75b211f7f5e01d4b1f6ace8447a68489ba3a Mon Sep 17 00:00:00 2001 From: irov Date: Fri, 25 Aug 2023 18:19:43 +0300 Subject: [PATCH 1/2] wip MENGINE_PLUGIN_APPLE_GENERALDATAPROTECTIONREGULATION --- ...DataProtectionRegulationScriptEmbedding.mm | 5 ++-- ...leGeneralDataProtectionRegulationService.h | 3 +++ ...eGeneralDataProtectionRegulationService.mm | 23 +++++++------------ .../AppleSentryApplicationDelegate.mm | 2 +- .../AppleSentryLoggerCapture.mm | 2 +- .../ApplePersistentSystem.cpp | 6 ++--- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm index 1c99281412..0469e53487 100644 --- a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm @@ -14,6 +14,7 @@ namespace Mengine { + ////////////////////////////////////////////////////////////////////////// namespace Detail { ////////////////////////////////////////////////////////////////////////// @@ -33,11 +34,11 @@ static void s_AppleGeneralDataProtectionRegulation_isGDPRPass( bool _passGDPR ) ////////////////////////////////////////////////////////////////////////// } ////////////////////////////////////////////////////////////////////////// - AppleGeneralDataProtectionRegulationScriptEmbedding::AppleGeneralDataProtectionRegulationEmbedding() + AppleGeneralDataProtectionRegulationScriptEmbedding::AppleGeneralDataProtectionRegulationScriptEmbedding() { } ////////////////////////////////////////////////////////////////////////// - AppleGeneralDataProtectionRegulationScriptEmbedding::~AppleGeneralDataProtectionRegulationEmbedding() + AppleGeneralDataProtectionRegulationScriptEmbedding::~AppleGeneralDataProtectionRegulationScriptEmbedding() { } ////////////////////////////////////////////////////////////////////////// diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.h b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.h index 6e185c5646..c3a2654f5b 100644 --- a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.h +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.h @@ -20,5 +20,8 @@ namespace Mengine public: void setGDPRPass( bool _passGDPR ) override; bool isGDPRPass() const override; + + protected: + bool m_passGDPR; }; } diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm index 2dd0ea3596..dce8341d34 100644 --- a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm @@ -14,6 +14,7 @@ { ////////////////////////////////////////////////////////////////////////// AppleGeneralDataProtectionRegulationService::AppleGeneralDataProtectionRegulationService() + : m_passGDPR(false) { } ////////////////////////////////////////////////////////////////////////// @@ -38,21 +39,13 @@ LOGGER_MESSAGE( "set GDPR pass [%d]" , _passGDPR ); - - if (@available(iOS 14.0, *)) { - UIWindowScene * foregroundScene = nil; - for( UIWindowScene * scene in UIApplication.sharedApplication.connectedScenes ) { - if( scene.activationState == UISceneActivationStateForegroundActive ) { - foregroundScene = scene; - } - } - - if( foregroundScene != nil ) { - [SKStoreReviewController requestReviewInScene:foregroundScene]; - } - } else if (@available(iOS 10.3, *)) { - [SKStoreReviewController requestReview]; - } + + m_passGDPR = _passGDPR; + } + ////////////////////////////////////////////////////////////////////////// + bool AppleGeneralDataProtectionRegulationService::isGDPRPass() const + { + return m_passGDPR; } ////////////////////////////////////////////////////////////////////////// } diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm b/src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm index 5574a976f4..e17ae2dde4 100644 --- a/src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm +++ b/src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm @@ -4,7 +4,7 @@ #include "Kernel/BuildMode.h" -#import +#import "Sentry/Sentry.h" @implementation AppleSentryApplicationDelegate diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm b/src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm index 5ca9116dcb..e463587814 100644 --- a/src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm +++ b/src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm @@ -5,7 +5,7 @@ #include "Config/StdString.h" -#import +#import "Sentry/Sentry.h" namespace Mengine { diff --git a/src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp b/src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp index c5923e28ee..69e20d7914 100644 --- a/src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp +++ b/src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp @@ -30,19 +30,19 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// bool ApplePersistentSystem::getPersistentArguments( Char * _value, size_t _capacity ) const { - bool successful = Helper::AppleGetUserDefaultsString( "MengineApplePersistentArguments", _value, _capacity ); + bool successful = Helper::AppleGetUserDefaultsString( "mengine.persistent.arguments", _value, _capacity ); return successful; } ////////////////////////////////////////////////////////////////////////// void ApplePersistentSystem::setPersistentArguments( const Char * _value ) { - Helper::AppleSetUserDefaultsString( "MengineApplePersistentArguments", _value ); + Helper::AppleSetUserDefaultsString( "mengine.persistent.arguments", _value ); } ////////////////////////////////////////////////////////////////////////// void ApplePersistentSystem::removePersistentArguments() { - Helper::AppleRemoveUserDefaultsString( "MengineApplePersistentArguments" ); + Helper::AppleRemoveUserDefaultsString( "mengine.persistent.arguments" ); } ////////////////////////////////////////////////////////////////////////// } From c64b4bbc3a60da55c06d2da425b7f86edb66b00d Mon Sep 17 00:00:00 2001 From: irov Date: Fri, 25 Aug 2023 22:21:45 +0300 Subject: [PATCH 2/2] fix apple AppleGeneralDataProtectionRegulationService --- src/Environment/Apple/AppleUserDefaults.h | 17 +++ src/Environment/Apple/AppleUserDefaults.mm | 109 ++++++++++++++++++ src/Environment/Apple/AppleUtils.h | 3 - src/Environment/Apple/AppleUtils.mm | 55 --------- src/Environment/Apple/CMakeLists.txt | 3 + ...eGeneralDataProtectionRegulationService.mm | 11 +- .../ApplePersistentSystem.cpp | 4 +- 7 files changed, 137 insertions(+), 65 deletions(-) create mode 100644 src/Environment/Apple/AppleUserDefaults.h create mode 100644 src/Environment/Apple/AppleUserDefaults.mm diff --git a/src/Environment/Apple/AppleUserDefaults.h b/src/Environment/Apple/AppleUserDefaults.h new file mode 100644 index 0000000000..9cdee57c89 --- /dev/null +++ b/src/Environment/Apple/AppleUserDefaults.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Config/Char.h" +#include "Config/StdDef.h" + +namespace Mengine +{ + namespace Helper + { + bool AppleGetUserDefaultsString( const Char * _key, Char * const _value, size_t _capacity ); + bool AppleSetUserDefaultsString( const Char * _key, const Char * _value ); + bool AppleGetUserDefaultsBoolean( const Char * _key, bool _default ); + bool AppleSetUserDefaultsBoolean( const Char * _key, bool _value ); + + bool AppleRemoveUserDefaults( const Char * _key ); + } +} diff --git a/src/Environment/Apple/AppleUserDefaults.mm b/src/Environment/Apple/AppleUserDefaults.mm new file mode 100644 index 0000000000..d7e872b455 --- /dev/null +++ b/src/Environment/Apple/AppleUserDefaults.mm @@ -0,0 +1,109 @@ +#include "AppleUserDefaults.h" + +#include "Kernel/StringCopy.h" + +#if defined(MENGINE_PLATFORM_MACOS) +# import +#else +# import +#endif + +namespace Mengine +{ + namespace Helper + { + ////////////////////////////////////////////////////////////////////////// + bool AppleGetUserDefaultsString( const Char * _key, Char * const _value, size_t _capacity ) + { + NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; + + if( defaults == nil ) + { + return false; + } + + NSString * _Nullable value = [defaults objectForKey:@(_key)]; + + if( value == nil ) + { + return false; + } + + const Char * value_str = [value UTF8String]; + + Helper::stringCopy( _value, value_str, _capacity ); + + return true; + } + ////////////////////////////////////////////////////////////////////////// + bool AppleSetUserDefaultsString( const Char * _key, const Char * _value ) + { + NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; + + if( defaults == nil ) + { + return false; + } + + [defaults setObject:@(_value) forKey:@(_key)]; + + [defaults synchronize]; + + return true; + } + ////////////////////////////////////////////////////////////////////////// + bool AppleGetUserDefaultsBoolean( const Char * _key, bool _default ) + { + NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; + + if( defaults == nil ) + { + return _default; + } + + NSNumber * _Nullable value = [defaults objectForKey:@(_key)]; + + if( value == nil ) + { + return _default; + } + + BOOL value_bool = [value boolValue]; + + return (bool)value_bool; + } + ////////////////////////////////////////////////////////////////////////// + bool AppleSetUserDefaultsBoolean( const Char * _key, bool _value ) + { + NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; + + if( defaults == nil ) + { + return false; + } + + [defaults setObject:@(_value) forKey:@(_key)]; + + [defaults synchronize]; + + return true; + } + ////////////////////////////////////////////////////////////////////////// + bool AppleRemoveUserDefaults( const Char * _key ) + { + NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; + + if( defaults == nil ) + { + return false; + } + + [defaults removeObjectForKey:@(_key)]; + + [defaults synchronize]; + + return true; + } + ////////////////////////////////////////////////////////////////////////// + } +} diff --git a/src/Environment/Apple/AppleUtils.h b/src/Environment/Apple/AppleUtils.h index f668521b86..36520cc7a2 100644 --- a/src/Environment/Apple/AppleUtils.h +++ b/src/Environment/Apple/AppleUtils.h @@ -12,8 +12,5 @@ namespace Mengine void AppleLogFormat( const Char * _format, ... ); void AppleLogFormatV( const Char * _format, MENGINE_VA_LIST_TYPE _va ); bool AppleOpenUrlInDefaultBrowser( const Char * _url ); - bool AppleGetUserDefaultsString( const Char * _key, Char * const _value, size_t _capacity ); - bool AppleSetUserDefaultsString( const Char * _key, const Char * _value ); - bool AppleRemoveUserDefaultsString( const Char * _key ); } } diff --git a/src/Environment/Apple/AppleUtils.mm b/src/Environment/Apple/AppleUtils.mm index 12763cbfa8..8b32658aad 100644 --- a/src/Environment/Apple/AppleUtils.mm +++ b/src/Environment/Apple/AppleUtils.mm @@ -56,60 +56,5 @@ bool AppleOpenUrlInDefaultBrowser( const Char * _url ) return true; } ////////////////////////////////////////////////////////////////////////// - bool AppleGetUserDefaultsString( const Char * _key, Char * const _value, size_t _capacity ) - { - NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; - - if( defaults == nil ) - { - return false; - } - - NSString * _Nullable value = [defaults objectForKey:@(_key)]; - - if( value == nil ) - { - return false; - } - - const Char * value_str = [value UTF8String]; - - Helper::stringCopy( _value, value_str, _capacity ); - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool AppleSetUserDefaultsString( const Char * _key, const Char * _value ) - { - NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; - - if( defaults == nil ) - { - return false; - } - - [defaults setObject:@(_value) forKey:@(_key)]; - - [defaults synchronize]; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool AppleRemoveUserDefaultsString( const Char * _key ) - { - NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; - - if( defaults == nil ) - { - return false; - } - - [defaults removeObjectForKey:@(_key)]; - - [defaults synchronize]; - - return true; - } - ////////////////////////////////////////////////////////////////////////// } } diff --git a/src/Environment/Apple/CMakeLists.txt b/src/Environment/Apple/CMakeLists.txt index 4f51e8023b..399b30a9c1 100644 --- a/src/Environment/Apple/CMakeLists.txt +++ b/src/Environment/Apple/CMakeLists.txt @@ -10,6 +10,9 @@ src AppleErrorHelper.mm AppleString.h AppleString.mm + + AppleUserDefaults.h + AppleUserDefaults.mm AppleAnalytics.h AppleAnalytics.mm diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm index dce8341d34..088a1a7058 100644 --- a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm @@ -1,12 +1,9 @@ #include "AppleGeneralDataProtectionRegulationService.h" -#include "Environment/Apple/AppleUtils.h" +#include "Environment/Apple/AppleUserDefaults.h" #include "Kernel/Logger.h" -#import -#import - //////////////////////////////////////////////////////////////////////////// SERVICE_FACTORY( AppleGeneralDataProtectionRegulationService, Mengine::AppleGeneralDataProtectionRegulationService ); ////////////////////////////////////////////////////////////////////////// @@ -24,7 +21,9 @@ ///////////////////////////////////////////////////////////////////////////// bool AppleGeneralDataProtectionRegulationService::_initializeService() { - //Empty + bool passGDPR = Helper::AppleGetUserDefaultsBoolean( "mengine.gdpr.pass", false ); + + m_passGDPR = passGDPR; return true; } @@ -39,6 +38,8 @@ LOGGER_MESSAGE( "set GDPR pass [%d]" , _passGDPR ); + + Helper::AppleSetUserDefaultsBoolean( "mengine.gdpr.pass", _passGDPR ); m_passGDPR = _passGDPR; } diff --git a/src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp b/src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp index 69e20d7914..a00f83823b 100644 --- a/src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp +++ b/src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp @@ -1,6 +1,6 @@ #include "ApplePersistentSystem.h" -#include "Environment/Apple/AppleUtils.h" +#include "Environment/Apple/AppleUserDefaults.h" ////////////////////////////////////////////////////////////////////////// SERVICE_FACTORY( PersistentSystem, Mengine::ApplePersistentSystem ); @@ -42,7 +42,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// void ApplePersistentSystem::removePersistentArguments() { - Helper::AppleRemoveUserDefaultsString( "mengine.persistent.arguments" ); + Helper::AppleRemoveUserDefaults( "mengine.persistent.arguments" ); } ////////////////////////////////////////////////////////////////////////// }