diff --git a/src/cloud.cpp b/src/cloud.cpp index b9bcdcef6..2dbcbd2e1 100644 --- a/src/cloud.cpp +++ b/src/cloud.cpp @@ -34,17 +34,6 @@ const char* se_get_pref_path(); #include #endif -#ifdef SE_PLATFORM_ANDROID -#include -extern "C" const void* sapp_android_get_native_activity(); -#endif - -#ifdef SE_PLATFORM_IOS -extern "C" { -#include "ios_support.h" -} -#endif - static bool pending_login = false; static bool pending_logout = false; @@ -639,34 +628,7 @@ void cloud_drive_authenticate(cloud_drive_t* drive) "&code_challenge=" + code_verifier + "&code_challenge_method=plain"; -#ifdef SE_PLATFORM_LINUX - std::string command = "xdg-open \"" + request + "\""; - system(command.c_str()); -#elif SE_PLATFORM_WINDOWS - std::string command = "start \"\" \"" + request + "\""; - system(command.c_str()); -#elif SE_PLATFORM_MACOS - std::string command = "open \"" + request + "\""; - system(command.c_str()); -#elif SE_PLATFORM_ANDROID - ANativeActivity* activity = (ANativeActivity*)sapp_android_get_native_activity(); - JavaVM* pJavaVM = activity->vm; - JNIEnv* pJNIEnv = activity->env; - jint nResult = pJavaVM->AttachCurrentThread(&pJNIEnv, NULL); - if (nResult != JNI_ERR) - { - jobject nativeActivity = activity->clazz; - jclass ClassNativeActivity = pJNIEnv->GetObjectClass(nativeActivity); - jmethodID MethodOpenURL = pJNIEnv->GetMethodID(ClassNativeActivity, "openCustomTab", "(Ljava/lang/String;)V"); - jstring jstrURL = pJNIEnv->NewStringUTF(request.c_str()); - pJNIEnv->CallVoidMethod(nativeActivity, MethodOpenURL, jstrURL); - pJavaVM->DetachCurrentThread(); - } -#elif SE_PLATFORM_IOS - se_ios_open_modal(request.c_str()); -#else - printf("Navigate to the following URL to authorize the application:\n%s\n", request.c_str()); -#endif + https_open_url(request.c_str()); // Listen on port 5000 for the oauth2 callback std::string refresh_path = drive->save_directory + "refresh_token.txt"; diff --git a/src/https.cpp b/src/https.cpp index f7f975d8d..eb6382821 100644 --- a/src/https.cpp +++ b/src/https.cpp @@ -20,6 +20,17 @@ extern "C" { #include #endif +#ifdef SE_PLATFORM_ANDROID +#include +extern "C" const void* sapp_android_get_native_activity(); +#endif + +#ifdef SE_PLATFORM_IOS +extern "C" { +#include "ios_support.h" +} +#endif + extern "C" { const char* se_get_pref_path(); } @@ -470,4 +481,46 @@ extern "C" void https_clear_cache() extern "C" void https_set_cache_enabled(bool enabled) { cache_enabled.store(enabled, std::memory_order_relaxed); +} + +extern "C" void https_open_url(const char* url) +{ + std::string request = url; +#if defined(SE_PLATFORM_LINUX) || defined(SE_PLATFORM_FREEBSD) + std::string command = "xdg-open \"" + request + "\""; + system(command.c_str()); +#elif defined(SE_PLATFORM_WINDOWS) + std::string command = "start \"\" \"" + request + "\""; + system(command.c_str()); +#elif defined(SE_PLATFORM_MACOS) + std::string command = "open \"" + request + "\""; + system(command.c_str()); +#elif defined(SE_PLATFORM_ANDROID) + ANativeActivity* activity = (ANativeActivity*)sapp_android_get_native_activity(); + JavaVM* pJavaVM = activity->vm; + JNIEnv* pJNIEnv = activity->env; + jint nResult = pJavaVM->AttachCurrentThread(&pJNIEnv, NULL); + if (nResult != JNI_ERR) + { + jobject nativeActivity = activity->clazz; + jclass ClassNativeActivity = pJNIEnv->GetObjectClass(nativeActivity); + jmethodID MethodOpenURL = pJNIEnv->GetMethodID(ClassNativeActivity, "openCustomTab", "(Ljava/lang/String;)V"); + jstring jstrURL = pJNIEnv->NewStringUTF(request.c_str()); + pJNIEnv->CallVoidMethod(nativeActivity, MethodOpenURL, jstrURL); + pJavaVM->DetachCurrentThread(); + } +#elif defined(SE_PLATFORM_IOS) + se_ios_open_modal(request.c_str()); +#elif defined(SE_PLATFORM_WEB) + EM_ASM({ + var win = window.open($0); + try { + win.focus(); + } else { + alert('Popups blocked'); + } + }, url); +#else + printf("Navigate to the following URL to authorize the application:\n%s\n", request.c_str()); +#endif } \ No newline at end of file diff --git a/src/https.hpp b/src/https.hpp index 866034fc0..ca16589eb 100644 --- a/src/https.hpp +++ b/src/https.hpp @@ -13,6 +13,7 @@ void https_shutdown(); uint64_t https_cache_size(); void https_clear_cache(); void https_set_cache_enabled(bool enabled); +void https_open_url(const char* url); #ifdef __cplusplus } diff --git a/src/main.c b/src/main.c index 062b418ff..a48d23425 100644 --- a/src/main.c +++ b/src/main.c @@ -6331,6 +6331,11 @@ void se_draw_menu_panel(){ retro_achievements_login(username, password); gui_state.settings.ra_needs_reload = true; } + igSameLine(0, 6); + if (se_button(ICON_FK_USER_PLUS " Register", (ImVec2){0, 0})) + { + https_open_url("https://retroachievements.org/createaccount.php"); + } if (pending_login) se_pop_disabled(); }else{ @@ -6362,7 +6367,10 @@ void se_draw_menu_panel(){ (ImVec2){screen_x-border_size,screen_y-border_size}, (ImVec2){screen_x+border_size+ava_dims.x,screen_y+border_size+ava_dims.y}, col,0,ImDrawCornerFlags_None); - igImageButton((ImTextureID)(intptr_t)image.id,(ImVec2){ava_dims.x,ava_dims.y},offset1,offset2,0,(ImVec4){1,1,1,1},(ImVec4){1,1,1,1}); + if (image.id != SG_INVALID_ID) + igImageButton((ImTextureID)(intptr_t)image.id,(ImVec2){ava_dims.x,ava_dims.y},offset1,offset2,0,(ImVec4){1,1,1,1},(ImVec4){1,1,1,1}); + else + igDummy(ava_dims); igSameLine(0,5); } igBeginGroup();