[price-quotes] Enable gnucash-cli to retrieve preferences on macOS.

By embedding a minimal Info.plist with a bundle ID into the executable.
This necessitated a change to binreloc because the unix-style install
depended on there being a bundle ID only when the program was run from
an application bundle.
This commit is contained in:
John Ralls 2022-10-17 10:06:21 -07:00
parent 2767587874
commit 1a906b00aa
5 changed files with 24 additions and 1 deletions

8
Info.plist Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>org.gnucash.Gnucash</string>
</dict>
</plist>

View File

@ -152,6 +152,7 @@ if (MAC_INTEGRATION)
target_link_libraries(gnucash ${OSX_EXTRA_LIBRARIES})
target_compile_options(gnucash-cli PRIVATE ${OSX_EXTRA_COMPILE_FLAGS})
target_link_libraries(gnucash-cli ${OSX_EXTRA_LIBRARIES})
target_link_options(gnucash-cli PRIVATE -Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_SOURCE_DIR}/Info.plist)
endif()
install(TARGETS gnucash gnucash-cli DESTINATION ${CMAKE_INSTALL_BINDIR})

View File

@ -365,6 +365,7 @@ Gnucash::add_quotes (const bo_str& uri)
int
Gnucash::report_quotes (const char* source, const StrVec& commodities, bool verbose)
{
gnc_prefs_init();
try
{
GncQuotes quotes;

View File

@ -173,7 +173,7 @@ m_version{}, m_sources{}, m_api_key{}
m_sources = std::move(sources);
auto av_key = gnc_prefs_get_string ("general.finance-quote", "alphavantage-api-key");
if (!av_key)
if (!(av_key && *av_key))
av_key = getenv("ALPHAVANTAGE_API_KEY");
if (av_key)

View File

@ -369,6 +369,7 @@ get_mac_bundle_prefix()
#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION
gchar *id = gtkosx_application_get_bundle_id ();
gchar *path = gtkosx_application_get_resource_path ();
gchar *basename = g_path_get_basename (path);
/* If id is nullthe app is unbundled and the path
is just the path to the application directory.
We already have that and our version is better.
@ -377,11 +378,23 @@ get_mac_bundle_prefix()
*/
if (id == NULL || g_getenv ("GNC_UNINSTALLED"))
{
g_free (basename);
g_free (path);
g_free (id);
return NULL;
}
g_free (id);
if (g_strcmp0 ("bin", basename) == 0)
{
g_free (path);
g_free (basename);
return NULL;
}
g_free (basename);
return path;
#endif
return NULL;