X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fmainwindow.cpp;h=9523ff976bd7cd737f5052e487c4e76cce91d403;hb=8cea1b650a0122369e8a3d60da1f263767b67614;hp=1cfe62240845dc50976b8517112972b7c26101c6;hpb=c50ee0bebf749b188e7dd4217b9755c08cb4be88;p=minitube diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1cfe622..9523ff9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -48,7 +48,6 @@ $END_LICENSE */ #endif #include "downloadmanager.h" #include "temporary.h" -#include "updatechecker.h" #include "ytsuggester.h" #if defined(APP_MAC_SEARCHFIELD) && !defined(APP_MAC_QMACTOOLBAR) #include "searchlineedit_mac.h" @@ -79,6 +78,10 @@ $END_LICENSE */ #include "yt3.h" #include "ytregions.h" +#include "invidious.h" +#include "videoapi.h" +#include "ytjs.h" + #ifdef MEDIA_QTAV #include "mediaqtav.h" #endif @@ -86,6 +89,10 @@ $END_LICENSE */ #include "mediampv.h" #endif +#ifdef UPDATER +#include "updater.h" +#endif + namespace { MainWindow *mainWindowInstance; } @@ -157,7 +164,16 @@ MainWindow::MainWindow() showHome(); #endif - QTimer::singleShot(1000, this, &MainWindow::lazyInit); + if (VideoAPI::impl() == VideoAPI::IV) { + Invidious::instance().initServers(); + } else if (VideoAPI::impl() == VideoAPI::YT3) { + YT3::instance().initApiKeys(); + } else if (VideoAPI::impl() == VideoAPI::JS) { + YTJS::instance(); + Invidious::instance().initServers(); + } + + QTimer::singleShot(100, this, &MainWindow::lazyInit); } void MainWindow::lazyInit() { @@ -216,7 +232,9 @@ void MainWindow::lazyInit() { ChannelAggregator::instance()->start(); - checkForUpdate(); +#ifdef UPDATER + Updater::instance().checkWithoutUI(); +#endif initialized = true; } @@ -653,6 +671,7 @@ void MainWindow::createActions() { action->setStatusTip(tr("Hide videos that may contain inappropriate content")); action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K)); action->setCheckable(true); + action->setVisible(VideoAPI::impl() != VideoAPI::IV); actionMap.insert("safeSearch", action); action = new QAction(tr("Toggle &Menu Bar"), this); @@ -769,6 +788,9 @@ void MainWindow::createMenus() { #endif helpMenu->addAction(getAction("reportIssue")); helpMenu->addAction(aboutAct); +#ifdef UPDATER + helpMenu->addAction(Updater::instance().getAction()); +#endif #ifdef APP_MAC_STORE helpMenu->addSeparator(); @@ -1789,53 +1811,6 @@ void MainWindow::dropEvent(QDropEvent *e) { } } -void MainWindow::checkForUpdate() { - static const QString updateCheckKey = "updateCheck"; - - // check every 24h - QSettings settings; - uint unixTime = QDateTime::currentDateTime().toTime_t(); - int lastCheck = settings.value(updateCheckKey).toInt(); - int secondsSinceLastCheck = unixTime - lastCheck; - // qDebug() << "secondsSinceLastCheck" << unixTime << lastCheck << secondsSinceLastCheck; - if (secondsSinceLastCheck < 86400) return; - - // check it out - UpdateChecker *updateChecker = new UpdateChecker(); - connect(updateChecker, &UpdateChecker::newVersion, this, - [this, updateChecker](const QString &version) { - updateChecker->deleteLater(); - QSettings settings; - QString checkedVersion = settings.value("checkedVersion").toString(); - if (checkedVersion == version) return; -#ifdef APP_SIMPLEUPDATE - simpleUpdateDialog(version); -#elif defined(APP_EXTRA) && !defined(APP_MAC) - UpdateDialog *dialog = new UpdateDialog(version, this); - dialog->show(); -#endif - }); - updateChecker->checkForUpdate(); - settings.setValue(updateCheckKey, unixTime); -} - -void MainWindow::simpleUpdateDialog(const QString &version) { - QMessageBox msgBox(this); - msgBox.setIconPixmap(IconUtils::pixmap(":/images/64x64/app.png", devicePixelRatioF())); - msgBox.setText(tr("%1 version %2 is now available.").arg(Constants::NAME, version)); - msgBox.setModal(true); - msgBox.setWindowModality(Qt::WindowModal); - msgBox.addButton(QMessageBox::Close); - QPushButton *laterButton = msgBox.addButton(tr("Remind me later"), QMessageBox::RejectRole); - QPushButton *updateButton = msgBox.addButton(tr("Update"), QMessageBox::AcceptRole); - msgBox.exec(); - if (msgBox.clickedButton() != laterButton) { - QSettings settings; - settings.setValue("checkedVersion", version); - } - if (msgBox.clickedButton() == updateButton) visitSite(); -} - bool MainWindow::needStatusBar() { return !statusToolBar->actions().isEmpty(); }