Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(native): add Locale module #938

Merged
merged 11 commits into from
Jul 3, 2020
Merged
4 changes: 4 additions & 0 deletions src/Core/App.re
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ let start = init => {

Revery_Native.initApp();

AppLog.infof(m =>
m("Operating in locale : %s", Revery_Native.Locale.getUser())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to add a log for this

);

let appLoop = () => {
_flushEvents();

Expand Down
1 change: 1 addition & 0 deletions src/Native/Locale.re
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external getUser: unit => string = "revery_getUserLocale";
5 changes: 4 additions & 1 deletion src/Native/ReveryCocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void revery_scheduleNotificationFromNow_cocoa(const char *title,
const char *body,
long onClickFunc, int mute,
int seconds);
void* revery_getIconHandle_cocoa();
void *revery_getIconHandle_cocoa();

/* Icon progress bar functions */
void revery_setIconProgress_cocoa(void* dt, double progress);
Expand All @@ -22,3 +22,6 @@ void revery_hideIconProgress_cocoa(void* ip);
/* Open functions */
int revery_openURL_cocoa(const char *url_string);
int revery_openFile_cocoa(const char *path_string);

/* Locale functions */
char *revery_getUserLocale_cocoa();
1 change: 1 addition & 0 deletions src/Native/Revery_Native.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module Dialog = Dialog;
module Icon = Icon;
module Notification = Notification;
module Shell = Shell;
module Locale = Locale;

include Initialization;
1 change: 1 addition & 0 deletions src/Native/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
notification notification_cocoa
icon icon_cocoa icon_win32
shell shell_cocoa shell_gtk shell_win32
locale locale_cocoa
utilities
ReveryAppDelegate ReveryAppDelegate_func
ReveryProgressBar)
Expand Down
29 changes: 29 additions & 0 deletions src/Native/locale.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>

#include <caml/alloc.h>
#include <caml/callback.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>
#include <string.h>

#include "caml_values.h"

#ifdef WIN32
#include "ReveryWin32.h"
#elif __APPLE__
#include "ReveryCocoa.h"
#else
#include "ReveryGtk.h"
#include <locale.h>
#endif

CAMLprim value revery_getUserLocale() {
CAMLparam0();
char *ret;
#ifdef __APPLE__
ret = revery_getUserLocale_cocoa();
#else
ret = setlocale(LC_CTYPE, NULL);
#endif
CAMLreturn(caml_copy_string(ret));
zbaylin marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 10 additions & 0 deletions src/Native/locale_cocoa.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifdef __APPLE__
#include <stdio.h>

#import <Cocoa/Cocoa.h>

char *revery_getUserLocale_cocoa() {
NSLocale *nsLocale = [NSLocale currentLocale];
return (char *)[[nsLocale localeIdentifier] UTF8String];
zbaylin marked this conversation as resolved.
Show resolved Hide resolved
}
#endif