From 3647e4ba3366445549727317bfd320d30dde8ac5 Mon Sep 17 00:00:00 2001 From: ut001910 Date: Mon, 2 Sep 2024 16:16:50 +0800 Subject: [PATCH] fix: Command execution rectification Command execution rectification Log: Command execution rectification --- src/backends/mpv/mpv_proxy.cpp | 13 ++--------- src/common/mainwindow.cpp | 25 ++++++--------------- src/common/platform/platform_mainwindow.cpp | 15 ++++--------- src/libdmr/compositing_manager.cpp | 17 ++++---------- src/libdmr/utils.cpp | 17 ++++++++++++++ src/libdmr/utils.h | 5 +++++ src/main.cpp | 7 ++---- src/widgets/toolbox_proxy.cpp | 11 +-------- 8 files changed, 42 insertions(+), 68 deletions(-) diff --git a/src/backends/mpv/mpv_proxy.cpp b/src/backends/mpv/mpv_proxy.cpp index 7e79023b0..a69597246 100644 --- a/src/backends/mpv/mpv_proxy.cpp +++ b/src/backends/mpv/mpv_proxy.cpp @@ -435,14 +435,7 @@ mpv_handle *MpvProxy::mpv_init() } //TODO(xxxxpengfei):暂未处理intel集显情况 if (CompositingManager::get().isZXIntgraphics() && !jmflag) { - QProcess process; - QStringList options; - options << "-c" << QString("apt policy cx4-linux-graphics-driver-dri | sed -n \'2p\'"); - process.start("/bin/bash", options); - process.waitForFinished(); - process.waitForReadyRead(); - - QString comStr = process.readAllStandardOutput(); + QString comStr = dmr::utils::runPipeProcess("apt policy cx4-linux-graphics-driver-dri | sed -n \'2p\'"); comStr = comStr.right(3).left(2); int version = comStr.toInt(); if (version >= 10) { @@ -766,9 +759,7 @@ bool isSpecialHWHardware() if (NotHWDev == s_DevType) { // dmidecode | grep -i “String 4”中的值来区分主板类型,PWC30表示PanguW(也就是W525) - process.start("bash", {"-c", "dmidecode -t 11 | grep -i \"String 4\""}); - process.waitForFinished(100); - info = process.readAll(); + info = dmr::utils::runPipeProcess("dmidecode -t 11 | grep -i \"String 4\""); if (info.contains("PWC30") || info.contains("PGUX")) { s_DevType = IsHWDev; } diff --git a/src/common/mainwindow.cpp b/src/common/mainwindow.cpp index 10dbf901f..8cd5f3ec3 100644 --- a/src/common/mainwindow.cpp +++ b/src/common/mainwindow.cpp @@ -64,7 +64,6 @@ //add by heyi //#define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */ //#define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */ - #define XATOM_MOVE_RESIZE "_NET_WM_MOVERESIZE" #define XDEEPIN_BLUR_REGION "_NET_WM_DEEPIN_BLUR_REGION" #define XDEEPIN_BLUR_REGION_ROUNDED "_NET_WM_DEEPIN_BLUR_REGION_ROUNDED" @@ -2079,13 +2078,10 @@ void MainWindow::requestAction(ActionFactory::ActionKind actionKind, bool bFromU // || result.contains("KLVV", Qt::CaseInsensitive) // || result.contains("L540", Qt::CaseInsensitive); - QProcess process; - process.start("bash", QStringList() << "-c" << "dmidecode | grep -i \"String 4\""); - process.waitForStarted(); - process.waitForFinished(); - result = process.readAll(); + + result = dmr::utils::runPipeProcess("dmidecode | grep -i \"String 4\""); boardVendorFlag = boardVendorFlag || result.contains("PWC30", Qt::CaseInsensitive); //w525 - process.close(); + // process.close(); } qInfo() << "Whether special mini mode is supported? " << boardVendorFlag; @@ -4186,17 +4182,10 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *pEvent) } } else { //通过窗口id查询窗口状态是否置顶,同步右键菜单中的选项状态 - QProcess above; - QStringList options; - options << "-c" << QString("xprop -id %1 | grep '_NET_WM_STATE(ATOM)'").arg(winId()); - above.start("bash", options); - if (above.waitForStarted() && above.waitForFinished()) { - QString drv = QString::fromUtf8(above.readAllStandardOutput().trimmed().constData()); - if (drv.contains("_NET_WM_STATE_ABOVE") != m_bWindowAbove) { - // requestAction(ActionFactory::WindowAbove); - m_bWindowAbove = drv.contains("_NET_WM_STATE_ABOVE"); - reflectActionToUI(ActionFactory::WindowAbove); - } + QString drv = dmr::utils::runPipeProcess(QString("xprop -id %1 | grep '_NET_WM_STATE(ATOM)'").arg(winId())); + if (drv.contains("_NET_WM_STATE_ABOVE") != m_bWindowAbove) { + m_bWindowAbove = drv.contains("_NET_WM_STATE_ABOVE"); + reflectActionToUI(ActionFactory::WindowAbove); } } diff --git a/src/common/platform/platform_mainwindow.cpp b/src/common/platform/platform_mainwindow.cpp index fec1219a7..b5388c752 100644 --- a/src/common/platform/platform_mainwindow.cpp +++ b/src/common/platform/platform_mainwindow.cpp @@ -61,7 +61,6 @@ //add by heyi //#define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */ //#define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */ - #define XATOM_MOVE_RESIZE "_NET_WM_MOVERESIZE" #define XDEEPIN_BLUR_REGION "_NET_WM_DEEPIN_BLUR_REGION" #define XDEEPIN_BLUR_REGION_ROUNDED "_NET_WM_DEEPIN_BLUR_REGION_ROUNDED" @@ -4169,16 +4168,10 @@ void Platform_MainWindow::contextMenuEvent(QContextMenuEvent *pEvent) return; //通过窗口id查询窗口状态是否置顶,同步右键菜单中的选项状态 - QProcess above; - QStringList options; - options << "-c" << QString("xprop -id %1 | grep '_NET_WM_STATE(ATOM)'").arg(winId()); - above.start("bash", options); - if (above.waitForStarted() && above.waitForFinished()) { - QString drv = QString::fromUtf8(above.readAllStandardOutput().trimmed().constData()); - if (drv.contains("_NET_WM_STATE_ABOVE") != m_bWindowAbove) { - m_bWindowAbove = drv.contains("_NET_WM_STATE_ABOVE"); - reflectActionToUI(ActionFactory::WindowAbove); - } + QString drv = dmr::utils::runPipeProcess(QString("xprop -id %1 | grep '_NET_WM_STATE(ATOM)'").arg(winId())); + if (drv.contains("_NET_WM_STATE_ABOVE") != m_bWindowAbove) { + m_bWindowAbove = drv.contains("_NET_WM_STATE_ABOVE"); + reflectActionToUI(ActionFactory::WindowAbove); } if(m_pMircastShowWidget->isVisible() ) {//投屏中屏蔽全屏、迷你模式,置顶菜单 diff --git a/src/libdmr/compositing_manager.cpp b/src/libdmr/compositing_manager.cpp index ea793707e..90470822c 100644 --- a/src/libdmr/compositing_manager.cpp +++ b/src/libdmr/compositing_manager.cpp @@ -93,19 +93,10 @@ class PlatformChecker */ static bool detect550Series() { - QProcess pcicheck; - pcicheck.start("bash -c \"lspci -nk | grep -i 'in use' -B 2 | grep -iE '1002:699f|1002:6987|6766:3d02' \""); //use vaapi. add adject Glenfly Tech Co., Ltd. Arise1020 [6766:3d02] - if (pcicheck.waitForFinished(1000)) { - QByteArray readData = pcicheck.readAllStandardOutput(); - if (!readData.isEmpty()) { - qInfo() << qPrintable("Detect 550 series, using vaapi. ") << readData; - return true; - } - - qInfo() << qPrintable("Detect NOT 550 series, using default."); - } else { - pcicheck.terminate(); - qWarning() << qPrintable("Detect 550 series, run lspci -n failed. ") << pcicheck.errorString(); + QString readData = dmr::utils::runPipeProcess("lspci -nk | grep -i 'in use' -B 2 | grep -iE '1002:699f|1002:6987|6766:3d02'"); + if (!readData.isEmpty()) { + qInfo() << qPrintable("Detect 550 series, using vaapi. ") << readData; + return true; } return false; diff --git a/src/libdmr/utils.cpp b/src/libdmr/utils.cpp index ba71df1c4..6181e5856 100644 --- a/src/libdmr/utils.cpp +++ b/src/libdmr/utils.cpp @@ -14,6 +14,23 @@ using namespace std; static bool isWayland = false; +QString runPipeProcess(QString cmd) { + FILE *pPipe = popen(cmd.toUtf8(), "r"); + QString strData; + if (pPipe) + { + while (!feof(pPipe)) + { + char tempStr[1024] = {0}; + fgets(tempStr, 1024, pPipe); + strData.append(QString::fromLocal8Bit(tempStr)); + } + fclose(pPipe); + return strData; + } + return strData; +} + void ShowInFileManager(const QString &path) { if (path.isEmpty() || !QFile::exists(path)) { diff --git a/src/libdmr/utils.h b/src/libdmr/utils.h index 48fe8549f..74781f481 100644 --- a/src/libdmr/utils.h +++ b/src/libdmr/utils.h @@ -53,6 +53,11 @@ QString ElideText(const QString &text, const QSize &size, * @param 配置保存的map */ void getPlayProperty(const char *path, QMap *&proMap); +/** + * @brief run cmd + * @param cmd + */ +QString runPipeProcess(QString cmd); } } diff --git a/src/main.cpp b/src/main.cpp index c6c04f276..3e70695e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -147,10 +147,7 @@ void killOldMovie() { QString processName = "deepin-movie"; - QProcess psProcess; - psProcess.start("bash", QStringList() << "-c" << "ps -eo pid,lstart,cmd | grep deepin-movie"); - psProcess.waitForFinished(); - QString output = psProcess.readAllStandardOutput(); + QString output = dmr::utils::runPipeProcess("ps -eo pid,lstart,cmd | grep deepin-movie"); QStringList lines = output.split("\n"); QStringList earlierProcessPids; @@ -313,10 +310,10 @@ int main(int argc, char *argv[]) if (clm.isSet("functioncall")) { movieName = getFunctionMovieName(); } - if (singleton && !runSingleInstance()) { if (clm.isSet("restart")) { sleep(2); + qWarning() << "killOldMovie"; if (!runSingleInstance()) { killOldMovie(); } diff --git a/src/widgets/toolbox_proxy.cpp b/src/widgets/toolbox_proxy.cpp index 449c75227..ada2bf768 100644 --- a/src/widgets/toolbox_proxy.cpp +++ b/src/widgets/toolbox_proxy.cpp @@ -865,20 +865,11 @@ void viewProgBarLoad::loadViewProgBar(QSize size) bool command = false; if(m_pEngine->duration() < 300) { - QProcess process; - process.setProgram("ffmpeg"); - QStringList options; - options << "-c" << QString("ffprobe -v quiet -show_frames %1 | grep \"pict_type=I\" | wc -l").arg(url.toLocalFile()); - process.start("/bin/bash", options); - process.waitForFinished(); - process.waitForReadyRead(); - - QString comStr = process.readAllStandardOutput(); + QString comStr = dmr::utils::runPipeProcess(QString("ffprobe -v quiet -show_frames %1 | grep \"pict_type=I\" | wc -l").arg(url.toLocalFile())); QString str = comStr.trimmed(); int pictI = str.toInt(); if (pictI < 5) command = true; - process.close(); } if (command) {