Skip to content
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(core, windows): Add api to access firebase cpp objects #11254

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/firebase_core/firebase_core/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# customers of the plugin.
cmake_minimum_required(VERSION 3.14)

set(FIREBASE_SDK_VERSION "10.5.0")
set(FIREBASE_SDK_VERSION "11.2.0")

if (EXISTS $ENV{FIREBASE_CPP_SDK_DIR}/include/firebase/version.h)
file(READ "$ENV{FIREBASE_CPP_SDK_DIR}/include/firebase/version.h" existing_version)
Expand Down Expand Up @@ -90,8 +90,8 @@ set(MSVC_RUNTIME_MODE MD)
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${FIREBASE_CPP_SDK_DIR}/include")
set(firebase_libs firebase_auth firebase_database firebase_app)
foreach(firebase_lib IN ITEMS ${firebase_libs})
set(FIREBASE_LIBS firebase_app firebase_auth firebase_remote_config)
Lyokone marked this conversation as resolved.
Show resolved Hide resolved
foreach(firebase_lib IN ITEMS ${FIREBASE_LIBS})
get_target_property(firebase_lib_path ${firebase_lib} IMPORTED_LOCATION)
string(REPLACE "Debug" "Release" firebase_lib_release_path ${firebase_lib_path})
set_target_properties(${firebase_lib} PROPERTIES
Expand All @@ -100,7 +100,9 @@ foreach(firebase_lib IN ITEMS ${firebase_libs})
)
endforeach()

target_link_libraries(${PLUGIN_NAME} PRIVATE "${firebase_libs}")
set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 rpcrt4 ole32 icu)

target_link_libraries(${PLUGIN_NAME} PRIVATE "${FIREBASE_LIBS}" "${ADDITIONAL_LIBS}")

target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <windows.h>

#include "firebase/app.h"
#include "firebase/auth.h"
#include "firebase/remote_config.h"
#include "messages.g.h"

// For getPlatformVersion; remove unless needed for your plugin implementation.
Expand All @@ -24,6 +26,8 @@
#include <string>
#include <vector>
using ::firebase::App;
using ::firebase::auth::Auth;
using ::firebase::remote_config::RemoteConfig;

namespace firebase_core_windows {

Expand All @@ -38,6 +42,26 @@ void FirebaseCorePlugin::RegisterWithRegistrar(
registrar->AddPlugin(std::move(plugin));
}

void *FirebaseCorePlugin::GetFirebaseApp(std::string appName) {
return App::GetInstance(appName.c_str());
}

void *FirebaseCorePlugin::GetFirebaseAuth(std::string appName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes me think that auth will probably need a tenantId parameter but I don't think this is available yet on C++.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of tenantId? I'd like to see how to map that into the c++ lib.

Copy link
Contributor

@Lyokone Lyokone Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to determine the tenant of the app: https://cloud.google.com/identity-platform/docs/multi-tenancy

App *app = App::GetInstance(appName.c_str());
if (app == nullptr) {
return nullptr;
}
return Auth::GetAuth(app);
}

void *FirebaseCorePlugin::GetFirebaseRemoteConfig(std::string appName) {
App *app = App::GetInstance(appName.c_str());
if (app == nullptr) {
return nullptr;
}
return RemoteConfig::GetInstance(app);
}

FirebaseCorePlugin::FirebaseCorePlugin() {}

FirebaseCorePlugin::~FirebaseCorePlugin() = default;
Expand Down Expand Up @@ -107,14 +131,17 @@ void FirebaseCorePlugin::InitializeCore(
std::function<void(ErrorOr<flutter::EncodableList> reply)> result) {
// TODO: Missing function to get the list of currently initialized apps
std::vector<PigeonInitializeResponse> initializedApps;
std::vector<App *> all_apps = App::GetApps();
for (const App *app : all_apps) {
initializedApps.push_back(AppToPigeonInitializeResponse(*app));
}

flutter::EncodableList encodableList;

// Insert the contents of the vector into the EncodableList
// for (const auto &item : initializedApps) {
// encodableList.push_back(flutter::EncodableValue(item));
//}
result(flutter::EncodableList());
for (const auto &item : initializedApps) {
encodableList.push_back(flutter::CustomEncodableValue(item));
}
result(encodableList);
}

void FirebaseCorePlugin::OptionsFromResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class FirebaseCorePlugin : public flutter::Plugin,
public FirebaseAppHostApi {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
static void *GetFirebaseApp(std::string appName);
static void *GetFirebaseAuth(std::string appName);
static void *GetFirebaseRemoteConfig(std::string appName);

FirebaseCorePlugin();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ void FirebaseCorePluginCApiRegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}

void* GetFirebaseApp(std::string appName) {
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseApp(appName);
}

void* GetFirebaseAuth(std::string appName) {
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseAuth(appName);
}

void* GetFirebaseRemoteConfig(std::string appName) {
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseRemoteConfig(
appName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <flutter_plugin_registrar.h>

#include <string>

#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
#else
Expand All @@ -22,6 +24,12 @@ extern "C" {
FLUTTER_PLUGIN_EXPORT void FirebaseCorePluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);

FLUTTER_PLUGIN_EXPORT void* GetFirebaseApp(std::string appName);

FLUTTER_PLUGIN_EXPORT void* GetFirebaseAuth(std::string appName);

FLUTTER_PLUGIN_EXPORT void* GetFirebaseRemoteConfig(std::string appName);

#if defined(__cplusplus)
} // extern "C"
#endif
Expand Down