Skip to content

Commit

Permalink
Linux Support
Browse files Browse the repository at this point in the history
  • Loading branch information
a3st committed Jul 9, 2024
1 parent 3ad5248 commit 442dabd
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 139 deletions.
48 changes: 30 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
cmake_minimum_required(VERSION 3.26.0)
project(Notes VERSION 1.0.0)
cmake_minimum_required(VERSION 3.25.1)

project(Notes VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (NOT TARGET simdjson)
add_subdirectory(thirdparty/simdjson)
endif()
include(FetchContent)

if (NOT TARGET libwebview_edge_static)
add_subdirectory(thirdparty/libwebview)
endif()
FetchContent_Declare(simdjson
SOURCE_DIR ${PROJECT_SOURCE_DIR}/thirdparty/simdjson
BINARY_DIR ${CMAKE_BINARY_DIR}/thirdparty/simdjson)

if (NOT TARGET SQLiteCpp)
add_subdirectory(thirdparty/SQLiteCpp)
endif()
FetchContent_Declare(libwebview
SOURCE_DIR ${PROJECT_SOURCE_DIR}/thirdparty/libwebview
BINARY_DIR ${CMAKE_BINARY_DIR}/thirdparty/libwebview)

if (NOT TARGET base64pp)
add_subdirectory(thirdparty/base64pp)
endif()
FetchContent_Declare(SQLiteCpp
SOURCE_DIR ${PROJECT_SOURCE_DIR}/thirdparty/SQLiteCpp
BINARY_DIR ${CMAKE_BINARY_DIR}/thirdparty/SQLiteCpp)

FetchContent_Declare(base64pp
SOURCE_DIR ${PROJECT_SOURCE_DIR}/thirdparty/base64pp
BINARY_DIR ${CMAKE_BINARY_DIR}/thirdparty/base64pp)

FetchContent_MakeAvailable(simdjson libwebview SQLiteCpp base64pp)

add_executable(Notes
src/exporters/txt.cpp
src/main.cpp
src/view_model.cpp
src/note_storage.cpp
src/note.cpp
app.rc)
src/note.cpp)

