Skip to content

Commit 642539f

Browse files
authored
V2024.6.9
Merge pull request #40 from NickvisionApps/next
2 parents cdd1642 + e6d3af3 commit 642539f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1140
-1263
lines changed

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# Changelog
22

3+
## 2024.6.9
4+
### Breaking Changes
5+
#### App
6+
- Removed `Nickvision::App::Aura`
7+
- Renamed `Nickvision::App::ConfigurationBase` to `Nickvision::App::DataFileBase`
8+
#### Filesystem
9+
- Removed `Nickvision::Filesystem::SystemDirectories` namespace
10+
- Removed `Nickvision::Filesystem::UserDirectories::get*` methods
11+
### New APIs
12+
#### App
13+
- Added `Nickvision::App::DataFileManager` class
14+
#### Filesystem
15+
- Added `Nickvision::Filesystem::UserDirectory` enum
16+
- Added `Nickvision::Filesystem::UserDirectories::get()`
17+
#### Notifications
18+
- Added `Nickvision::Notifications::NotifyIcon::getForHWND()`
19+
#### Localization
20+
- Added `Nickvision::Localization::Documentation::getHelpUrl()`
21+
#### System
22+
- Added `Nickvision::System::DeploymentMode` enum
23+
- Added `Nickvision::System::OperatingSystem` enum
24+
- Added `Nickvision::System::Environment::getOperatingSystem()`
25+
- Added `Nickvision::System::Environment::getDeploymentMode()`
26+
- Added `Nickvision::System::Environment::getExecutableDirectory()`
27+
- Added `Nickvision::System::Environment::getLocaleName()`
28+
- Added `Nickvision::System::Environment::getPath()`
29+
- Added `Nickvision::System::Environment::findDependency()`
30+
### Fixes
31+
#### Filesystem
32+
- `Nickvision::Filesystem::UserDirectories` will now fetch proper `macOS` directories
33+
#### Localization
34+
- `Nickvision::Localization::Gettext::init()` will ensure the domainName is lowercase and contains no spaces
35+
#### Update
36+
- Fixed an issue where Updater would crash if failed to fetch json
37+
338
## 2024.6.8
439
### Breaking Changes
540
None

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
2121

