message: Show unlock for balance check dialog before the window opens.
diff: @@ -280,8 +280,6 @@ int main(int argc, char *argv[])
  {
  // Put this in a block, so that the Model objects are cleaned up before
  // calling Shutdown().
  - InitMessage("...Start UI...");
  -
  paymentServer->setOptionsModel(&optionsModel);
  ClientModel clientModel(&optionsModel);
  @@ -289,31 +287,47 @@ int main(int argc, char *argv[])
  window.setClientModel(&clientModel);
  window.setWalletModel(&walletModel);
  - // Manually create a blockChangedEvent to set initial values for the UI
  {
  - LOCK(cs_main);
  + InitMessage("Update balance...");
  + // Get locks upfront
  + LOCK2(cs_main, pwalletMain->cs_wallet);
  +
  + // Manually create a blockChangedEvent to set initial values for the UI
  BlockChangedEvent blockChangedEvent = {nBestHeight, GetNumBlocksOfPeers(), IsInitialBlockDownload(), nNodeMode == NT_FULL ?
  pindexBest ? pindexBest->GetBlockTime() : GENESIS_BLOCK_TIME :
  pindexBestHeader ? pindexBestHeader->GetBlockTime() : GENESIS_BLOCK_TIME};
  uiInterface.NotifyBlocksChanged(blockChangedEvent);
  +
  + // Check if wallet unlock is needed to determine current balance
  + if (pwalletMain->IsLocked() && pwalletMain->CountLockedAnonOutputs() > 0)
  + {
  + WalletModel::UnlockContext unlockContext = walletModel.requestUnlock(WalletModel::UnlockMode::rescan);
  + if (!unlockContext.isValid())
  + {
  + InitMessage("Shutdown...");
  + StartShutdown();
  + }
  + }
  }
  + if (!ShutdownRequested())
  + {
  + InitMessage("...Start UI...");
  window.loadIndex();
  -
  // Now that initialization/startup is done, process any command-line
  // spectre: URIs
  QObject::connect(paymentServer, SIGNAL(receivedURI(QString)), &window, SLOT(handleURI(QString)));
  QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
  - if (pwalletMain->IsLocked() && pwalletMain->CountLockedAnonOutputs() > 0)
  - emit walletModel.requireUnlock(WalletModel::UnlockMode::rescan);
  -
  #if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
  WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("Spectrecoin Core did't yet exit safely..."), (HWND)window.winId());
  #endif
  app.exec();
  + }
  + else
  + QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
  window.hide();
  window.setClientModel(0);
  