mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-03 08:52:39 +00:00
Android: Expose config changed callbacks
This commit is contained in:
parent
2ece642cf8
commit
d80f9d53fc
5 changed files with 91 additions and 0 deletions
44
Source/Android/jni/Config/ConfigChangedCallback.cpp
Normal file
44
Source/Android/jni/Config/ConfigChangedCallback.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright 2023 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "Common/Config/Config.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
struct ConfigChangedCallbackContext
|
||||
{
|
||||
jobject runnable;
|
||||
Config::ConfigChangedCallbackID callback_id;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_settings_model_ConfigChangedCallback_initialize(
|
||||
JNIEnv* env, jclass, jobject runnable)
|
||||
{
|
||||
auto* context = new ConfigChangedCallbackContext;
|
||||
|
||||
jobject runnable_global = env->NewGlobalRef(runnable);
|
||||
context->runnable = runnable_global;
|
||||
context->callback_id = Config::AddConfigChangedCallback([runnable_global] {
|
||||
IDCache::GetEnvForThread()->CallVoidMethod(runnable_global, IDCache::GetRunnableRun());
|
||||
});
|
||||
|
||||
return reinterpret_cast<jlong>(context);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_settings_model_ConfigChangedCallback_deinitialize(
|
||||
JNIEnv* env, jclass, jlong pointer)
|
||||
{
|
||||
auto* context = reinterpret_cast<ConfigChangedCallbackContext*>(pointer);
|
||||
|
||||
Config::RemoveConfigChangedCallback(context->callback_id);
|
||||
env->DeleteGlobalRef(context->runnable);
|
||||
|
||||
delete context;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue