-
Notifications
You must be signed in to change notification settings - Fork 114
Add API method: electron.app.getCountryName #647
Conversation
…untry name), this returns the ISO country code
…hich also includes encoding (ex: `de_DE.UTF-8`)
atom/browser/api/atom_api_app.cc
Outdated
#elif defined(OS_LINUX) | ||
// for more info, see: | ||
// https://en.cppreference.com/w/cpp/locale/setlocale | ||
setlocale(LC_ALL, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setLocale? That doesn't seem right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs, I believe this is needed to initialize the locale for the purpose of using the C functions in locale.h. By passing ""
, this means to use whatever the user has configured as the locale (as opposed to what the C library defaults to or an arbitrary locale, such as es-MX
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, but the initialization only need to run once per program startup. This will initialize it every time you call this API
// https://developer.apple.com/documentation/corefoundation/1543547-cflocalegetvalue?language=objc | ||
// https://developer.apple.com/documentation/corefoundation/cflocalekey?language=objc | ||
CFLocaleRef cflocale = CFLocaleCopyCurrent(); | ||
CFStringRef country_code = (CFStringRef)CFLocaleGetValue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to check (!country_code) here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
atom/browser/api/atom_api_app.cc
Outdated
// for more info, see: | ||
// https://en.cppreference.com/w/cpp/locale/setlocale | ||
setlocale(LC_ALL, ""); | ||
country = std::string(setlocale(LC_ALL, NULL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have to check the return value of setlocale, if it returns null and then you pass it to std::string. program crashes.
00483f1
to
a7336b6
Compare
…ady forre-review). - macOS checks return values before continuing; also avoids null std::string assignment - Linux implementation was updated to save the current locale before change it to user-preferred locale (found a good example on gnu.org - see https://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html) - Windows version checks length before calling UTF conversion
a7336b6
to
a593ea2
Compare
Add API method: electron.app.getCountryName
Add API method: electron.app.getCountryName
To be used to properly solve brave/browser-laptop#14647
electron.app.getLocale
method because it would return the language (not the country)base
namespace, but those all returned empty string for locale (as if it wasn't initialized properly)This PR can be merged into C68 AND C69. ex: would be good to have a 8.0.10 and a 8.1.x build 😄