Skip to content

Commit

Permalink
V2024.6.1
Browse files Browse the repository at this point in the history
- Improved performance of loading spotlight images (Fixes #19)
  • Loading branch information
nlogozzo committed Jun 5, 2024
1 parent 0ae19c7 commit ce316fc
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 56 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (POLICY CMP0141)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>: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)

Expand Down
2 changes: 1 addition & 1 deletion inno/setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion libspotlight/include/controllers/mainwindowcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace Nickvision::Spotlight::Shared::Controllers
Nickvision::Taskbar::TaskbarItem m_taskbar;
Nickvision::Events::Event<Nickvision::Notifications::NotificationSentEventArgs> m_notificationSent;
Nickvision::Events::Event<Nickvision::Notifications::ShellNotificationSentEventArgs> m_shellNotificationSent;
Models::SpotlightManager m_spotlightManager;
std::shared_ptr<Models::SpotlightManager> m_spotlightManager;
Nickvision::Events::Event<Nickvision::Events::EventArgs> m_imagesSynced;
};
}
Expand Down
16 changes: 16 additions & 0 deletions libspotlight/include/models/spotlightimagetype.h
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions libspotlight/include/models/spotlightmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <filesystem>
#include <vector>
#include "spotlightimagetype.h"
#include "spotlightsupport.h"

namespace Nickvision::Spotlight::Shared::Models
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions libspotlight/src/controllers/mainwindowcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -71,7 +71,7 @@ namespace Nickvision::Spotlight::Shared::Controllers

const std::vector<std::filesystem::path>& MainWindowController::getSpotlightImages() const
{
return m_spotlightManager.getImages();
return m_spotlightManager->getImages();
}

Event<EventArgs>& MainWindowController::configurationSaved()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -146,9 +146,10 @@ namespace Nickvision::Spotlight::Shared::Controllers
{
checkForUpdates();
}
m_spotlightManager = std::make_shared<SpotlightManager>();
std::thread syncWorker{ [this]()
{
m_spotlightManager.sync();
m_spotlightManager->sync();
m_imagesSynced.invoke({});
} };
syncWorker.detach();
Expand Down Expand Up @@ -233,7 +234,7 @@ namespace Nickvision::Spotlight::Shared::Controllers

void MainWindowController::setImageAsDesktopBackground(int index)
{
if(m_spotlightManager.setAsDesktopBackground(static_cast<size_t>(index)))
if(m_spotlightManager->setAsDesktopBackground(static_cast<size_t>(index)))
{
m_notificationSent.invoke({ _("Image set as desktop background"), NotificationSeverity::Success });
}
Expand All @@ -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<size_t>(index), path))
if(m_spotlightManager->exportImage(static_cast<size_t>(index), path))
{
m_notificationSent.invoke({ std::vformat(_("Image exported to {}"), std::make_format_args(CodeHelpers::unmove(path.string()))), NotificationSeverity::Success });
}
Expand All @@ -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 });
}
Expand Down
52 changes: 27 additions & 25 deletions libspotlight/src/models/spotlightmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,18 @@ namespace Nickvision::Spotlight::Shared::Models
{
Aura::getActive().getLogger().log(Logging::LogLevel::Debug, "Loading spotlight images...");
m_images.clear();
std::function<void(const std::filesystem::directory_entry&)> 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).");
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion org.nickvision.spotlight.winui/App.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
22 changes: 11 additions & 11 deletions resources/po/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nlogozzo225@gmail.com>\n"
"Language-Team: Italian <https://hosted.weblate.org/projects/"
"nickvision-spotlight/app/it/>\n"
"Language-Team: Italian <https://hosted.weblate.org/projects/nickvision-"
"spotlight/app/it/>\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -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 ""

Expand Down
18 changes: 9 additions & 9 deletions resources/po/spotlight.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -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 ""

Expand Down

0 comments on commit ce316fc

Please sign in to comment.