Skip to content

Commit

Permalink
[price-quotes] Enable gnucash-cli to retrieve preferences on macOS.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jralls committed Oct 17, 2022
1 parent 2767587 commit 1a906b0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions gnucash/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
1 change: 1 addition & 0 deletions gnucash/gnucash-commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libgnucash/app-utils/gnc-quotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions libgnucash/core-utils/binreloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down

0 comments on commit 1a906b0

Please sign in to comment.