if(WIN32)
set_target_properties(Notes
Expand All @@ -36,6 +40,8 @@ set_target_properties(Notes
LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:windows /ENTRY:mainCRTStartup"
LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:windows /ENTRY:mainCRTStartup"
)

target_sources(Notes PRIVATE app.rc)
endif()

target_include_directories(Notes PRIVATE
Expand All @@ -44,11 +50,17 @@ target_include_directories(Notes PRIVATE

target_precompile_headers(Notes PRIVATE ${PROJECT_SOURCE_DIR}/include/precompiled.hpp)

target_link_libraries(Notes PUBLIC
target_link_libraries(Notes PRIVATE
base64pp
SQLiteCpp
simdjson
libwebview_edge_static)
libwebview_edge)

if(WIN32)
target_link_libraries(Notes PRIVATE libwebview_edge)
elseif(UNIX)
target_link_libraries(Notes PRIVATE libwebview_webkit)
endif()

add_custom_command(
TARGET Notes
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Download all dependencies (thirdparty) using --recursive git.

### Requirements

- C++23 Compiler
- CMake 3.26.0
- Visual Studio 2022 or Clang-18
- CMake 3.25.1+

## Thirdparties

- [base64pp](https://github.com/matheusgomes28/base64pp)
- [libwebview](https://github.com/a3st/libwebview)
- [simdjson](https://github.com/simdjson/simdjson)
- [SQLiteCpp](https://github.com/SRombauts/SQLiteCpp)
- [SQLiteCpp](https://github.com/SRombauts/SQLiteCpp)
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ int32_t main(int32_t argc, char** argv)
{
try
{
libwebview::App app("notes-app", "Notes", 580, 600, true, false);
app.setMinWindowSize(580, 600);
libwebview::App app("app.dl.notes", "Notes", 580, 600, true, false);
app.setWindowMinSize(580, 600);

notes::ViewModel viewModel(&app);

Expand Down
File renamed without changes
File renamed without changes
51 changes: 42 additions & 9 deletions ui/dist/app.bundle.js

Large diffs are not rendered by default.

File renamed without changes
161 changes: 121 additions & 40 deletions ui/src/components/editor.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,94 @@
<template>
<div class="editor-container">
<div class="header-input-container">
<input type="text" placeholder="Придумайте что написать..." v-model="title" @focus="onFocusInput($event)" />
<input
type="text"
placeholder="Придумайте что написать..."
v-model="title"
@focus="onFocusInput"
/>
</div>

<div v-show="isOpenEditor" class="body-input-container">
<div v-if="isPreview" style="display: flex; padding: 10px; height: calc(100% - 80px);">
<div class="markdown-container" v-html="previewText" @mousedown="onSwitchVisibleEditorClick($event)"></div>
<div
v-if="isPreview"
style="display: flex; padding: 10px; height: calc(100% - 80px)"
>
<div
class="markdown-container"
v-html="previewText"
@mousedown="onSwitchVisibleEditorClick"
></div>
</div>
<div v-else style="display: flex; padding: 10px; height: calc(100% - 80px);">
<div
v-else
style="display: flex; padding: 10px; height: calc(100% - 80px)"
>
<textarea placeholder="Заметка..." v-model="content"></textarea>
</div>

<div class="footer-input-container">
<div style="display: flex; flex-direction: row; align-items: center; width: 100%;">
<div style="display: flex; flex-direction: row; gap: 10px;">
<button title="Предпросмотр" class="btn-icon circle" style="width: 36px; height: 36px;" @click="onSwitchVisibleClick($event)">
<object style="pointer-events: none;" data="images/eye.svg" width="20" height="20"></object>
<div
style="
display: flex;
flex-direction: row;
align-items: center;
width: 100%;
"
>
<div style="display: flex; flex-direction: row; gap: 10px">
<button
title="Предпросмотр"
class="btn-icon circle"
style="width: 36px; height: 36px"
@click="onSwitchVisibleClick"
>
<img
:src="require('../images/eye.svg')"
width="20"
height="20"
/>
</button>

<button v-show="this.id != -1" id="export-btn" title="Экспорт" class="btn-icon circle" style="width: 36px; height: 36px;" @click="onExportClick($event)">
<object style="pointer-events: none;" data="images/file-export.svg" width="20" height="20"></object>
<button
v-show="this.id != -1"
id="export-btn"
title="Экспорт"
class="btn-icon circle"
style="width: 36px; height: 36px"
@click="onExportClick"
>
<img
:src="require('../images/file-export.svg')"
width="20"
height="20"
/>
</button>
</div>
<div style="display: flex; flex-direction: row; margin-left: auto;">
<button class="btn-text" @click="onSaveClick($event)" style="font-weight: bold;" v-bind:disabled="!isChanged || this.title.length == 0">Сохранить</button>
<button class="btn-text" @click="onCloseClick($event)" style="font-weight: bold;">Закрыть</button>
<div
style="
display: flex;
flex-direction: row;
margin-left: auto;
"
>
<button
class="btn-text"
@click="onSaveClick"
style="font-weight: bold"
v-bind:disabled="
!isChanged || this.title.length == 0
"
>
Сохранить
</button>
<button
class="btn-text"
@click="onCloseClick"
style="font-weight: bold"
>
Закрыть
</button>
</div>
</div>
</div>
Expand All @@ -34,67 +97,82 @@
</template>

<script>
import { marked } from 'marked';
import { ctxmenu } from 'ctxmenu';
import $ from 'jquery';
import { marked } from "marked";
import { ctxmenu } from "ctxmenu";
import $ from "jquery";
export default {
emits: ['save'],
emits: ["save"],
data() {
return {
isOpenEditor: false,
isPreview: false,
isChanged: false,
content: "",
title: "",
id: -1
}
id: -1,
};
},
computed: {
previewText() {
return marked(this.content);
}
},
},
watch: {
content: {
handler(value, oldValue) {
this.isChanged = true;
}
},
},
title: {
handler(value, oldValue) {
this.isChanged = true;
}
}
},
},
},
methods: {
onFocusInput(e) {
$('.header-input-container input').attr('placeholder', 'Заголовок');
$(".header-input-container input").attr("placeholder", "Заголовок");
this.isOpenEditor = true;
},
onCloseClick(e) {
$('.header-input-container input')
.attr('placeholder', 'Придумайте что написать...')
$(".header-input-container input").attr(
"placeholder",
"Придумайте что написать..."
);
this.title = "";
this.content = "";
this.isOpenEditor = false;
this.isPreview = false;
this.id = -1;
},
onSaveClick(e) {
webview.invoke('saveNote', this.id, this.title, btoa(unescape(encodeURIComponent(this.content)))).then(
id => this.id = id);
this.$emit('save', e);
webview
.invoke(
"saveNote",
this.id,
this.title,
btoa(unescape(encodeURIComponent(this.content)))
)
.then((id) => (this.id = id));
this.$emit("save", e);
this.isChanged = false;
},
onExportClick(e) {
e.stopPropagation();
ctxmenu.show([
{ text: "Экспорт" },
{ text: ".TXT", action: () => webview.invoke('exportNote', this.id, 'txt') }
], e.target);
ctxmenu.show(
[
{ text: "Экспорт" },
{
text: ".TXT",
action: () =>
webview.invoke("exportNote", this.id, "txt"),
},
],
e.target
);
},
open(preview) {
this.isOpenEditor = true;
Expand All @@ -118,22 +196,25 @@ export default {
this.isPreview = !this.isPreview;
},
onSwitchVisibleEditorClick(e) {
const containerElement = $('.markdown-container');
if(e.offsetX >= containerElement.width() - 15 || e.offsetY >= containerElement.height() - 15) {
const containerElement = $(".markdown-container");
if (
e.offsetX >= containerElement.width() - 15 ||
e.offsetY >= containerElement.height() - 15
) {
return;
}
this.isPreview = false;
}
}
}
},
},
};
</script>

<style>
.editor-container {
display: flex;
flex-direction: column;
border-radius: 10px;
background-color: white;
background-color: white;
outline: rgb(78, 78, 78) solid 1.5px;
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.137);
}
Expand Down
Loading

0 comments on commit 442dabd

Please sign in to comment.