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: Fixed custom mode exceptions #589

Open
wants to merge 1 commit into
base: develop/snipe
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions assets/resources/data/GstSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"options": [
{
"key": "crash",
"type": "checkbox",
"type": "combobox",
"hide": true,
"default": false
"default": 0
}
]
}
Expand Down Expand Up @@ -368,4 +368,4 @@
]
}
]
}
}
11 changes: 10 additions & 1 deletion src/common/dmr_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,19 @@ Settings::Settings()
if (index == 1) {
if (voFamily) {
voFamily->setData("items", QStringList() << "OpenGL");
auto decodeFamily = m_pSettings->option("base.decode.Decodemode");
if (decodeFamily)
decodeFamily->setData("items", QStringList() << "vaapi" << "vaapi-copy" << "vdpau" << "vdpau-copy");
}
} else if (index == 2) {
if (voFamily)
if (voFamily) {
if (voFamily->value().toInt() == 0) {
auto decodeFamily = m_pSettings->option("base.decode.Decodemode");
if (decodeFamily)
decodeFamily->setData("items", QStringList());
}
voFamily->setData("items", QStringList() << "" << "gpu" << "vaapi" << "vdpau" << "xv" << "x11");
}
}
emit baseChanged(key, value);
}
Expand Down
56 changes: 35 additions & 21 deletions src/common/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ MainWindow::MainWindow(QWidget *parent)
qInfo() << "session Path is :" << path;
connect(dynamic_cast<MpvProxy *>(m_pEngine->getMpvProxy()),&MpvProxy::crashCheck,&Settings::get(),&Settings::crashCheck);
//解码初始化
// decodeInit();
decodeInit();
}

void MainWindow::setupTitlebar()
Expand Down Expand Up @@ -2877,6 +2877,12 @@ void MainWindow::handleSettings(DSettingsDialog *dsd)
dsd ->show();
#endif

static QEventLoop loop;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider refactoring the blocking "wait-for file change" pattern into a single helper that uses asynchronous signals instead of nested QEventLoop calls to reduce complexity.

Consider refactoring the blocking “wait‐for file change” pattern into a single helper that uses asynchronous signals instead of nested QEventLoop calls. For example, define a helper that wraps a QFileSystemWatcher and emits a signal when a file changes:

// FileWatcherHelper.h
class FileWatcherHelper : public QObject {
    Q_OBJECT
public:
    explicit FileWatcherHelper(const QString &path, QObject *parent = nullptr)
      : QObject(parent), m_fileWatcher(new QFileSystemWatcher(this)) {
        m_fileWatcher->addPath(path);
        connect(m_fileWatcher, &QFileSystemWatcher::fileChanged, this, &FileWatcherHelper::fileUpdated);
    }
signals:
    void fileUpdated();
private:
    QFileSystemWatcher *m_fileWatcher;
};

Then replace the repeated static QEventLoop and QFileSystemWatcher blocks with an asynchronous slot:

// Instead of blocking using loop.exec(), use a slot or lambda
auto watcher = new FileWatcherHelper(Settings::get().configPath(), this);
connect(watcher, &FileWatcherHelper::fileUpdated, this, [this, watcher]() {
    // Execute the logic that should run after file update
    Settings::get().setInternalOption("global_volume", m_nDisplayVolume > 100 ? 100 : m_nDisplayVolume);
    Settings::get().onSetCrash();
    m_pEngine->savePlaybackPosition();
    // Clean up watcher if no longer needed:
    watcher->deleteLater();
});

This approach removes nested loops while preserving the original functionality. Adjust other identical patterns similarly to reduce complexity and improve maintainability.

