Skip to content

Commit

Permalink
And share_text, toast, recreate
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 22, 2023
1 parent 87d0c21 commit ac47476
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 51 deletions.
4 changes: 4 additions & 0 deletions Common/System/Request.h
Expand Up @@ -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);
}
4 changes: 4 additions & 0 deletions Common/System/System.h
Expand Up @@ -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).
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion UI/ControlMappingScreen.cpp
Expand Up @@ -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", "");
Expand Down
16 changes: 2 additions & 14 deletions UI/GameSettingsScreen.cpp
Expand Up @@ -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"));
Expand Down Expand Up @@ -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_) {
Expand Down
2 changes: 1 addition & 1 deletion UI/MainScreen.cpp
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion UI/MiscScreens.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
}

Expand Down
19 changes: 15 additions & 4 deletions android/jni/app-android.cpp
Expand Up @@ -539,9 +539,6 @@ bool System_GetPropertyBool(SystemProperty prop) {
}
}

void System_Notify(SystemNotification notification) {
}

std::string Android_GetInputDeviceDebugString() {
if (!nativeActivity) {
return "(N/A)";
Expand Down Expand Up @@ -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 &param1, const std::string &param2, int param3) {
switch (type) {
case SystemRequestType::EXIT_APP:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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") {
Expand Down
13 changes: 1 addition & 12 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Expand Up @@ -1403,18 +1403,7 @@ public boolean processCommand(String command, String params) {
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");
Expand Down
8 changes: 4 additions & 4 deletions ios/ViewController.mm
Expand Up @@ -165,10 +165,10 @@ - (void)viewSafeAreaInsetsDidChange {
[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;
}
}

Expand Down
21 changes: 7 additions & 14 deletions ios/main.mm
Expand Up @@ -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 &param1, const std::string &param2, int param3) {
switch (type) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ac47476

Please sign in to comment.