Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/irov/Mengine
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Aug 26, 2023
2 parents cc1f0ad + c64b4bb commit f926f83
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 85 deletions.
17 changes: 17 additions & 0 deletions src/Environment/Apple/AppleUserDefaults.h
Original file line number Diff line number Diff line change
@@ -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 );
}
}
109 changes: 109 additions & 0 deletions src/Environment/Apple/AppleUserDefaults.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "AppleUserDefaults.h"

#include "Kernel/StringCopy.h"

#if defined(MENGINE_PLATFORM_MACOS)
# import <AppKit/AppKit.h>
#else
# import <UIKit/UIKit.h>
#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;
}
//////////////////////////////////////////////////////////////////////////
}
}
3 changes: 0 additions & 3 deletions src/Environment/Apple/AppleUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
55 changes: 0 additions & 55 deletions src/Environment/Apple/AppleUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
//////////////////////////////////////////////////////////////////////////
}
}
3 changes: 3 additions & 0 deletions src/Environment/Apple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ src
AppleErrorHelper.mm
AppleString.h
AppleString.mm

AppleUserDefaults.h
AppleUserDefaults.mm

AppleAnalytics.h
AppleAnalytics.mm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Mengine
{
//////////////////////////////////////////////////////////////////////////
namespace Detail
{
//////////////////////////////////////////////////////////////////////////
Expand All @@ -33,11 +34,11 @@ static void s_AppleGeneralDataProtectionRegulation_isGDPRPass( bool _passGDPR )
//////////////////////////////////////////////////////////////////////////
}
//////////////////////////////////////////////////////////////////////////
AppleGeneralDataProtectionRegulationScriptEmbedding::AppleGeneralDataProtectionRegulationEmbedding()
AppleGeneralDataProtectionRegulationScriptEmbedding::AppleGeneralDataProtectionRegulationScriptEmbedding()
{
}
//////////////////////////////////////////////////////////////////////////
AppleGeneralDataProtectionRegulationScriptEmbedding::~AppleGeneralDataProtectionRegulationEmbedding()
AppleGeneralDataProtectionRegulationScriptEmbedding::~AppleGeneralDataProtectionRegulationScriptEmbedding()
{
}
//////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ namespace Mengine
public:
void setGDPRPass( bool _passGDPR ) override;
bool isGDPRPass() const override;

protected:
bool m_passGDPR;
};
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#include "AppleGeneralDataProtectionRegulationService.h"

#include "Environment/Apple/AppleUtils.h"
#include "Environment/Apple/AppleUserDefaults.h"

#include "Kernel/Logger.h"

#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>

////////////////////////////////////////////////////////////////////////////
SERVICE_FACTORY( AppleGeneralDataProtectionRegulationService, Mengine::AppleGeneralDataProtectionRegulationService );
//////////////////////////////////////////////////////////////////////////
namespace Mengine
{
//////////////////////////////////////////////////////////////////////////
AppleGeneralDataProtectionRegulationService::AppleGeneralDataProtectionRegulationService()
: m_passGDPR(false)
{
}
//////////////////////////////////////////////////////////////////////////
Expand All @@ -23,7 +21,9 @@
/////////////////////////////////////////////////////////////////////////////
bool AppleGeneralDataProtectionRegulationService::_initializeService()
{
//Empty
bool passGDPR = Helper::AppleGetUserDefaultsBoolean( "mengine.gdpr.pass", false );

m_passGDPR = passGDPR;

return true;
}
Expand All @@ -39,20 +39,14 @@
, _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];
}
Helper::AppleSetUserDefaultsBoolean( "mengine.gdpr.pass", _passGDPR );

m_passGDPR = _passGDPR;
}
//////////////////////////////////////////////////////////////////////////
bool AppleGeneralDataProtectionRegulationService::isGDPRPass() const
{
return m_passGDPR;
}
//////////////////////////////////////////////////////////////////////////
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "Kernel/BuildMode.h"

#import <Sentry/Sentry.h>
#import "Sentry/Sentry.h"

@implementation AppleSentryApplicationDelegate

Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "Config/StdString.h"

#import <Sentry/Sentry.h>
#import "Sentry/Sentry.h"

namespace Mengine
{
Expand Down
8 changes: 4 additions & 4 deletions src/Systems/ApplePersistentSystem/ApplePersistentSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ApplePersistentSystem.h"

#include "Environment/Apple/AppleUtils.h"
#include "Environment/Apple/AppleUserDefaults.h"

//////////////////////////////////////////////////////////////////////////
SERVICE_FACTORY( PersistentSystem, Mengine::ApplePersistentSystem );
Expand Down Expand Up @@ -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::AppleRemoveUserDefaults( "mengine.persistent.arguments" );
}
//////////////////////////////////////////////////////////////////////////
}

0 comments on commit f926f83

Please sign in to comment.