Skip to content

Conversation

@web3shannon
Copy link
Contributor

@web3shannon web3shannon commented May 19, 2019

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.

@web3shannon web3shannon changed the title fix the bug of OPEN CONFIGURATION FILE on Mac qt: fix the bug of OPEN CONFIGURATION FILE on Mac May 19, 2019
@fanquake
Copy link
Member

to run "open -t qtum.conf

What is qtum.conf ?

@web3shannon
Copy link
Contributor Author

web3shannon commented May 19, 2019

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

@hebasto
Copy link
Member

hebasto commented May 19, 2019

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 ;)

@web3shannon
Copy link
Contributor Author

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

@hebasto
Copy link
Member

hebasto commented May 19, 2019

Concept ACK. Will test.

@hebasto
Copy link
Member

hebasto commented May 19, 2019

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";

@web3shannon
Copy link
Contributor Author

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

@jonasschnelli
Copy link
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

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fanquake fanquake changed the title qt: fix the bug of OPEN CONFIGURATION FILE on Mac qt: fix opening bitcoin.conf via Preferences on macOS May 30, 2019
@hebasto
Copy link
Member

hebasto commented Jun 3, 2019

re-ACK 6e6494b

@fanquake
Copy link
Member

fanquake commented Jun 3, 2019

tACK 6e6494b on macOS 10.14.x

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

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

Using this PR (6e6494b):

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

@fanquake fanquake added this to the 0.18.1 milestone Jun 3, 2019
#ifdef Q_OS_MAC
// Workaround for macOS-specific behavior; see #15409.
if (!res) {
res = QProcess::startDetached("/usr/bin/open", QStringList{"-t", boostPathToQString(pathConfig)});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just "open"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explicit path seems better, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@laanwj laanwj merged commit 6e6494b into bitcoin:master Jun 3, 2019
laanwj added a commit that referenced this pull request Jun 3, 2019
6e6494b qt: fix opening bitcoin.conf via Preferences on macOS; see #15409 (shannon1916)

Pull request description:

  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.

ACKs for commit 6e6494:
  hebasto:
    re-ACK 6e6494b
  fanquake:
    tACK 6e6494b on macOS 10.14.x

Tree-SHA512: 60e898f4cb77cfd7b8adbc8d33fbebf46bac2a801bdcf40cae15e24b78ad56b1f32358b1879b670623d9f8651dea93961d34269358cea18f4e15b089a8ffcfbf
@fanquake
Copy link
Member

fanquake commented Jun 7, 2019

Backported in #16035.

maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Jun 7, 2019
HashUnlimited pushed a commit to HashUnlimited/chaincoin that referenced this pull request Aug 23, 2019
Bushstar pushed a commit to Bushstar/omnicore that referenced this pull request Aug 24, 2019
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request May 20, 2020
a41da9f [QT] fix opening *.conf/log files on macOS when there is no default app to open them. (furszy)

Pull request description:

  Built on top of #1515, only last commit counts for this.

  When MacOS has no default app to open *.conf and *.log throws an error instead of try to open them with a text editor. This PR solves the issue.

  Coming from btc@[16044](bitcoin#16044)

ACKs for top commit:
  random-zebra:
    utACK a41da9f
  Fuzzbawls:
    utACK a41da9f

Tree-SHA512: 5316e3a501576ed240cff9db32526eba7456112b8ad3024e5095a924a1da27f5ad5033fb3a4c50df305d262362e66abdffe2d17ff942895893e9889750dc8bf8
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 12, 2020
Summary:
6e6494b3fb345848025494cb7a79c5bf8f35e417 qt: fix opening bitcoin.conf via Preferences on macOS; see #15409 (shannon1916)

Pull request description:

  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.

---

Backport of Core [[bitcoin/bitcoin#16044 | PR16044]]

Test Plan:
  ninja all check check-functional

I don't have a mac to test this unfortunately

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D8665
kwvg added a commit to kwvg/dash that referenced this pull request Nov 4, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Nov 11, 2021
pravblockc pushed a commit to pravblockc/dash that referenced this pull request Nov 18, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The configuration file could not be opened.

6 participants