Skip to content

Commit

Permalink
V2024.12.0 (#54)
Browse files Browse the repository at this point in the history
* Version Bump

* System - Fix `Environment::getExecutableDirectory()` on macOS

* Notifications - Add FreeDesktop Notification Support to `ShellNotification::send

* Update shellnotification.h

* Update changelog
  • Loading branch information
nlogozzo authored Dec 17, 2024
1 parent f4178ea commit 913fff1
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
with:
pkgs: boost-json curl gettext-libintl glib gtest libsecret maddy openssl
triplet: x64-linux
revision: a54c4ba3aef5fe56cf11192f4476aaf057876551
revision: b322364f06308bdd24823f9d8f03fe0cc86fd46f
token: ${{ secrets.GITHUB_TOKEN }}
github-binarycache: true
- name: "Build"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
with:
pkgs: boost-json curl gettext-libintl glib gtest maddy openssl
triplet: arm64-osx
revision: a54c4ba3aef5fe56cf11192f4476aaf057876551
revision: b322364f06308bdd24823f9d8f03fe0cc86fd46f
token: ${{ secrets.GITHUB_TOKEN }}
github-binarycache: true
- name: "Build"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
pkgs: boost-json curl gettext-libintl gtest maddy sqlcipher
triplet: x64-windows
revision: 3b57fb2e1ff55613db14d2aaf0a30529289c7050
revision: b322364f06308bdd24823f9d8f03fe0cc86fd46f
token: ${{ secrets.GITHUB_TOKEN }}
github-binarycache: true
- name: "Build"
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 2024.12.0
### Breaking Changes
None
### New APIs
None
### Fixes
#### Notifications
- Fixed an issue where `ShellNotification::send()` did not work on non-GTK linux applications
#### System
- Fixed an issue where `Environment::getExecutableDirectory()` did not return the correct path on macOS

## 2024.11.1
### Breaking Changes
None
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")

#libnick Definition
project ("libnick" LANGUAGES C CXX VERSION 2024.11.1 DESCRIPTION "A cross-platform base for native Nickvision applications.")
project ("libnick" LANGUAGES C CXX VERSION 2024.12.0 DESCRIPTION "A cross-platform base for native Nickvision applications.")
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(CTest)
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "libnick"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "2024.11.1"
PROJECT_NUMBER = "2024.12.0"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The above dependencies must be installed, *plus* the following for Linux systems
### macOS
The above dependencies must be installed, *plus* the following for macOS systems:
- glib
- libsecret
- libsecret (Only required if `-DUSE_LIBSECRET="ON"`)
- openssl
- Used for sqlcipher, as libnick manually builds sqlcipher on macOS as the vcpkg port is broken.

Expand Down Expand Up @@ -92,6 +92,7 @@ A C++20 compiler is also required to build libnick.
#### macOS
1. From the `build` folder, run `cmake .. -DCMAKE_BUILD_TYPE=Release`.
- To skip building libnick's test suite, add `-DBUILD_TESTING="OFF"` to the end of the command.
- To use `libsecret` instead of macOS's built in security library, add `-DUSE_LIBSECRET="ON"` to the end of the command.
- If you plan to install libnick, add `-DCMAKE_INSTALL_PREFIX=PATH_TO_INSTALL_DIR` to the end of the command, replacing `PATH_TO_INSTALL_DIR` with the path of where you'd like libnick to install to.
1. From the `build` folder, run `cmake --build .`.
1. After these commands complete, libnick will be successfully built and its binaries can be found in the `build` folder.
Expand Down
6 changes: 3 additions & 3 deletions include/notifications/shellnotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ namespace Nickvision::Notifications::ShellNotification
#elif defined(__linux__)
/**
* @brief Sends a notification to the shell.
* @brief Uses Gio.Notification on Linux.
* @brief Supports the action "open" with action param being a path of a file or folder to open. The app must define an "app.open" action to handle this event.
* @brief Uses Gio.Notification on GTK applications.
* @brief Uses FreeDesktop Notifications on non-GTK applications.
* @brief Supports the action "open" with action param being a path of a file or folder to open. The app must define an "app.open" action to handle this event. (GTK applications only)
* @param e ShellNotificationSentEventArgs
* @param appId The application's id
* @param openText Localized text of "Open"
Expand All @@ -52,7 +53,6 @@ namespace Nickvision::Notifications::ShellNotification
#elif defined(__APPLE__)
/**
* @brief Sends a notification to the shell.
* @brief Uses NSUserNotification on macOS.
* @param e ShellNotificationSentEventArgs
*/
void send(const ShellNotificationSentEventArgs& e);
Expand Down
21 changes: 12 additions & 9 deletions manual/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@

libnick provides Nickvision apps with a common set of cross-platform APIs for managing system and desktop app functionality such as network management, taskbar icons, translations, app updates, and more.

## 2024.11.1
## 2024.12.0
### Breaking Changes
None
### New APIs
None
### Fixes
- Fixed compilation issues for older macOS systems
#### Notifications
- Fixed an issue where `ShellNotification::send()` did not work on non-GTK linux applications
#### System
- Fixed an issue where `Environment::getExecutableDirectory()` did not return the correct path on macOS

## Dependencies
The following are a list of dependencies used by libnick.

### All Platforms
- boost-json
- gtest
- jsoncpp
- libcurl
- libintl
- maddy
Expand All @@ -32,14 +35,13 @@ The above dependencies must be installed, *plus* the following for Windows syste
The above dependencies must be installed, *plus* the following for Linux systems:
- glib
- libsecret
- libuuid
- openssl
- Used for sqlcipher, as libnick manually builds sqlcipher on Linux as the vcpkg port is broken.

### macOS
The above dependencies must be installed, *plus* the following for macOS systems:
- glib
- libsecret
- libsecret (Only required if `-DUSE_LIBSECRET="ON"`)
- openssl
- Used for sqlcipher, as libnick manually builds sqlcipher on macOS as the vcpkg port is broken.

Expand Down Expand Up @@ -67,16 +69,16 @@ A C++20 compiler is also required to build libnick.
1. Set the `VCPKG_ROOT` environment variable to the path of your vcpkg installation's root directory.
#### Windows
1. Set the `VCPKG_DEFAULT_TRIPLET` environment variable to `x64-windows`
1. Run `vcpkg install curl gettext-libintl gtest jsoncpp maddy sqlcipher`
1. Run `vcpkg install boost-json curl gettext-libintl gtest maddy sqlcipher`
#### Linux
1. Set the `VCPKG_DEFAULT_TRIPLET` environment variable to `x64-linux`
1. Run `vcpkg install curl gettext-libintl glib gtest jsoncpp libsecret libuuid maddy openssl`
1. Run `vcpkg install boost-json curl gettext-libintl glib gtest libsecret maddy openssl`
#### macOS (Intel)
1. Set the `VCPKG_DEFAULT_TRIPLET` environment variable to `x64-osx`
1. Run `vcpkg install curl gettext-libintl glib gtest jsoncpp libsecret maddy openssl`
1. Run `vcpkg install boost-json curl gettext-libintl glib gtest libsecret maddy openssl`
#### macOS (Apple Silicon)
1. Set the `VCPKG_DEFAULT_TRIPLET` environment variable to `arm64-osx`
1. Run `vcpkg install curl gettext-libintl glib gtest jsoncpp libsecret maddy openssl`
1. Run `vcpkg install boost-json curl gettext-libintl glib gtest libsecret maddy openssl`

### Building
1. First, clone/download the repo.
Expand All @@ -97,6 +99,7 @@ A C++20 compiler is also required to build libnick.
#### macOS
1. From the `build` folder, run `cmake .. -DCMAKE_BUILD_TYPE=Release`.
- To skip building libnick's test suite, add `-DBUILD_TESTING="OFF"` to the end of the command.
- To use `libsecret` instead of macOS's built in security library, add `-DUSE_LIBSECRET="ON"` to the end of the command.
- If you plan to install libnick, add `-DCMAKE_INSTALL_PREFIX=PATH_TO_INSTALL_DIR` to the end of the command, replacing `PATH_TO_INSTALL_DIR` with the path of where you'd like libnick to install to.
1. From the `build` folder, run `cmake --build .`.
1. After these commands complete, libnick will be successfully built and its binaries can be found in the `build` folder.
Expand Down
32 changes: 27 additions & 5 deletions src/notifications/shellnotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Nickvision::Notifications
icon->notify(e);
std::thread t{ [icon]()
{
std::this_thread::sleep_for(std::chrono::seconds(5));
std::this_thread::sleep_for(std::chrono::seconds(10));
delete icon;
} };
t.detach();
Expand All @@ -40,20 +40,27 @@ namespace Nickvision::Notifications
#elif defined(__linux__)
void ShellNotification::send(const ShellNotificationSentEventArgs& e, const std::string& appId, const std::string& openText)
{
std::string iconPath;
if(!Environment::hasVariable("SNAP"))
{
iconPath = appId + "-symbolic";
}
else
{
iconPath = Environment::getVariable("SNAP") + "/usr/share/icons/hicolor/symbolic/apps/" + appId + "-symbolic.svg";
}
if (g_application_get_default())
{
GNotification* notification{ g_notification_new(e.getTitle().c_str()) };
GIcon* icon{ nullptr };
GFile* fileIcon{ nullptr };
if (!Environment::hasVariable("SNAP"))
{
std::string name{ appId + "-symbolic" };
icon = g_themed_icon_new(name.c_str());
icon = g_themed_icon_new(iconPath.c_str());
}
else
{
std::string path{ Environment::getVariable("SNAP") + "/usr/share/icons/hicolor/symbolic/apps/" + appId + "-symbolic.svg"};
fileIcon = g_file_new_for_path(path.c_str());
fileIcon = g_file_new_for_path(iconPath.c_str());
icon = g_file_icon_new(fileIcon);
}
g_notification_set_body(notification, e.getMessage().c_str());
Expand Down Expand Up @@ -82,6 +89,21 @@ namespace Nickvision::Notifications
g_object_unref(G_OBJECT(icon));
g_object_unref(G_OBJECT(notification));
}
else
{
GDBusConnection* connection{ g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr) };
if(connection)
{
GVariant* params{ g_variant_new("(susssasa{sv}i)", appId.c_str(), 0, iconPath.c_str(), e.getTitle().c_str(), e.getMessage().c_str(), nullptr, nullptr, -1) };
GVariant* result{ g_dbus_connection_call_sync(connection, "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify", params, nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr) };
if(result)
{
g_variant_unref(result);
}
g_variant_unref(params);
g_object_unref(G_OBJECT(connection));
}
}
}
#elif defined(__APPLE__)
void ShellNotification::send(const ShellNotificationSentEventArgs& e)
Expand Down
12 changes: 6 additions & 6 deletions src/system/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#ifdef _WIN32
#include <windows.h>
#elif defined(__APPLE__)
#include <libproc.h>
#include <unistd.h>
#include <mach-o/dyld.h>
#include <sys/syslimits.h>
#endif

using namespace Nickvision::App;
Expand Down Expand Up @@ -47,11 +47,11 @@ namespace Nickvision::System
#elif defined(__linux__)
executableDirectory = std::filesystem::canonical("/proc/self/exe").parent_path();
#elif defined(__APPLE__)
char pth[PROC_PIDPATHINFO_MAXSIZE];
int len{ proc_pidpath(getpid(), pth, sizeof(pth)) };
if(len > 0)
char path[PATH_MAX+1];
uint32_t size{ sizeof(path) };
if(_NSGetExecutablePath(path, &size) == 0)
{
executableDirectory = std::filesystem::path(std::string(pth, len)).parent_path();
executableDirectory = std::filesystem::canonical(path).parent_path();
}
#endif
return executableDirectory;
Expand Down

0 comments on commit 913fff1

Please sign in to comment.