Skip to content

Commit

Permalink
Fix exit application behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
JSUYA committed Sep 8, 2023
1 parent 073c673 commit 2ebe11c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 42 deletions.
43 changes: 19 additions & 24 deletions flutter/shell/platform/tizen/channels/platform_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifdef COMMON_PROFILE
#include "flutter/shell/platform/tizen/channels/tizen_shell.h"
#endif
#include "flutter/shell/platform/tizen/flutter_tizen_view.h"
#include "flutter/shell/platform/tizen/logger.h"
#include "flutter/shell/platform/tizen/tizen_view.h"
#include "flutter/shell/platform/tizen/tizen_window.h"
Expand Down Expand Up @@ -55,8 +54,6 @@ constexpr char kExitRequestError[] = "ExitApplication error";
constexpr char kExitResponseKey[] = "response";
constexpr char kExitResponseCancel[] = "cancel";
constexpr char kExitResponseExit[] = "exit";
constexpr char kInvalidExitRequestMessage[] =
"Invalid application exit request.";

constexpr char kTextKey[] = "text";
constexpr char kValueKey[] = "value";
Expand Down Expand Up @@ -157,22 +154,22 @@ void PlatformChannel::HandleMethodCall(
rapidjson::Value(ClipboardHasStrings()), allocator);
result->Success(document);
} else if (method == kExitApplicationMethod) {
const rapidjson::Value& document = *arguments;
rapidjson::Value::ConstMemberIterator iter =
document.FindMember(kExitTypeKey);
if (iter == document.MemberEnd()) {
result->Error(kExitRequestError, kInvalidExitRequestMessage);
arguments->FindMember(kExitTypeKey);
if (iter == arguments->MemberEnd()) {
result->Error(kExitRequestError, "Invalid application exit request.");
return;
}

const std::string& exit_type = iter->value.GetString();
if (exit_type == kExitTypeRequired) {
if (auto* view = dynamic_cast<FlutterTizenView*>(view_->GetView())) {
view->ExitApplication();
}
rapidjson::Document document;
document.SetObject();
if (!initialization_complete_ || exit_type == kExitTypeRequired) {
ui_app_exit();
document.AddMember(kExitResponseKey, kExitResponseExit,
document.GetAllocator());
result->Success(document);
} else if (exit_type == kExitTypeCancelable) {
rapidjson::Document document;
document.SetObject();
RequestAppExit(exit_type);
document.AddMember(kExitResponseKey, kExitResponseCancel,
document.GetAllocator());
Expand All @@ -181,9 +178,7 @@ void PlatformChannel::HandleMethodCall(
result->Error(kExitRequestError, "Invalid type.");
}
} else if (method == kInitializationCompleteMethod) {
if (auto* view = dynamic_cast<FlutterTizenView*>(view_->GetView())) {
view->SetInitializationComplete(true);
}
initialization_complete_ = true;
result->Success();
} else if (method == kRestoreSystemUiOverlaysMethod) {
RestoreSystemUiOverlays();
Expand Down Expand Up @@ -216,12 +211,10 @@ void PlatformChannel::HandleMethodCall(
}

void PlatformChannel::SystemNavigatorPop() {
if (auto* tizen_view = dynamic_cast<TizenView*>(view_)) {
tizen_view->SetFocus(false);
if (auto* view = dynamic_cast<TizenView*>(view_)) {
view->SetFocus(false);
} else {
if (auto* view = dynamic_cast<FlutterTizenView*>(view_->GetView())) {
view->ExitApplication();
}
ui_app_exit();
}
}

Expand Down Expand Up @@ -306,6 +299,10 @@ 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);
Expand All @@ -328,9 +325,7 @@ void PlatformChannel::RequestAppExitSuccess(const rapidjson::Document* result) {
}
const std::string& exit_type = itr->value.GetString();
if (exit_type == kExitResponseExit) {
if (auto* view = dynamic_cast<FlutterTizenView*>(view_->GetView())) {
view->ExitApplication();
}
ui_app_exit();
}
}

Expand Down
3 changes: 3 additions & 0 deletions flutter/shell/platform/tizen/channels/platform_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class PlatformChannel {

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

// Whether or not initialization is complete from the platform.
bool initialization_complete_ = false;

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

Expand Down
8 changes: 1 addition & 7 deletions flutter/shell/platform/tizen/flutter_tizen_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ void FlutterTizenView::Resize(int32_t width, int32_t height) {
tizen_view_->SetGeometry(geometry);
}

void FlutterTizenView::ExitApplication() {
if (initialization_complete_) {
ui_app_exit();
}
}

bool FlutterTizenView::OnMakeCurrent() {
return engine_->renderer()->OnMakeCurrent();
}
Expand Down Expand Up @@ -362,7 +356,7 @@ void FlutterTizenView::OnKey(const char* key,
engine->navigation_channel()->PopRoute();
}
} else if (symbol == kExitKey && !is_down) {
engine->view()->ExitApplication();
ui_app_exit();
}
});
}
Expand Down
9 changes: 0 additions & 9 deletions flutter/shell/platform/tizen/flutter_tizen_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class FlutterTizenView : public TizenViewEventHandlerDelegate {

void Resize(int32_t width, int32_t height);

void ExitApplication();

// Callbacks for clearing context, settings context and swapping buffers,
// these are typically called on an engine-controlled (non-platform) thread.
bool OnMakeCurrent();
Expand Down Expand Up @@ -119,10 +117,6 @@ class FlutterTizenView : public TizenViewEventHandlerDelegate {

TextInputChannel* text_input_channel() { return text_input_channel_.get(); }

void SetInitializationComplete(bool initialization_complete) {
initialization_complete_ = initialization_complete;
}

private:
// Struct holding the state of an individual pointer. The engine doesn't keep
// track of which buttons have been pressed, so it's the embedder's
Expand Down Expand Up @@ -182,9 +176,6 @@ class FlutterTizenView : public TizenViewEventHandlerDelegate {
// The plugin registrar managing internal plugins.
std::unique_ptr<PluginRegistrar> internal_plugin_registrar_;

// Whether or not initialization is complete from the platform.
bool initialization_complete_ = false;

// A plugin that implements the Tizen window channel.
std::unique_ptr<WindowChannel> window_channel_;

Expand Down
2 changes: 0 additions & 2 deletions flutter/shell/platform/tizen/tizen_view_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class TizenViewBase {
view_delegate_ = view_delegate;
}

TizenViewEventHandlerDelegate* GetView() { return view_delegate_; }

virtual void Show() = 0;

TizenInputMethodContext* input_method_context() {
Expand Down

0 comments on commit 2ebe11c

Please sign in to comment.