Defer heavy UI model loading for faster startup
- Address table and transaction table now load asynchronously via QTimer::singleShot after the event loop starts instead of blocking the constructor - MessageModel (secure messaging) lazy-loaded 1s after wallet init or on-demand when navigating to message page - Splash screen stays visible until window.show() completes - Guard updateConfirmations() against empty transaction table Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <QFont>
|
||||
#include <QColor>
|
||||
#include <QTimer>
|
||||
|
||||
const QString AddressTableModel::Send = "S";
|
||||
const QString AddressTableModel::Receive = "R";
|
||||
@@ -145,7 +146,7 @@ AddressTableModel::AddressTableModel(CWallet *wallet, WalletModel *parent) :
|
||||
{
|
||||
columns << tr("Label") << tr("Address");
|
||||
priv = new AddressTablePriv(wallet, this);
|
||||
priv->refreshAddressTable();
|
||||
QTimer::singleShot(0, this, SLOT(refreshAddressTable()));
|
||||
}
|
||||
|
||||
AddressTableModel::~AddressTableModel()
|
||||
@@ -326,6 +327,12 @@ void AddressTableModel::updateEntry(const QString &address, const QString &label
|
||||
priv->updateEntry(address, label, isMine, status);
|
||||
}
|
||||
|
||||
void AddressTableModel::refreshAddressTable()
|
||||
{
|
||||
priv->refreshAddressTable();
|
||||
reset();
|
||||
}
|
||||
|
||||
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, int addressType)
|
||||
{
|
||||
std::string strLabel = label.toStdString();
|
||||
|
||||
@@ -89,6 +89,7 @@ signals:
|
||||
void defaultAddressChanged(const QString &address);
|
||||
|
||||
public slots:
|
||||
void refreshAddressTable();
|
||||
/* Update address list from core.
|
||||
*/
|
||||
void updateEntry(const QString &address, const QString &label, bool isMine, int status);
|
||||
|
||||
@@ -225,8 +225,7 @@ TransactionTableModel::TransactionTableModel(CWallet* wallet, WalletModel *paren
|
||||
cachedNumBlocks(0)
|
||||
{
|
||||
columns << QString() << tr("Date") << tr("Type") << tr("Address") << tr("Amount");
|
||||
|
||||
priv->refreshWallet();
|
||||
QTimer::singleShot(0, this, SLOT(refreshWallet()));
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(updateConfirmations()));
|
||||
@@ -248,8 +247,17 @@ void TransactionTableModel::updateTransaction(const QString &hash, int status)
|
||||
priv->updateWallet(updated, status);
|
||||
}
|
||||
|
||||
void TransactionTableModel::refreshWallet()
|
||||
{
|
||||
priv->refreshWallet();
|
||||
reset();
|
||||
}
|
||||
|
||||
void TransactionTableModel::updateConfirmations()
|
||||
{
|
||||
if(!priv->size())
|
||||
return;
|
||||
|
||||
if(nBestHeight != cachedNumBlocks)
|
||||
{
|
||||
cachedNumBlocks = nBestHeight;
|
||||
|
||||
@@ -77,6 +77,7 @@ private:
|
||||
QVariant txAddressDecoration(const TransactionRecord *wtx) const;
|
||||
|
||||
public slots:
|
||||
void refreshWallet();
|
||||
void updateTransaction(const QString &hash, int status);
|
||||
void updateConfirmations();
|
||||
void updateDisplayUnit();
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "clientmodel.h"
|
||||
#include "walletmodel.h"
|
||||
#include "optionsmodel.h"
|
||||
#include "messagemodel.h"
|
||||
#include "guiutil.h"
|
||||
#include "guiconstants.h"
|
||||
|
||||
@@ -224,16 +223,11 @@ int main(int argc, char *argv[])
|
||||
// Put this in a block, so that the Model objects are cleaned up before
|
||||
// calling Shutdown().
|
||||
|
||||
if (splashref)
|
||||
splash.finish(&window);
|
||||
|
||||
ClientModel clientModel(&optionsModel);
|
||||
WalletModel walletModel(pwalletMain, &optionsModel);
|
||||
MessageModel messageModel(pwalletMain, &walletModel);
|
||||
|
||||
window.setClientModel(&clientModel);
|
||||
window.setWalletModel(&walletModel);
|
||||
window.setMessageModel(&messageModel);
|
||||
|
||||
// If -min option passed, start window minimized.
|
||||
if(GetBoolArg("-min"))
|
||||
@@ -245,6 +239,9 @@ int main(int argc, char *argv[])
|
||||
window.show();
|
||||
}
|
||||
|
||||
if (splashref)
|
||||
splash.finish(&window);
|
||||
|
||||
// Place this here as guiref has to be defined if we don't want to lose URIs
|
||||
ipcInit(argc, argv);
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ TrianglesGUI::TrianglesGUI(bool fIsTestnet, QWidget *parent):
|
||||
ui(new Ui::MainWindow),
|
||||
clientModel(0),
|
||||
walletModel(0),
|
||||
messageModel(0),
|
||||
encryptWalletAction(0),
|
||||
changePassphraseAction(0),
|
||||
unlockWalletAction(0),
|
||||
@@ -594,6 +595,9 @@ void TrianglesGUI::setWalletModel(WalletModel *walletModel)
|
||||
|
||||
// Ask for passphrase if needed
|
||||
connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
|
||||
|
||||
// Load secure messaging after the main window can render.
|
||||
QTimer::singleShot(1000, this, SLOT(ensureMessageModel()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,6 +618,14 @@ void TrianglesGUI::setMessageModel(MessageModel *messageModel)
|
||||
}
|
||||
}
|
||||
|
||||
void TrianglesGUI::ensureMessageModel()
|
||||
{
|
||||
if(messageModel || !walletModel)
|
||||
return;
|
||||
|
||||
setMessageModel(new MessageModel(pwalletMain, walletModel, this));
|
||||
}
|
||||
|
||||
void TrianglesGUI::createTrayIcon()
|
||||
{
|
||||
#ifndef Q_OS_MAC
|
||||
@@ -1025,6 +1037,8 @@ void TrianglesGUI::gotoSendCoinsPage()
|
||||
|
||||
void TrianglesGUI::gotoMessagePage()
|
||||
{
|
||||
ensureMessageModel();
|
||||
|
||||
messageAction->setChecked(true);
|
||||
centralWidget->setCurrentWidget(messagePage);
|
||||
|
||||
|
||||
@@ -180,6 +180,7 @@ public slots:
|
||||
|
||||
|
||||
private slots:
|
||||
void ensureMessageModel();
|
||||
|
||||
void menuFileRequested();
|
||||
void menuOperationsRequested();
|
||||
|
||||
Reference in New Issue
Block a user