diff --git a/CMakeLists.txt b/CMakeLists.txt index 10a6b8c..97d37e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if (POLICY CMP0141) set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") endif() -project("org.nickvision.spotlight" LANGUAGES C CXX VERSION 2024.6.0 DESCRIPTION "Find your favorite Windows spotlight images.") +project("org.nickvision.spotlight" LANGUAGES C CXX VERSION 2024.6.1 DESCRIPTION "Find your favorite Windows spotlight images.") set(SHORT_NAME "spotlight") include(GNUInstallDirs) diff --git a/inno/setup.iss b/inno/setup.iss index 03707e6..0e2d42e 100644 --- a/inno/setup.iss +++ b/inno/setup.iss @@ -3,7 +3,7 @@ #define MyAppName "Nickvision Spotlight" #define MyAppShortName "Spotlight" -#define MyAppVersion "2024.6.0" +#define MyAppVersion "2024.6.1" #define MyAppPublisher "Nickvision" #define MyAppURL "https://nickvision.org" #define MyAppExeName "org.nickvision.spotlight.winui.exe" diff --git a/libspotlight/include/controllers/mainwindowcontroller.h b/libspotlight/include/controllers/mainwindowcontroller.h index 44a0bcf..6ff47e2 100644 --- a/libspotlight/include/controllers/mainwindowcontroller.h +++ b/libspotlight/include/controllers/mainwindowcontroller.h @@ -144,7 +144,7 @@ namespace Nickvision::Spotlight::Shared::Controllers Nickvision::Taskbar::TaskbarItem m_taskbar; Nickvision::Events::Event m_notificationSent; Nickvision::Events::Event m_shellNotificationSent; - Models::SpotlightManager m_spotlightManager; + std::shared_ptr m_spotlightManager; Nickvision::Events::Event m_imagesSynced; }; } diff --git a/libspotlight/include/models/spotlightimagetype.h b/libspotlight/include/models/spotlightimagetype.h new file mode 100644 index 0000000..628719c --- /dev/null +++ b/libspotlight/include/models/spotlightimagetype.h @@ -0,0 +1,16 @@ +#ifndef SPOTLIGHTIMAGETYPE_H +#define SPOTLIGHTIMAGETYPE_H + +namespace Nickvision::Spotlight::Shared::Models +{ + /** + * @brief Types of spotlight images. + */ + enum class SpotlightImageType + { + LockScreen = 0, + Desktop + }; +} + +#endif //SPOTLIGHTIMAGETYPE_H \ No newline at end of file diff --git a/libspotlight/include/models/spotlightmanager.h b/libspotlight/include/models/spotlightmanager.h index 4a4e309..49b62fe 100644 --- a/libspotlight/include/models/spotlightmanager.h +++ b/libspotlight/include/models/spotlightmanager.h @@ -3,6 +3,7 @@ #include #include +#include "spotlightimagetype.h" #include "spotlightsupport.h" namespace Nickvision::Spotlight::Shared::Models @@ -66,6 +67,12 @@ namespace Nickvision::Spotlight::Shared::Models bool setAsDesktopBackground(const std::filesystem::path& image) const; private: + /** + * @brief Processes a directory entry. + * @param entry The directory entry to process + * @param type The type of spotlight image + */ + void processEntry(const std::filesystem::directory_entry& entry, SpotlightImageType type); std::filesystem::path m_spotlightLockScreenDir; std::filesystem::path m_spotlightDesktopDir; std::filesystem::path m_dataDir; diff --git a/libspotlight/src/controllers/mainwindowcontroller.cpp b/libspotlight/src/controllers/mainwindowcontroller.cpp index af4e7d5..943d7b8 100644 --- a/libspotlight/src/controllers/mainwindowcontroller.cpp +++ b/libspotlight/src/controllers/mainwindowcontroller.cpp @@ -28,7 +28,7 @@ namespace Nickvision::Spotlight::Shared::Controllers Aura::getActive().init("org.nickvision.spotlight", "Nickvision Spotlight", "Spotlight", Logging::LogLevel::Info); #endif AppInfo& appInfo{ Aura::getActive().getAppInfo() }; - appInfo.setVersion({ "2024.6.0" }); + appInfo.setVersion({ "2024.6.1" }); appInfo.setShortName(_("Spotlight")); appInfo.setDescription(_("Find your favorite Windows spotlight images")); appInfo.setSourceRepo("https://github.com/NickvisionApps/Spotlight"); @@ -71,7 +71,7 @@ namespace Nickvision::Spotlight::Shared::Controllers const std::vector& MainWindowController::getSpotlightImages() const { - return m_spotlightManager.getImages(); + return m_spotlightManager->getImages(); } Event& MainWindowController::configurationSaved() @@ -101,7 +101,7 @@ namespace Nickvision::Spotlight::Shared::Controllers { builder << StringHelpers::toString(name) << std::endl; } - switch(m_spotlightManager.getSupportLevel()) + switch(m_spotlightManager->getSupportLevel()) { case SpotlightSupport::Full: builder << "Spotlight Support Level: Full" << std::endl; @@ -146,9 +146,10 @@ namespace Nickvision::Spotlight::Shared::Controllers { checkForUpdates(); } + m_spotlightManager = std::make_shared(); std::thread syncWorker{ [this]() { - m_spotlightManager.sync(); + m_spotlightManager->sync(); m_imagesSynced.invoke({}); } }; syncWorker.detach(); @@ -233,7 +234,7 @@ namespace Nickvision::Spotlight::Shared::Controllers void MainWindowController::setImageAsDesktopBackground(int index) { - if(m_spotlightManager.setAsDesktopBackground(static_cast(index))) + if(m_spotlightManager->setAsDesktopBackground(static_cast(index))) { m_notificationSent.invoke({ _("Image set as desktop background"), NotificationSeverity::Success }); } @@ -245,7 +246,7 @@ namespace Nickvision::Spotlight::Shared::Controllers void MainWindowController::exportImage(int index, const std::filesystem::path& path) { - if(m_spotlightManager.exportImage(static_cast(index), path)) + if(m_spotlightManager->exportImage(static_cast(index), path)) { m_notificationSent.invoke({ std::vformat(_("Image exported to {}"), std::make_format_args(CodeHelpers::unmove(path.string()))), NotificationSeverity::Success }); } @@ -257,7 +258,7 @@ namespace Nickvision::Spotlight::Shared::Controllers void MainWindowController::exportAllImages(const std::filesystem::path& path) { - if(m_spotlightManager.exportAllImages(path)) + if(m_spotlightManager->exportAllImages(path)) { m_notificationSent.invoke({ std::vformat(_("Images exported to {}"), std::make_format_args(CodeHelpers::unmove(path.string()))), NotificationSeverity::Success }); } diff --git a/libspotlight/src/models/spotlightmanager.cpp b/libspotlight/src/models/spotlightmanager.cpp index 8c4fd99..76f1466 100644 --- a/libspotlight/src/models/spotlightmanager.cpp +++ b/libspotlight/src/models/spotlightmanager.cpp @@ -61,41 +61,18 @@ namespace Nickvision::Spotlight::Shared::Models { Aura::getActive().getLogger().log(Logging::LogLevel::Debug, "Loading spotlight images..."); m_images.clear(); - std::function processEntry{ [&](const std::filesystem::directory_entry& entry) - { - boost::gil::rgb8_image_t img; - boost::gil::read_image(entry.path().string(), img, boost::gil::jpeg_tag()); - if(img.width() > img.height()) - { - std::filesystem::path newPath{ m_dataDir / (entry.path().stem().string() + ".jpg") }; - std::filesystem::copy_file(entry.path(), newPath, std::filesystem::copy_options::overwrite_existing); - } - } }; if(std::filesystem::exists(m_spotlightLockScreenDir)) { for(const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(m_spotlightLockScreenDir)) { - if(entry.file_size() / 1000 >= 200) - { - processEntry(entry); - } + processEntry(entry, SpotlightImageType::LockScreen); } } if(std::filesystem::exists(m_spotlightDesktopDir)) { for(const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator(m_spotlightDesktopDir)) { - if(entry.path().extension() == ".jpg") - { - processEntry(entry); - } - } - } - for(const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(m_dataDir)) - { - if(entry.path().extension() == ".jpg") - { - m_images.push_back(entry.path()); + processEntry(entry, SpotlightImageType::Desktop); } } Aura::getActive().getLogger().log(Logging::LogLevel::Info, "Loaded " + std::to_string(m_images.size()) + " image(s)."); @@ -164,4 +141,29 @@ namespace Nickvision::Spotlight::Shared::Models } return setAsDesktopBackground(it - m_images.begin()); } + + void SpotlightManager::processEntry(const std::filesystem::directory_entry& entry, SpotlightImageType type) + { + std::filesystem::path newPath{ m_dataDir / (entry.path().stem().string() + ".jpg") }; + if(type == SpotlightImageType::LockScreen && entry.file_size() / 1000 < 200) + { + return; + } + else if(type == SpotlightImageType::Desktop && entry.path().extension() != ".jpg") + { + return; + } + else if(std::filesystem::exists(newPath)) + { + m_images.push_back(newPath); + return; + } + boost::gil::rgb8_image_t img; + boost::gil::read_image(entry.path().string(), img, boost::gil::jpeg_tag()); + if(img.width() > img.height()) + { + std::filesystem::copy_file(entry.path(), newPath, std::filesystem::copy_options::skip_existing); + m_images.push_back(newPath); + } + } } \ No newline at end of file diff --git a/org.nickvision.spotlight.winui/App.xaml.cpp b/org.nickvision.spotlight.winui/App.xaml.cpp index bf5f9ef..145b998 100644 --- a/org.nickvision.spotlight.winui/App.xaml.cpp +++ b/org.nickvision.spotlight.winui/App.xaml.cpp @@ -23,7 +23,7 @@ namespace winrt::Nickvision::Spotlight::WinUI::implementation throw; }); #endif - m_controller->getAppInfo().setChangelog("- Added support for spotlight images fetched by\nthe Windows desktop\n- Added a new flip view mode\n- Redesign user interface"); + m_controller->getAppInfo().setChangelog("- Improved performance of loading spotlight images"); m_systemTheme = RequestedTheme() == ApplicationTheme::Light ? ElementTheme::Light : ElementTheme::Dark; switch (m_controller->getTheme()) { diff --git a/resources/po/it.po b/resources/po/it.po index 2aa98cd..e14e98c 100644 --- a/resources/po/it.po +++ b/resources/po/it.po @@ -7,11 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-06-04 13:18-0400\n" +"POT-Creation-Date: 2024-06-04 20:23-0400\n" "PO-Revision-Date: 2024-06-04 18:22+0000\n" "Last-Translator: Nick Logozzo \n" -"Language-Team: Italian \n" +"Language-Team: Italian \n" "Language: it\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -47,35 +47,35 @@ msgstr "David Lapshin" msgid "translator-credits" msgstr "Nicholas Logozzo" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:183 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:184 msgid "New update available" msgstr "Nuovo aggiornamento disponibile" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:211 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:212 msgid "Unable to download and install update" msgstr "Scaricamento dell'aggiornamento non riuscito" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:238 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:239 msgid "Image set as desktop background" msgstr "La foto impostata come sfondo" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:242 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:243 msgid "Unable to set image as desktop background" msgstr "impostazione della foto come sfondo non riuscita" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:250 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:251 msgid "Image exported to {}" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:254 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:255 msgid "Unable to export image" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:262 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:263 msgid "Images exported to {}" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:266 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:267 msgid "Unable to export images" msgstr "" diff --git a/resources/po/spotlight.pot b/resources/po/spotlight.pot index 8168d72..2abc5b0 100644 --- a/resources/po/spotlight.pot +++ b/resources/po/spotlight.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-06-04 14:24-0400\n" +"POT-Creation-Date: 2024-06-04 22:53-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -45,35 +45,35 @@ msgstr "" msgid "translator-credits" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:183 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:184 msgid "New update available" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:211 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:212 msgid "Unable to download and install update" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:238 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:239 msgid "Image set as desktop background" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:242 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:243 msgid "Unable to set image as desktop background" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:250 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:251 msgid "Image exported to {}" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:254 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:255 msgid "Unable to export image" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:262 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:263 msgid "Images exported to {}" msgstr "" -#: libspotlight/src/controllers/mainwindowcontroller.cpp:266 +#: libspotlight/src/controllers/mainwindowcontroller.cpp:267 msgid "Unable to export images" msgstr ""