Skip to content

Commit

Permalink
feat: 使用队列更新cookie,避免线程冲突
Browse files Browse the repository at this point in the history
  • Loading branch information
s12mmm3 committed Jan 19, 2025
1 parent 526d101 commit 7990d6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 46 deletions.
18 changes: 10 additions & 8 deletions QCloudMusicApi/apihelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QMetaMethod>
#include <QPluginLoader>
#include <QThread>
#include <QUrl>
#include <QUrlQuery>

Expand Down Expand Up @@ -63,7 +64,8 @@ void ApiHelper::afterInvoke(QVariantMap& ret)

QVariantMap ApiHelper::invoke(QString member, QVariantMap arg)
{
beforeInvoke(arg);
auto connectionType = QThread::currentThread() == this->thread() ? Qt::DirectConnection : Qt::BlockingQueuedConnection;
QMetaObject::invokeMethod(this, [&]() { beforeInvoke(arg); }, connectionType);

QVariantMap ret;

Expand All @@ -79,12 +81,12 @@ QVariantMap ApiHelper::invoke(QString member, QVariantMap arg)
}
if (useNative) {
QMetaObject::invokeMethod(this, member.toUtf8(),
Qt::DirectConnection,
Q_RETURN_ARG(QVariantMap, ret),
Q_ARG(QVariantMap, arg));
connectionType,
Q_RETURN_ARG(QVariantMap, ret),
Q_ARG(QVariantMap, arg));
}

afterInvoke(ret);
QMetaObject::invokeMethod(this, [&]() { afterInvoke(arg); }, connectionType);

return ret;
}
Expand All @@ -102,9 +104,9 @@ QVariantMap ApiHelper::invokeUrl(QString url)
arg[queryItem.first] = queryItem.second;
}
DEBUG << "host" << qurl.host()
<< "port" << qurl.port()
<< "member" << member
<< "arg" << arg;
<< "port" << qurl.port()
<< "member" << member
<< "arg" << arg;
return invoke(member, arg);
}

Expand Down
38 changes: 0 additions & 38 deletions QCloudMusicApi/definevaluehelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,4 @@ Q_SIGNALS: \
private: \
type m_##valueName = defaultValue;


#define DEFINE_VALUEADD(type, valueName, defaultValue) \
Q_PROPERTY(type valueName READ READ_NAME(valueName) WRITE WRITE_NAME(valueName) NOTIFY NOTIFY_NAME(valueName)) \
public: \
type READ_NAME(valueName)() const { return m_##valueName; } \
void WRITE_NAME(valueName)(type valueName) { \
if(valueName == 0) { \
return; \
} \
m_##valueName += valueName; \
emit NOTIFY_NAME(valueName)(); \
}; \
void INIT_NAME(valueName)(type valueName){ \
if(valueName == m_##valueName) { \
return; \
} \
m_##valueName = valueName;\
emit NOTIFY_NAME(valueName)(); \
};\
Q_SIGNALS: \
void NOTIFY_NAME(valueName)(); \
private: \
type m_##valueName = defaultValue;


#define DEFINE_VALUE_FORCE(type, valueName, defaultValue) \
Q_PROPERTY(type valueName READ READ_NAME(valueName) WRITE WRITE_NAME(valueName) NOTIFY NOTIFY_NAME(valueName)) \
public: \
type READ_NAME(valueName)() const { return m_##valueName; } \
void WRITE_NAME(valueName)(type valueName) { \
m_##valueName = valueName; \
emit NOTIFY_NAME(valueName)(); \
} \
Q_SIGNALS: \
void NOTIFY_NAME(valueName)(); \
private: \
type m_##valueName = defaultValue;

#endif // DEFINEVALUEHELPER_H

0 comments on commit 7990d6e

Please sign in to comment.