mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Implement cover plugin 1868 (#1897)
* implement_cover_plugin_#1868 * code cleanup * fix: CI issue fix * fix: cover plugin implementation finalized * fix: localization fixes * fix: added add cover button * chore: optimize the cover plugin code * feat: auto hide the add button and cover buttons when leaving --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
#include "include/appflowy_backend/appflowy_flutter_backend_plugin.h"
|
||||
|
||||
// This must be included before many other Windows headers.
|
||||
#include <windows.h>
|
||||
@ -13,70 +12,85 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include "include/appflowy_backend/app_flowy_backend_plugin.h"
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
|
||||
class AppFlowyBackendPlugin : public flutter::Plugin {
|
||||
public:
|
||||
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
|
||||
class AppFlowyBackendPlugin : public flutter::Plugin
|
||||
{
|
||||
public:
|
||||
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
|
||||
|
||||
AppFlowyBackendPlugin();
|
||||
AppFlowyBackendPlugin();
|
||||
|
||||
virtual ~AppFlowyBackendPlugin();
|
||||
virtual ~AppFlowyBackendPlugin();
|
||||
|
||||
private:
|
||||
// Called when a method is called on this plugin's channel from Dart.
|
||||
void HandleMethodCall(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||
};
|
||||
private:
|
||||
// Called when a method is called on this plugin's channel from Dart.
|
||||
void HandleMethodCall(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||
};
|
||||
|
||||
// static
|
||||
void AppFlowyBackendPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarWindows *registrar) {
|
||||
auto channel =
|
||||
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), "appflowy_backend",
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
// static
|
||||
void AppFlowyBackendPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarWindows *registrar)
|
||||
{
|
||||
auto channel =
|
||||
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), "appflowy_backend",
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
|
||||
auto plugin = std::make_unique<AppFlowyBackendPlugin>();
|
||||
auto plugin = std::make_unique<AppFlowyBackendPlugin>();
|
||||
|
||||
channel->SetMethodCallHandler(
|
||||
[plugin_pointer = plugin.get()](const auto &call, auto result) {
|
||||
plugin_pointer->HandleMethodCall(call, std::move(result));
|
||||
});
|
||||
channel->SetMethodCallHandler(
|
||||
[plugin_pointer = plugin.get()](const auto &call, auto result)
|
||||
{
|
||||
plugin_pointer->HandleMethodCall(call, std::move(result));
|
||||
});
|
||||
|
||||
registrar->AddPlugin(std::move(plugin));
|
||||
}
|
||||
|
||||
AppFlowyBackendPlugin::AppFlowyBackendPlugin() {}
|
||||
|
||||
AppFlowyBackendPlugin::~AppFlowyBackendPlugin() {}
|
||||
|
||||
void AppFlowyBackendPlugin::HandleMethodCall(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||
if (method_call.method_name().compare("getPlatformVersion") == 0) {
|
||||
std::ostringstream version_stream;
|
||||
version_stream << "Windows ";
|
||||
if (IsWindows10OrGreater()) {
|
||||
version_stream << "10+";
|
||||
} else if (IsWindows8OrGreater()) {
|
||||
version_stream << "8";
|
||||
} else if (IsWindows7OrGreater()) {
|
||||
version_stream << "7";
|
||||
}
|
||||
result->Success(flutter::EncodableValue(version_stream.str()));
|
||||
} else {
|
||||
result->NotImplemented();
|
||||
registrar->AddPlugin(std::move(plugin));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
AppFlowyBackendPlugin::AppFlowyBackendPlugin() {}
|
||||
|
||||
AppFlowyBackendPlugin::~AppFlowyBackendPlugin() {}
|
||||
|
||||
void AppFlowyBackendPlugin::HandleMethodCall(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
||||
{
|
||||
if (method_call.method_name().compare("getPlatformVersion") == 0)
|
||||
{
|
||||
std::ostringstream version_stream;
|
||||
version_stream << "Windows ";
|
||||
if (IsWindows10OrGreater())
|
||||
{
|
||||
version_stream << "10+";
|
||||
}
|
||||
else if (IsWindows8OrGreater())
|
||||
{
|
||||
version_stream << "8";
|
||||
}
|
||||
else if (IsWindows7OrGreater())
|
||||
{
|
||||
version_stream << "7";
|
||||
}
|
||||
result->Success(flutter::EncodableValue(version_stream.str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
result->NotImplemented();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void AppFlowyBackendPluginRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
FlutterDesktopPluginRegistrarRef registrar)
|
||||
{
|
||||
AppFlowyBackendPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
}
|
||||
}
|
@ -5,8 +5,9 @@
|
||||
#include "appflowy_flutter_backend_plugin.h"
|
||||
|
||||
void AppFlowyBackendPluginCApiRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
appflowy_backend::AppFlowyBackendPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
FlutterDesktopPluginRegistrarRef registrar)
|
||||
{
|
||||
appflowy_backend::AppFlowyBackendPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
}
|
||||
|
Reference in New Issue
Block a user