Skip to content

Commit 3e64c9e

Browse files
committed
Harmony port: locale
1 parent 56e42de commit 3e64c9e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/core/ohos/SDL_ohos.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "SDL_internal.h"
2-
#include "dynapi/SDL_dynapi_overrides.h"
32
#include <EGL/egl.h>
43
#include <EGL/eglplatform.h>
54
#include <dlfcn.h>
@@ -58,6 +57,7 @@ typedef struct
5857
napiCallbackArg arg[16];
5958
napiArgType type;
6059
napiCallbackArg ret;
60+
bool returned;
6161
} napiCallbackData;
6262

6363
void OHOS_windowUpdateAttributes(SDL_Window *w)
@@ -209,9 +209,9 @@ static void sdlJSCallback(napi_env env, napi_value jsCb, void *content, void *da
209209
case String:
210210
{
211211
size_t stringSize = 0;
212-
napi_get_value_string_utf8(env, args[1], NULL, 0, &stringSize);
212+
napi_get_value_string_utf8(env, v, NULL, 0, &stringSize);
213213
char *value = SDL_malloc(stringSize + 1);
214-
napi_get_value_string_utf8(env, args[1], value, stringSize + 1, &stringSize);
214+
napi_get_value_string_utf8(env, v, value, stringSize + 1, &stringSize);
215215
ar->ret.data.str = value;
216216
break;
217217
}
@@ -221,6 +221,7 @@ static void sdlJSCallback(napi_env env, napi_value jsCb, void *content, void *da
221221
break;
222222
}
223223
}
224+
ar->returned = true;
224225
}
225226

226227
void OHOS_MessageBox(const char* title, const char* message)
@@ -239,6 +240,24 @@ void OHOS_MessageBox(const char* title, const char* message)
239240
napi_call_threadsafe_function(napiEnv.func, data, napi_tsfn_nonblocking);
240241
}
241242

243+
const char* OHOS_Locale()
244+
{
245+
napiCallbackData *data = SDL_malloc(sizeof(napiCallbackData));
246+
SDL_memset(data, 0, sizeof(napiCallbackData));
247+
data->func = "fetchLocale";
248+
data->argCount = 0;
249+
data->type = String;
250+
data->returned = false;
251+
252+
napi_call_threadsafe_function(napiEnv.func, data, napi_tsfn_nonblocking);
253+
254+
while (!data->returned) {}
255+
256+
const char* d = data->ret.data.str;
257+
SDL_free(data);
258+
return d;
259+
}
260+
242261
static napi_value sdlCallbackInit(napi_env env, napi_callback_info info)
243262
{
244263
napiEnv.env = env;

src/core/ohos/SDL_ohos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ int OHOS_FetchWidth();
1313
int OHOS_FetchHeight();
1414

1515
void OHOS_MessageBox(const char* title, const char* message);
16+
const char* OHOS_Locale();
1617

1718
typedef struct SDL_VideoData {
1819
SDL_Rect textRect;

0 commit comments

Comments
 (0)