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

fix(auth, windows): add pluginregistry to properly restore state on Windows #12114

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

#include "firebase_auth_plugin.h"
#include <firebase_core/firebase_core_plugin_c_api.h>

// This must be included before many other Windows headers.
#include <windows.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ abstract class FirebaseAuthPlatform extends PlatformInterface {
required Map<dynamic, dynamic> pluginConstants,
}) {
var currentUser = pluginConstants['APP_CURRENT_USER'];
print('pluginConstants: $pluginConstants');
print('currentUser: $currentUser');

if (currentUser != null) {
currentUser as List<Object?>;
Expand Down
3 changes: 3 additions & 0 deletions packages/firebase_core/firebase_core/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ list(APPEND PLUGIN_SOURCES
"firebase_core_plugin.h"
"messages.g.cpp"
"messages.g.h"
"flutter_firebase_plugin.h"
"flutter_firebase_plugin_registry.h"
"flutter_firebase_plugin_registry.cpp"
)

# Read version from pubspec.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
#include <vector>

#include "firebase_core_plugin.h"
#include "flutter_firebase_plugin_registry.h"

void FirebaseCorePluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
firebase_core_windows::FirebaseCorePlugin::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}

void RegisterPlugin(
std::string channelName,
void* flutterFirebasePlugin) {
FlutterFirebasePlugin* fireplugin = static_cast<FlutterFirebasePlugin*>(flutterFirebasePlugin);

firebase_core_windows::FlutterFirebasePluginRegistry::registerPlugin(
channelName, fireplugin);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#ifndef FLUTTER_FIREBASE_PLUGIN_H
#define FLUTTER_FIREBASE_PLUGIN_H

#include <future>
#include <map>
#include <string>

#include "firebase/app.h"
#include "firebase/future.h"
#include <flutter/standard_method_codec.h>

class FlutterFirebasePlugin {
public:
virtual ~FlutterFirebasePlugin() {}
virtual firebase::Future<flutter::EncodableMap> getPluginConstantsForFirebaseApp(firebase::App firebaseApp) = 0;
virtual firebase::Future<void> didReinitializeFirebaseCore() = 0;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "flutter_firebase_plugin_registry.h"

#include <any>
#include <exception>

#include "firebase/app.h"
#include "firebase/util.h"

#include "flutter/encodable_value.h"

namespace firebase_core_windows {

std::unordered_map<std::string, FlutterFirebasePlugin*>
FlutterFirebasePluginRegistry::registeredPlugins;

void FlutterFirebasePluginRegistry::registerPlugin(
std::string channelName, FlutterFirebasePlugin* flutterFirebasePlugin) {
registeredPlugins[channelName] = flutterFirebasePlugin;
}

flutter::EncodableMap FlutterFirebasePluginRegistry::getPluginConstantsForFirebaseApp(
firebase::App firebaseApp) {
flutter::EncodableMap pluginConstants;

for (const auto& entry : registeredPlugins) {
std::string channelName = entry.first;
FlutterFirebasePlugin* plugin = entry.second;

firebase::Future future =
plugin->getPluginConstantsForFirebaseApp(firebaseApp);
}

return pluginConstants;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef FLUTTER_FIREBASE_PLUGIN_REGISTRY_H
#define FLUTTER_FIREBASE_PLUGIN_REGISTRY_H

#include <any>
#include <future>
#include <string>
#include <unordered_map>

#include "firebase/app.h"
#include "firebase/future.h"
#include "flutter_firebase_plugin.h"

namespace firebase_core_windows {

class FlutterFirebasePluginRegistry {
private:
static std::unordered_map<std::string, FlutterFirebasePlugin*>
registeredPlugins;

public:
static void registerPlugin(std::string channelName,
FlutterFirebasePlugin* flutterFirebasePlugin);
static flutter::EncodableMap getPluginConstantsForFirebaseApp(
firebase::App firebaseApp);
static firebase::Future<void> didReinitializeFirebaseCore();
};

}

#endif // FLUTTER_FIREBASE_PLUGIN_REGISTRY_H
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@
FLUTTER_PLUGIN_EXPORT void FirebaseCorePluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);

FLUTTER_PLUGIN_EXPORT void RegisterPlugin(
std::string channelName,
void* flutterFirebasePlugin);

#endif // FLUTTER_PLUGIN_FIREBASE_CORE_PLUGIN_C_API_H_
Loading