1717#include < QMessageBox>
1818#include < QProgressDialog>
1919#include < QPushButton>
20+ #include < QGuiApplication>
21+ #include < QScreen>
2022#if defined(Q_OS_WIN)
2123#include < QWindow>
2224#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@@ -119,6 +121,13 @@ void KiwixApp::init()
119121 });
120122
121123 restoreWindowState ();
124+
125+ // Initialize and run update checker if enabled
126+ if (m_settingsManager.getAutoCheckUpdates ()) {
127+ QTimer::singleShot (1000 , this , [this ]() {
128+ checkForUpdates (false ); // Auto-check
129+ });
130+ }
122131}
123132
124133void KiwixApp::setupDirectoryMonitoring ()
@@ -483,7 +492,7 @@ void KiwixApp::createActions()
483492
484493 CREATE_ACTION_ICON_SHORTCUT (CheckUpdatesAction, " update" , gt (" check-update-title" ), QKeySequence (Qt::CTRL | Qt::Key_U));
485494 connect (mpa_actions[CheckUpdatesAction], &QAction::triggered,
486- this , &KiwixApp:: checkForUpdates);
495+ this , [ this ]() { checkForUpdates ( true ); } );
487496
488497 CREATE_ACTION (FeedbackAction, gt (" feedback" ));
489498 HIDE_ACTION (FeedbackAction);
@@ -627,57 +636,76 @@ QString KiwixApp::getPrevSaveDir() const
627636 return dir.exists () ? prevSaveDir : DEFAULT_SAVE_DIR ;
628637}
629638
630- void KiwixApp::checkForUpdates ()
639+ void KiwixApp::checkForUpdates (bool manualCheck )
631640{
632641 if (!mp_versionChecker) {
633642 mp_versionChecker = std::make_unique<VersionChecker>();
634643 connect (mp_versionChecker.get (), &VersionChecker::updateAvailable,
635644 this , &KiwixApp::handleUpdateCheckResult);
636645 connect (mp_versionChecker.get (), &VersionChecker::noUpdateAvailable,
637- this , &KiwixApp:: handleNoUpdateAvailable);
646+ this , [ this ](){ handleNoUpdateAvailable ( false ); } );
638647 connect (mp_versionChecker.get (), &VersionChecker::checkFailed,
639648 this , &KiwixApp::handleUpdateCheckFailed);
640649 }
650+
651+ if (manualCheck) {
652+ // Reconnect signal for manual check to show "no update" message
653+ disconnect (mp_versionChecker.get (), &VersionChecker::noUpdateAvailable, nullptr , nullptr );
654+ connect (mp_versionChecker.get (), &VersionChecker::noUpdateAvailable,
655+ this , [this ](){ handleNoUpdateAvailable (true ); });
656+ }
657+
641658 mp_versionChecker->checkForUpdates ();
642659}
643660
644661void KiwixApp::handleUpdateCheckResult (const QString& latestVersion)
645662{
646- QMessageBox msgBox;
663+ // Create a non-intrusive notification
664+ QMessageBox msgBox (getMainWindow ());
665+ msgBox.setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
647666 msgBox.setIcon (QMessageBox::Information);
648667 msgBox.setWindowTitle (gt (" update-available-title" ));
649- msgBox.setText (gt (" update-available" ).replace (" {{VERSION}}" , latestVersion) +
650- " \n " + gt (" current-version" ).replace (" {{VERSION}}" , version));
651- msgBox.setInformativeText (gt (" update-available-message" ));
668+ msgBox.setText (gt (" update-available" ).replace (" {{VERSION}}" , latestVersion));
652669
653670 auto installButton = msgBox.addButton (gt (" install-update" ), QMessageBox::ActionRole);
654- msgBox.addButton (gt (" remind-later" ), QMessageBox::ActionRole); // Remove variable since it's unused
671+ msgBox.addButton (gt (" remind-later" ), QMessageBox::ActionRole);
655672 msgBox.addButton (QMessageBox::Close);
656-
673+
674+ // Position the notification in the bottom right corner
675+ if (QScreen* screen = QGuiApplication::primaryScreen ()) {
676+ QRect screenGeometry = screen->geometry ();
677+ msgBox.show (); // We need to show it first to get its size
678+ msgBox.hide ();
679+ int x = screenGeometry.width () - msgBox.width () - 20 ;
680+ int y = screenGeometry.height () - msgBox.height () - 20 ;
681+ msgBox.move (x, y);
682+ }
683+
657684 msgBox.exec ();
658685
659686 if (msgBox.clickedButton () == installButton) {
660- // Create QProgressDialog as a member variable so it stays in scope
687+ // Create QProgressDialog for download progress
661688 auto * progressDialog = new QProgressDialog (gt (" downloading-update" ),
662689 gt (" cancel" ),
663690 0 , 100 ,
664691 getMainWindow ());
665692 progressDialog->setWindowModality (Qt::WindowModal);
666693
667- // Connect with progressDialog instead of progress
694+ // Connect progress updates
668695 connect (mp_versionChecker.get (), &VersionChecker::downloadProgress,
669696 progressDialog, [progressDialog](qint64 received, qint64 total) {
670697 progressDialog->setValue ((received * 100 ) / total);
671698 });
672699
700+ // Handle installation failures
673701 connect (mp_versionChecker.get (), &VersionChecker::installationFailed,
674702 this , [this ](const QString& error) {
675703 QMessageBox::critical (getMainWindow (),
676704 gt (" update-error-title" ),
677705 gt (" update-error-message" ).replace (" {{ERROR}}" , error));
678706 });
679707
680- // Let's get the download URL for the latest version
708+ // Get download URL and start update process
681709 QString downloadUrl = mp_versionChecker->getDownloadUrl (latestVersion);
682710 mp_versionChecker->downloadAndInstallUpdate (downloadUrl, latestVersion);
683711
@@ -689,12 +717,14 @@ void KiwixApp::handleUpdateCheckResult(const QString& latestVersion)
689717 }
690718}
691719
692- void KiwixApp::handleNoUpdateAvailable ()
720+ void KiwixApp::handleNoUpdateAvailable (bool showMessage )
693721{
694- QMessageBox::information (nullptr ,
695- gt (" check-update-title" ),
696- gt (" no-update-available" ) + " \n " +
697- gt (" current-version" ).replace (" {{VERSION}}" , version));
722+ if (showMessage) {
723+ QMessageBox::information (nullptr ,
724+ gt (" check-update-title" ),
725+ gt (" no-update-available" ) + " \n " +
726+ gt (" current-version" ).replace (" {{VERSION}}" , version));
727+ }
698728}
699729
700730void KiwixApp::handleUpdateCheckFailed (const QString& error)
0 commit comments