From 6cd196511db5a3ac65d0852177ae612084239e4f Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Mon, 6 Nov 2023 13:48:12 +0100 Subject: [PATCH] Utils: Fix Terminal.app script for macOS 14 The "where its tab 1 = newTab" fails on macOS 14.0. I've also added some logging to make investigating future potential problems quicker. I've filed feedback to apple here: https://feedbackassistant.apple.com/feedback/13341074 Fixes: QTCREATORBUG-29246 Change-Id: I79c6f75daa34a3c346934ee2c21a5dfc9daf3cff Reviewed-by: Eike Ziller Reviewed-by: --- .../utils/externalterminalprocessimpl.cpp | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/externalterminalprocessimpl.cpp b/src/libs/utils/externalterminalprocessimpl.cpp index 5cff874eb76..380dd633f54 100644 --- a/src/libs/utils/externalterminalprocessimpl.cpp +++ b/src/libs/utils/externalterminalprocessimpl.cpp @@ -8,7 +8,11 @@ #include "terminalcommand.h" #include "utilstr.h" +#include #include +#include + +Q_LOGGING_CATEGORY(log, "terminal.externalprocess", QtWarningMsg) namespace Utils { @@ -33,6 +37,16 @@ static const QLatin1String TerminalAppScriptAttached{R"( end tell )"}; +static const QLatin1String TerminalAppScriptAttachedWithoutWindowClose{R"( + tell application "Terminal" + activate + set newTab to do script "%1 && exit" + repeat until ((count of processes of newTab) = 0) + delay 0.1 + end repeat + end tell +)"}; + static const QLatin1String TerminalAppScriptDetached{R"( tell application "Terminal" activate @@ -52,8 +66,17 @@ expected_str ProcessStubCreator::startStubProcess(const ProcessSetupData bool detached = setupData.m_terminalMode == TerminalMode::Detached; if (HostOsInfo::isMacHost()) { + // There is a bug in macOS 14.0 where the script fails if it tries to find + // the window id. We will have to check in future versions of macOS if they fixed + // the issue. + static const QVersionNumber osVersionNumber = QVersionNumber::fromString( + QSysInfo::productVersion()); + static const QMap terminalMap = { - {"Terminal.app", {TerminalAppScriptAttached, TerminalAppScriptDetached}}, + {"Terminal.app", + {osVersionNumber.majorVersion() >= 14 ? TerminalAppScriptAttachedWithoutWindowClose + : TerminalAppScriptAttached, + TerminalAppScriptDetached}}, }; if (terminalMap.contains(terminal.command.toString())) { @@ -101,6 +124,17 @@ expected_str ProcessStubCreator::startStubProcess(const ProcessSetupData Tr::tr("Failed to start terminal process: \"%1\".").arg(process->errorString())); } + QObject::connect(process, &Process::readyReadStandardOutput, process, [process] { + const QString output = process->readAllStandardOutput(); + if (!output.isEmpty()) + qCWarning(log).noquote() << output; + }); + QObject::connect(process, &Process::readyReadStandardError, process, [process] { + const QString output = process->readAllStandardError(); + if (!output.isEmpty()) + qCCritical(log).noquote() << output; + }); + QObject::connect(process, &Process::done, m_interface, &TerminalInterface::onStubExited); return 0;