Terminal: Use QtcProcess to start terminal window

Previously DesktopDevice::openTerminal used custom code to open a
terminal window. This patch changes it to use QtcProcess with
TerminalMode::On.

This also removes the need for "openTerminal.py" on macOS.

Change-Id: Iec978bdd19487ff8e59dcd88c35c2d01b0681022
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-03-14 09:09:55 +01:00
parent 50a214de9e
commit 44074accc7
19 changed files with 102 additions and 216 deletions

View File

@@ -3,10 +3,10 @@
#include "terminalhooks.h"
#include "terminalinterface.h"
#include "filepath.h"
#include "qtcprocess.h"
#include "terminalcommand.h"
#include "terminalinterface.h"
#include <QTemporaryFile>
@@ -14,10 +14,9 @@ namespace Utils::Terminal {
FilePath defaultShellForDevice(const FilePath &deviceRoot)
{
if (!deviceRoot.needsDevice())
return {};
if (deviceRoot.osType() == OsTypeWindows)
return deviceRoot.withNewPath("cmd.exe").searchInPath();
// TODO: Windows ?
const Environment env = deviceRoot.deviceEnvironment();
FilePath shell = FilePath::fromUserInput(env.value_or("SHELL", "/bin/sh"));
@@ -41,18 +40,23 @@ class ExternalTerminalProcessImpl final : public TerminalInterface
void startStubProcess(const CommandLine &cmd, const ProcessSetupData &) override
{
const TerminalCommand terminal = TerminalCommand::terminalEmulator();
if (HostOsInfo::isWindowsHost()) {
m_terminalProcess.setCommand(cmd);
QObject::connect(&m_terminalProcess, &QtcProcess::done, this, [this] {
m_interface->onStubExited();
});
m_terminalProcess.setCreateConsoleOnWindows(true);
m_terminalProcess.setProcessMode(ProcessMode::Writer);
m_terminalProcess.start();
} else if (HostOsInfo::isMacHost()) {
} else if (HostOsInfo::isMacHost() && terminal.command == "Terminal.app") {
QTemporaryFile f;
f.setAutoRemove(false);
f.open();
f.setPermissions(QFile::ExeUser | QFile::ReadUser | QFile::WriteUser);
f.write("#!/bin/sh\n");
f.write("clear\n");
f.write(QString("exec '%1' %2\n")
.arg(cmd.executable().nativePath())
.arg(cmd.arguments())
@@ -64,11 +68,10 @@ class ExternalTerminalProcessImpl final : public TerminalInterface
= QString("tell app \"Terminal\" to do script \"'%1'; rm -f '%1'; exit\"")
.arg(path);
m_terminalProcess.setCommand({"osascript", {"-e", exe}});
m_terminalProcess.setCommand(
{"osascript", {"-e", "tell app \"Terminal\" to activate", "-e", exe}});
m_terminalProcess.runBlocking();
} else {
const TerminalCommand terminal = TerminalCommand::terminalEmulator();
CommandLine cmdLine = {terminal.command, {terminal.executeArgs}};
cmdLine.addCommandLineAsArgs(cmd, CommandLine::Raw);