-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement web support for Firebase Remote Config
- Loading branch information
Showing
11 changed files
with
535 additions
and
0 deletions.
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
1 change: 1 addition & 0 deletions
1
packages/firebase_remote_config/firebase_remote_config_web/.gitignore
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 @@ | ||
.flutter-plugins-dependencies |
10 changes: 10 additions & 0 deletions
10
packages/firebase_remote_config/firebase_remote_config_web/.metadata
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,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 659dc8129d4edb9166e9a0d600439d135740933f | ||
channel: beta | ||
|
||
project_type: plugin |
27 changes: 27 additions & 0 deletions
27
packages/firebase_remote_config/firebase_remote_config_web/LICENSE
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,27 @@ | ||
// Copyright 2017-2020 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
16 changes: 16 additions & 0 deletions
16
packages/firebase_remote_config/firebase_remote_config_web/README.md
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,16 @@ | ||
# firebase_remote_config_web | ||
|
||
The web implementation of `firebase_remote_config`. | ||
|
||
## Getting Started | ||
|
||
To get started with Firebase Remote Config on Web, | ||
please [see the documentation](https://firebase.flutter.dev/docs/remote-config/overview) | ||
available at [https://firebase.flutter.dev](https://firebase.flutter.dev) | ||
|
||
Once installed, Firebase Remote Config needs to be configured for Web Installation. | ||
Please [see the documentation](https://firebase.flutter.dev/docs/remote-config/overview#3-web-only-add-the-sdk) on Web | ||
Installation. | ||
|
||
To learn more about Firebase Remote Config, please visit | ||
the [Firebase website](https://firebase.google.com/products/remote-config). |
162 changes: 162 additions & 0 deletions
162
...ges/firebase_remote_config/firebase_remote_config_web/lib/firebase_remote_config_web.dart
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,162 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:firebase_remote_config_platform_interface/firebase_remote_config_platform_interface.dart'; | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||
import 'package:firebase_core_web/firebase_core_web_interop.dart' | ||
as core_interop; | ||
import 'interop/firebase_remote_config.dart' as remote_config_interop; | ||
|
||
/// Web implementation of [FirebaseRemoteConfigPlatform]. | ||
class FirebaseRemoteConfigWeb extends FirebaseRemoteConfigPlatform { | ||
/// The entry point for the [FirebaseRemoteConfigWeb] class. | ||
FirebaseRemoteConfigWeb({FirebaseApp? app}) | ||
: _webRemoteConfig = remote_config_interop.getRemoteConfigInstance( | ||
core_interop.app(app?.name), | ||
), | ||
super(appInstance: app); | ||
|
||
/// Stub initializer to allow the [registerWith] to create an instance without | ||
/// registering the web delegates or listeners. | ||
FirebaseRemoteConfigWeb._() | ||
: _webRemoteConfig = null, | ||
super(appInstance: null); | ||
|
||
/// Instance of functions from the web plugin | ||
final remote_config_interop.RemoteConfig? _webRemoteConfig; | ||
|
||
/// Create the default instance of the [FirebaseRemoteConfigPlatform] as a [FirebaseRemoteConfigWeb] | ||
static void registerWith(Registrar registrar) { | ||
FirebaseRemoteConfigPlatform.instance = FirebaseRemoteConfigWeb.instance; | ||
} | ||
|
||
/// Returns an instance of [FirebaseRemoteConfigWeb]. | ||
static FirebaseRemoteConfigWeb get instance { | ||
return FirebaseRemoteConfigWeb._(); | ||
} | ||
|
||
@override | ||
FirebaseRemoteConfigPlatform delegateFor({FirebaseApp? app}) { | ||
return FirebaseRemoteConfigWeb(app: app); | ||
} | ||
|
||
/// Returns the [DateTime] of the last successful fetch. | ||
/// | ||
/// If no successful fetch has been made a [DateTime] representing | ||
/// the epoch (1970-01-01 UTC) is returned. | ||
@override | ||
DateTime get lastFetchTime { | ||
return _webRemoteConfig!.fetchTime; | ||
} | ||
|
||
/// Returns the status of the last fetch attempt. | ||
@override | ||
RemoteConfigFetchStatus get lastFetchStatus { | ||
switch (_webRemoteConfig!.lastFetchStatus) { | ||
case remote_config_interop.RemoteConfigFetchStatus.failure: | ||
return RemoteConfigFetchStatus.failure; | ||
case remote_config_interop.RemoteConfigFetchStatus.success: | ||
return RemoteConfigFetchStatus.success; | ||
case remote_config_interop.RemoteConfigFetchStatus.notFetchedYet: | ||
return RemoteConfigFetchStatus.noFetchYet; | ||
case remote_config_interop.RemoteConfigFetchStatus.throttle: | ||
return RemoteConfigFetchStatus.throttle; | ||
} | ||
} | ||
|
||
/// Returns the [RemoteConfigSettings] of the current instance. | ||
@override | ||
RemoteConfigSettings get settings { | ||
return RemoteConfigSettings( | ||
fetchTimeout: _webRemoteConfig!.settings.fetchTimeoutMillis, | ||
minimumFetchInterval: _webRemoteConfig!.settings.minimumFetchInterval, | ||
); | ||
} | ||
|
||
/// Makes the last fetched config available to getters. | ||
/// | ||
/// Returns a [bool] that is true if the config parameters | ||
/// were activated. Returns a [bool] that is false if the | ||
/// config parameters were already activated. | ||
@override | ||
Future<bool> activate() { | ||
return _webRemoteConfig!.activate(); | ||
} | ||
|
||
/// Ensures the last activated config are available to getters. | ||
@override | ||
Future<void> ensureInitialized() { | ||
return _webRemoteConfig!.ensureInitialized(); | ||
} | ||
|
||
/// Fetches and caches configuration from the Remote Config service. | ||
@override | ||
Future<void> fetch() { | ||
return _webRemoteConfig!.fetch(); | ||
} | ||
|
||
/// Performs a fetch and activate operation, as a convenience. | ||
/// | ||
/// Returns [bool] in the same way that is done for [activate]. | ||
@override | ||
Future<bool> fetchAndActivate() { | ||
return _webRemoteConfig!.fetchAndActivate(); | ||
} | ||
|
||
/// Returns a Map of all Remote Config parameters. | ||
@override | ||
Map<String, RemoteConfigValue> getAll() { | ||
// TODO implement | ||
throw UnimplementedError('getAll() is not implemented'); | ||
} | ||
|
||
/// Gets the value for a given key as a bool. | ||
@override | ||
bool getBool(String key) { | ||
return _webRemoteConfig!.getBoolean(key); | ||
} | ||
|
||
/// Gets the value for a given key as an int. | ||
@override | ||
int getInt(String key) { | ||
return _webRemoteConfig!.getNumber(key).toInt(); | ||
} | ||
|
||
/// Gets the value for a given key as a double. | ||
@override | ||
double getDouble(String key) { | ||
return _webRemoteConfig!.getNumber(key).toDouble(); | ||
} | ||
|
||
/// Gets the value for a given key as a String. | ||
@override | ||
String getString(String key) { | ||
return _webRemoteConfig!.getString(key); | ||
} | ||
|
||
/// Gets the [RemoteConfigValue] for a given key. | ||
@override | ||
RemoteConfigValue getValue(String key) { | ||
// TODO implement | ||
throw UnimplementedError('getValue() is not implemented'); | ||
} | ||
|
||
/// Sets the [RemoteConfigSettings] for the current instance. | ||
@override | ||
Future<void> setConfigSettings(RemoteConfigSettings remoteConfigSettings) { | ||
_webRemoteConfig!.settings.minimumFetchInterval = | ||
remoteConfigSettings.minimumFetchInterval; | ||
_webRemoteConfig!.settings.fetchTimeoutMillis = | ||
remoteConfigSettings.fetchTimeout; | ||
return Future<void>.value(); | ||
} | ||
|
||
/// Sets the default parameter values for the current instance. | ||
@override | ||
Future<void> setDefaults(Map<String, dynamic> defaultParameters) { | ||
_webRemoteConfig!.defaultConfig = defaultParameters; | ||
return Future<void>.value(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/firebase_remote_config/firebase_remote_config_web/lib/interop/firebase_interop.dart
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,16 @@ | ||
// Copyright 2021, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// ignore_for_file: public_member_api_docs | ||
|
||
@JS('firebase') | ||
library firebase_interop.firebase; | ||
|
||
import 'package:firebase_core_web/firebase_core_web_interop.dart'; | ||
|
||
import 'package:js/js.dart'; | ||
import 'firebase_remote_config_interop.dart'; | ||
|
||
@JS() | ||
external RemoteConfigJsImpl remoteConfig([AppJsImpl app]); |
Oops, something went wrong.