Skip to content

Commit a41da9f

Browse files
committed
[QT] fix opening *.conf/log files on macOS when there is no default app to open them.
1 parent e941230 commit a41da9f

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/qt/guiutil.cpp

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ extern double NSAppKitVersionNumber;
8383
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
8484

8585
#include <CoreServices/CoreServices.h>
86+
#include <QProcess>
8687

8788
void ForceActivation();
8889
#endif
@@ -402,44 +403,40 @@ void bringToFront(QWidget* w)
402403
}
403404
}
404405

405-
bool openDebugLogfile()
406+
/* Open file with the associated application */
407+
bool openFile(boost::filesystem::path path, bool isTextFile)
406408
{
407-
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
409+
bool ret = false;
410+
if (boost::filesystem::exists(path)) {
411+
ret = QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(path)));
412+
#ifdef Q_OS_MAC
413+
// Workaround for macOS-specific behavior; see btc@15409.
414+
if (isTextFile && !ret) {
415+
ret = QProcess::startDetached("/usr/bin/open", QStringList{"-t", boostPathToQString(path)});
416+
}
417+
#endif
418+
}
419+
return ret;
420+
}
408421

409-
/* Open debug.log with the associated application */
410-
if (boost::filesystem::exists(pathDebug))
411-
return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathDebug)));
412-
return false;
422+
bool openDebugLogfile()
423+
{
424+
return openFile(GetDataDir() / "debug.log", true);
413425
}
414426

415427
bool openConfigfile()
416428
{
417-
boost::filesystem::path pathConfig = GetConfigFile();
418-
419-
/* Open pivx.conf with the associated application */
420-
if (boost::filesystem::exists(pathConfig))
421-
return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
422-
return false;
429+
return openFile(GetConfigFile(), true);
423430
}
424431

425432
bool openMNConfigfile()
426433
{
427-
boost::filesystem::path pathConfig = GetMasternodeConfigFile();
428-
429-
/* Open masternode.conf with the associated application */
430-
if (boost::filesystem::exists(pathConfig))
431-
return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
432-
return false;
434+
return openFile(GetMasternodeConfigFile(), true);
433435
}
434436

435437
bool showBackups()
436438
{
437-
boost::filesystem::path pathBackups = GetDataDir() / "backups";
438-
439-
/* Open folder with default browser */
440-
if (boost::filesystem::exists(pathBackups))
441-
return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathBackups)));
442-
return false;
439+
return openFile(GetDataDir() / "backups", false);
443440
}
444441

445442
void SubstituteFonts(const QString& language)

0 commit comments

Comments
 (0)