Skip to content

Commit ff3f1b2

Browse files
fix(main_window): update sendSavingNotify to return notification ID
- Change sendSavingNotify from void to unsigned int to return the notification ID. - Implement logic to close the notification in exitRecord using the returned ID. - Adjust related calls in stopRecord to handle the notification ID correctly. This improves the notification handling during the recording process, ensuring that users receive accurate feedback on the saving status. bug: https://pms.uniontech.com/bug-view-359845.html
1 parent 90e110a commit ff3f1b2

4 files changed

Lines changed: 43 additions & 9 deletions

File tree

src/main_window.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -988,10 +988,10 @@ QString MainWindow::libPath(const QString &strlib)
988988
return list.last();
989989
}
990990

991-
void MainWindow::sendSavingNotify()
991+
quint32 MainWindow::sendSavingNotify()
992992
{
993993
if (Utils::isRootUser) {
994-
return;
994+
return RecordProcess::RECORD_SAVING_NOTIFY_ID_INVALID;
995995
}
996996
// Popup notify.
997997
QDBusInterface notification("org.freedesktop.Notifications",
@@ -1001,7 +1001,7 @@ void MainWindow::sendSavingNotify()
10011001
QStringList actions;
10021002
actions << "_close" << tr("Ignore");
10031003
int timeout = 3000;
1004-
unsigned int id = 0;
1004+
quint32 id = RecordProcess::RECORD_SAVING_NOTIFY_ID_INVALID;
10051005

10061006
QList<QVariant> arg;
10071007
arg << Utils::appName // (QCoreApplication::applicationName()) appname
@@ -1012,7 +1012,10 @@ void MainWindow::sendSavingNotify()
10121012
<< actions // actions
10131013
<< QVariantMap() // hints
10141014
<< timeout; // timeout
1015-
notification.callWithArgumentList(QDBus::AutoDetect, "Notify", arg);
1015+
QDBusMessage reply = notification.callWithArgumentList(QDBus::AutoDetect, "Notify", arg);
1016+
if (reply.type() == QDBusMessage::ReplyMessage && !reply.arguments().isEmpty())
1017+
return reply.arguments().constFirst().toUInt();
1018+
return RecordProcess::RECORD_SAVING_NOTIFY_ID_INVALID;
10161019
}
10171020

10181021
void MainWindow::forciblySavingNotify()
@@ -1028,7 +1031,7 @@ void MainWindow::forciblySavingNotify()
10281031
QStringList actions;
10291032
actions << "_close" << tr("Ignore");
10301033
int timeout = 3000;
1031-
unsigned int id = 0;
1034+
quint32 id = RecordProcess::RECORD_SAVING_NOTIFY_ID_INVALID;
10321035

10331036
QList<QVariant> arg;
10341037
arg << Utils::appName //(QCoreApplication::applicationName()) // appname
@@ -7268,9 +7271,9 @@ void MainWindow::stopRecord()
72687271
}
72697272
hide();
72707273
emit releaseEvent();
7271-
// 正在保存录屏文件通知,全屏录制时不需进行通知
7274+
// 正在保存录屏文件通知全屏录制时不需进行通知;完成时用 CloseNotification 关闭本条再弹「录制完成」
72727275
if (!m_isFullScreenRecord)
7273-
sendSavingNotify();
7276+
recordProcess.setRecordSavingNotifyId(sendSavingNotify());
72747277
// 状态栏闪烁停止
72757278
if (Utils::isTabletEnvironment && m_tabletRecorderHandle) {
72767279
m_tabletRecorderHandle->stop();

src/main_window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class MainWindow : public QMainWindow
389389
* @return true=完整文件路径,false=目录路径
390390
*/
391391
bool parsePathArgument(const QString &path, QString &outDir, QString &outFileName, QString &outFormat);
392-
void sendSavingNotify();
392+
quint32 sendSavingNotify();
393393
// 强制录屏保存退出通知,3D->2D模式
394394
void forciblySavingNotify();
395395

src/record_process.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ static QDBusMessage callTrayRecorderIcon(const QString &function)
8787
return recorderInterface.call(function);
8888
}
8989

