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

Add exit application method to system channel #46

Merged
merged 4 commits into from
Nov 21, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions flutter/shell/platform/tizen/channels/platform_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <map>

#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_result_functions.h"
#include "flutter/shell/platform/common/json_method_codec.h"
#include "flutter/shell/platform/tizen/channels/feedback_manager.h"
#ifdef COMMON_PROFILE
Expand All @@ -26,6 +27,10 @@ constexpr char kChannelName[] = "flutter/platform";
constexpr char kGetClipboardDataMethod[] = "Clipboard.getData";
constexpr char kSetClipboardDataMethod[] = "Clipboard.setData";
constexpr char kClipboardHasStringsMethod[] = "Clipboard.hasStrings";
constexpr char kExitApplicationMethod[] = "System.exitApplication";
constexpr char kRequestAppExitMethod[] = "System.requestAppExit";
constexpr char kInitializationCompleteMethod[] =
"System.initializationComplete";
constexpr char kPlaySoundMethod[] = "SystemSound.play";
constexpr char kHapticFeedbackVibrateMethod[] = "HapticFeedback.vibrate";
constexpr char kSystemNavigatorPopMethod[] = "SystemNavigator.pop";
Expand All @@ -42,6 +47,14 @@ constexpr char kSetSystemUIOverlayStyleMethod[] =
constexpr char kIsLiveTextInputAvailable[] =
"LiveText.isLiveTextInputAvailable";

constexpr char kExitTypeKey[] = "type";
constexpr char kExitTypeCancelable[] = "cancelable";
constexpr char kExitTypeRequired[] = "required";
constexpr char kExitRequestError[] = "ExitApplication error";
constexpr char kExitResponseKey[] = "response";
constexpr char kExitResponseCancel[] = "cancel";
constexpr char kExitResponseExit[] = "exit";

constexpr char kTextKey[] = "text";
constexpr char kValueKey[] = "value";
constexpr char kTextPlainFormat[] = "text/plain";
Expand Down Expand Up @@ -140,6 +153,33 @@ void PlatformChannel::HandleMethodCall(
document.AddMember(rapidjson::Value(kValueKey, allocator),
rapidjson::Value(ClipboardHasStrings()), allocator);
result->Success(document);
} else if (method == kExitApplicationMethod) {
rapidjson::Value::ConstMemberIterator iter =
arguments->FindMember(kExitTypeKey);
if (iter == arguments->MemberEnd()) {
result->Error(kExitRequestError, "Invalid application exit request.");
return;
}

const std::string& exit_type = iter->value.GetString();
rapidjson::Document document;
document.SetObject();
if (!initialization_complete_ || exit_type == kExitTypeRequired) {
ui_app_exit();
document.AddMember(kExitResponseKey, kExitResponseExit,
document.GetAllocator());
result->Success(document);
swift-kim marked this conversation as resolved.
Show resolved Hide resolved
} else if (exit_type == kExitTypeCancelable) {
RequestAppExit(exit_type);
document.AddMember(kExitResponseKey, kExitResponseCancel,
document.GetAllocator());
result->Success(document);
} else {
result->Error(kExitRequestError, "Invalid type.");
}
} else if (method == kInitializationCompleteMethod) {
initialization_complete_ = true;
result->Success();
} else if (method == kRestoreSystemUiOverlaysMethod) {
RestoreSystemUiOverlays();
result->Success();
Expand Down Expand Up @@ -258,6 +298,37 @@ void PlatformChannel::RestoreSystemUiOverlays() {
}
}

void PlatformChannel::RequestAppExit(const std::string exit_type) {
if (!initialization_complete_) {
ui_app_exit();
return;
}
auto callback = std::make_unique<MethodResultFunctions<rapidjson::Document>>(
[this](const rapidjson::Document* response) {
RequestAppExitSuccess(response);
},
nullptr, nullptr);
auto args = std::make_unique<rapidjson::Document>();
args->SetObject();
args->AddMember(kExitTypeKey, exit_type, args->GetAllocator());
channel_->InvokeMethod(kRequestAppExitMethod, std::move(args),
std::move(callback));
}

void PlatformChannel::RequestAppExitSuccess(const rapidjson::Document* result) {
rapidjson::Value::ConstMemberIterator itr =
result->FindMember(kExitResponseKey);
if (itr == result->MemberEnd() || !itr->value.IsString()) {
FT_LOG(Error) << "Application request response did not contain a valid "
"response value";
return;
}
const std::string& exit_type = itr->value.GetString();
if (exit_type == kExitResponseExit) {
ui_app_exit();
}
}

void PlatformChannel::SetEnabledSystemUiOverlays(
const std::vector<std::string>& overlays) {
if (auto* window = dynamic_cast<TizenWindow*>(view_)) {
Expand Down
5 changes: 5 additions & 0 deletions flutter/shell/platform/tizen/channels/platform_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ class PlatformChannel {
void SetClipboardData(const std::string& data);
bool ClipboardHasStrings();
void RestoreSystemUiOverlays();
void RequestAppExit(const std::string exit_type);
void RequestAppExitSuccess(const rapidjson::Document* result);
void SetEnabledSystemUiOverlays(const std::vector<std::string>& overlays);
void SetPreferredOrientations(const std::vector<std::string>& orientations);

std::unique_ptr<MethodChannel<rapidjson::Document>> channel_;

// Whether or not initialization is complete from the framework.
bool initialization_complete_ = false;
swift-kim marked this conversation as resolved.
Show resolved Hide resolved

// A reference to the native view managed by FlutterTizenView.
TizenViewBase* view_ = nullptr;

Expand Down