mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-03 00:06:09 +00:00
Use uniform_int_distribution for generating PINs
This commit is contained in:
parent
16bb4a148e
commit
d1c4ca5eae
@ -187,7 +187,7 @@ CenteredGridView {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!model.busy) {
|
if (!model.busy) {
|
||||||
var pin = ("0000" + Math.floor(Math.random() * 10000)).slice(-4)
|
var pin = computerModel.generatePinString()
|
||||||
|
|
||||||
// Kick off pairing in the background
|
// Kick off pairing in the background
|
||||||
computerModel.pairComputer(index, pin)
|
computerModel.pairComputer(index, pin)
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
|
||||||
ComputerModel::ComputerModel(QObject* object)
|
ComputerModel::ComputerModel(QObject* object)
|
||||||
: QAbstractListModel(object) {}
|
: QAbstractListModel(object) {}
|
||||||
|
|
||||||
@ -135,6 +137,16 @@ void ComputerModel::renameComputer(int computerIndex, QString name)
|
|||||||
m_ComputerManager->renameHost(m_Computers[computerIndex], name);
|
m_ComputerManager->renameHost(m_Computers[computerIndex], name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Use QRandomGenerator when we drop Qt 5.9 support
|
||||||
|
QString ComputerModel::generatePinString()
|
||||||
|
{
|
||||||
|
std::uniform_int_distribution<int> dist(0, 9999);
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 engine(rd());
|
||||||
|
|
||||||
|
return QString::asprintf("%04u", dist(engine));
|
||||||
|
}
|
||||||
|
|
||||||
void ComputerModel::pairComputer(int computerIndex, QString pin)
|
void ComputerModel::pairComputer(int computerIndex, QString pin)
|
||||||
{
|
{
|
||||||
Q_ASSERT(computerIndex < m_Computers.count());
|
Q_ASSERT(computerIndex < m_Computers.count());
|
||||||
|
@ -31,6 +31,8 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE void deleteComputer(int computerIndex);
|
Q_INVOKABLE void deleteComputer(int computerIndex);
|
||||||
|
|
||||||
|
Q_INVOKABLE QString generatePinString();
|
||||||
|
|
||||||
Q_INVOKABLE void pairComputer(int computerIndex, QString pin);
|
Q_INVOKABLE void pairComputer(int computerIndex, QString pin);
|
||||||
|
|
||||||
Q_INVOKABLE void wakeComputer(int computerIndex);
|
Q_INVOKABLE void wakeComputer(int computerIndex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user