90+
static void closeFdoNotification(quint32 id)
91+
{
92+
if (id == RecordProcess::RECORD_SAVING_NOTIFY_ID_INVALID)
93+
return;
94+
QDBusInterface notification("org.freedesktop.Notifications",
95+
"/org/freedesktop/Notifications",
96+
"org.freedesktop.Notifications",
97+
QDBusConnection::sessionBus());
98+
notification.call("CloseNotification", id);
99+
}
100+
101+
void RecordProcess::setRecordSavingNotifyId(quint32 id)
102+
{
103+
m_recordSavingNotifyId = id;
104+
}
105+
90106
RecordProcess::RecordProcess(QObject *parent) : QObject(parent)
91107
{
92108
qCDebug(dsrApp) << "Record process control class initialized.";
@@ -804,6 +820,7 @@ void RecordProcess::onExitGstRecord()
804820
//开始录屏
805821
void RecordProcess::startRecord()
806822
{
823+
m_recordSavingNotifyId = RECORD_SAVING_NOTIFY_ID_INVALID;
807824
getScreenRecordSavePath();
808825
//使用QtConcurrent::run受cpu核心线程数的影响,线程池默认大小为CPU核心线程数大小,由于程序中通过此方法启动的线程数超出4个,故再次设置线程池大小
809826
QThreadPool::globalInstance()->setMaxThreadCount(QThreadPool::globalInstance()->maxThreadCount() > 6 ? QThreadPool::globalInstance()->maxThreadCount() : 10);
@@ -959,7 +976,11 @@ void RecordProcess::stopRecord()
959976
void RecordProcess::exitRecord(QString newSavePath)
960977
{
961978
if (!Utils::isRootUser && !m_isFullScreenRecord) {
962-
qCInfo(dsrApp) << __LINE__ << __func__ << "正在弹出保存完成的通知...";
979+
qCInfo(dsrApp) << __LINE__ << __func__ << "关闭「正在保存」通知(若有)并弹出保存完成通知";
980+
if (m_recordSavingNotifyId != RECORD_SAVING_NOTIFY_ID_INVALID) {
981+
closeFdoNotification(m_recordSavingNotifyId);
982+
m_recordSavingNotifyId = RECORD_SAVING_NOTIFY_ID_INVALID;
983+
}
963984
// Popup notify.
964985
QDBusInterface notification("org.freedesktop.Notifications",
965986
"/org/freedesktop/Notifications",

src/record_process.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class RecordProcess : public QObject
4141
static const int RECORD_FRAMERATE_24;
4242
static const int RECORD_FRAMERATE_30;
4343

44+
static constexpr quint32 RECORD_SAVING_NOTIFY_ID_INVALID = 0;
45+
4446
explicit RecordProcess(QObject *parent = nullptr);
4547
~RecordProcess();
4648

@@ -72,6 +74,12 @@ class RecordProcess : public QObject
7274
* @param flag
7375
*/
7476
void setFullScreenRecord(bool flag);
77+
78+
/**
79+
* @brief 由 MainWindow 在弹出「正在保存」通知后传入 Notify 返回的 id,
80+
* exitRecord 弹出「录制完成」前会先 CloseNotification 关闭该通知。
81+
*/
82+
void setRecordSavingNotifyId(quint32 id);
7583
private:
7684
/**
7785
* @brief x11协议下ffmpeg录制视频
@@ -195,6 +203,8 @@ private slots:
195203
*/
196204
bool m_isFullScreenRecord = false;
197205

206+
quint32 m_recordSavingNotifyId = RECORD_SAVING_NOTIFY_ID_INVALID;
207+
198208
signals:
199209
void recordingStopped();
200210
void recordingStarted(); // 录屏开始信号

0 commit comments

Comments
 (0)