2222
#libnick Definition
23-
project ("libnick" LANGUAGES C CXX VERSION 2024.6.8 DESCRIPTION "A cross-platform base for native Nickvision applications.")
23+
project ("libnick" LANGUAGES C CXX VERSION 2024.6.9 DESCRIPTION "A cross-platform base for native Nickvision applications.")
2424
include(CMakePackageConfigHelpers)
2525
include(GNUInstallDirs)
2626
include(CTest)
@@ -32,8 +32,8 @@ if(NOT WIN32)
3232
endif()
3333
add_library (${PROJECT_NAME}
3434
"src/app/appinfo.cpp"
35-
"src/app/aura.cpp"
36-
"src/app/configurationbase.cpp"
35+
"src/app/datafilebase.cpp"
36+
"src/app/datafilemanager.cpp"
3737
"src/app/interprocesscommunicator.cpp"
3838
"src/app/windowgeometry.cpp"
3939
"src/database/sqlcontext.cpp"
@@ -43,7 +43,6 @@ add_library (${PROJECT_NAME}
4343
"src/database/sqlvalue.cpp"
4444
"src/filesystem/filesystemchangedeventargs.cpp"
4545
"src/filesystem/filesystemwatcher.cpp"
46-
"src/filesystem/systemdirectories.cpp"
4746
"src/filesystem/userdirectories.cpp"
4847
"src/helpers/codehelpers.cpp"
4948
"src/helpers/stringhelpers.cpp"
@@ -54,6 +53,7 @@ add_library (${PROJECT_NAME}
5453
"src/keyring/passwordstrength.cpp"
5554
"src/keyring/store.cpp"
5655
"src/keyring/systemcredentials.cpp"
56+
"src/localization/documentation.cpp"
5757
"src/localization/gettext.cpp"
5858
"src/logging/logger.cpp"
5959
"src/network/curleasy.cpp"
@@ -146,16 +146,17 @@ export(EXPORT "${PROJECT_NAME}Targets" FILE "${CMAKE_BINARY_DIR}/cmake/${PROJECT
146146
#libnick Test
147147
if (BUILD_TESTING)
148148
add_executable(${PROJECT_NAME}_test
149-
"tests/auratests.cpp"
150149
"tests/codetests.cpp"
151150
"tests/databasetests.cpp"
151+
"tests/datafiletests.cpp"
152152
"tests/eventtests.cpp"
153153
"tests/filewatchertests.cpp"
154154
"tests/ipctests.cpp"
155155
"tests/keyringtests.cpp"
156156
"tests/loggingtests.cpp"
157157
"tests/main.cpp"
158158
"tests/networktests.cpp"
159+
"tests/notificationtests.cpp"
159160
"tests/passwordtests.cpp"
160161
"tests/storetests.cpp"
161162
"tests/stringtests.cpp"

docs/app.md

Lines changed: 55 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ This module contains types and functions for creating Nickvision applications.
44

55
## Table of Contents
66
- [AppInfo](#appinfo)
7-
- [Aura](#aura)
8-
- [ConfigurationBase](#configurationbase)
7+
- [DataFileBase](#datafilebase)
8+
- [DataFileManager](#datafilemanager)
99
- [InterProcessCommunicator](#interprocesscommunicator)
1010
- [WindowGeometry](#windowgeometry)
1111

@@ -45,7 +45,7 @@ Path: `Nickvision::App::AppInfo`
4545
- The application description.
4646
- Ex: `"A template for Nickvision applications."`
4747
- ```
48-
Nickvision::Version Version: get, set
48+
Nickvision::Update::Version Version: get, set
4949
```
5050
- The application version.
5151
- Ex: `2023.12.0`
@@ -125,111 +125,14 @@ Path: `Nickvision::App::AppInfo`
125125
- Returns: A list of entries in the following format: `"{key} {value}"`.
126126
- Ex: `AppInfo::convertUrlMapToVector({ { "a", "a2" }, { "b", "b2" } })` will return `std::vector<std::string>{ "a a2", "b b2" }`.
127127
128-
## Aura
129-
Description: An application base.
128+
## DataFileBase
129+
Description: A base class for json data files.
130130
131-
Interface: [aura.h](/include/app/aura.h)
131+
Interface: [datafilebase.h](/include/app/datafilebase.h)
132132
133133
Type: `class`
134134
135-
Path: `Nickvision::App::Aura`
136-
137-
### Member Variables
138-
- ```
139-
Nickvision::App::AppInfo& AppInfo: get
140-
```
141-
- The AppInfo object for the application
142-
- ```
143-
InterProcessCommunicator& IPC: get
144-
```
145-
- The application's inter process communicator
146-
- ```
147-
const Logger& Logger: get
148-
```
149-
- The application's logger
150-
- ```
151-
std::filesystem::path& ExecutableDirectory: get
152-
```
153-
- The path of the executable's directory.
154-
- ```
155-
bool IsRunningOnWindows: get
156-
```
157-
- Whether or not the app is running on Windows
158-
- ```
159-
bool IsRunningOnLinux: get
160-
```
161-
- Whether or not the app is running on Linux
162-
- ```
163-
bool IsRunningOnMac: get
164-
```
165-
- Whether or not the app is running on macOS
166-
- ```
167-
bool IsRunningViaFlatpak: get
168-
```
169-
- Whether or not the app is running via Flatpak
170-
- ```
171-
bool IsRunningViaSnap: get
172-
```
173-
- Whether or not the app is running via Snap
174-
- ```
175-
bool IsRunningViaLocal: get
176-
```
177-
- Whether or not the app is running locally
178-
179-
### Methods
180-
- ```cpp
181-
bool init(const std::string& id, const std::string& name, const std::string& englishShortName, Logging:LogLevel logLevel)
182-
```
183-
- Accepts: An application id, id, an application name, name, an application english short name, englishShortName, and the application log level, logLevel.
184-
- Returns: True if initialized, else false.
185-
- Throws: `std::runtime_error` if the gettext system fails to initialize.
186-
- Throws: `std::runtime_error` if unable to get the executable directory path.
187-
- Note: This also calls Localization::Gettext::init().
188-
- ```cpp
189-
const std::filesystem::path& findDependency(std::string dependency)
190-
```
191-
- Accepts: The name of a dependency to find, dependency.
192-
- Returns: The path of the dependency on disk if found.
193-
- Returns: An empty path if the dependency was not found on disk.
194-
- Ex: `Aura::findDependency("cmd")` on Windows will return `C:\Windows\System32\cmd.exe`.
195-
- Ex: `Aura::findDependency("bash")` on Linux will return `/usr/bin/bash`.
196-
- ```cpp
197-
std::string getHelpUrl(const std::string& pageName)
198-
```
199-
- Accepts: The name of the documentation page to get the help url for, pageName.
200-
- Returns: The url for the documentation page. This will be a yelp url for Linux and a website url for Windows and Linux snaps.
201-
- Note: HtmlDocsStore should be set for Aura::getActive()::getAppInfo(). For Nickvision apps, this will be: `https://raw.githubusercontent.com/NickvisionApps/SHORT_APP_NAME/main/APP_NAME.Shared/Docs/html`, but can be customized for any app.
202-
- ```cpp
203-
T& getConfig<T>(const std::string& key)
204-
```
205-
- Accepts: The string key of the config file, key.
206-
- Returns: A reference to the configuration object of type T with key key.
207-
- Throws: `std::invalid_argument` if key is empty
208-
- Note: T must be a type that derives from `Nickvision::ConfigurationBase`
209-
- Ex: `getConfig<Configuration>("config")` will return the `Configuration` object parsed from a `config.json` file on disk.
210-
- ```cpp
211-
Notifications::NotifyIcon& getNotifyIcon(HWND hwnd)
212-
```
213-
- Accepts: The window handle for the notify icon, hwnd.
214-
- Returns: The application's NotifyIcon.
215-
- Note: The hwnd only needs to be valid on the first call to establish the new NotifyIcon.
216-
- Note: The new NotifyIcon will be hidden by default.
217-
- Note: This function is only available on Windows.
218-
219-
### Static Functions
220-
- ```cpp
221-
Nickvision::Aura& getActive()
222-
```
223-
- Returns: The reference to the singleton `Aura` object.
224-
225-
## ConfigurationBase
226-
Description: A base class for configuration files.
227-
228-
Interface: [configurationbase.h](/include/app/configurationbase.h)
229-
230-
Type: `class`
231-
232-
Path: `Nickvision::App::ConfigurationBase`
135+
Path: `Nickvision::App::DataFileBase`
233136
234137
### Member Variables
235138
- ```
@@ -241,48 +144,48 @@ Path: `Nickvision::App::ConfigurationBase`
241144
- ```cpp
242145
Event<Nickvision::Events::EventArgs> Saved
243146
```
244-
- Invoked when the configuration file is saved to disk
147+
- Invoked when the configuration file is saved to disk.
245148

246149
### Methods
247150
- ```cpp
248-
ConfigurationBase(const std::string& key)
151+
DataFileBase(const std::string& key, const std::string& appName)
249152
```
250-
- Constructs the ConfigurationBase, loading the file from disk
251-
- Accepts: The key of the configuration file, key
252-
- Throws: `std::invalid_argument` if key is empty
153+
- Constructs the DataFileBase, loading the file from disk.
154+
- Accepts: The key of the configuration file, key, and the name of the app the file belongs to.
155+
- Throws: `std::invalid_argument` if key is empty.
253156
- ```cpp
254157
bool save()
255158
```
256-
- Returns: `true` if the configuration file was saved to disk
257-
- Returns: `false` if saving to disk failed
159+
- Returns: `true` if the configuration file was saved to disk.
160+
- Returns: `false` if saving to disk failed.
258161

259-
### Creating Your Own Configuration Files
260-
The purpose of `ConfigurationBase` is to act as a base when defining your own configuration objects that you would like to be saved and retrieved from disk.
162+
### Creating Your Own Data Files
163+
The purpose of `DataFileBase` is to act as a base when defining your own data objects that you would like to be saved and retrieved from disk.
261164

262165
Here are some key points when defining your own configuration objects:
263-
- Your configuration object's constructor must take a `const std::string& key` parameter and pass it to `ConfigurationBase`'s constructor.
264-
- Although you will not use key in your own implementation, it is required for `ConfigurationBase`'s functionality and will be filled-in by the `Aura::getConfig()` method.
265-
- `ConfigurationBase` exposes a protected `m_json` object which you must use in your implementation of getting and storing variables of your configuration object.
266-
- If this `m_json` object is not used, your configuration object will not be stored to disk correctly.
267-
- You must explicitly call the `save` method on your configuration object when you want to save the configuration to disk. Writing to the `m_json` object is not enough to trigger saving the file on disk
166+
- Your data object's constructor must take `const std::string& key` and `const std::string& appName` parameters and pass it to `DataFileBase`'s constructor.
167+
- Although you will not use `key` and `appName` in your own implementation, it is required for `DataFileBase`'s functionality and will be filled-in by the `DataFileManager`.
168+
- `DataFileBase` exposes a protected `m_json` object which you must use in your implementation of getting and storing variables of your data object.
169+
- If this `m_json` object is not used, your data object will not be stored to disk correctly.
170+
- You must explicitly call the `save` method on your configuration object when you want to save the configuration to disk. Writing to the `m_json` object is not enough to trigger saving the file on disk.
268171

269-
Here is an example of a custom configuration object using `ConfigurationBase`:
172+
Here is an example of a custom configuration object using `DataFileBase`:
270173
```cpp
271174
using namespace Nickvision::App;
272175

273-
class AppConfig : public ConfigurationBase
176+
class AppConfig : public DataFileBase
274177
{
275178
public:
276-
AppConfig(const std::string& key)
277-
: ConfigurationBase{ key }
179+
AppConfig(const std::string& key, const std::string& appName)
180+
: DataFileBase{ key, appName }
278181
{
279182

280183
}
281184

282185
int getPreviousCount() const
283186
{
284-
//0 is the default value of PreviousCount (i.e. if it does not exist in the file)
285-
return m_json.get("PreviousCount", 0).asInt();
187+
//0 is the default value of PreviousCount (i.e. if it does not exist in the file)
188+
return m_json.get("PreviousCount", 0).asInt();
286189
}
287190

288191
void setPreviousCount(int count)
@@ -291,15 +194,15 @@ public:
291194
}
292195
};
293196
```
294-
This object can now be used by an Aura-based application:
197+
This object can now be used with the `DataFileManager`:
295198
```cpp
296199
using namespace Nickvision::App;
297200
using namespace Nickvision::Events;
298201

299202
int main()
300203
{
301-
Aura::getActive().init(...);
302-
AppConfig& config{ Aura::getActive().getConfig<AppConfig>("config") };
204+
DataFileManager dfm{ "AppName" };
205+
AppConfig& config{ dfm.get<AppConfig>("config") };
303206
config.saved() += [](const EventArgs& e) { std::cout << "Config saved to disk." << std::endl; };
304207
if(config.getPreviousCount() > 0)
305208
{
@@ -309,6 +212,30 @@ int main()
309212
config.save(); //lambda will be invoked on success
310213
}
311214
```
215+
216+
## DataFileManager
217+
Description: A manager of data files for an application.
218+
219+
Interface: [datafilemanager.h](/include/app/datafilemanager.h)
220+
221+
Type: `class`
222+
223+
Path: `Nickvision::App::DataFileManager`
224+
225+
### Methods
226+
- ```cpp
227+
DataFileManager(const std::string& appName)
228+
```
229+
- Constructs a DataFileManager.
230+
- Accepts: The name of the application, appName (used in determining the path to store data files on disk).
231+
- ```cpp
232+
T& get<T>(const std::string& key)
233+
```
234+
- Accepts: The string key of the data file, key.
235+
- Returns: A reference to the data object of type T with key key.
236+
- Throws: `std::invalid_argument` if key is empty
237+
- Note: T must be a type that derives from `Nickvision::App::DataFileBase`
238+
- Ex: `get<Configuration>("abc")` will return the `Configuration` object parsed from a `abc.json` file on disk.
312239

313240
## InterProcessCommunicator
314241
Description: An inter process communicator (server/client).
@@ -372,7 +299,6 @@ using namespace Nickvision::App;
372299
373300
int main(int argc, char*[] argv)
374301
{
375-
Aura::getActive().init(...);
376302
std::vector<std::string> modernArgs;
377303
for(int i = 0; i < argc; i++)
378304
{
@@ -381,7 +307,7 @@ int main(int argc, char*[] argv)
381307
modernArgs.push_back({ argv[i] });
382308
}
383309
}
384-
InterProcessCommunicator& ipc{ Aura::getActuve().getIPC() };
310+
InterProcessCommunicator& ipc{ "appid" };
385311
ipc.commandReceived() += [](const Events::ParamEventArgs<std::vector<std::string>>& args) { ... };
386312
ipc.communicate(modernArgs, true);
387313
}

0 commit comments

Comments
 (0)