Skip to content

Commit 7d497e2

Browse files
committed
fixes #387 - suppress output from desktop notify command
1 parent d582e75 commit 7d497e2

4 files changed

Lines changed: 50 additions & 13 deletions

File tree

lib/common/src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
#pragma once
99

10-
#define NCHAT_VERSION "5.9.15"
10+
#define NCHAT_VERSION "5.10.1"

src/nchat.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
2-
.TH NCHAT "1" "August 2025" "nchat 5.9.15" "User Commands"
2+
.TH NCHAT "1" "August 2025" "nchat 5.10.1" "User Commands"
33
.SH NAME
44
nchat \- ncurses chat
55
.SH SYNOPSIS

src/uimodel.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ void UiModel::Impl::OpenLink(const std::string& p_Url)
10261026
std::string cmd = cmdTemplate;
10271027
StrUtil::ReplaceString(cmd, "%1", p_Url);
10281028

1029-
RunCommand(cmd);
1029+
RunProgram(cmd);
10301030
}
10311031

10321032
void UiModel::Impl::OpenAttachment(const std::string& p_Path)
@@ -1049,10 +1049,51 @@ void UiModel::Impl::OpenAttachment(const std::string& p_Path)
10491049
std::string cmd = cmdTemplate;
10501050
StrUtil::ReplaceString(cmd, "%1", p_Path);
10511051

1052-
RunCommand(cmd);
1052+
RunProgram(cmd);
10531053
}
10541054

1055-
void UiModel::Impl::RunCommand(const std::string& p_Cmd)
1055+
// Used when taking over terminal is disallowed or when output needs to be captured
1056+
bool UiModel::Impl::RunCommand(const std::string& p_Cmd, std::string* p_StdOut /*= nullptr*/)
1057+
{
1058+
const bool logStdErr = Log::GetDebugEnabled();
1059+
const std::string stdoutFile = (p_StdOut != nullptr) ? FileUtil::MkTempFile() : "/dev/null";
1060+
const std::string stderrFile = logStdErr ? FileUtil::MkTempFile() : "/dev/null";
1061+
const std::string cmdPrefix = "2>'" + stderrFile + "' ";
1062+
const std::string cmdSuffix = " >'" + stdoutFile + "'";
1063+
const std::string cmd = cmdPrefix + p_Cmd + cmdSuffix;
1064+
1065+
// run command
1066+
LOG_TRACE("cmd \"%s\" start", cmd.c_str());
1067+
const int rv = system(cmd.c_str());
1068+
if (rv != 0)
1069+
{
1070+
LOG_WARNING("cmd \"%s\" failed (%d)", cmd.c_str(), rv);
1071+
}
1072+
1073+
// stdout
1074+
if ((p_StdOut != nullptr) && FileUtil::Exists(stdoutFile))
1075+
{
1076+
*p_StdOut = FileUtil::ReadFile(stdoutFile);
1077+
FileUtil::RmFile(stdoutFile);
1078+
}
1079+
1080+
// stderr
1081+
if (logStdErr && FileUtil::Exists(stderrFile))
1082+
{
1083+
const std::string stderrStr = FileUtil::ReadFile(stderrFile);
1084+
FileUtil::RmFile(stderrFile);
1085+
if (!stderrStr.empty())
1086+
{
1087+
LOG_DEBUG("cmd \"%s\" stderr:", cmd.c_str());
1088+
Log::Dump(stderrStr.c_str());
1089+
}
1090+
}
1091+
1092+
return (rv == 0);
1093+
}
1094+
1095+
// Used when taking over terminal is allowed
1096+
void UiModel::Impl::RunProgram(const std::string& p_Cmd)
10561097
{
10571098
bool isBackground = (p_Cmd.back() == '&');
10581099

@@ -2624,12 +2665,7 @@ void UiModel::Impl::DesktopNotifyUnread(const std::string& p_Name, const std::st
26242665
StrUtil::ReplaceString(cmd, "%2", text);
26252666

26262667
// run command
2627-
LOG_TRACE("cmd \"%s\" start", cmd.c_str());
2628-
int rv = system(cmd.c_str());
2629-
if (rv != 0)
2630-
{
2631-
LOG_WARNING("cmd \"%s\" failed (%d)", cmd.c_str(), rv);
2632-
}
2668+
RunCommand(cmd);
26332669
}
26342670

26352671
void UiModel::Impl::SetHistoryInteraction(bool p_HistoryInteraction)
@@ -3141,7 +3177,7 @@ void UiModel::Impl::StartExtCall(const std::string& p_Phone)
31413177
std::string cmd = cmdTemplate;
31423178
StrUtil::ReplaceString(cmd, "%1", p_Phone);
31433179

3144-
RunCommand(cmd);
3180+
RunProgram(cmd);
31453181
}
31463182

31473183
void UiModel::Impl::SendProtocolRequest(const std::string& p_ProfileId, std::shared_ptr<RequestMessage> p_Request)

src/uimodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class UiModel
6666
void OnKeyOpenAttachment(std::string p_FilePath = std::string());
6767
void OpenLink(const std::string& p_Url);
6868
void OpenAttachment(const std::string& p_Path);
69-
void RunCommand(const std::string& p_Cmd);
69+
bool RunCommand(const std::string& p_Cmd, std::string* p_StdOut = nullptr);
70+
void RunProgram(const std::string& p_Cmd);
7071
void OnKeyOpenLink();
7172
std::string OnKeySaveAttachment(std::string p_FilePath = std::string());
7273
void TransferFile(const std::vector<std::string>& p_FilePaths);

0 commit comments

Comments
 (0)