@@ -24,6 +24,7 @@ bool TipOfTheDayPlugin::init()
2424 netManager = new QNetworkAccessManager (this );
2525
2626 connect (this , SIGNAL (tipsAvailable ()), this , SLOT (showOnStartup ()));
27+ connect (MAINWINDOW , SIGNAL (sessionInitiallyRestored ()), this , SLOT (showOnStartup ()));
2728 connect (STATUSFIELD , SIGNAL (linkActivated (const QString&)), this , SLOT (openTotdFromLink (const QString&)));
2829 fetchtTips ();
2930
@@ -150,7 +151,7 @@ void TipOfTheDayPlugin::fetchtTips()
150151
151152void TipOfTheDayPlugin::showOnStartup ()
152153{
153- if (!cfg.Totd .ShowOnStartup .get () || tips.isEmpty ())
154+ if (!cfg.Totd .ShowOnStartup .get () || tips.isEmpty () || ! MAINWINDOW -> isSessionRestoringFinished () )
154155 return ;
155156
156157 QStringList shownList = cfg.Totd .RecentlyShown .get ();
@@ -163,17 +164,23 @@ void TipOfTheDayPlugin::showOnStartup()
163164 shownList.clear ();
164165 }
165166
166- // Prepare list of tips not shown yet and use random tip from that list,
167- // then find what index is has in the tips list and use it
168- QList<Tip> notShownList;
169- for (const Tip& tip : tips)
167+ // For first run the first tip should be shown (it's just good for the 1st tip).
168+ // Then randomize the rest.
169+ if (!shownList.isEmpty ())
170170 {
171- if (!shownList.contains (tip.summary ))
172- notShownList << tip;
171+ // Prepare list of tips not shown yet and use random tip from that list,
172+ // then find what index is has in the tips list and use it
173+ QList<Tip> notShownList;
174+ for (const Tip& tip : tips)
175+ {
176+ if (!shownList.contains (tip.summary ))
177+ notShownList << tip;
178+ }
179+
180+ quint32 randInt = QRandomGenerator::securelySeeded ().bounded (notShownList.size ());
181+ Tip tipToUse = notShownList[randInt];
182+ idx = tips.indexOf (tipToUse);
173183 }
174- QRandomGenerator randGen;
175- Tip tipToUse = notShownList[randGen.generate () % notShownList.size ()];
176- idx = tips.indexOf (tipToUse);
177184 }
178185
179186 notifyInfo (tr (" <b>Quick tip:</b> %1 - <a href=\" %2\" >Learn more</a>" ).arg (tips[idx].summary , openTotdUrl + QString::number (idx)));
@@ -197,6 +204,5 @@ void TipOfTheDayPlugin::markAsRead(const QString& summary)
197204 {
198205 shownList << summary;
199206 cfg.Totd .RecentlyShown .set (shownList);
200- qDebug () << " marked, total" << shownList.size ();
201207 }
202208}
0 commit comments