Skip to content

Commit

Permalink
Register button
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Aug 18, 2024
1 parent 8fe6cf4 commit dcb7508
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 40 deletions.
40 changes: 1 addition & 39 deletions src/cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ const char* se_get_pref_path();
#include <emscripten.h>
#endif

#ifdef SE_PLATFORM_ANDROID
#include <android/native_activity.h>
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;

Expand Down Expand Up @@ -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";
Expand Down
53 changes: 53 additions & 0 deletions src/https.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ extern "C" {
#include <emscripten.h>
#endif

#ifdef SE_PLATFORM_ANDROID
#include <android/native_activity.h>
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();
}
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/https.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit dcb7508

Please sign in to comment.