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

fix: Command execution rectification #512

Merged
merged 1 commit into from
Sep 4, 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
13 changes: 2 additions & 11 deletions src/backends/mpv/mpv_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 7 additions & 18 deletions src/common/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

Expand Down
15 changes: 4 additions & 11 deletions src/common/platform/platform_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() ) {//投屏中屏蔽全屏、迷你模式,置顶菜单
Expand Down
17 changes: 4 additions & 13 deletions src/libdmr/compositing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/libdmr/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@

static bool isWayland = false;

QString runPipeProcess(QString cmd) {

Check warning on line 17 in src/libdmr/utils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'cmd' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
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)) {
Expand Down
5 changes: 5 additions & 0 deletions src/libdmr/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ QString ElideText(const QString &text, const QSize &size,
* @param 配置保存的map
*/
void getPlayProperty(const char *path, QMap<QString, QString> *&proMap);
/**
* @brief run cmd
* @param cmd
*/
QString runPipeProcess(QString cmd);
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
11 changes: 1 addition & 10 deletions src/widgets/toolbox_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading