8
8
9
9
#include < map>
10
10
11
+ #include " flutter/shell/platform/common/client_wrapper/include/flutter/method_result_functions.h"
11
12
#include " flutter/shell/platform/common/json_method_codec.h"
12
13
#include " flutter/shell/platform/tizen/channels/feedback_manager.h"
13
14
#ifdef COMMON_PROFILE
@@ -26,6 +27,10 @@ constexpr char kChannelName[] = "flutter/platform";
26
27
constexpr char kGetClipboardDataMethod [] = " Clipboard.getData" ;
27
28
constexpr char kSetClipboardDataMethod [] = " Clipboard.setData" ;
28
29
constexpr char kClipboardHasStringsMethod [] = " Clipboard.hasStrings" ;
30
+ constexpr char kExitApplicationMethod [] = " System.exitApplication" ;
31
+ constexpr char kRequestAppExitMethod [] = " System.requestAppExit" ;
32
+ constexpr char kInitializationCompleteMethod [] =
33
+ " System.initializationComplete" ;
29
34
constexpr char kPlaySoundMethod [] = " SystemSound.play" ;
30
35
constexpr char kHapticFeedbackVibrateMethod [] = " HapticFeedback.vibrate" ;
31
36
constexpr char kSystemNavigatorPopMethod [] = " SystemNavigator.pop" ;
@@ -42,6 +47,14 @@ constexpr char kSetSystemUIOverlayStyleMethod[] =
42
47
constexpr char kIsLiveTextInputAvailable [] =
43
48
" LiveText.isLiveTextInputAvailable" ;
44
49
50
+ constexpr char kExitTypeKey [] = " type" ;
51
+ constexpr char kExitTypeCancelable [] = " cancelable" ;
52
+ constexpr char kExitTypeRequired [] = " required" ;
53
+ constexpr char kExitRequestError [] = " ExitApplication error" ;
54
+ constexpr char kExitResponseKey [] = " response" ;
55
+ constexpr char kExitResponseCancel [] = " cancel" ;
56
+ constexpr char kExitResponseExit [] = " exit" ;
57
+
45
58
constexpr char kTextKey [] = " text" ;
46
59
constexpr char kValueKey [] = " value" ;
47
60
constexpr char kTextPlainFormat [] = " text/plain" ;
@@ -140,6 +153,33 @@ void PlatformChannel::HandleMethodCall(
140
153
document.AddMember (rapidjson::Value (kValueKey , allocator),
141
154
rapidjson::Value (ClipboardHasStrings ()), allocator);
142
155
result->Success (document);
156
+ } else if (method == kExitApplicationMethod ) {
157
+ rapidjson::Value::ConstMemberIterator iter =
158
+ arguments->FindMember (kExitTypeKey );
159
+ if (iter == arguments->MemberEnd ()) {
160
+ result->Error (kExitRequestError , " Invalid application exit request." );
161
+ return ;
162
+ }
163
+
164
+ const std::string& exit_type = iter->value .GetString ();
165
+ rapidjson::Document document;
166
+ document.SetObject ();
167
+ if (!initialization_complete_ || exit_type == kExitTypeRequired ) {
168
+ ui_app_exit ();
169
+ document.AddMember (kExitResponseKey , kExitResponseExit ,
170
+ document.GetAllocator ());
171
+ result->Success (document);
172
+ } else if (exit_type == kExitTypeCancelable ) {
173
+ RequestAppExit (exit_type);
174
+ document.AddMember (kExitResponseKey , kExitResponseCancel ,
175
+ document.GetAllocator ());
176
+ result->Success (document);
177
+ } else {
178
+ result->Error (kExitRequestError , " Invalid type." );
179
+ }
180
+ } else if (method == kInitializationCompleteMethod ) {
181
+ initialization_complete_ = true ;
182
+ result->Success ();
143
183
} else if (method == kRestoreSystemUiOverlaysMethod ) {
144
184
RestoreSystemUiOverlays ();
145
185
result->Success ();
@@ -258,6 +298,37 @@ void PlatformChannel::RestoreSystemUiOverlays() {
258
298
}
259
299
}
260
300
301
+ void PlatformChannel::RequestAppExit (const std::string exit_type) {
302
+ if (!initialization_complete_) {
303
+ ui_app_exit ();
304
+ return ;
305
+ }
306
+ auto callback = std::make_unique<MethodResultFunctions<rapidjson::Document>>(
307
+ [this ](const rapidjson::Document* response) {
308
+ RequestAppExitSuccess (response);
309
+ },
310
+ nullptr , nullptr );
311
+ auto args = std::make_unique<rapidjson::Document>();
312
+ args->SetObject ();
313
+ args->AddMember (kExitTypeKey , exit_type, args->GetAllocator ());
314
+ channel_->InvokeMethod (kRequestAppExitMethod , std::move (args),
315
+ std::move (callback));
316
+ }
317
+
318
+ void PlatformChannel::RequestAppExitSuccess (const rapidjson::Document* result) {
319
+ rapidjson::Value::ConstMemberIterator itr =
320
+ result->FindMember (kExitResponseKey );
321
+ if (itr == result->MemberEnd () || !itr->value .IsString ()) {
322
+ FT_LOG (Error) << " Application request response did not contain a valid "
323
+ " response value" ;
324
+ return ;
325
+ }
326
+ const std::string& exit_type = itr->value .GetString ();
327
+ if (exit_type == kExitResponseExit ) {
328
+ ui_app_exit ();
329
+ }
330
+ }
331
+
261
332
void PlatformChannel::SetEnabledSystemUiOverlays (
262
333
const std::vector<std::string>& overlays) {
263
334
if (auto * window = dynamic_cast <TizenWindow*>(view_)) {
0 commit comments