Skip to content

Commit

Permalink
Taskbar and Filesystem APIs (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo authored Dec 25, 2023
1 parent a924532 commit b6a6195
Show file tree
Hide file tree
Showing 34 changed files with 1,042 additions and 112 deletions.
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions:
contents: read
env:
BUILD_TYPE: Release
GITHUB_ACTIONS: true
jobs:
build:
name: ${{ matrix.config.name }}
Expand Down
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ include(GNUInstallDirs)
#libaura Library Setup
include_directories(${PROJECT_SOURCE_DIR}/include)
add_library (${PROJECT_NAME}
src/events/eventargs.cpp
src/filesystem/filesystemchangedeventargs.cpp
src/filesystem/filesystemwatcher.cpp
src/helpers/stringhelpers.cpp
src/helpers/webhelpers.cpp
src/keyring/credential.cpp
Expand All @@ -33,6 +34,7 @@ add_library (${PROJECT_NAME}
src/network/networkstatechangedeventargs.cpp
src/notifications/notificationsenteventargs.cpp
src/notifications/shellnotificationsenteventargs.cpp
src/taskbar/taskbaritem.cpp
src/update/updater.cpp
src/appinfo.cpp
src/aura.cpp
Expand All @@ -53,15 +55,17 @@ find_package(maddy REQUIRED)
find_package(sqlcipher REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PUBLIC Intl::Intl JsonCpp::JsonCpp CURL::libcurl maddy::maddy sqlcipher::sqlcipher)
if(LINUX)
find_package(PkgConfig REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(libsecret REQUIRED CONFIG)
find_package(libuuid REQUIRED CONFIG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(glib-2.0 REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(gio-2.0 REQUIRED IMPORTED_TARGET gio-2.0)
pkg_check_modules(gmodule-2.0 REQUIRED IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(gobject-2.0 REQUIRED IMPORTED_TARGET gobject-2.0)
pkg_check_modules(gthread-2.0 REQUIRED IMPORTED_TARGET gthread-2.0)
target_link_libraries(${PROJECT_NAME} PUBLIC libsecret::libsecret libuuid::libuuid PkgConfig::glib-2.0 PkgConfig::gio-2.0 PkgConfig::gmodule-2.0 PkgConfig::gobject-2.0 PkgConfig::gthread-2.0)
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads libsecret::libsecret libuuid::libuuid PkgConfig::glib-2.0 PkgConfig::gio-2.0 PkgConfig::gmodule-2.0 PkgConfig::gobject-2.0 PkgConfig::gthread-2.0)
endif()
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
Expand All @@ -82,13 +86,15 @@ if(NOT SKIP_TESTS)
add_executable(${PROJECT_NAME}_test
tests/auratests.cpp
tests/eventtests.cpp
tests/filewatchertests.cpp
tests/keyringtests.cpp
tests/main.cpp
tests/networktests.cpp
tests/passwordtests.cpp
tests/storetests.cpp
tests/stringtests.cpp
tests/systemcredentialstests.cpp
tests/taskbartests.cpp
tests/updatertests.cpp
tests/versiontests.cpp
tests/webtests.cpp)
Expand Down
20 changes: 13 additions & 7 deletions include/aura.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if (defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS))
#define _CRT_SECURE_NO_WARNINGS
#endif

#ifndef AURA_H
#define AURA_H

Expand All @@ -15,10 +19,6 @@ namespace Nickvision::Aura
class Aura
{
public:
/**
* @brief Destructs an Aura object.
*/
~Aura();
/**
* @brief Gets the AppInfo object for the application.
*/
Expand All @@ -35,15 +35,15 @@ namespace Nickvision::Aura
static_assert(std::is_base_of_v<ConfigurationBase, T> == true, "T must derive from ConfigurationBase");
if (!m_configFiles.contains(key))
{
m_configFiles[key] = static_cast<ConfigurationBase*>(new T(key));
m_configFiles[key] = std::make_unique<T>(key);
}
return *static_cast<T*>(m_configFiles[key]);
return *static_cast<T*>(m_configFiles[key].get());
}

private:
Aura(const std::string& id, const std::string& name);
AppInfo m_appInfo;
std::map<std::string, ConfigurationBase*> m_configFiles;
std::map<std::string, std::unique_ptr<ConfigurationBase>> m_configFiles;

public:
/**
Expand All @@ -59,6 +59,12 @@ namespace Nickvision::Aura
* @return The active aura instance
*/
static Aura& getActive();
/**
* @brief Gets a system environment variable.
* @param key The environment variable to get
* @return The environment variable if found, else empty string
*/
static std::string getEnvVar(const std::string& key);

private:
static std::unique_ptr<Aura> m_instance;
Expand Down
2 changes: 1 addition & 1 deletion include/events/eventargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Nickvision::Aura::Events
/**
* @brief Constructs an EventArgs.
*/
EventArgs();
EventArgs() = default;
};
}

Expand Down
18 changes: 18 additions & 0 deletions include/filesystem/fileaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef FILEACTION_H
#define FILEACTION_H

namespace Nickvision::Aura::Filesystem
{
/**
* @brief Actions that cause a file to change.
*/
enum class FileAction
{
Added = 1,
Removed,
Modified,
Renamed
};
}

#endif //FILEACTION_H
39 changes: 39 additions & 0 deletions include/filesystem/filesystemchangedeventargs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef FILESYSTEMCHANGEDEVENTARGS_H
#define FILESYSTEMCHANGEDEVENTARGS_H

#include <filesystem>
#include "fileaction.h"
#include "events/eventargs.h"

namespace Nickvision::Aura::Filesystem
{
/**
* @brief Event args for when a file system object is changed.
*/
class FileSystemChangedEventArgs : public Events::EventArgs
{
public:
/**
* @brief Constructs a FileSystemChangedEventArgs.
* @param path The path of the file/folder that changed
* @param why The action that caused the file to change
*/
FileSystemChangedEventArgs(const std::filesystem::path& path, FileAction why);
/**
* @brief Gets the path of the changed file system object.
* @return The path of the changed file/folder
*/
const std::filesystem::path& getPath() const;
/**
* @brief Gets the action that caused the file to change.
* @return The action that caused the file to change
*/
FileAction getWhy() const;

private:
std::filesystem::path m_path;
FileAction m_why;
};
}

#endif //FILESYSTEMCHANGEDEVENTARGS_H
100 changes: 100 additions & 0 deletions include/filesystem/filesystemwatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#ifndef FILESYSTEMWATCHER_H
#define FILESYSTEMWATCHER_H

#include <filesystem>
#include <mutex>
#include <thread>
#include <vector>
#include "filesystemchangedeventargs.h"
#include "watcherflags.h"
#include "events/event.h"
#ifdef _WIN32
#include <windows.h>
#endif

namespace Nickvision::Aura::Filesystem
{
/**
* @brief A watcher of a file system folder.
*/
class FileSystemWatcher
{
public:
/**
* @brief Constructs a FileSystemWatcher.
* @param path The path of the folder to watch
* @param includeSubdirectories Whether or not to include subdirectories for the folder
* @param watcherFlags The flags of what to watch changes for
* @exception std::runtime_error Thrown if unable to initialize watcher
*/
FileSystemWatcher(const std::filesystem::path& path, bool includeSubdirectories, WatcherFlags watcherFlags = WatcherFlags::FileName | WatcherFlags::DirectoryName | WatcherFlags::Attributes | WatcherFlags::Size | WatcherFlags::LastWrite | WatcherFlags::LastAccess);
/**
* @brief Deconstructs a FileSystemWatcher.
*/
~FileSystemWatcher();
/**
* @brief Gets the path of the file system object being watched.
* @return The path of the folder being watched
*/
const std::filesystem::path& getPath() const;
/**
* @brief Gets the flags of what to watch changed for.
* @return The flags of watched properties
*/
WatcherFlags getWatcherFlags() const;
/**
* @brief Gets whether or not subdirectories of the folder are watched.
* @return True if subdirectories watched, else false
*/
bool getIncludeSubdirectories() const;
/**
* @brief Gets the event for when the watched file system object is changed.
* @return The changed event
*/
Events::Event<FileSystemChangedEventArgs>& changed();
/**
* @brief Gets whether or not the file extension is being watched.
* @param extension The file extension to check
* @return True if watched, else false
*/
bool containsExtension(const std::filesystem::path& extension);
/**
* @brief Adds an extension of a file to watch for changes in the folder.
* @param extension The file extension to add
* @return True if successful, else false
*/
bool addExtensionFilter(const std::filesystem::path& extension);
/**
* @brief Removes an extension of a file to watch for changes in the folder.
* @param extension The file extension to remove
* @return True if successful, else false
*/
bool removeExtensionFilter(const std::filesystem::path& extension);
/**
* @brief Clears all extensions to watch.
* @return True if successful, else false
*/
bool clearExtensionFilters();

private:
/**
* @brief Runs the loop to watch a folder for changes.
*/
void watch();
mutable std::mutex m_mutex;
std::filesystem::path m_path;
bool m_includeSubdirectories;
WatcherFlags m_watcherFlags;
Events::Event<FileSystemChangedEventArgs> m_changed;
bool m_watching;
std::vector<std::filesystem::path> m_extensionFilters;
std::jthread m_watchThread;
#ifdef _WIN32
HANDLE m_terminateEvent;
#elif defined(__linux__)
int m_notify;
#endif
};
}

#endif //FILESYSTEMWATCHER_H
24 changes: 24 additions & 0 deletions include/filesystem/watcherflags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef WATCHERFLAGS_H
#define WATCHERFLAGS_H

#include "enumflags.h"

namespace Nickvision::Aura::Filesystem
{
/**
* @brief Flags to describe properties of a file system object that can change.
*/
enum class WatcherFlags
{
FileName = 1,
DirectoryName = 2,
Attributes = 4,
Size = 8,
LastWrite = 16,
LastAccess = 32
};

DEFINE_ENUM_FLAG_OPERATORS(WatcherFlags);
}

#endif
6 changes: 1 addition & 5 deletions include/network/networkmonitor.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef NETWORKMONITOR_H
#define NETWORKMONITOR_H

#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "networkstatechangedeventargs.h"
#include "events/event.h"

Expand Down Expand Up @@ -42,7 +38,7 @@ namespace Nickvision::Aura::Network
private:
Events::Event<NetworkStateChangedEventArgs> m_stateChanged;
NetworkState m_connectionState;
#ifndef _WIN32
#ifdef __linux__
unsigned long m_networkChangedHandlerId;
#endif
};
Expand Down
1 change: 1 addition & 0 deletions include/notifications/notificationsenteventargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Nickvision::Aura::Notifications
* @return The parameter of the additional action
*/
const std::string& getActionParam() const;

protected:
std::string m_message;
NotificationSeverity m_severity;
Expand Down
1 change: 1 addition & 0 deletions include/notifications/shellnotificationsenteventargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Nickvision::Aura::Notifications
* @return The title of the notification
*/
const std::string& getTitle() const;

protected:
std::string m_title;
};
Expand Down
4 changes: 0 additions & 4 deletions include/systemdirectories.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef SYSTEMDIRECTORIES_H
#define SYSTEMDIRECTORIES_H

#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <filesystem>
#include <vector>

Expand Down
19 changes: 19 additions & 0 deletions include/taskbar/progressstate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef PROGRESSSTATE_H
#define PROGRESSSTATE_H

namespace Nickvision::Aura::Taskbar
{
/**
* @brief States of progress on a taskbar button.
*/
enum class ProgressState
{
NoProgress = 0,
Indeterminate = 1,
Normal = 2,
Error = 4,
Paused = 8
};
}

#endif //PROGRESSSTATE_H
Loading

0 comments on commit b6a6195

Please sign in to comment.