qt: fix opening bitcoin.conf via Preferences on macOS #16044

pull web3shannon wants to merge 1 commits into bitcoin:master from web3shannon:master changing 1 files +10 −1
  1. web3shannon commented at 8:48 AM on May 19, 2019: contributor

    Fix #15409. The QT wallet fail to open the configuration file on Mac, when these is no default application for *.conf files.

    Here is a feasible way to solve this bug. When QDesktopServices::openUrl fails to open file:///path/bitcoin.conf with its default application, use QProcess::startDetached to run open -t /path/bitcoin.conf command instead, so as to open the configuration file with system's default text editor.

  2. fanquake added the label GUI on May 19, 2019
  3. fanquake added the label macOS on May 19, 2019
  4. web3shannon renamed this:
    fix the bug of OPEN CONFIGURATION FILE on Mac
    qt: fix the bug of OPEN CONFIGURATION FILE on Mac
    on May 19, 2019
  5. fanquake commented at 8:59 AM on May 19, 2019: member

    to run "open -t qtum.conf

    What is qtum.conf ?

  6. web3shannon commented at 9:01 AM on May 19, 2019: contributor

    Sorry. Since I find this bug initially in the Qtum blockchain, I wrote it wrong and have changed the text...

  7. hebasto commented at 10:07 AM on May 19, 2019: member

    The mentioned issue #15409 is related to the setting a default application to open *.conf files. This can be easily achieved via macOS GUI.

    /usr/bin/open -t forces to open a file with default text editor. This implies the setting a default application to open *.conf files will not work, right? @shannon1916 your PR description could be edited using this GitHub tips ;)

  8. web3shannon commented at 12:37 PM on May 19, 2019: contributor

    @hebasto The PR description is modified as you suggest.

    And, /usr/bin/open -t only works when QDesktopServices::openUrl fails, as detailed in the PR description.

  9. hebasto commented at 12:43 PM on May 19, 2019: member

    Concept ACK. Will test.

  10. hebasto commented at 2:28 PM on May 19, 2019: member

    tACK 57b30ce16cf6d4d2e6a30e70ede7f2bdd5fbc003 modulo nits (macOS 10.13.6)

    As my system already has a default app to open *.conf files, the next patch was applied for testing purpose:

    diff --git a/src/util/system.cpp b/src/util/system.cpp
    index 6925bda4e..a5e24c0f3 100644
    --- a/src/util/system.cpp
    +++ b/src/util/system.cpp
    @@ -72 +72 @@ const int64_t nStartupTime = GetTime();
    -const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
    +const char * const BITCOIN_CONF_FILENAME = "bitcoin.conftest";
    
  11. in src/qt/guiutil.cpp:406 in 57b30ce16c outdated
     399 | @@ -399,7 +400,13 @@ bool openBitcoinConf()
     400 |      configFile.close();
     401 |  
     402 |      /* Open bitcoin.conf with the associated application */
     403 | -    return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
     404 | +    bool res = QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
     405 | +#if defined(Q_OS_MAC)
     406 | +    if (!res)
     407 | +        res = QProcess::startDetached("/usr/bin/open", QStringList() << "-t" << boostPathToQString(pathConfig));
    


    hebasto commented at 2:52 PM on May 19, 2019:

    nit: could if statement be placed in braces?

    micronit: using an initializer list is shorter:

    QStringList{"-t", boostPathToQString(pathConfig)}
    

    web3shannon commented at 12:44 AM on May 20, 2019:

    fixed in the new commit

  12. in src/qt/guiutil.cpp:404 in 57b30ce16c outdated
     399 | @@ -399,7 +400,13 @@ bool openBitcoinConf()
     400 |      configFile.close();
     401 |  
     402 |      /* Open bitcoin.conf with the associated application */
     403 | -    return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
     404 | +    bool res = QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
     405 | +#if defined(Q_OS_MAC)
    


    hebasto commented at 2:54 PM on May 19, 2019:

    nit: #ifdef is more common in Bitcoin Core code base ;)


    web3shannon commented at 12:44 AM on May 20, 2019:

    fixed in the new commit

  13. web3shannon commented at 12:56 AM on May 20, 2019: contributor

    @hebasto The default app for *.conf files can be set in System Preferences -> Default Apps -> Extensions, as shown below image

  14. jonasschnelli commented at 9:25 AM on May 20, 2019: contributor

    Too bad this required a MAC #ifdef and a fixed path to an executable. But I guess it's an acceptable fix. utACK 0ebaa3ad8c252e8d6da37ac62ed568237bbb4bad

  15. in src/qt/guiutil.cpp:406 in 0ebaa3ad8c outdated
     399 | @@ -399,7 +400,14 @@ bool openBitcoinConf()
     400 |      configFile.close();
     401 |  
     402 |      /* Open bitcoin.conf with the associated application */
     403 | -    return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
     404 | +    bool res = QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
     405 | +#ifdef Q_OS_MAC
     406 | +    if (!res) {
    


    laanwj commented at 3:19 PM on May 20, 2019:

    I think this needs a comment why this fallback is necessary.


    web3shannon commented at 2:08 AM on May 21, 2019:

    A comment like https://github.com/bitcoin/bitcoin/blob/master/src/qt/guiutil.cpp#L944 ? Like // Workaround for macOS-only Qt bug; see: ISSUE [#15409](/bitcoin-bitcoin/15409/)?


    fanquake commented at 8:35 PM on May 30, 2019:

    @shannon1916 A comment like // Workaround for macOS-only Qt bug; see [#15409](/bitcoin-bitcoin/15409/) should be ok. Once you've added it can you squash all of your commits.


    hebasto commented at 7:26 AM on May 31, 2019:

    IMO, this issue is not a Qt bug. This PR addresses macOS-specific behavior. May I suggest a comment // Workaround for macOS-specific behavior; see [#15409](/bitcoin-bitcoin/15409/). ?


    web3shannon commented at 6:01 AM on June 3, 2019:

    Done

  16. fanquake commented at 9:23 PM on May 30, 2019: member

    Concept ACK

    Have checked that this change works on macOS with and without a .conf file already in place. In the later case a blank .conf is created and opened.

    Will re-ack post comment fix-up and squash.

  17. fanquake renamed this:
    qt: fix the bug of OPEN CONFIGURATION FILE on Mac
    qt: fix opening bitcoin.conf via Preferences on macOS
    on May 30, 2019
  18. qt: fix opening bitcoin.conf via Preferences on macOS; see #15409 6e6494b3fb
  19. hebasto commented at 6:48 AM on June 3, 2019: member

    re-ACK 6e6494b3fb345848025494cb7a79c5bf8f35e417

  20. fanquake commented at 2:09 PM on June 3, 2019: member

    tACK https://github.com/bitcoin/bitcoin/commit/6e6494b3fb345848025494cb7a79c5bf8f35e417 on macOS 10.14.x

    Using master (c7cfd20a77ce57d200b3b9e5e0dfb0d63818abdc) you cannot open bitcoin.conf through the preferences menu:

    Screen Shot 2019-06-03 at 9 56 04 am

    Using this PR (6e6494b3fb345848025494cb7a79c5bf8f35e417):

    Opening an existing bitcoin.conf works, and if one doesn't exist, a blank one is created and opened.

    lldb Bitcoin-Qt.app -- -regtest
    (lldb) target create "Bitcoin-Qt.app"
    Current executable set to 'Bitcoin-Qt.app' (x86_64).
    (lldb) settings set -- target.run-args  "-regtest"
    (lldb) run
    Process 40791 launched: '/Users/michael/github/bitcoin/Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt' (x86_64)
    2019-06-03 10:00:00.852544-0400 Bitcoin-Qt[40791:8481788] MessageTracer: Falling back to default whitelist
    2019-06-03 10:00:07.232235-0400 open[40799:8481923] MessageTracer: Falling back to default whitelist
    2019-06-03 10:00:19.079914-0400 open[40928:8482455] MessageTracer: Falling back to default whitelist
    
  21. fanquake added the label Needs backport on Jun 3, 2019
  22. fanquake added this to the milestone 0.18.1 on Jun 3, 2019
  23. in src/qt/guiutil.cpp:407 in 6e6494b3fb
     399 | @@ -399,7 +400,15 @@ bool openBitcoinConf()
     400 |      configFile.close();
     401 |  
     402 |      /* Open bitcoin.conf with the associated application */
     403 | -    return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
     404 | +    bool res = QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
     405 | +#ifdef Q_OS_MAC
     406 | +    // Workaround for macOS-specific behavior; see #15409.
     407 | +    if (!res) {
     408 | +        res = QProcess::startDetached("/usr/bin/open", QStringList{"-t", boostPathToQString(pathConfig)});
    


    promag commented at 3:32 PM on June 3, 2019:

    Just "open"?


    hebasto commented at 4:13 PM on June 3, 2019:
    high-sierra:~ hebasto$ /usr/bin/open
    Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s <partial SDK name>][-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]
    Help: Open opens files from a shell.
          By default, opens each file using the default application for that file.  
          If the file is in the form of a URL, the file will be opened as a URL.
    Options: 
          -a                Opens with the specified application.
          -b                Opens with the specified application bundle identifier.
          -e                Opens with TextEdit.
          -t                Opens with default text editor.
          -f                Reads input from standard input and opens with TextEdit.
          -F  --fresh       Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.
          -R, --reveal      Selects in the Finder instead of opening.
          -W, --wait-apps   Blocks until the used applications are closed (even if they were already running).
              --args        All remaining arguments are passed in argv to the application's main() function instead of opened.
          -n, --new         Open a new instance of the application even if one is already running.
          -j, --hide        Launches the app hidden.
          -g, --background  Does not bring the application to the foreground.
          -h, --header      Searches header file locations for headers matching the given filenames, and opens them.
          -s                For -h, the SDK to use; if supplied, only SDKs whose names contain the argument value are searched.
                            Otherwise the highest versioned SDK in each platform is used.
    

    hebasto commented at 4:16 PM on June 3, 2019:

    The explicit path seems better, right?


    laanwj commented at 9:19 PM on June 3, 2019:

    As this is an OS specific hack, I think hardcoding the path seems fine, it's always that.

  24. laanwj merged this on Jun 3, 2019
  25. laanwj closed this on Jun 3, 2019

  26. laanwj referenced this in commit 6520330087 on Jun 3, 2019
  27. MarcoFalke referenced this in commit f272bbe73b on Jun 7, 2019
  28. fanquake commented at 8:03 AM on June 7, 2019: member

    Backported in #16035.

  29. fanquake removed the label Needs backport on Jun 7, 2019
  30. MarcoFalke referenced this in commit b55cbe82d9 on Jun 7, 2019
  31. HashUnlimited referenced this in commit 732e55dac1 on Aug 23, 2019
  32. Bushstar referenced this in commit 3da1698cc0 on Aug 24, 2019
  33. random-zebra referenced this in commit 93df7ce6ec on May 20, 2020
  34. Fabcien referenced this in commit a01b61c5f1 on Dec 12, 2020
  35. kittywhiskers referenced this in commit 7441edb10c on Nov 3, 2021
  36. kittywhiskers referenced this in commit 81d22b7ea2 on Nov 4, 2021
  37. kittywhiskers referenced this in commit 843e6d4c86 on Nov 11, 2021
  38. pravblockc referenced this in commit 7436f56400 on Nov 18, 2021
  39. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me