From ac47476253d44e8660e4cb543f1168ae543f3846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 22 Mar 2023 22:55:53 +0100 Subject: [PATCH] And share_text, toast, recreate --- Common/System/Request.h | 4 ++++ Common/System/System.h | 4 ++++ UI/ControlMappingScreen.cpp | 12 ++++++++++- UI/GameSettingsScreen.cpp | 16 ++------------ UI/MainScreen.cpp | 2 +- UI/MiscScreens.cpp | 3 ++- android/jni/app-android.cpp | 19 +++++++++++++---- .../src/org/ppsspp/ppsspp/NativeActivity.java | 13 +----------- ios/ViewController.mm | 8 +++---- ios/main.mm | 21 +++++++------------ 10 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Common/System/Request.h b/Common/System/Request.h index 4860588854..b42c96fc9e 100644 --- a/Common/System/Request.h +++ b/Common/System/Request.h @@ -112,3 +112,7 @@ inline void System_GPSCommand(const std::string &command) { inline void System_MicrophoneCommand(const std::string &command) { g_requestManager.MakeSystemRequest(SystemRequestType::MICROPHONE_COMMAND, nullptr, command, "", 0); } + +inline void System_ShareText(const std::string &text) { + g_requestManager.MakeSystemRequest(SystemRequestType::SHARE_TEXT, nullptr, text, "", 0); +} diff --git a/Common/System/System.h b/Common/System/System.h index 3f4c8e3f84..8c3774c342 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -71,6 +71,8 @@ enum class SystemRequestType { CAMERA_COMMAND, GPS_COMMAND, MICROPHONE_COMMAND, + + SHARE_TEXT, }; // Implementations are supposed to process the request, and post the response to the g_RequestManager (see Message.h). @@ -175,6 +177,8 @@ enum class SystemNotification { BOOT_DONE, // this is sent from EMU thread! Make sure that Host handles it properly! SYMBOL_MAP_UPDATED, SWITCH_UMD_UPDATED, + ROTATE_UPDATED, + FORCE_RECREATE_ACTIVITY, }; std::string System_GetProperty(SystemProperty prop); diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index de04aef59a..5dbe5c4db6 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -718,7 +718,17 @@ void TouchTestScreen::render() { ui_context->Flush(); } -void RecreateActivity(); +void RecreateActivity() { + const int SYSTEM_JELLYBEAN = 16; + if (System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= SYSTEM_JELLYBEAN) { + INFO_LOG(SYSTEM, "Sending recreate"); + System_Notify(SystemNotification::FORCE_RECREATE_ACTIVITY); + INFO_LOG(SYSTEM, "Got back from recreate"); + } else { + auto gr = GetI18NCategory("Graphics"); + System_Toast(gr->T("Must Restart", "You must restart PPSSPP for this change to take effect")); + } +} UI::EventReturn TouchTestScreen::OnImmersiveModeChange(UI::EventParams &e) { System_SendMessage("immersive", ""); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 50b47a5677..6d3004fe3a 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1193,23 +1193,11 @@ UI::EventReturn GameSettingsScreen::OnAutoFrameskip(UI::EventParams &e) { UI::EventReturn GameSettingsScreen::OnScreenRotation(UI::EventParams &e) { INFO_LOG(SYSTEM, "New display rotation: %d", g_Config.iScreenRotation); INFO_LOG(SYSTEM, "Sending rotate"); - System_SendMessage("rotate", ""); + System_Notify(SystemNotification::ROTATE_UPDATED); INFO_LOG(SYSTEM, "Got back from rotate"); return UI::EVENT_DONE; } -void RecreateActivity() { - const int SYSTEM_JELLYBEAN = 16; - if (System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= SYSTEM_JELLYBEAN) { - INFO_LOG(SYSTEM, "Sending recreate"); - System_SendMessage("recreate", ""); - INFO_LOG(SYSTEM, "Got back from recreate"); - } else { - auto gr = GetI18NCategory("Graphics"); - System_SendMessage("toast", gr->T("Must Restart", "You must restart PPSSPP for this change to take effect")); - } -} - UI::EventReturn GameSettingsScreen::OnAdhocGuides(UI::EventParams &e) { auto n = GetI18NCategory("Networking"); System_LaunchUrl(LaunchUrlType::BROWSER_URL, n->T("MultiplayerHowToURL", "https://github.com/hrydgard/ppsspp/wiki/How-to-play-multiplayer-games-with-PPSSPP")); @@ -1348,7 +1336,7 @@ void GameSettingsScreen::onFinish(DialogResult result) { Reporting::Enable(enableReports_, "report.ppsspp.org"); Reporting::UpdateConfig(); if (!g_Config.Save("GameSettingsScreen::onFinish")) { - System_SendMessage("toast", "Failed to save settings!\nCheck permissions, or try to restart the device."); + System_Toast("Failed to save settings!\nCheck permissions, or try to restart the device."); } if (editThenRestore_) { diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 875d9c07b8..2fa799e9b7 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1428,7 +1428,7 @@ UI::EventReturn MainScreen::OnForums(UI::EventParams &e) { UI::EventReturn MainScreen::OnExit(UI::EventParams &e) { // Let's make sure the config was saved, since it may not have been. if (!g_Config.Save("MainScreen::OnExit")) { - System_SendMessage("toast", "Failed to save settings!\nCheck permissions, or try to restart the device."); + System_Toast("Failed to save settings!\nCheck permissions, or try to restart the device."); } // Request the framework to exit cleanly. diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index d6a5c4fecc..84dbbbe80f 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -29,6 +29,7 @@ #include "Common/System/Display.h" #include "Common/System/NativeApp.h" #include "Common/System/System.h" +#include "Common/System/Request.h" #include "Common/Math/curves.h" #include "Common/File/VFS/VFS.h" @@ -872,7 +873,7 @@ UI::EventReturn CreditsScreen::OnDiscord(UI::EventParams &e) { UI::EventReturn CreditsScreen::OnShare(UI::EventParams &e) { auto cr = GetI18NCategory("PSPCredits"); - System_SendMessage("sharetext", cr->T("CheckOutPPSSPP", "Check out PPSSPP, the awesome PSP emulator: https://www.ppsspp.org/")); + System_ShareText(cr->T("CheckOutPPSSPP", "Check out PPSSPP, the awesome PSP emulator: https://www.ppsspp.org/")); return UI::EVENT_DONE; } diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 8af62f0988..a7e3747553 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -539,9 +539,6 @@ bool System_GetPropertyBool(SystemProperty prop) { } } -void System_Notify(SystemNotification notification) { -} - std::string Android_GetInputDeviceDebugString() { if (!nativeActivity) { return "(N/A)"; @@ -1028,6 +1025,17 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv } } +void System_Notify(SystemNotification notification) { + switch (notification) { + case SystemNotification::ROTATE_UPDATED: + PushCommand("rotate", ""); + break; + case SystemNotification::FORCE_RECREATE_ACTIVITY: + PushCommand("recreate", ""); + break; + } +} + bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { switch (type) { case SystemRequestType::EXIT_APP: @@ -1061,6 +1069,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string case SystemRequestType::MICROPHONE_COMMAND: PushCommand("microphone_command", param1); break; + case SystemRequestType::SHARE_TEXT: + PushCommand("share_text", param1); + break; default: return false; } @@ -1226,7 +1237,7 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessage(JNIEnv *env std::string msg = GetJavaString(env, message); std::string prm = GetJavaString(env, param); - // Some messages are caught by app-android. + // Some messages are caught by app-android. TODO: Should be all. if (msg == "moga") { mogaVersion = prm; } else if (msg == "permission_pending") { diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 439f8a2b7a..d8e4622950 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -1403,18 +1403,7 @@ public abstract class NativeActivity extends Activity { Log.e(TAG, e.toString()); return false; } - } else if (command.equals("sharejpeg")) { - try { - Intent share = new Intent(Intent.ACTION_SEND); - share.setType("image/jpeg"); - share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + params)); - startActivity(Intent.createChooser(share, "Share Picture")); - return true; - } catch (Exception e) { // For example, android.content.ActivityNotFoundException - Log.e(TAG, e.toString()); - return false; - } - } else if (command.equals("sharetext")) { + } else if (command.equals("share_text")) { try { Intent sendIntent = new Intent(); sendIntent.setType("text/plain"); diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 9c4ff956ff..a693dd771c 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -165,10 +165,10 @@ static LocationHelper *locationHelper; [super viewSafeAreaInsetsDidChange]; char safeArea[100]; // we use 0.0f instead of safeAreaInsets.bottom because the bottom overlay isn't disturbing (for now) - snprintf(safeArea, sizeof(safeArea), "%f:%f:%f:%f", - self.view.safeAreaInsets.left, self.view.safeAreaInsets.right, - self.view.safeAreaInsets.top, 0.0f); - System_SendMessage("safe_insets", safeArea); + g_safeInsetLeft = self.view.safeAreaInsets.left; + g_safeInsetRight = self.view.safeAreaInsets.right; + g_safeInsetTop = self.view.safeAreaInsets.top; + g_safeInsetBottom = 0.0f; } } diff --git a/ios/main.mm b/ios/main.mm index 44cd031cc0..a6a5ec4bf3 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -176,20 +176,7 @@ void System_Notify(SystemNotification notification) { } } -void System_SendMessage(const char *command, const char *parameter) { - if (!strcmp(command, "sharetext")) { - NSString *text = [NSString stringWithUTF8String:parameter]; - [sharedViewController shareText:text]; - } else if (!strcmp(command, "safe_insets")) { - float left, right, top, bottom; - if (4 == sscanf(parameter, "%f:%f:%f:%f", &left, &right, &top, &bottom)) { - g_safeInsetLeft = left; - g_safeInsetRight = right; - g_safeInsetTop = top; - g_safeInsetBottom = bottom; - } - } -} +void System_SendMessage(const char *command, const char *parameter) {} bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { switch (type) { @@ -244,6 +231,12 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string stopLocation(); } return true; + case SystemRequestType::SHARE_TEXT: + { + NSString *text = [NSString stringWithUTF8String:param1.c_str()]; + [sharedViewController shareText:text]; + return true; + } default: return false; }