macOS: Initialize standard NSUserDefaults as early as possible

The standard user defaults are initialized from an ordered list of domains,
as documented by NSUserDefaults.standardUserDefaults. This includes e.g.
parsing command line arguments, such as -AppleLocale "fr_FR", as well as
global defaults. AppKit does this during [NSUserDefaults init], which in
turn initializes the locale returned by CFLocaleCopyCurrent() and
NSLocale.currentLocale.

If those functions are called before NSUserDefaults does its thing the
locale will already have been created, and the logic in NSUserDefaults
won't have any effect -- nor is there any way for us to set/override
the locale after this.

To ensure that the -AppleLocale command line override is available through
the lower level Core Foundation preferences APIs, we need to initialize
the user defaults as early as possible via the Foundation-API.

Change-Id: I906a5a8b05a7216e60020ec45f8da725b801d2c5
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Tor Arne Vestbø 2021-02-05 19:10:24 +01:00
parent 9bc849f9c4
commit 62af65551f
1 changed files with 15 additions and 0 deletions

View File

@ -67,6 +67,21 @@ QT_BEGIN_NAMESPACE
// --------------------------------------------------------------------------
static void initializeStandardUserDefaults()
{
// The standard user defaults are initialized from an ordered list of domains,
// as documented by NSUserDefaults.standardUserDefaults. This includes e.g.
// parsing command line arguments, such as -AppleFooBar "baz", as well as
// global defaults. To ensure that these defaults are available through
// the lower level Core Foundation preferences APIs, we need to initialize
// them as early as possible via the Foundation-API, as the lower level APIs
// do not do this initialization.
Q_UNUSED(NSUserDefaults.standardUserDefaults);
}
Q_CONSTRUCTOR_FUNCTION(initializeStandardUserDefaults);
// --------------------------------------------------------------------------
QCFString::operator QString() const
{
if (string.isEmpty() && value)