Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Supports dsg-terminal-exec scheme #340

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions 3rdparty/terminalwidget/lib/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,15 +737,6 @@ void Session::done(int exitStatus)
emit finished();
return;
}

/************************ Add by sunchengxi 2020-09-15:Bug#42864 无法同时打开多个终端 Begin************************/
if (false == _autoClose && false == _wantedClose && _shellProcess->exitStatus() == QProcess::NormalExit) {
qDebug() << "autoClose is false.";
emit titleChanged();
emit finished();
return;
}
/************************ Add by sunchengxi 2020-09-15:Bug#42864 无法同时打开多个终端 End ************************/
if(exitStatus != 0)
{
QString message;
Expand All @@ -764,6 +755,12 @@ void Session::done(int exitStatus)
//sendText(infoText);
emit titleChanged();
}
else
{
sendText("\n");
sendText(tr("Press any keys to exit"));
}
emit almostFinished();
}

Emulation * Session::emulation() const
Expand Down
6 changes: 6 additions & 0 deletions 3rdparty/terminalwidget/lib/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ public slots:
/** Emitted when the terminal process starts. */
void started();

/**
* @brief Emitted when terminal process exits and session
* is still waiting for any key pressed to close.
*/
void almostFinished();

/**
* Emitted when the terminal process exits.
*/
Expand Down
3 changes: 3 additions & 0 deletions 3rdparty/terminalwidget/lib/qtermwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ void QTermWidget::addSnapShotTimer()
m_termDisplay = m_impl->m_terminalDisplay;
connect(m_interactionTimer, &QTimer::timeout, this, &QTermWidget::snapshot);
connect(m_termDisplay.data(), &Konsole::TerminalDisplay::keyPressedSignal, this, &QTermWidget::interactionHandler);
connect(currSession, &Session::almostFinished, m_termDisplay, [=] {
connect(m_termDisplay, &TerminalDisplay::keyPressedSignal, currSession, &Session::finished);
});

// take a snapshot of the session state periodically in the background
auto backgroundTimer = new QTimer(currSession);
Expand Down
3 changes: 2 additions & 1 deletion src/deepin-terminal.desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Desktop Entry]
Categories=DDE;Utility;System;TerminalEmulator;
Comment=Use the command line
Exec=deepin-terminal
Exec=deepin-terminal %u
GenericName=Terminal
Icon=deepin-terminal
Keywords=shell;prompt;command;commandline;
Expand All @@ -11,6 +11,7 @@ TryExec=deepin-terminal
Type=Application
X-Deepin-Vendor=deepin
Actions=new-window;quake-mode;
MimeType=x-scheme-handler/dsg-terminal-exec

# Translations:
# Do not manually modify!
Expand Down
14 changes: 13 additions & 1 deletion src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QCommandLineParser>
#include <QTranslator>
#include <QElapsedTimer>
#include <QUrl>

DWIDGET_USE_NAMESPACE

Expand All @@ -45,9 +46,20 @@ int main(int argc, char *argv[])

// 参数解析
TermProperties properties;
Utils::parseCommandLine(app.arguments(), properties, true);
QStringList args = app.arguments();

for (int i = 0; i < args.size(); i++) {
if (args[i].startsWith("dsg-terminal-exec://")) {
QString execCMD = args[i];
execCMD.remove("dsg-terminal-exec://");
args += "-e";
args += QUrl::fromPercentEncoding(execCMD.toUtf8());
break;
}
}

Utils::parseCommandLine(app.arguments(), properties, true);

if(!(args.contains("-w") || args.contains("--work-directory"))) {
args += "-w";
args += QDir::currentPath();
Expand Down
Loading