Skip to content

Commit

Permalink
Rename Navigation plugin
Browse files Browse the repository at this point in the history
-raname to go_router
-make argument parsing conditional
-treat state as an object, not string
-google_log_in refresh token logic

Signed-off-by: Joel Winarske <[email protected]>
  • Loading branch information
Joel Winarske authored and jwinarske committed Oct 24, 2023
1 parent 5c700ac commit c54ef7c
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 145 deletions.
6 changes: 3 additions & 3 deletions cmake/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ if (BUILD_BACKEND_WAYLAND_EGL)
endif ()
endif ()

option(BUILD_PLUGIN_NAVIGATION "Includes Navigation Plugin" ON)
if (BUILD_PLUGIN_NAVIGATION)
ENABLE_PLUGIN(navigation)
option(BUILD_PLUGIN_GO_ROUTER "Includes Go Router Plugin" ON)
if (BUILD_PLUGIN_GO_ROUTER)
ENABLE_PLUGIN(go_router)
endif ()

option(BUILD_PLUGIN_ACCESSIBILITY "Includes Accessibility Plugin" ON)
Expand Down
8 changes: 4 additions & 4 deletions shell/platform_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#ifdef ENABLE_PLUGIN_GSTREAMER_EGL
#include "static_plugins/gstreamer_egl/gstreamer_egl.h"
#endif
#ifdef ENABLE_PLUGIN_NAVIGATION
#include "static_plugins/navigation/navigation.h"
#ifdef ENABLE_PLUGIN_GO_ROUTER
#include "static_plugins/go_router/go_router.h"
#endif
#ifdef ENABLE_PLUGIN_COMP_SURF
#include "static_plugins/comp_surf/comp_surf.h"
Expand Down Expand Up @@ -97,8 +97,8 @@ PlatformChannel::PlatformChannel() {
RegisterCallback(GstreamerEgl::kChannelGstreamerInitialize,
&GstreamerEgl::OnInitialize);
#endif
#ifdef ENABLE_PLUGIN_NAVIGATION
RegisterCallback(Navigation::kChannelName, &Navigation::OnPlatformMessage);
#ifdef ENABLE_PLUGIN_GO_ROUTER
RegisterCallback(GoRouter::kChannelName, &GoRouter::OnPlatformMessage);
#endif
#ifdef ENABLE_PLUGIN_COMP_SURF
RegisterCallback(CompositorSurfacePlugin::kChannelName,
Expand Down
80 changes: 80 additions & 0 deletions shell/static_plugins/go_router/go_router.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2020 Toyota Connected North America
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "go_router.h"

#include <flutter/shell/platform/common/json_method_codec.h>

#include "engine.h"

void GoRouter::OnPlatformMessage(const FlutterPlatformMessage* message,
void* userdata) {
std::unique_ptr<std::vector<uint8_t>> result;
auto engine = reinterpret_cast<Engine*>(userdata);
auto& codec = flutter::JsonMethodCodec::GetInstance();
auto obj = codec.DecodeMethodCall(message->message, message->message_size);

auto method = obj->method_name();

if (method == kSelectSingleEntryHistory) {
spdlog::info("({}) [go_router] Select Single Entry History",
engine->GetIndex());
result = codec.EncodeSuccessEnvelope();
} else if (method == kSelectMultiEntryHistory) {
spdlog::info("({}) [go_router] Select Multiple Entry History",
engine->GetIndex());
result = codec.EncodeSuccessEnvelope();
} else if (method == kMethodSystemNavigatorPop) {
spdlog::info("({}) [go_router] Pop", engine->GetIndex());
result = codec.EncodeSuccessEnvelope();
} else if (method == kRouteInformationUpdated) {
auto args = obj->arguments();
std::string uri;
if (args->HasMember("uri") && (*args)["uri"].IsString()) {
uri = (*args)["uri"].GetString();
}
std::string location;
if (args->HasMember("location") && (*args)["location"].IsString()) {
location = (*args)["location"].GetString();
}
bool replace{};
if (args->HasMember("replace") && (*args)["replace"].IsBool()) {
replace = (*args)["replace"].GetBool();
}
if (!location.empty()) {
spdlog::info(
"({}) [go_router] Route Information Updated"
"\n\tlocation: {} \n\treplace: {}",
engine->GetIndex(), location, replace);
} else {
spdlog::info(
"({}) [go_router] Route Information Updated"
"\n\turi: {} \n\treplace: {}",
engine->GetIndex(), uri, replace);
}

if (args->HasMember("state") && (*args)["state"].IsObject()) {
spdlog::info("({}) [go_router] State Object Valid", engine->GetIndex());
}

result = codec.EncodeSuccessEnvelope();
} else {
SPDLOG_DEBUG("({}) [go_router] {} is unhandled", engine->GetIndex(),
method);
result = codec.EncodeErrorEnvelope("unhandled_method", "unhandled Method");
}

engine->SendPlatformMessageResponse(message->response_handle, result->data(),
result->size());
}
102 changes: 102 additions & 0 deletions shell/static_plugins/go_router/go_router.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2020 Toyota Connected North America
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <shell/platform/embedder/embedder.h>
#include <string>

class GoRouter {
public:
static constexpr char kChannelName[] = "flutter/navigation";

/**
* @brief Callback function for platform messages about navigation
* @param[in] message Receive message
* @param[in] userdata Pointer to User data
* @return void
* @relation
* flutter
*/
static void OnPlatformMessage(const FlutterPlatformMessage* message,
void* userdata);

private:
/// Removes the topmost Flutter instance, presenting what was before it.
///
/// On Android, removes this activity from the stack and returns to the
/// previous activity.
///
/// On iOS, calls `popViewControllerAnimated:` if the root view controller is
/// a `UINavigationController`, or `dismissViewControllerAnimated:completion:`
/// if the top view controller is a `FlutterViewController`.
///
/// The optional `animated` parameter is ignored on all platforms
/// except iOS where it is an argument to the aforementioned methods.
///
/// This method should be preferred over calling `dart:io`'s [exit] method, as
/// the latter may cause the underlying platform to act as if the application
/// had crashed.
static constexpr char kMethodSystemNavigatorPop[] =
"SystemNavigator.pop";
/// Selects the single-entry history mode.
///
/// On web, this switches the browser history model to one that only tracks a
/// single entry, so that calling [routeInformationUpdated] replaces the
/// current entry.
///
/// Currently, this is ignored on other platforms.
///
/// See also:
///
/// * [selectMultiEntryHistory], which enables the browser history to have
/// multiple entries.
static constexpr char kSelectSingleEntryHistory[] =
"selectSingleEntryHistory";
/// Selects the multiple-entry history mode.
///
/// On web, this switches the browser history model to one that tracks all
/// updates to [routeInformationUpdated] to form a history stack. This is the
/// default.
///
/// Currently, this is ignored on other platforms.
///
/// See also:
///
/// * [selectSingleEntryHistory], which forces the history to only have one
/// entry.
static constexpr char kSelectMultiEntryHistory[] = "selectMultiEntryHistory";
/// Notifies the platform for a route information change.
///
/// On web, this method behaves differently based on the single-entry or
/// multiple-entries history mode. Use the [selectSingleEntryHistory] and
/// [selectMultiEntryHistory] to toggle between modes.
///
/// For single-entry mode, this method replaces the current URL and state in
/// the current history entry. The flag `replace` is ignored.
///
/// For multiple-entries mode, this method creates a new history entry on top
/// of the current entry if the `replace` is false, thus the user will be on a
/// new history entry as if the user has visited a new page, and the browser
/// back button brings the user back to the previous entry. If `replace` is
/// true, this method only updates the URL and the state in the current
/// history entry without pushing a new one.
///
/// This method is ignored on other platforms.
///
/// The `replace` flag defaults to false.
static constexpr char kRouteInformationUpdated[] = "routeInformationUpdated";
};
15 changes: 14 additions & 1 deletion shell/static_plugins/google_sign_in/google_sign_in.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ rapidjson::Document GoogleSignIn::RefreshToken(

// Has token expired?
auto now = Utils::GetEpochTimeInSeconds();
if (now > expires_at) {
spdlog::trace("[google_sign_in] Now: {}", now);
spdlog::trace("[google_sign_in] Token Expires At: {}", expires_at);
if (expires_at > now) {
spdlog::debug("[Google Sign In] Token Expires In {} Seconds",
now - expires_at);
return std::move(client_credential_doc);
Expand Down Expand Up @@ -183,13 +185,24 @@ rapidjson::Document GoogleSignIn::RefreshToken(

doc.Parse(response.c_str());
if (doc.GetParseError() != rapidjson::kParseErrorNone) {
spdlog::error("[google_sign_in] Failure Parsing Refresh Token Response: {}",
static_cast<int>(doc.GetParseError()));
doc.Parse("{}");
return std::move(doc);
}

auto resp = doc.GetObject();
auto& allocator = doc.GetAllocator();

if (resp.HasMember("error") && resp["error"].IsString() &&
resp.HasMember("error_description") &&
resp["error_description"].IsString()) {
spdlog::error("[google_sign_in] Refresh Token Error: {} - {}",
resp["error"].GetString(),
resp["error_description"].GetString());
return std::move(doc);
}

// change expires_in to expires_at
auto expires_in = resp[kKeyExpiresIn].GetInt64();
resp.RemoveMember(kKeyExpiresIn);
Expand Down
85 changes: 0 additions & 85 deletions shell/static_plugins/navigation/navigation.cc

This file was deleted.

49 changes: 0 additions & 49 deletions shell/static_plugins/navigation/navigation.h

This file was deleted.

Loading

0 comments on commit c54ef7c

Please sign in to comment.