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

John Ralls jralls at code.gnucash.org
Mon Oct 17 13:06:37 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/1a906b00 (commit)
	from  https://github.com/Gnucash/gnucash/commit/27675878 (commit)



commit 1a906b00aafdea41fabd106f330951ab965b1afe
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Oct 17 10:06:21 2022 -0700

    [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.

diff --git a/Info.plist b/Info.plist
new file mode 100644
index 000000000..9a4056cfd
--- /dev/null
+++ b/Info.plist
@@ -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>
diff --git a/gnucash/CMakeLists.txt b/gnucash/CMakeLists.txt
index 7cd30a83d..254aece47 100644
--- a/gnucash/CMakeLists.txt
+++ b/gnucash/CMakeLists.txt
@@ -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})
diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 8fc91e918..2014a9013 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -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;
diff --git a/libgnucash/app-utils/gnc-quotes.cpp b/libgnucash/app-utils/gnc-quotes.cpp
index e236c1ef4..42a878520 100644
--- a/libgnucash/app-utils/gnc-quotes.cpp
+++ b/libgnucash/app-utils/gnc-quotes.cpp
@@ -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)
diff --git a/libgnucash/core-utils/binreloc.c b/libgnucash/core-utils/binreloc.c
index 557f9d20f..828b9acc2 100644
--- a/libgnucash/core-utils/binreloc.c
+++ b/libgnucash/core-utils/binreloc.c
@@ -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;



Summary of changes:
 Info.plist                          |  8 ++++++++
 gnucash/CMakeLists.txt              |  1 +
 gnucash/gnucash-commands.cpp        |  1 +
 libgnucash/app-utils/gnc-quotes.cpp |  2 +-
 libgnucash/core-utils/binreloc.c    | 13 +++++++++++++
 5 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 Info.plist



More information about the gnucash-changes mailing list