QFileSystemWatcher fileWatcher;
fileWatcher.addPath(Settings::get().configPath());
connect(&fileWatcher, &QFileSystemWatcher::fileChanged, this, [=](){
loop.quit();
});
if (Settings::get().settings()->getOption("base.decode.select").toInt() != decodeType &&
(Settings::get().settings()->getOption("base.decode.select").toInt() == 3 || decodeType == 3)) {
DDialog msgBox;
Expand All @@ -2886,7 +2892,9 @@ void MainWindow::handleSettings(DSettingsDialog *dsd)
msgBox.addButton(tr("Restart"), true, DDialog::ButtonType::ButtonWarning);
msgBox.setOnButtonClickedClose(true);
if (msgBox.exec() == 1) {
Settings::get().settings()->setOption("set.start.crash", "2");
Settings::get().settings()->setOption(QString("set.start.crash"), 2);
Settings::get().settings()->sync();
loop.exec();
qApp->exit(2);
} else {
if (decodeType != 3) {
Expand All @@ -2909,7 +2917,9 @@ void MainWindow::handleSettings(DSettingsDialog *dsd)
msgBox.addButton(tr("Restart"), true, DDialog::ButtonType::ButtonWarning);
msgBox.setOnButtonClickedClose(true);
if (msgBox.exec() == 1) {
Settings::get().settings()->setOption("set.start.crash", "2");
Settings::get().settings()->setOption(QString("set.start.crash"), 2);
Settings::get().settings()->sync();
loop.exec();
qApp->exit(2);
} else {
if (decodeType != 3) {
Expand Down Expand Up @@ -3692,7 +3702,6 @@ void MainWindow::closeEvent(QCloseEvent *pEvent)
m_nLastCookie = 0;
}

Settings::get().onSetCrash();
if (Settings::get().isSet(Settings::ResumeFromLast)) {
int nCur = 0;
nCur = m_pEngine->playlist().current();
Expand All @@ -3701,18 +3710,16 @@ void MainWindow::closeEvent(QCloseEvent *pEvent)
}
}

int volume = Settings::get().internalOption("global_volume").toInt();
if (m_nDisplayVolume != volume) {
static QEventLoop loop;
QFileSystemWatcher fileWatcher;
fileWatcher.addPath(Settings::get().configPath());
connect(&fileWatcher, &QFileSystemWatcher::fileChanged, this, [=](){
loop.quit();
});
//关闭窗口时保存音量值
Settings::get().setInternalOption("global_volume", m_nDisplayVolume > 100 ? 100 : m_nDisplayVolume);
loop.exec();
}
static QEventLoop loop;
QFileSystemWatcher fileWatcher;
fileWatcher.addPath(Settings::get().configPath());
connect(&fileWatcher, &QFileSystemWatcher::fileChanged, this, [=](){
loop.quit();
});
//关闭窗口时保存音量值
Settings::get().setInternalOption("global_volume", m_nDisplayVolume > 100 ? 100 : m_nDisplayVolume);
Settings::get().onSetCrash();
loop.exec();
m_pEngine->savePlaybackPosition();

pEvent->accept();
Expand Down Expand Up @@ -4378,13 +4385,20 @@ void MainWindow::decodeInit()
return;

//崩溃检测
bool bcatch = Settings::get().settings()->getOption(QString("set.start.crash")).toBool();
if (bcatch) {
int bcatch = Settings::get().settings()->getOption(QString("set.start.crash")).toInt();
switch (bcatch) {
case 1:
pMpvProxy->setDecodeModel(DecodeMode::AUTO);
Settings::get().settings()->setOption(QString("base.decode.select"),DecodeMode::AUTO);
} else {
int value = Settings::get().settings()->getOption(QString("base.decode.select")).toInt();
pMpvProxy->setDecodeModel(value);
break;
case 2:
pMpvProxy->setDecodeModel(Settings::get().settings()->
getOption(QString("base.decode.select")).toInt());
dmr::Settings::get().crashCheck();
break;
case 0:
default:
break;
}
}

Expand Down
53 changes: 34 additions & 19 deletions src/common/platform/platform_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ Platform_MainWindow::Platform_MainWindow(QWidget *parent)
qInfo() << "session Path is :" << path;
connect(dynamic_cast<MpvProxy *>(m_pEngine->getMpvProxy()),&MpvProxy::crashCheck,&Settings::get(),&Settings::crashCheck);
//解码初始化
//decodeInit();
decodeInit();
}

void Platform_MainWindow::setupTitlebar()
Expand Down Expand Up @@ -2922,6 +2922,12 @@ void Platform_MainWindow::handleSettings(DSettingsDialog *dsd)
dsd ->show();
#endif

static QEventLoop loop;
QFileSystemWatcher fileWatcher;
fileWatcher.addPath(Settings::get().configPath());
connect(&fileWatcher, &QFileSystemWatcher::fileChanged, this, [=](){
loop.quit();
});
if (Settings::get().settings()->getOption("base.decode.select").toInt() != decodeType &&
(Settings::get().settings()->getOption("base.decode.select").toInt() == 3 || decodeType == 3)) {
DDialog msgBox;
Expand All @@ -2931,7 +2937,9 @@ void Platform_MainWindow::handleSettings(DSettingsDialog *dsd)
msgBox.addButton(tr("Restart"), true, DDialog::ButtonType::ButtonWarning);
msgBox.setOnButtonClickedClose(true);
if (msgBox.exec() == 1) {
Settings::get().settings()->setOption("set.start.crash", "2");
Settings::get().settings()->setOption(QString("set.start.crash"), 2);
Settings::get().settings()->sync();
loop.exec();
qApp->exit(2);
} else {
if (decodeType != 3) {
Expand All @@ -2956,6 +2964,8 @@ void Platform_MainWindow::handleSettings(DSettingsDialog *dsd)
msgBox.setOnButtonClickedClose(true);
if (msgBox.exec() == 1) {
Settings::get().settings()->setOption("set.start.crash", "2");
Settings::get().settings()->sync();
loop.exec();
qApp->exit(2);
} else {
if (decodeType != 3) {
Expand Down Expand Up @@ -3685,18 +3695,16 @@ void Platform_MainWindow::closeEvent(QCloseEvent *pEvent)
Settings::get().setInternalOption("playlist_pos", nCur);
}
}
int volume = Settings::get().internalOption("global_volume").toInt();
if (m_nDisplayVolume != volume) {
static QEventLoop loop;
QFileSystemWatcher fileWatcher;
fileWatcher.addPath(Settings::get().configPath());
connect(&fileWatcher, &QFileSystemWatcher::fileChanged, this, [=](){
loop.quit();
});
//关闭窗口时保存音量值
Settings::get().setInternalOption("global_volume", m_nDisplayVolume > 100 ? 100 : m_nDisplayVolume);
loop.exec();
}
static QEventLoop loop;
QFileSystemWatcher fileWatcher;
fileWatcher.addPath(Settings::get().configPath());
connect(&fileWatcher, &QFileSystemWatcher::fileChanged, this, [=](){
loop.quit();
});
//关闭窗口时保存音量值
Settings::get().setInternalOption("global_volume", m_nDisplayVolume > 100 ? 100 : m_nDisplayVolume);
Settings::get().onSetCrash();
loop.exec();
m_pEngine->savePlaybackPosition();

pEvent->accept();
Expand Down Expand Up @@ -4394,13 +4402,20 @@ void Platform_MainWindow::decodeInit()
return;

//崩溃检测
bool bcatch = Settings::get().settings()->getOption(QString("set.start.crash")).toBool();
if (bcatch) {
int bcatch = Settings::get().settings()->getOption(QString("set.start.crash")).toInt();
switch (bcatch) {
case 1:
pMpvProxy->setDecodeModel(DecodeMode::AUTO);
Settings::get().settings()->setOption(QString("base.decode.select"),DecodeMode::AUTO);
} else {
int value = Settings::get().settings()->getOption(QString("base.decode.select")).toInt();
pMpvProxy->setDecodeModel(value);
break;
case 2:
pMpvProxy->setDecodeModel(Settings::get().settings()->
getOption(QString("base.decode.select")).toInt());
dmr::Settings::get().crashCheck();
break;
case 0:
default:
break;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ int main(int argc, char *argv[])
}
Dtk::Core::DLogManager::registerFileAppender();

dmr::Settings::get().crashCheck();

bool singleton = !dmr::Settings::get().isSet(dmr::Settings::MultipleInstance);
QString movieName = "";
if (clm.isSet("functioncall")) {
Expand Down