-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
4,866 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BasedOnStyle: Microsoft | ||
AlwaysBreakTemplateDeclarations: true | ||
NamespaceIndentation: All | ||
PointerAlignment: Left | ||
ReferenceAlignment: Left | ||
IndentCaseLabels: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build/* | ||
.vscode | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[submodule "thirdparty/simdjson"] | ||
path = thirdparty/simdjson | ||
url = https://github.com/simdjson/simdjson | ||
[submodule "thirdparty/SQLiteCpp"] | ||
path = thirdparty/SQLiteCpp | ||
url = https://github.com/SRombauts/SQLiteCpp | ||
[submodule "thirdparty/base64pp"] | ||
path = thirdparty/base64pp | ||
url = https://github.com/matheusgomes28/base64pp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 3.26.0) | ||
project(Notes VERSION 1.0.0) | ||
|
||
set(CMAKE_CXX_STANDARD 23) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
add_subdirectory(thirdparty/simdjson) | ||
add_subdirectory(thirdparty/libwebview) | ||
add_subdirectory(thirdparty/SQLiteCpp) | ||
add_subdirectory(thirdparty/base64pp) | ||
|
||
add_executable(Notes | ||
src/main.cpp | ||
src/app.cpp | ||
src/note.cpp) | ||
|
||
target_include_directories(Notes PRIVATE | ||
${PROJECT_SOURCE_DIR}/src | ||
${PROJECT_SOURCE_DIR}/include) | ||
|
||
target_precompile_headers(Notes PRIVATE ${PROJECT_SOURCE_DIR}/include/precompiled.hpp) | ||
|
||
target_link_libraries(Notes PUBLIC | ||
base64pp | ||
SQLiteCpp | ||
simdjson | ||
libwebview_edge_static) | ||
|
||
add_custom_command( | ||
TARGET Notes | ||
POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ui/dist ${PROJECT_BINARY_DIR}/resources) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
# Notes | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "note.hpp" | ||
#include "webview.hpp" | ||
#include <SQLiteCpp/SQLiteCpp.h> | ||
|
||
namespace notes | ||
{ | ||
class App | ||
{ | ||
public: | ||
App(); | ||
|
||
int32_t run(int32_t const argc, char** argv); | ||
|
||
private: | ||
libwebview::App app; | ||
SQLite::Database database; | ||
std::vector<std::unique_ptr<Note>> notes; | ||
|
||
bool loadNotesFromDB(); | ||
bool tryCreateNotesDB(); | ||
}; | ||
} // namespace notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
namespace notes | ||
{ | ||
class Note | ||
{ | ||
public: | ||
Note(const std::string_view noteName, const std::string_view noteData); | ||
|
||
/*! | ||
@brief Present note in JSON format | ||
@return JSON formatted string | ||
*/ | ||
std::string dump(); | ||
|
||
/*! | ||
@brief Get note name | ||
@return Note name | ||
*/ | ||
std::string_view getName() const; | ||
|
||
/*! | ||
@brief Get note data in base64 format | ||
@return Base64 formatted string | ||
*/ | ||
std::string_view getData() const; | ||
|
||
private: | ||
std::string noteName; | ||
std::string noteData; | ||
}; | ||
} // namespace notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <string_view> | ||
#include <sstream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "app.hpp" | ||
#include "precompiled.hpp" | ||
#include <base64pp/base64pp.h> | ||
|
||
namespace notes | ||
{ | ||
App::App() | ||
: database("notes.db", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE), | ||
app("notes-app", "Notes", 580, 600, true, true) | ||
{ | ||
if (!this->tryCreateNotesDB()) | ||
{ | ||
throw std::runtime_error("An error occurred when adding a new table to the database"); | ||
} | ||
|
||
app.bind("getNotesFromDB", [&](libwebview::EventArgs const& args) { | ||
if(this->loadNotesFromDB()) { | ||
|
||
|
||
} | ||
}); | ||
} | ||
|
||
int32_t App::run(int32_t const argc, char** argv) | ||
{ | ||
if (app.run("resources/index.html")) | ||
{ | ||
return EXIT_SUCCESS; | ||
} | ||
else | ||
{ | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
bool App::loadNotesFromDB() | ||
{ | ||
if (database.tableExists("notes")) | ||
{ | ||
return false; | ||
} | ||
|
||
std::string const dbSelectSQL("SELECT `name`, `data` FROM `notes`"); | ||
|
||
SQLite::Statement query(database, dbSelectSQL); | ||
while (query.executeStep()) | ||
{ | ||
std::string const noteName = query.getColumn(0).getString(); | ||
std::string const noteData = query.getColumn(1).getString(); | ||
|
||
auto note = std::make_unique<Note>(noteName, noteData); | ||
notes.emplace_back(std::move(note)); | ||
} | ||
return true; | ||
} | ||
|
||
bool App::tryCreateNotesDB() | ||
{ | ||
if (database.tableExists("notes")) | ||
{ | ||
return true; | ||
} | ||
|
||
std::string const dbCreateSQL("CREATE TABLE `notes` (`id` INTEGER PRIMARY KEY, `name` TEXT, `data` BLOB)"); | ||
|
||
int32_t result = database.tryExec(dbCreateSQL); | ||
if (result != SQLite::OK) | ||
{ | ||
return false; | ||
} | ||
|
||
std::string const noteName = "Первая заметка"; | ||
std::string const noteData = | ||
"IyDQn9GA0LjQstC10YIhCiMjIyDQrdGC0L4g0L/" | ||
"QtdGA0LLQsNGPINC30LDQvNC10YLQutCwINCyINGA0LDQt9C80LXRgtC60LUgTWFya2Rvd24KCtCQINC90LjQttC1INC/" | ||
"0YDQtdC00YHRgtCw0LLQu9C10L0g0L7QsdGL0YfQvdGL0Lkg0YHQv9C40YHQvtC6INC30LDQtNCw0YcsINC60L7RgtC+" | ||
"0YDRi9C1INC90LXQvtCx0YXQvtC00LjQvNC+INCx0YvQu9C+INGA0LXQsNC70LjQt9C+0LLQsNGC0YwKCtCh0L/" | ||
"QuNGB0L7QuiDQt9Cw0LTQsNGHOgoKMS4g0JTQvtC00LXQu9Cw0YLRjCBVSSDQt9Cw0LzQtdGC0L7QujsKMi4g0J/" | ||
"QvtC00LrQu9GO0YfQuNGC0YwgU1FMaXRlINCyINC60LDRh9C10YHRgtCy0LUg0JHQlDsKMy4g0KDQtdCw0LvQuNC30L7QstCw0YLRjCDQs" | ||
"tC30LDQuNC80L7QtNC10LnRgdGC0LLQuNC1ICpCYWNrZW5kKiDQuCAqRnJvbnRlbmQqINC/" | ||
"0YDQuNC70L7QttC10L3QuNGPINGH0LXRgNC10Lcg0LfQsNC/" | ||
"0YDQvtGB0Ysg0LIgKkpTT04qINGE0L7RgNC80LDRgtC1CgrQkCDQstC+" | ||
"0YIg0YHRgtGA0L7QutCwINC90LAgKlB5dGhvbio6IGBwcmludCgiSGVsbG8gd29ybGQhIilgCgohW2xpYndlYnZpZXddKGh0dHBzOi8vZ2" | ||
"l0aHViLmNvbS9hM3N0L2xpYndlYnZpZXcvcmF3L21haW4vc3BsYXNoLW1haW4ucG5nKQ=="; | ||
|
||
std::string const dbAddFirstNoteSQL = | ||
std::format("INSERT INTO `notes` (`name`, `data`) VALUES ('{}', '{}')", noteName, noteData); | ||
|
||
database.exec(dbAddFirstNoteSQL); | ||
return true; | ||
} | ||
} // namespace notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "app.hpp" | ||
#include "precompiled.hpp" | ||
|
||
int32_t main(int32_t argc, char** argv) | ||
{ | ||
try | ||
{ | ||
notes::App app; | ||
return app.run(argc, argv); | ||
} | ||
catch (std::exception e) | ||
{ | ||
std::cerr << e.what() << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "note.hpp" | ||
#include "precompiled.hpp" | ||
|
||
namespace notes | ||
{ | ||
Note::Note(const std::string_view noteName, const std::string_view noteData) | ||
: noteName(noteName), noteData(noteData) | ||
{ | ||
} | ||
|
||
std::string Note::dump() | ||
{ | ||
std::stringstream stream; | ||
stream << "{\"name\":\"" << noteName << "\",data:\"" << noteData << "\"}"; | ||
return stream.str(); | ||
} | ||
|
||
std::string_view Note::getName() const | ||
{ | ||
return noteName; | ||
} | ||
|
||
std::string_view Note::getData() const | ||
{ | ||
return noteData; | ||
} | ||
} // namespace notes |
Binary file not shown.
Oops, something went wrong.