generated from nventive/Template
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add forcedupdate firebase implementation #409
Draft
Marc-Antoine-Soucy
wants to merge
4
commits into
main
Choose a base branch
from
dev/maso/remoteconfig
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/app/ApplicationTemplate.Mobile/LinkWithSwiftSystemLibrariesWorkaround.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
<Project> | ||
<!-- Target needed until LinkWithSwiftSystemLibraries makes it into the SDK: https://github.com/xamarin/xamarin-macios/pull/20463 --> | ||
<Target Name="LinkWithSwift" DependsOnTargets="_ParseBundlerArguments;_DetectSdkLocations" BeforeTargets="_LinkNativeExecutable"> | ||
<PropertyGroup> | ||
<_SwiftPlatform Condition="$(RuntimeIdentifier.StartsWith('iossimulator-'))">iphonesimulator</_SwiftPlatform> | ||
<_SwiftPlatform Condition="$(RuntimeIdentifier.StartsWith('ios-'))">iphoneos</_SwiftPlatform> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<_CustomLinkFlags Include="-L" /> | ||
<_CustomLinkFlags Include="/usr/lib/swift" /> | ||
<_CustomLinkFlags Include="-L" /> | ||
<_CustomLinkFlags Include="$(_SdkDevPath)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/$(_SwiftPlatform)" /> | ||
<_CustomLinkFlags Include="-Wl,-rpath" /> | ||
<_CustomLinkFlags Include="-Wl,/usr/lib/swift" /> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/app/ApplicationTemplate.Shared.Views/RemoteConfigRepository.Android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#if __ANDROID__ | ||
using System; | ||
using System.Reactive.Subjects; | ||
using ApplicationTemplate.DataAccess; | ||
using Firebase.RemoteConfig; | ||
|
||
namespace ApplicationTemplate.Views; | ||
|
||
/// <summary> | ||
/// RemoteConfigRepository is a repository for Firebase Remote Config. | ||
/// </summary> | ||
public sealed class RemoteConfigRepository : IKillSwitchRepository, IMinimumVersionReposiory, IDisposable | ||
{ | ||
private Subject<bool> _killSwitchSubject = new Subject<bool>(); | ||
private Subject<Version> _versionSubject = new Subject<Version>(); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RemoteConfigRepository"/> class. | ||
/// </summary> | ||
public RemoteConfigRepository() | ||
{ | ||
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance; | ||
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() | ||
.SetMinimumFetchIntervalInSeconds(3600) | ||
.Build(); | ||
mFirebaseRemoteConfig.SetConfigSettingsAsync(configSettings); | ||
|
||
FetchRemoteConfig(); | ||
ListenForRealTimeChanges(); | ||
} | ||
|
||
private void FetchRemoteConfig() | ||
{ | ||
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance; | ||
mFirebaseRemoteConfig.FetchAndActivate() | ||
.AddOnCompleteListener(new FetchCompleteListener(this)); | ||
} | ||
|
||
private void ListenForRealTimeChanges() | ||
{ | ||
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.Instance; | ||
|
||
mFirebaseRemoteConfig.AddOnConfigUpdateListener(new ConfigUpdateListener(this)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IObservable<Version> MinimumVersionObservable => _versionSubject; | ||
|
||
/// <inheritdoc /> | ||
public void CheckMinimumVersion() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IObservable<bool> ObserveKillSwitchActivation() | ||
{ | ||
return _killSwitchSubject; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Dispose() | ||
{ | ||
_killSwitchSubject.Dispose(); | ||
_versionSubject.Dispose(); | ||
} | ||
|
||
private sealed class FetchCompleteListener : Java.Lang.Object, Android.Gms.Tasks.IOnCompleteListener | ||
{ | ||
private readonly RemoteConfigRepository _repository; | ||
|
||
public FetchCompleteListener(RemoteConfigRepository repository) | ||
{ | ||
_repository = repository; | ||
} | ||
|
||
public void OnComplete(Android.Gms.Tasks.Task task) | ||
{ | ||
if (task.IsSuccessful) | ||
{ | ||
_repository._killSwitchSubject.OnNext(FirebaseRemoteConfig.Instance.GetBoolean("kill_switch")); | ||
_repository._versionSubject.OnNext(new Version(FirebaseRemoteConfig.Instance.GetString("minimum_version"))); | ||
} | ||
} | ||
} | ||
|
||
private sealed class ConfigUpdateListener : Java.Lang.Object, IConfigUpdateListener | ||
{ | ||
private readonly RemoteConfigRepository _repository; | ||
|
||
public ConfigUpdateListener(RemoteConfigRepository repository) | ||
{ | ||
_repository = repository; | ||
} | ||
|
||
public void OnError(FirebaseRemoteConfigException p0) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void OnUpdate(ConfigUpdate p0) | ||
{ | ||
var instance = FirebaseRemoteConfig.Instance; | ||
|
||
instance.FetchAndActivate(); | ||
var isKillSwitchActivated = FirebaseRemoteConfig.Instance.GetBoolean("kill_switch"); | ||
var minimumVersion = new Version(FirebaseRemoteConfig.Instance.GetString("minimum_version")); | ||
|
||
_repository._killSwitchSubject.OnNext(isKillSwitchActivated); | ||
_repository._versionSubject.OnNext(minimumVersion); | ||
} | ||
} | ||
} | ||
#endif |
96 changes: 96 additions & 0 deletions
96
src/app/ApplicationTemplate.Shared.Views/RemoteConfigRepository.Ios.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#if __IOS__ | ||
using System; | ||
using System.Reactive.Subjects; | ||
using ApplicationTemplate.DataAccess; | ||
using Firebase.RemoteConfig; | ||
using Foundation; | ||
|
||
namespace ApplicationTemplate.Views; | ||
|
||
/// <summary> | ||
/// Implementation of the killswitch repository and the minimum version with Firebase Remote Config for iOS. | ||
/// </summary> | ||
public sealed class RemoteConfigRepository : IKillSwitchRepository, IMinimumVersionReposiory, IDisposable | ||
{ | ||
private BehaviorSubject<bool> _killSwitchSubject = new BehaviorSubject<bool>(default); | ||
private BehaviorSubject<Version> _versionSubject = new BehaviorSubject<Version>(default); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RemoteConfigRepository"/> class. | ||
/// </summary> | ||
public RemoteConfigRepository() | ||
{ | ||
Firebase.Core.App.Configure(); | ||
// Enabling developer mode, allows for frequent refreshes of the cache | ||
RemoteConfig.SharedInstance.ConfigSettings = new RemoteConfigSettings(); | ||
|
||
object[] values = { false, "1.0.0" }; | ||
object[] keys = { "kill_switch", "minimum_version" }; | ||
var defaultValues = NSDictionary.FromObjectsAndKeys(values, keys, keys.Length); | ||
RemoteConfig.SharedInstance.SetDefaults(defaultValues); | ||
|
||
// CacheExpirationSeconds is set to CacheExpiration here, indicating that any previously | ||
// fetched and cached config would be considered expired because it would have been fetched | ||
// more than CacheExpiration seconds ago. Thus the next fetch would go to the server unless | ||
// throttling is in progress. The default expiration duration is 43200 (12 hours). | ||
RemoteConfig.SharedInstance.Fetch(10, (status, error) => | ||
{ | ||
switch (status) | ||
{ | ||
case RemoteConfigFetchStatus.Success: | ||
Console.WriteLine("Config Fetched!"); | ||
|
||
// Call this method to make fetched parameter values available to your app | ||
RemoteConfig.SharedInstance.Activate(); | ||
|
||
_killSwitchSubject.OnNext(RemoteConfig.SharedInstance["kill_switch"].BoolValue); | ||
_versionSubject.OnNext(new Version(RemoteConfig.SharedInstance["minimum_version"].StringValue)); | ||
break; | ||
|
||
case RemoteConfigFetchStatus.Throttled: | ||
case RemoteConfigFetchStatus.NoFetchYet: | ||
case RemoteConfigFetchStatus.Failure: | ||
Console.WriteLine("Config not fetched..."); | ||
break; | ||
} | ||
}); | ||
|
||
RemoteConfig.SharedInstance.AddObserver(new NSString("kill_switch"), NSKeyValueObservingOptions.New, (nSObservedChange) => | ||
{ | ||
if (nSObservedChange.NewValue is NSNumber nSNumber) | ||
{ | ||
_killSwitchSubject.OnNext(nSNumber.BoolValue); | ||
} | ||
}); | ||
RemoteConfig.SharedInstance.AddObserver(new NSString("minimum_version"), NSKeyValueObservingOptions.New, (nSObservedChange) => | ||
{ | ||
if (nSObservedChange.NewValue is NSString nSString) | ||
{ | ||
_versionSubject.OnNext(new Version(nSString)); | ||
} | ||
}); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IObservable<Version> MinimumVersionObservable => _versionSubject; | ||
|
||
/// <inheritdoc /> | ||
public void CheckMinimumVersion() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IObservable<bool> ObserveKillSwitchActivation() | ||
{ | ||
return _killSwitchSubject; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Dispose() | ||
{ | ||
_killSwitchSubject.Dispose(); | ||
_versionSubject.Dispose(); | ||
} | ||
} | ||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need to keep those for the functional tests to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The services exist in the view layer, this doesnt have access to the service?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could try to create some sort of thing that would get the viewservice here, would that be something we really want to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functional tests don't use anything from the View layer. So I guess this adds to my original question. 😋