From af0d09205430a4c98a1491a6fe3906a67b98913a Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 1 Aug 2020 03:37:16 +0200 Subject: [PATCH] Use sparkle to check for updates on macOS and Windows --- CMakeLists.txt | 17 ++++++++++++++--- dist/windows/strawberry.nsi.in | 2 ++ src/CMakeLists.txt | 2 ++ src/config.h.in | 1 + src/core/mainwindow.cpp | 25 +++++++++++++++++++++++-- src/main.cpp | 9 +++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da2ee9481..f05dfa718 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,9 +252,20 @@ set(SINGLEAPPLICATION_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/singleap set(SINGLEAPPLICATION_LIBRARIES singleapplication) set(SINGLECOREAPPLICATION_LIBRARIES singlecoreapplication) -if (APPLE) - find_library(SPARKLE Sparkle) -endif (APPLE) +if(APPLE) + find_library(SPARKLE Sparkle PATHS /usr/local/Caskroom/sparkle/1.22.0 NAMES Sparkle Sparkle.framework) +endif(APPLE) + +if((NOT SPARKLE) AND (APPLE OR WIN32)) + if(WITH_QT6) + pkg_check_modules(QTSPARKLE qtsparkle-qt6) + else() + pkg_check_modules(QTSPARKLE qtsparkle-qt5) + endif() + if(QTSPARKLE_FOUND) + set(HAVE_QTSPARKLE ON) + endif() +endif() if (WIN32) # RC compiler diff --git a/dist/windows/strawberry.nsi.in b/dist/windows/strawberry.nsi.in index 3feaf41fe..3852d46be 100644 --- a/dist/windows/strawberry.nsi.in +++ b/dist/windows/strawberry.nsi.in @@ -223,6 +223,7 @@ Section "Strawberry" Strawberry File "libbrotlidec.dll" File "libpsl-5.dll" File "liborc-0.4-0.dll" + File "libqtsparkle-qt5.dll" !ifdef arch_x86 File "libgcc_s_sjlj-1.dll" @@ -452,6 +453,7 @@ Section "Uninstall" Delete "$INSTDIR\libbrotlidec.dll" Delete "$INSTDIR\libpsl-5.dll" Delete "$INSTDIR\liborc-0.4-0.dll" + Delete "$INSTDIR\libqtsparkle-qt5.dll" !ifdef arch_x86 Delete "$INSTDIR\libgcc_s_sjlj-1.dll" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df8bcdf97..7190ba389 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -973,6 +973,7 @@ link_directories( ${QT_LIBRARY_DIRS} ${SINGLEAPPLICATION_LIBRARY_DIRS} ${SINGLECOREAPPLICATION_LIBRARY_DIRS} + ${QTSPARKLE_LIBRARY_DIRS} ) if(HAVE_ALSA) @@ -1076,6 +1077,7 @@ target_link_libraries(strawberry_lib PUBLIC ${QT_LIBRARIES} ${SINGLEAPPLICATION_LIBRARIES} ${SINGLECOREAPPLICATION_LIBRARIES} + ${QTSPARKLE_LIBRARIES} libstrawberry-common libstrawberry-tagreader ) diff --git a/src/config.h.in b/src/config.h.in index c57b5ad41..97616eb9d 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -37,6 +37,7 @@ #cmakedefine HAVE_LIBMTP #cmakedefine HAVE_LIBPULSE #cmakedefine HAVE_SPARKLE +#cmakedefine HAVE_QTSPARKLE #cmakedefine HAVE_CHROMAPRINT #cmakedefine HAVE_GLOBALSHORTCUTS #cmakedefine USE_INSTALL_PREFIX diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 5755a04c8..dc3db9836 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -20,6 +20,7 @@ */ #include "config.h" +#include "version.h" #include #include @@ -70,6 +71,7 @@ #include "core/logging.h" #include "core/closure.h" +#include "core/network.h" #include "mainwindow.h" #include "ui_mainwindow.h" @@ -181,6 +183,10 @@ # include "windows7thumbbar.h" #endif +#ifdef HAVE_QTSPARKLE +# include +#endif + const char *MainWindow::kSettingsGroup = "MainWindow"; const char *MainWindow::kAllFilesFilterSpec = QT_TR_NOOP("All Files (*)"); @@ -681,8 +687,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co thumbbar_->SetActions(QList() << ui_->action_previous_track << ui_->action_play_pause << ui_->action_stop << ui_->action_next_track << nullptr << ui_->action_love); #endif -#if (defined(Q_OS_MACOS) && defined(HAVE_SPARKLE)) - // Add check for updates item to application menu. +#if defined(HAVE_SPARKLE) || defined(HAVE_QTSPARKLE) QAction *check_updates = ui_->menu_tools->addAction(tr("Check for updates...")); check_updates->setMenuRole(QAction::ApplicationSpecificRole); connect(check_updates, SIGNAL(triggered(bool)), SLOT(CheckForUpdates())); @@ -887,6 +892,22 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co app_->scrobbler()->Submit(); } +#ifdef HAVE_QTSPARKLE + QUrl sparkle_url; +#if defined(Q_OS_MACOS) + sparkle_url.setUrl("https://www.strawberrymusicplayer.org/sparkle-macos"); +#elif defined(Q_OS_WIN) + sparkle_url.setUrl("https://www.strawberrymusicplayer.org/sparkle-windows"); +#endif + if (!sparkle_url.isEmpty()) { + qLog(Debug) << "Creating Qt Sparkle updater"; + qtsparkle::Updater *updater = new qtsparkle::Updater(sparkle_url, this); + updater->SetNetworkAccessManager(new NetworkAccessManager(this)); + updater->SetVersion(STRAWBERRY_VERSION_PACKAGE); + connect(check_updates, SIGNAL(triggered()), updater, SLOT(CheckNow())); + } +#endif + qLog(Debug) << "Started" << QThread::currentThread(); initialized_ = true; diff --git a/src/main.cpp b/src/main.cpp index d7d5dd27b..7a636f9ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -77,6 +77,10 @@ #include #include +#ifdef HAVE_QTSPARKLE +# include +#endif + #ifdef HAVE_DBUS # include "core/mpris.h" #endif @@ -242,6 +246,11 @@ int main(int argc, char* argv[]) { translations->LoadTranslation("strawberry", ":/translations", language); translations->LoadTranslation("strawberry", a.applicationDirPath(), language); translations->LoadTranslation("strawberry", QDir::currentPath(), language); + +#ifdef HAVE_QTSPARKLE + qtsparkle::LoadTranslations(language); +#endif + #endif Application app;