Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
a3st committed Jun 1, 2024
1 parent d630831 commit a864f9d
Show file tree
Hide file tree
Showing 33 changed files with 4,866 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .clang-format
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/*
.vscode
node_modules
9 changes: 9 additions & 0 deletions .gitmodules
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
32 changes: 32 additions & 0 deletions CMakeLists.txt
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)
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# Notes
24 changes: 24 additions & 0 deletions include/app.hpp
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
32 changes: 32 additions & 0 deletions include/note.hpp
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
6 changes: 6 additions & 0 deletions include/precompiled.hpp
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>
92 changes: 92 additions & 0 deletions src/app.cpp
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
16 changes: 16 additions & 0 deletions src/main.cpp
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;
}
}
27 changes: 27 additions & 0 deletions src/note.cpp
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
1 change: 1 addition & 0 deletions thirdparty/SQLiteCpp
Submodule SQLiteCpp added at bcb4c7
1 change: 1 addition & 0 deletions thirdparty/base64pp
Submodule base64pp added at 432c94
1 change: 1 addition & 0 deletions thirdparty/simdjson
Submodule simdjson added at ee8515
Binary file added ui/dist/7c8d04cd831df3033c8a.ttf
Binary file not shown.
Loading

0 comments on commit a864f9d

Please sign in to comment.