Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
catto | d4b4bd9363 |
|
@ -1,64 +0,0 @@
|
||||||
name: 'publish'
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- release
|
|
||||||
- main
|
|
||||||
|
|
||||||
# This workflow will trigger on each push to the `release` branch to create or update a GitHub release, build your app, and upload the artifacts to the release.
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish-tauri:
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
settings:
|
|
||||||
- platform: 'macos-latest' # for Arm based macs (M1 and above).
|
|
||||||
args: '--target aarch64-apple-darwin'
|
|
||||||
- platform: 'macos-latest' # for Intel based macs.
|
|
||||||
args: '--target x86_64-apple-darwin'
|
|
||||||
- platform: 'ubuntu-22.04' # for Tauri v1 you could replace this with ubuntu-20.04.
|
|
||||||
args: ''
|
|
||||||
- platform: 'windows-latest'
|
|
||||||
args: ''
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.settings.platform }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: setup node
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: lts/*
|
|
||||||
|
|
||||||
- name: install Rust stable
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
with:
|
|
||||||
# Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds.
|
|
||||||
targets: ${{ matrix.settings.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
|
|
||||||
|
|
||||||
- name: install dependencies (ubuntu only)
|
|
||||||
if: matrix.settings.platform == 'ubuntu-22.04' # This must match the platform value defined above.
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
|
|
||||||
# webkitgtk 4.0 is for Tauri v1 - webkitgtk 4.1 is for Tauri v2.
|
|
||||||
# You can remove the one that doesn't apply to your app to speed up the workflow a bit.
|
|
||||||
|
|
||||||
- name: install frontend dependencies
|
|
||||||
run: npm install # change this to npm, pnpm or bun depending on which one you use.
|
|
||||||
|
|
||||||
- uses: tauri-apps/tauri-action@v0
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
tagName: app-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
|
|
||||||
releaseName: 'App v__VERSION__'
|
|
||||||
releaseBody: 'See the assets to download this version and install.'
|
|
||||||
releaseDraft: true
|
|
||||||
prerelease: false
|
|
||||||
args: ${{ matrix.settings.args }}
|
|
||||||
|
|
21
README.md
21
README.md
|
@ -5,24 +5,3 @@ This template should help get you started developing with Tauri in vanilla HTML,
|
||||||
## Recommended IDE Setup
|
## Recommended IDE Setup
|
||||||
|
|
||||||
- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
||||||
|
|
||||||
# Android Build
|
|
||||||
https://v2.tauri.app/start/prerequisites/#android
|
|
||||||
|
|
||||||
Use the SDK Manager in Android Studio to install the following:
|
|
||||||
|
|
||||||
Android SDK Platform
|
|
||||||
Android SDK Platform-Tools
|
|
||||||
NDK (Side by side)
|
|
||||||
Android SDK Build-Tools
|
|
||||||
Android SDK Command-line Tools
|
|
||||||
|
|
||||||
|
|
||||||
`export JAVA_HOME=/opt/android-studio/jbr`
|
|
||||||
|
|
||||||
```
|
|
||||||
export ANDROID_HOME="$HOME/Android/Sdk"
|
|
||||||
export NDK_HOME="$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)"
|
|
||||||
```
|
|
||||||
|
|
||||||
`rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android`
|
|
109
index.html
109
index.html
|
@ -1,10 +1,11 @@
|
||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="stylesheet" href="/src/styles.css" />
|
<link rel="stylesheet" href="/src/styles.css" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Snotes</title>
|
<title>Snotes Deck</title>
|
||||||
<script type="module" src="/src/main.ts" defer></script>
|
<script type="module" src="/src/main.ts" defer></script>
|
||||||
<style>
|
<style>
|
||||||
.logo.vite:hover {
|
.logo.vite:hover {
|
||||||
|
@ -18,48 +19,26 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div class="top-bar">
|
||||||
<div class="menu" id="contextMenu">
|
<div class="menu" id="contextMenu">
|
||||||
<button id="deleteButton">Delete</button>
|
<button id="deleteButton">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="top-bar">
|
|
||||||
<div id="button-row">
|
<div id="button-row">
|
||||||
<button class="row" id="show-notes-button">Refresh Notes</button>
|
<button class="row" id="show-notes-button">Refresh Notes</button>
|
||||||
<button class="row" type="submit" id="save-button">Save</button>
|
<button type="submit" id="save-button">Save</button>
|
||||||
<button class="row" id="new-button">New</button>
|
<button class="row" id="new-button">New</button>
|
||||||
<button class="row" id="image-button">OCR</button>
|
<button class="row" id="image-button">OCR</button>
|
||||||
<button class="row" id="export-button">Export</button>
|
<input type="file" id="fileInput" accept="image/*" style="display: none;" />
|
||||||
<button class="row" id="settings-button">Settings</button>
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
id="fileInput"
|
|
||||||
accept="image/*"
|
|
||||||
style="display: none"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="sidebar">
|
<div class="sidebar">
|
||||||
<div class="resizable-handle"></div>
|
|
||||||
<div class="searchbar-container">
|
<div class="searchbar-container">
|
||||||
<img
|
<input id="reverse-toggle" type="checkbox" checked="true"> Reverse
|
||||||
id="reverse-icon-asc"
|
<input type="search" name="note-search" id="note-searchbar" placeholder="Search...">
|
||||||
src="./src/assets/sort-from-bottom-to-top.svg"
|
|
||||||
/>
|
|
||||||
<img
|
|
||||||
id="reverse-icon-desc"
|
|
||||||
src="./src/assets/sort-from-top-to-bottom.svg"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
name="note-search"
|
|
||||||
id="note-searchbar"
|
|
||||||
placeholder="Search..."
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div class="note-sidebar-container" id="note-sidebar-container">
|
||||||
class="note-sidebar-container unselectable"
|
|
||||||
id="note-sidebar-container"
|
|
||||||
>
|
|
||||||
<!-- This is how the generated notes will look like:
|
<!-- This is how the generated notes will look like:
|
||||||
<div class="sidebar-note rightclick-element">
|
<div class="sidebar-note rightclick-element">
|
||||||
<span class="sidebar-note-id">1</span>
|
<span class="sidebar-note-id">1</span>
|
||||||
|
@ -70,74 +49,26 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="editor">
|
<div class="editor">
|
||||||
<input
|
<input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" id="create-tag"
|
||||||
autocomplete="off"
|
placeholder="Tag..." />
|
||||||
autocorrect="off"
|
<textarea autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" id="create-input"
|
||||||
autocapitalize="off"
|
placeholder="Type your note here..."></textarea>
|
||||||
spellcheck="false"
|
|
||||||
id="create-tag"
|
|
||||||
placeholder="Tag..."
|
|
||||||
/>
|
|
||||||
|
|
||||||
<textarea
|
|
||||||
autocomplete="off"
|
|
||||||
autocorrect="off"
|
|
||||||
autocapitalize="off"
|
|
||||||
spellcheck="false"
|
|
||||||
id="create-input"
|
|
||||||
placeholder="Type your note here..."
|
|
||||||
></textarea>
|
|
||||||
|
|
||||||
<p id="create-msg"></p>
|
<p id="create-msg"></p>
|
||||||
|
|
||||||
<p style="white-space: pre-line" id="notes-list"></p>
|
<p style="white-space: pre-line" id="notes-list"></p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="id-modal-bg"></div>
|
<div id="id-modal-bg"></div>
|
||||||
<div id="id-modal-container">
|
<div id="id-modal-container">
|
||||||
<div class="openbyid-bar-container">
|
<div class="openbyid-bar-container">
|
||||||
<input
|
<input type="text" name="id-search" id="id-search" placeholder="Note ID...">
|
||||||
type="text"
|
|
||||||
name="id-search"
|
|
||||||
id="id-search"
|
|
||||||
placeholder="Note ID..."
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="settings-modal-container">
|
|
||||||
<div class="settings-flex">
|
|
||||||
<h2 class="row"><code>SNOTES</code></h2>
|
|
||||||
<p><small id="app-version"></small></p>
|
|
||||||
<div class="fontsize-setting">
|
|
||||||
<h3>Font Size (in px)</h3>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
name="fontsize"
|
|
||||||
id="fontsize-setting-input"
|
|
||||||
placeholder=""
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div id="ocrlanguage-setting">
|
|
||||||
<div>
|
|
||||||
<h3>OCR Language</h3>
|
|
||||||
<a
|
|
||||||
style="display: inline"
|
|
||||||
href="https://tesseract-ocr.github.io/tessdoc/Data-Files"
|
|
||||||
target="_blank"
|
|
||||||
>Language Codes</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
name="ocrlanguage"
|
|
||||||
id="ocr-language-setting-input"
|
|
||||||
placeholder="eng"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button class="save-button" id="save-settings-button">Save</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
|
@ -176,8 +176,6 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"home",
|
"home",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
|
||||||
"serde_derive",
|
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -198,12 +196,6 @@ version = "0.4.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memchr"
|
|
||||||
version = "2.7.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.2.18"
|
version = "0.2.18"
|
||||||
|
@ -227,9 +219,9 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.91"
|
version = "1.0.79"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "307e3004becf10f5a6e0d59d20f3cd28231b0e0827a96cd3e0ce6d14bc1e4bb3"
|
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
@ -265,18 +257,18 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.215"
|
version = "1.0.197"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.215"
|
version = "1.0.197"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -285,12 +277,11 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.133"
|
version = "1.0.115"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377"
|
checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
@ -303,9 +294,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.89"
|
version = "2.0.58"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e"
|
checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
@ -8,8 +8,6 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.37"
|
chrono = "0.4.37"
|
||||||
home = "0.5.9"
|
home = "0.5.9"
|
||||||
serde = "1.0.215"
|
|
||||||
serde_derive = "1.0.215"
|
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.115"
|
||||||
[dependencies.rusqlite]
|
[dependencies.rusqlite]
|
||||||
version = "0.31.0"
|
version = "0.31.0"
|
||||||
|
|
|
@ -2,8 +2,6 @@ use chrono::Local;
|
||||||
use home::home_dir;
|
use home::home_dir;
|
||||||
use rusqlite::{Connection, Result};
|
use rusqlite::{Connection, Result};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::fs;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
pub struct Note {
|
pub struct Note {
|
||||||
id: i32,
|
id: i32,
|
||||||
|
@ -12,19 +10,9 @@ pub struct Note {
|
||||||
tag: String,
|
tag: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_db_dir() -> PathBuf {
|
|
||||||
let dir = home_dir().unwrap().join(".snotes-data");
|
|
||||||
dbg!(&dir);
|
|
||||||
if !&dir.exists() {
|
|
||||||
fs::create_dir(&dir).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
dir.join(".snotes.db")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_db() -> Result<()> {
|
pub fn init_db() -> Result<()> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db)?;
|
let connection = Connection::open(home)?;
|
||||||
|
|
||||||
let query_table = "
|
let query_table = "
|
||||||
CREATE TABLE IF NOT EXISTS notes (
|
CREATE TABLE IF NOT EXISTS notes (
|
||||||
|
@ -33,6 +21,11 @@ pub fn init_db() -> Result<()> {
|
||||||
date TEXT NOT NULL,
|
date TEXT NOT NULL,
|
||||||
tag TEXT
|
tag TEXT
|
||||||
);
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS favourites (
|
||||||
|
fid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
nid INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (nid) REFERENCES notes (nid) ON DELETE CASCADE
|
||||||
|
);
|
||||||
";
|
";
|
||||||
|
|
||||||
match connection.execute(query_table, []) {
|
match connection.execute(query_table, []) {
|
||||||
|
@ -44,8 +37,8 @@ pub fn init_db() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_note(content: &String, tag: &String) -> Result<()> {
|
pub fn create_note(content: &String, tag: &String) -> Result<()> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db)?;
|
let connection = Connection::open(home)?;
|
||||||
let date = Local::now();
|
let date = Local::now();
|
||||||
let date_string = date.format("%m-%d-%y %H:%M").to_string();
|
let date_string = date.format("%m-%d-%y %H:%M").to_string();
|
||||||
let tag_string = if *tag == String::new() {
|
let tag_string = if *tag == String::new() {
|
||||||
|
@ -56,7 +49,7 @@ pub fn create_note(content: &String, tag: &String) -> Result<()> {
|
||||||
|
|
||||||
let query_insert = "INSERT INTO notes (content, date, tag) VALUES (?1, ?2, ?3)";
|
let query_insert = "INSERT INTO notes (content, date, tag) VALUES (?1, ?2, ?3)";
|
||||||
|
|
||||||
match connection.execute(query_insert, [content, &date_string, &tag_string]) {
|
match connection.execute(query_insert, [&content, &date_string, &tag_string]) {
|
||||||
Ok(v) => println!("CREATE OK {}", v),
|
Ok(v) => println!("CREATE OK {}", v),
|
||||||
Err(e) => println!("CREATE ERR {}", e),
|
Err(e) => println!("CREATE ERR {}", e),
|
||||||
};
|
};
|
||||||
|
@ -65,8 +58,8 @@ pub fn create_note(content: &String, tag: &String) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_notes(all: bool, tag: &str) -> Result<String, String> {
|
pub fn show_notes(all: bool, tag: &str) -> Result<String, String> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db).unwrap();
|
let connection = Connection::open(home).unwrap();
|
||||||
|
|
||||||
let mut query = "SELECT * FROM notes LIMIT 10".to_string();
|
let mut query = "SELECT * FROM notes LIMIT 10".to_string();
|
||||||
|
|
||||||
|
@ -110,8 +103,8 @@ pub fn show_notes(all: bool, tag: &str) -> Result<String, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_latest_note() -> Result<(), String> {
|
pub fn delete_latest_note() -> Result<(), String> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db).map_err(|e| format!("Database Error: {e}"))?;
|
let connection = Connection::open(home).map_err(|e| format!("Database Error: {e}"))?;
|
||||||
|
|
||||||
let query = String::from("DELETE FROM NOTES WHERE nid = (SELECT MAX(nid) FROM notes)");
|
let query = String::from("DELETE FROM NOTES WHERE nid = (SELECT MAX(nid) FROM notes)");
|
||||||
|
|
||||||
|
@ -125,8 +118,8 @@ pub fn delete_latest_note() -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_specific_note(id: i32) -> Result<(), String> {
|
pub fn delete_specific_note(id: i32) -> Result<(), String> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db).map_err(|e| format!("Database Error: {e}"))?;
|
let connection = Connection::open(home).map_err(|e| format!("Database Error: {e}"))?;
|
||||||
|
|
||||||
let query = "DELETE FROM notes WHERE nid = ?1";
|
let query = "DELETE FROM notes WHERE nid = ?1";
|
||||||
match connection.execute(query, [id]) {
|
match connection.execute(query, [id]) {
|
||||||
|
@ -137,8 +130,8 @@ pub fn delete_specific_note(id: i32) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn edit_specific_note(id: i32, tag: &str, content: &str) -> Result<(), String> {
|
pub fn edit_specific_note(id: i32, tag: &str, content: &str) -> Result<(), String> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?;
|
let connection = Connection::open(home).map_err(|e| format!("Database Error: {}", e))?;
|
||||||
|
|
||||||
let query = "UPDATE notes SET tag = ?1, content = ?2 WHERE nid = ?3";
|
let query = "UPDATE notes SET tag = ?1, content = ?2 WHERE nid = ?3";
|
||||||
match connection.execute(query, [&tag, &content, &id.to_string().as_str()]) {
|
match connection.execute(query, [&tag, &content, &id.to_string().as_str()]) {
|
||||||
|
@ -150,8 +143,8 @@ pub fn edit_specific_note(id: i32, tag: &str, content: &str) -> Result<(), Strin
|
||||||
|
|
||||||
/// Looks for matches in both content and tag.
|
/// Looks for matches in both content and tag.
|
||||||
pub fn search_notes(query: &str) -> Result<String, String> {
|
pub fn search_notes(query: &str) -> Result<String, String> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?;
|
let connection = Connection::open(home).map_err(|e| format!("Database Error: {}", e))?;
|
||||||
|
|
||||||
let query = format!(
|
let query = format!(
|
||||||
"SELECT * FROM notes WHERE nid LIKE '%{}%' OR content LIKE '%{}%' OR tag LIKE '%{}%'",
|
"SELECT * FROM notes WHERE nid LIKE '%{}%' OR content LIKE '%{}%' OR tag LIKE '%{}%'",
|
||||||
|
@ -195,8 +188,8 @@ pub fn search_notes(query: &str) -> Result<String, String> {
|
||||||
/// get latest note
|
/// get latest note
|
||||||
/// Returns a json array string of size 1
|
/// Returns a json array string of size 1
|
||||||
pub fn get_latest_note() -> Result<String, String> {
|
pub fn get_latest_note() -> Result<String, String> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?;
|
let connection = Connection::open(home).map_err(|e| format!("Database Error: {}", e))?;
|
||||||
|
|
||||||
let query = "SELECT * FROM notes WHERE ROWID IN (SELECT max(ROWID) FROM notes);
|
let query = "SELECT * FROM notes WHERE ROWID IN (SELECT max(ROWID) FROM notes);
|
||||||
"
|
"
|
||||||
|
@ -236,10 +229,10 @@ pub fn get_latest_note() -> Result<String, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_note_by_id(id: u32) -> Result<String, String> {
|
pub fn get_note_by_id(id: u32) -> Result<String, String> {
|
||||||
let db = get_db_dir();
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?;
|
let connection = Connection::open(home).map_err(|e| format!("Database Error: {}", e))?;
|
||||||
|
|
||||||
let query = format!("SELECT * FROM notes WHERE nid IS {};", id);
|
let query = format!("SELECT * FROM notes WHERE nid IS {};", id.to_string());
|
||||||
let mut prepare = connection
|
let mut prepare = connection
|
||||||
.prepare(&query)
|
.prepare(&query)
|
||||||
.map_err(|e| format!("Query Error: {}", e))?;
|
.map_err(|e| format!("Query Error: {}", e))?;
|
||||||
|
@ -274,42 +267,6 @@ pub fn get_note_by_id(id: u32) -> Result<String, String> {
|
||||||
Ok(json_string)
|
Ok(json_string)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all notes as a json
|
|
||||||
pub fn export_all() -> Result<String, String> {
|
|
||||||
let db = get_db_dir();
|
|
||||||
let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?;
|
|
||||||
|
|
||||||
let query = "SELECT * FROM notes";
|
|
||||||
let mut prepare = connection.prepare(query).unwrap();
|
|
||||||
|
|
||||||
let notes = prepare
|
|
||||||
.query_map([], |row| {
|
|
||||||
Ok(Note {
|
|
||||||
id: row.get(0)?,
|
|
||||||
content: row.get(1)?,
|
|
||||||
date: row.get(2)?,
|
|
||||||
tag: row.get(3)?,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut json_array = Vec::new();
|
|
||||||
|
|
||||||
for note in notes {
|
|
||||||
let unwrapped = note.unwrap();
|
|
||||||
let note_json = json!({
|
|
||||||
"id": unwrapped.id,
|
|
||||||
"date": unwrapped.date,
|
|
||||||
"content": unwrapped.content,
|
|
||||||
"tag": unwrapped.tag
|
|
||||||
});
|
|
||||||
json_array.push(note_json);
|
|
||||||
}
|
|
||||||
|
|
||||||
let json_string = serde_json::to_string_pretty(&json_array).unwrap();
|
|
||||||
Ok(json_string)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -325,5 +282,6 @@ mod tests {
|
||||||
fn test_id_10() {
|
fn test_id_10() {
|
||||||
let result = get_note_by_id(10).unwrap();
|
let result = get_note_by_id(10).unwrap();
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
|
assert!(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,11 @@
|
||||||
"name": "snotes-deck",
|
"name": "snotes-deck",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^2.1.1",
|
"@tauri-apps/api": "^1",
|
||||||
"@tauri-apps/plugin-dialog": "^2.0.1",
|
|
||||||
"@tauri-apps/plugin-fs": "^2.0.2",
|
|
||||||
"@tauri-apps/plugin-shell": "^2.0.1",
|
|
||||||
"tesseract.js": "^5.0.5"
|
"tesseract.js": "^5.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tauri-apps/cli": "^2.1.0",
|
"@tauri-apps/cli": "^1",
|
||||||
"typescript": "^5.0.2",
|
"typescript": "^5.0.2",
|
||||||
"vite": "^5.0.0"
|
"vite": "^5.0.0"
|
||||||
}
|
}
|
||||||
|
@ -584,21 +581,24 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/api": {
|
"node_modules/@tauri-apps/api": {
|
||||||
"version": "2.1.1",
|
"version": "1.5.3",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-1.5.3.tgz",
|
||||||
"integrity": "sha512-fzUfFFKo4lknXGJq8qrCidkUcKcH2UHhfaaCNt4GzgzGaW2iS26uFOg4tS3H4P8D6ZEeUxtiD5z0nwFF0UN30A==",
|
"integrity": "sha512-zxnDjHHKjOsrIzZm6nO5Xapb/BxqUq1tc7cGkFXsFkGTsSWgCPH1D8mm0XS9weJY2OaR73I3k3S+b7eSzJDfqA==",
|
||||||
"license": "Apache-2.0 OR MIT",
|
"engines": {
|
||||||
|
"node": ">= 14.6.0",
|
||||||
|
"npm": ">= 6.6.0",
|
||||||
|
"yarn": ">= 1.19.1"
|
||||||
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"type": "opencollective",
|
"type": "opencollective",
|
||||||
"url": "https://opencollective.com/tauri"
|
"url": "https://opencollective.com/tauri"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli": {
|
"node_modules/@tauri-apps/cli": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli/-/cli-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli/-/cli-1.5.11.tgz",
|
||||||
"integrity": "sha512-K2VhcKqBhAeS5pNOVdnR/xQRU6jwpgmkSL2ejHXcl0m+kaTggT0WRDQnFtPq6NljA7aE03cvwsbCAoFG7vtkJw==",
|
"integrity": "sha512-B475D7phZrq5sZ3kDABH4g2mEoUIHtnIO+r4ZGAAfsjMbZCwXxR/jlMGTEL+VO3YzjpF7gQe38IzB4vLBbVppw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"tauri": "tauri.js"
|
"tauri": "tauri.js"
|
||||||
},
|
},
|
||||||
|
@ -610,27 +610,26 @@
|
||||||
"url": "https://opencollective.com/tauri"
|
"url": "https://opencollective.com/tauri"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@tauri-apps/cli-darwin-arm64": "2.1.0",
|
"@tauri-apps/cli-darwin-arm64": "1.5.11",
|
||||||
"@tauri-apps/cli-darwin-x64": "2.1.0",
|
"@tauri-apps/cli-darwin-x64": "1.5.11",
|
||||||
"@tauri-apps/cli-linux-arm-gnueabihf": "2.1.0",
|
"@tauri-apps/cli-linux-arm-gnueabihf": "1.5.11",
|
||||||
"@tauri-apps/cli-linux-arm64-gnu": "2.1.0",
|
"@tauri-apps/cli-linux-arm64-gnu": "1.5.11",
|
||||||
"@tauri-apps/cli-linux-arm64-musl": "2.1.0",
|
"@tauri-apps/cli-linux-arm64-musl": "1.5.11",
|
||||||
"@tauri-apps/cli-linux-x64-gnu": "2.1.0",
|
"@tauri-apps/cli-linux-x64-gnu": "1.5.11",
|
||||||
"@tauri-apps/cli-linux-x64-musl": "2.1.0",
|
"@tauri-apps/cli-linux-x64-musl": "1.5.11",
|
||||||
"@tauri-apps/cli-win32-arm64-msvc": "2.1.0",
|
"@tauri-apps/cli-win32-arm64-msvc": "1.5.11",
|
||||||
"@tauri-apps/cli-win32-ia32-msvc": "2.1.0",
|
"@tauri-apps/cli-win32-ia32-msvc": "1.5.11",
|
||||||
"@tauri-apps/cli-win32-x64-msvc": "2.1.0"
|
"@tauri-apps/cli-win32-x64-msvc": "1.5.11"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-darwin-arm64": {
|
"node_modules/@tauri-apps/cli-darwin-arm64": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-1.5.11.tgz",
|
||||||
"integrity": "sha512-ESc6J6CE8hl1yKH2vJ+ALF+thq4Be+DM1mvmTyUCQObvezNCNhzfS6abIUd3ou4x5RGH51ouiANeT3wekU6dCw==",
|
"integrity": "sha512-2NLSglDb5VfvTbMtmOKWyD+oaL/e8Z/ZZGovHtUFyUSFRabdXc6cZOlcD1BhFvYkHqm+TqGaz5qtPR5UbqDs8A==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
|
@ -640,14 +639,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-darwin-x64": {
|
"node_modules/@tauri-apps/cli-darwin-x64": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-1.5.11.tgz",
|
||||||
"integrity": "sha512-TasHS442DFs8cSH2eUQzuDBXUST4ECjCd0yyP+zZzvAruiB0Bg+c8A+I/EnqCvBQ2G2yvWLYG8q/LI7c87A5UA==",
|
"integrity": "sha512-/RQllHiJRH2fJOCudtZlaUIjofkHzP3zZgxi71ZUm7Fy80smU5TDfwpwOvB0wSVh0g/ciDjMArCSTo0MRvL+ag==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
|
@ -657,14 +655,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-linux-arm-gnueabihf": {
|
"node_modules/@tauri-apps/cli-linux-arm-gnueabihf": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-1.5.11.tgz",
|
||||||
"integrity": "sha512-aP7ZBGNL4ny07Cbb6kKpUOSrmhcIK2KhjviTzYlh+pPhAptxnC78xQGD3zKQkTi2WliJLPmBYbOHWWQa57lQ9w==",
|
"integrity": "sha512-IlBuBPKmMm+a5LLUEK6a21UGr9ZYd6zKuKLq6IGM4tVweQa8Sf2kP2Nqs74dMGIUrLmMs0vuqdURpykQg+z4NQ==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm"
|
"arm"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
|
@ -674,14 +671,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-linux-arm64-gnu": {
|
"node_modules/@tauri-apps/cli-linux-arm64-gnu": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-1.5.11.tgz",
|
||||||
"integrity": "sha512-ZTdgD5gLeMCzndMT2f358EkoYkZ5T+Qy6zPzU+l5vv5M7dHVN9ZmblNAYYXmoOuw7y+BY4X/rZvHV9pcGrcanQ==",
|
"integrity": "sha512-w+k1bNHCU/GbmXshtAhyTwqosThUDmCEFLU4Zkin1vl2fuAtQry2RN7thfcJFepblUGL/J7yh3Q/0+BCjtspKQ==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
|
@ -691,14 +687,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-linux-arm64-musl": {
|
"node_modules/@tauri-apps/cli-linux-arm64-musl": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.5.11.tgz",
|
||||||
"integrity": "sha512-NzwqjUCilhnhJzusz3d/0i0F1GFrwCQbkwR6yAHUxItESbsGYkZRJk0yMEWkg3PzFnyK4cWTlQJMEU52TjhEzA==",
|
"integrity": "sha512-PN6/dl+OfYQ/qrAy4HRAfksJ2AyWQYn2IA/2Wwpaa7SDRz2+hzwTQkvajuvy0sQ5L2WCG7ymFYRYMbpC6Hk9Pg==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
|
@ -708,14 +703,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-linux-x64-gnu": {
|
"node_modules/@tauri-apps/cli-linux-x64-gnu": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-1.5.11.tgz",
|
||||||
"integrity": "sha512-TyiIpMEtZxNOQmuFyfJwaaYbg3movSthpBJLIdPlKxSAB2BW0VWLY3/ZfIxm/G2YGHyREkjJvimzYE0i37PnMA==",
|
"integrity": "sha512-MTVXLi89Nj7Apcvjezw92m7ZqIDKT5SFKZtVPCg6RoLUBTzko/BQoXYIRWmdoz2pgkHDUHgO2OMJ8oKzzddXbw==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
|
@ -725,14 +719,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-linux-x64-musl": {
|
"node_modules/@tauri-apps/cli-linux-x64-musl": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-1.5.11.tgz",
|
||||||
"integrity": "sha512-/dQd0TlaxBdJACrR72DhynWftzHDaX32eBtS5WBrNJ+nnNb+znM3gON6nJ9tSE9jgDa6n1v2BkI/oIDtypfUXw==",
|
"integrity": "sha512-kwzAjqFpz7rvTs7WGZLy/a5nS5t15QKr3E9FG95MNF0exTl3d29YoAUAe1Mn0mOSrTJ9Z+vYYAcI/QdcsGBP+w==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
|
@ -742,14 +735,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-win32-arm64-msvc": {
|
"node_modules/@tauri-apps/cli-win32-arm64-msvc": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-1.5.11.tgz",
|
||||||
"integrity": "sha512-NdQJO7SmdYqOcE+JPU7bwg7+odfZMWO6g8xF9SXYCMdUzvM2Gv/AQfikNXz5yS7ralRhNFuW32i5dcHlxh4pDg==",
|
"integrity": "sha512-L+5NZ/rHrSUrMxjj6YpFYCXp6wHnq8c8SfDTBOX8dO8x+5283/vftb4vvuGIsLS4UwUFXFnLt3XQr44n84E67Q==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
|
@ -759,14 +751,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-win32-ia32-msvc": {
|
"node_modules/@tauri-apps/cli-win32-ia32-msvc": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-1.5.11.tgz",
|
||||||
"integrity": "sha512-f5h8gKT/cB8s1ticFRUpNmHqkmaLutT62oFDB7N//2YTXnxst7EpMIn1w+QimxTvTk2gcx6EcW6bEk/y2hZGzg==",
|
"integrity": "sha512-oVlD9IVewrY0lZzTdb71kNXkjdgMqFq+ohb67YsJb4Rf7o8A9DTlFds1XLCe3joqLMm4M+gvBKD7YnGIdxQ9vA==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"ia32"
|
"ia32"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
|
@ -776,14 +767,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/cli-win32-x64-msvc": {
|
"node_modules/@tauri-apps/cli-win32-x64-msvc": {
|
||||||
"version": "2.1.0",
|
"version": "1.5.11",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-1.5.11.tgz",
|
||||||
"integrity": "sha512-P/+LrdSSb5Xbho1LRP4haBjFHdyPdjWvGgeopL96OVtrFpYnfC+RctB45z2V2XxqFk3HweDDxk266btjttfjGw==",
|
"integrity": "sha512-1CexcqUFCis5ypUIMOKllxUBrna09McbftWENgvVXMfA+SP+yPDPAVb8fIvUcdTIwR/yHJwcIucmTB4anww4vg==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0 OR MIT",
|
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
|
@ -792,33 +782,6 @@
|
||||||
"node": ">= 10"
|
"node": ">= 10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tauri-apps/plugin-dialog": {
|
|
||||||
"version": "2.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-dialog/-/plugin-dialog-2.0.1.tgz",
|
|
||||||
"integrity": "sha512-fnUrNr6EfvTqdls/ufusU7h6UbNFzLKvHk/zTuOiBq01R3dTODqwctZlzakdbfSp/7pNwTKvgKTAgl/NAP/Z0Q==",
|
|
||||||
"license": "MIT OR Apache-2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@tauri-apps/api": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@tauri-apps/plugin-fs": {
|
|
||||||
"version": "2.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-fs/-/plugin-fs-2.0.2.tgz",
|
|
||||||
"integrity": "sha512-4YZaX2j7ta81M5/DL8aN10kTnpUkEpkPo1FTYPT8Dd0ImHe3azM8i8MrtjrDGoyBYLPO3zFv7df/mSCYF8oA0Q==",
|
|
||||||
"license": "MIT OR Apache-2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@tauri-apps/api": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@tauri-apps/plugin-shell": {
|
|
||||||
"version": "2.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-shell/-/plugin-shell-2.0.1.tgz",
|
|
||||||
"integrity": "sha512-akU1b77sw3qHiynrK0s930y8zKmcdrSD60htjH+mFZqv5WaakZA/XxHR3/sF1nNv9Mgmt/Shls37HwnOr00aSw==",
|
|
||||||
"license": "MIT OR Apache-2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@tauri-apps/api": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@types/estree": {
|
"node_modules/@types/estree": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
|
||||||
|
|
|
@ -10,14 +10,11 @@
|
||||||
"tauri": "tauri"
|
"tauri": "tauri"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^2.1.1",
|
"@tauri-apps/api": "^1",
|
||||||
"@tauri-apps/plugin-dialog": "^2.0.1",
|
|
||||||
"@tauri-apps/plugin-fs": "^2.0.2",
|
|
||||||
"@tauri-apps/plugin-shell": "^2.0.1",
|
|
||||||
"tesseract.js": "^5.0.5"
|
"tesseract.js": "^5.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tauri-apps/cli": "^2.1.0",
|
"@tauri-apps/cli": "^1",
|
||||||
"typescript": "^5.0.2",
|
"typescript": "^5.0.2",
|
||||||
"vite": "^5.0.0"
|
"vite": "^5.0.0"
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "snotes-deck"
|
name = "snotes-deck"
|
||||||
version = "0.0.15"
|
version = "0.0.0"
|
||||||
description = "A simple little Note App"
|
description = "A simple little Note App"
|
||||||
authors = ["you"]
|
authors = ["you"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -8,17 +8,14 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-build = { version = "2", features = [] }
|
tauri-build = { version = "1", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri = { version = "2", features = [] }
|
tauri = { version = "1", features = ["shell-open"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
libsnotes = { path = "../libsnotes" }
|
libsnotes = { path = "../libsnotes" }
|
||||||
home = "0.5.9"
|
home = "0.5.9"
|
||||||
tauri-plugin-shell = "2"
|
|
||||||
tauri-plugin-dialog = "2"
|
|
||||||
tauri-plugin-fs = "2"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
|
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"identifier": "migrated",
|
|
||||||
"description": "permissions that were migrated from v1",
|
|
||||||
"local": true,
|
|
||||||
"windows": [
|
|
||||||
"main"
|
|
||||||
],
|
|
||||||
"permissions": [
|
|
||||||
"core:default",
|
|
||||||
"fs:allow-read-file",
|
|
||||||
"fs:allow-write-file",
|
|
||||||
"fs:allow-read-dir",
|
|
||||||
"shell:allow-open",
|
|
||||||
"dialog:allow-open",
|
|
||||||
"dialog:allow-save",
|
|
||||||
"dialog:allow-message",
|
|
||||||
"dialog:allow-ask",
|
|
||||||
"dialog:allow-confirm",
|
|
||||||
"shell:default",
|
|
||||||
"dialog:default",
|
|
||||||
"fs:default"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -5,27 +5,11 @@ use std::fs;
|
||||||
|
|
||||||
use home::home_dir;
|
use home::home_dir;
|
||||||
use libsnotes::show_notes;
|
use libsnotes::show_notes;
|
||||||
use tauri::{
|
|
||||||
menu::{AboutMetadata, MenuBuilder, MenuItemBuilder, SubmenuBuilder},
|
|
||||||
Emitter,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn export_all_notes() -> String {
|
fn greet(name: &str) -> String {
|
||||||
let res = libsnotes::export_all().unwrap();
|
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||||
println!("{}", &res);
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn get_app_version() -> String {
|
|
||||||
env!("CARGO_PKG_VERSION").to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn init_db() {
|
|
||||||
libsnotes::init_db().unwrap();
|
|
||||||
println!("initted")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get ALL notes in the Database. If you don't want this, set show_notes(false)
|
/// get ALL notes in the Database. If you don't want this, set show_notes(false)
|
||||||
|
@ -43,7 +27,8 @@ fn get_latest_note() -> String {
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn get_note_by_id(id: u32) -> String {
|
fn get_note_by_id(id: u32) -> String {
|
||||||
libsnotes::get_note_by_id(id).unwrap()
|
let result = libsnotes::get_note_by_id(id).unwrap();
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
@ -92,8 +77,7 @@ fn init_settings() {
|
||||||
|
|
||||||
let settings = r#"
|
let settings = r#"
|
||||||
{
|
{
|
||||||
"fontSize": "16px",
|
"fontSize": "16px"
|
||||||
"ocrLanguage": "eng",
|
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
@ -106,55 +90,10 @@ fn init_settings() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn save_settings(settings: String) {
|
|
||||||
fs::write(
|
|
||||||
home_dir()
|
|
||||||
.unwrap()
|
|
||||||
.join(".snotes-data/snotes-settings.json"),
|
|
||||||
settings,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.setup(|app| {
|
|
||||||
app.handle();
|
|
||||||
|
|
||||||
let settings = MenuItemBuilder::new("Export All")
|
|
||||||
.id("exportall")
|
|
||||||
//.accelerator("CmdOrCtrl+,")
|
|
||||||
.build(app)?;
|
|
||||||
|
|
||||||
let app_submenu = SubmenuBuilder::new(app, "File")
|
|
||||||
.about(Some(AboutMetadata {
|
|
||||||
..Default::default()
|
|
||||||
}))
|
|
||||||
.separator()
|
|
||||||
.item(&settings)
|
|
||||||
.build()?;
|
|
||||||
|
|
||||||
let menu = MenuBuilder::new(app).items(&[&app_submenu]).build()?;
|
|
||||||
|
|
||||||
app.set_menu(menu)?;
|
|
||||||
|
|
||||||
app.on_menu_event(move |app, event| {
|
|
||||||
if event.id() == settings.id() {
|
|
||||||
// emit a window event to the frontend
|
|
||||||
let _event = app.emit("custom-event", "/exportall");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.plugin(tauri_plugin_fs::init())
|
|
||||||
.plugin(tauri_plugin_dialog::init())
|
|
||||||
.plugin(tauri_plugin_shell::init())
|
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
export_all_notes,
|
greet,
|
||||||
get_app_version,
|
|
||||||
init_db,
|
|
||||||
get_notes_list,
|
get_notes_list,
|
||||||
get_latest_note,
|
get_latest_note,
|
||||||
get_note_by_id,
|
get_note_by_id,
|
||||||
|
@ -163,8 +102,7 @@ fn main() {
|
||||||
delete_specific_note,
|
delete_specific_note,
|
||||||
update_specific_note,
|
update_specific_note,
|
||||||
init_settings,
|
init_settings,
|
||||||
load_settings,
|
load_settings
|
||||||
save_settings
|
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|
|
@ -2,12 +2,36 @@
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
"beforeBuildCommand": "npm run build",
|
"beforeBuildCommand": "npm run build",
|
||||||
"frontendDist": "../dist",
|
"devPath": "http://localhost:1420",
|
||||||
"devUrl": "http://localhost:1420"
|
"distDir": "../dist",
|
||||||
|
"withGlobalTauri": true
|
||||||
|
},
|
||||||
|
"package": {
|
||||||
|
"productName": "snotes-deck",
|
||||||
|
"version": "0.0.7"
|
||||||
|
},
|
||||||
|
"tauri": {
|
||||||
|
"allowlist": {
|
||||||
|
"all": false,
|
||||||
|
"shell": {
|
||||||
|
"all": false,
|
||||||
|
"open": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"windows": [
|
||||||
|
{
|
||||||
|
"title": "Snotes Deck",
|
||||||
|
"width": 800,
|
||||||
|
"height": 600
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"security": {
|
||||||
|
"csp": null
|
||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"active": true,
|
"active": true,
|
||||||
"targets": "all",
|
"targets": "all",
|
||||||
|
"identifier": "space.maidsin.snotes-deck",
|
||||||
"icon": [
|
"icon": [
|
||||||
"icons/32x32.png",
|
"icons/32x32.png",
|
||||||
"icons/128x128.png",
|
"icons/128x128.png",
|
||||||
|
@ -15,24 +39,6 @@
|
||||||
"icons/icon.icns",
|
"icons/icon.icns",
|
||||||
"icons/icon.ico"
|
"icons/icon.ico"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"productName": "snotes-deck",
|
|
||||||
"mainBinaryName": "snotes-deck",
|
|
||||||
"version": "0.0.15",
|
|
||||||
"identifier": "space.maidsin.snotes-deck",
|
|
||||||
"plugins": {},
|
|
||||||
"app": {
|
|
||||||
"withGlobalTauri": true,
|
|
||||||
"windows": [
|
|
||||||
{
|
|
||||||
"title": "Snotes",
|
|
||||||
"width": 800,
|
|
||||||
"height": 600,
|
|
||||||
"useHttpsScheme": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"security": {
|
|
||||||
"csp": null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
|
||||||
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M4 8H13" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round"/>
|
|
||||||
<path d="M6 13H13" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round"/>
|
|
||||||
<path d="M8 18H13" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round"/>
|
|
||||||
<path d="M17 20V4L20 8" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 575 B |
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
|
||||||
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M4 16L13 16" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round"/>
|
|
||||||
<path d="M6 11H13" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round"/>
|
|
||||||
<path d="M8 6L13 6" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round"/>
|
|
||||||
<path d="M17 4L17 20L20 16" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 584 B |
|
@ -0,0 +1,6 @@
|
||||||
|
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
|
||||||
|
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.5 KiB |
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||||
|
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||||
|
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000"
|
||||||
|
preserveAspectRatio="xMidYMid meet">
|
||||||
|
|
||||||
|
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||||
|
fill="#2D79C7" stroke="none">
|
||||||
|
<path d="M430 5109 c-130 -19 -248 -88 -325 -191 -53 -71 -83 -147 -96 -247
|
||||||
|
-6 -49 -9 -813 -7 -2166 l3 -2090 22 -65 c54 -159 170 -273 328 -323 l70 -22
|
||||||
|
2140 0 2140 0 66 23 c160 55 272 169 322 327 l22 70 0 2135 0 2135 -22 70
|
||||||
|
c-49 157 -155 265 -319 327 l-59 23 -2115 1 c-1163 1 -2140 -2 -2170 -7z
|
||||||
|
m3931 -2383 c48 -9 120 -26 160 -39 l74 -23 3 -237 c1 -130 0 -237 -2 -237 -3
|
||||||
|
0 -26 14 -53 30 -61 38 -197 84 -310 106 -110 20 -293 15 -368 -12 -111 -39
|
||||||
|
-175 -110 -175 -193 0 -110 97 -197 335 -300 140 -61 309 -146 375 -189 30
|
||||||
|
-20 87 -68 126 -107 119 -117 164 -234 164 -426 0 -310 -145 -518 -430 -613
|
||||||
|
-131 -43 -248 -59 -445 -60 -243 -1 -405 24 -577 90 l-68 26 0 242 c0 175 -3
|
||||||
|
245 -12 254 -9 9 -9 12 0 12 7 0 12 -4 12 -9 0 -17 139 -102 223 -138 136 -57
|
||||||
|
233 -77 382 -76 145 0 224 19 295 68 75 52 100 156 59 242 -41 84 -135 148
|
||||||
|
-374 253 -367 161 -522 300 -581 520 -23 86 -23 253 -1 337 73 275 312 448
|
||||||
|
682 492 109 13 401 6 506 -13z m-1391 -241 l0 -205 -320 0 -320 0 0 -915 0
|
||||||
|
-915 -255 0 -255 0 0 915 0 915 -320 0 -320 0 0 205 0 205 895 0 895 0 0 -205z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.4 KiB |
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
663
src/main.ts
663
src/main.ts
|
@ -1,9 +1,6 @@
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/tauri";
|
||||||
import { save } from "@tauri-apps/plugin-dialog";
|
|
||||||
import { Note, Settings } from "./model";
|
import { Note, Settings } from "./model";
|
||||||
import { createWorker } from "tesseract.js";
|
import { createWorker } from 'tesseract.js';
|
||||||
import { writeTextFile } from "@tauri-apps/plugin-fs";
|
|
||||||
import { homeDir } from "@tauri-apps/api/path";
|
|
||||||
|
|
||||||
let notesMsgEl: HTMLElement | null;
|
let notesMsgEl: HTMLElement | null;
|
||||||
|
|
||||||
|
@ -12,9 +9,10 @@ let createNoteTagEl: HTMLInputElement | null;
|
||||||
|
|
||||||
let searchbarEl: HTMLInputElement | null;
|
let searchbarEl: HTMLInputElement | null;
|
||||||
let noteSidebarContainerEl: HTMLDivElement | null;
|
let noteSidebarContainerEl: HTMLDivElement | null;
|
||||||
|
let noteSidebarReverseCheckboxEl: HTMLInputElement | null;
|
||||||
let searchbarContents = "";
|
let searchbarContents = "";
|
||||||
|
|
||||||
let noteArray: Note[] = [];
|
let noteArray: Note[] = []
|
||||||
|
|
||||||
/** ID of current note, if we're editing an existing note */
|
/** ID of current note, if we're editing an existing note */
|
||||||
let currentNoteId: number | null = null;
|
let currentNoteId: number | null = null;
|
||||||
|
@ -24,17 +22,16 @@ let idModalActive = false;
|
||||||
|
|
||||||
let typingTimer: number | null = null;
|
let typingTimer: number | null = null;
|
||||||
const AUTOSAVE_DELAY = 5000;
|
const AUTOSAVE_DELAY = 5000;
|
||||||
const BACKGROUND_COLOR = "#252525";
|
|
||||||
const BACKGROUND_COLOR_HOVER = "#5C5C5C";
|
|
||||||
|
|
||||||
enum EditorState {
|
enum EditorState {
|
||||||
NEW,
|
NEW,
|
||||||
EDITING,
|
EDITING
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SearchState {
|
enum SearchState {
|
||||||
EMPTY,
|
EMPTY,
|
||||||
RESULTS,
|
RESULTS
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Editor always initializes in the NEW state */
|
/** Editor always initializes in the NEW state */
|
||||||
|
@ -52,21 +49,21 @@ async function saveNote() {
|
||||||
if (createNoteContentEl && createNoteTagEl) {
|
if (createNoteContentEl && createNoteTagEl) {
|
||||||
switch (editorState) {
|
switch (editorState) {
|
||||||
case EditorState.NEW:
|
case EditorState.NEW:
|
||||||
console.log("creating new note..");
|
console.log("creating new note..")
|
||||||
await invoke("create_note", {
|
await invoke("create_note", {
|
||||||
content: createNoteContentEl.value,
|
content: createNoteContentEl.value,
|
||||||
tag: createNoteTagEl.value,
|
tag: createNoteTagEl.value
|
||||||
});
|
});
|
||||||
//clearEditor();
|
//clearEditor();
|
||||||
refreshSidebarAndOpenLatestNote();
|
refreshSidebarAndOpenLatestNote();
|
||||||
break;
|
break;
|
||||||
case EditorState.EDITING:
|
case EditorState.EDITING:
|
||||||
console.log("updating existing note..");
|
console.log("updating existing note..")
|
||||||
if (currentNoteId !== null) {
|
if (currentNoteId !== null) {
|
||||||
await invoke("update_specific_note", {
|
await invoke("update_specific_note", {
|
||||||
id: currentNoteId,
|
id: currentNoteId,
|
||||||
content: createNoteContentEl.value,
|
content: createNoteContentEl.value,
|
||||||
tag: createNoteTagEl.value,
|
tag: createNoteTagEl.value
|
||||||
});
|
});
|
||||||
// do not clear the editor
|
// do not clear the editor
|
||||||
//clearEditor();
|
//clearEditor();
|
||||||
|
@ -93,7 +90,7 @@ async function showNotes() {
|
||||||
id: jsonObj.id,
|
id: jsonObj.id,
|
||||||
content: jsonObj.content,
|
content: jsonObj.content,
|
||||||
date: jsonObj.date,
|
date: jsonObj.date,
|
||||||
tag: jsonObj.tag,
|
tag: jsonObj.tag
|
||||||
}));
|
}));
|
||||||
|
|
||||||
fillNoteSidebar(noteArray, reversed);
|
fillNoteSidebar(noteArray, reversed);
|
||||||
|
@ -101,6 +98,7 @@ async function showNotes() {
|
||||||
searchNote(searchbarContents);
|
searchNote(searchbarContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
async function retrieveNotes(): Promise<Array<JSON>> {
|
async function retrieveNotes(): Promise<Array<JSON>> {
|
||||||
const notesString: string = await invoke("get_notes_list");
|
const notesString: string = await invoke("get_notes_list");
|
||||||
|
@ -118,20 +116,12 @@ async function retrieveNotes(): Promise<Array<JSON>> {
|
||||||
window.addEventListener("DOMContentLoaded", async () => {
|
window.addEventListener("DOMContentLoaded", async () => {
|
||||||
// settings
|
// settings
|
||||||
settings = await loadSettings();
|
settings = await loadSettings();
|
||||||
// db
|
|
||||||
await invoke("init_db");
|
|
||||||
|
|
||||||
console.log("ACTUAL SETTINGS IN FRONTEND: ", settings.fontSize);
|
console.log("ACTUAL SETTINGS IN FRONTEND: ", settings.fontSize)
|
||||||
createNoteContentEl = document.querySelector("#create-input");
|
createNoteContentEl = document.querySelector("#create-input");
|
||||||
createNoteTagEl = document.querySelector("#create-tag");
|
createNoteTagEl = document.querySelector("#create-tag");
|
||||||
searchbarEl = document.querySelector("#note-searchbar");
|
searchbarEl = document.querySelector("#note-searchbar");
|
||||||
notesMsgEl = document.querySelector("#notes-list");
|
notesMsgEl = document.querySelector("#notes-list");
|
||||||
|
|
||||||
// apply font size
|
|
||||||
if (createNoteContentEl) {
|
|
||||||
createNoteContentEl.style.fontSize = settings.fontSize + "px";
|
|
||||||
}
|
|
||||||
|
|
||||||
showNotes();
|
showNotes();
|
||||||
document.querySelector("#save-button")?.addEventListener("click", (e) => {
|
document.querySelector("#save-button")?.addEventListener("click", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -143,35 +133,23 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||||
clearEditor();
|
clearEditor();
|
||||||
showNotes();
|
showNotes();
|
||||||
});
|
});
|
||||||
document
|
document.querySelector("#show-notes-button")?.addEventListener("click", (e) => {
|
||||||
.querySelector("#show-notes-button")
|
|
||||||
?.addEventListener("click", (e) => {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
showNotes();
|
showNotes();
|
||||||
});
|
});
|
||||||
document.querySelector("#export-button")?.addEventListener("click", (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
exportNote(createNoteContentEl ? createNoteContentEl.value : null);
|
|
||||||
});
|
|
||||||
document.querySelector("#settings-button")?.addEventListener("click", (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
handleOpenSettingsModal();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pressing TAB should insert intends in the editor.
|
// Pressing TAB should insert intends in the editor.
|
||||||
// This could potentially cause issues later...
|
// This could potentially cause issues later...
|
||||||
document
|
document.querySelector("#create-input")?.addEventListener("keydown", (event: Event) => {
|
||||||
.querySelector("#create-input")
|
|
||||||
?.addEventListener("keydown", (event: Event) => {
|
|
||||||
const e = event as KeyboardEvent;
|
const e = event as KeyboardEvent;
|
||||||
if (e.key === "Tab") {
|
if (e.key === 'Tab') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const target = e.target as HTMLTextAreaElement;
|
const target = e.target as HTMLTextAreaElement;
|
||||||
const start = target.selectionStart;
|
const start = target.selectionStart;
|
||||||
const end = target.selectionEnd;
|
const end = target.selectionEnd;
|
||||||
|
|
||||||
const newValue =
|
const newValue = target.value.substring(0, start) +
|
||||||
target.value.substring(0, start) + "\t" + target.value.substring(end);
|
"\t" + target.value.substring(end);
|
||||||
|
|
||||||
target.value = newValue;
|
target.value = newValue;
|
||||||
|
|
||||||
|
@ -181,9 +159,7 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
|
||||||
// searchbar event listener
|
// searchbar event listener
|
||||||
|
|
||||||
document
|
document.querySelector("#note-searchbar")?.addEventListener("input", (event: Event) => {
|
||||||
.querySelector("#note-searchbar")
|
|
||||||
?.addEventListener("input", (event: Event) => {
|
|
||||||
const target = event.target as HTMLInputElement;
|
const target = event.target as HTMLInputElement;
|
||||||
const input = target.value;
|
const input = target.value;
|
||||||
|
|
||||||
|
@ -195,28 +171,16 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||||
searchbarContents = input;
|
searchbarContents = input;
|
||||||
|
|
||||||
searchNote(input);
|
searchNote(input);
|
||||||
});
|
})
|
||||||
|
|
||||||
// sidebar reverse toggle
|
// sidebar reverse toggle
|
||||||
|
noteSidebarReverseCheckboxEl = document.querySelector('#reverse-toggle');
|
||||||
let reverseIconAscEl = document.querySelector(
|
if (noteSidebarReverseCheckboxEl) {
|
||||||
"#reverse-icon-asc"
|
console.log(noteSidebarReverseCheckboxEl.value);
|
||||||
) as HTMLImageElement | null;
|
noteSidebarReverseCheckboxEl.addEventListener("click", (e: Event) => {
|
||||||
let reverseIconDescEl = document.querySelector(
|
const target = e.target as HTMLInputElement
|
||||||
"#reverse-icon-desc"
|
toggleReverse(target.checked);
|
||||||
) as HTMLImageElement | null;
|
})
|
||||||
if (reverseIconAscEl && reverseIconDescEl) {
|
|
||||||
reverseIconDescEl.style.display = "none";
|
|
||||||
|
|
||||||
const toggle = () => {
|
|
||||||
toggleReverse(
|
|
||||||
reverseIconAscEl as HTMLImageElement,
|
|
||||||
reverseIconDescEl as HTMLImageElement
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
reverseIconAscEl.addEventListener("click", toggle);
|
|
||||||
reverseIconDescEl.addEventListener("click", toggle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto-save timer
|
// auto-save timer
|
||||||
|
@ -230,70 +194,44 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (createNoteContentEl) {
|
if (createNoteContentEl) {
|
||||||
createNoteContentEl.style.fontSize = settings.fontSize;
|
createNoteContentEl.style.fontSize = settings.fontSize
|
||||||
}
|
}
|
||||||
|
|
||||||
// OCR
|
// OCR
|
||||||
const uploadOcrImageButtonEl = document.getElementById(
|
const uploadOcrImageButtonEl = document.getElementById('image-button') as HTMLButtonElement;
|
||||||
"image-button"
|
const ocrFileInputEl = document.getElementById('fileInput') as HTMLInputElement;
|
||||||
) as HTMLButtonElement;
|
uploadOcrImageButtonEl.addEventListener('click', () => {
|
||||||
const ocrFileInputEl = document.getElementById(
|
|
||||||
"fileInput"
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
uploadOcrImageButtonEl.addEventListener("click", () => {
|
|
||||||
ocrFileInputEl.click(); // Simulate click on the file input
|
ocrFileInputEl.click(); // Simulate click on the file input
|
||||||
});
|
});
|
||||||
|
|
||||||
ocrFileInputEl.addEventListener("change", (event) => {
|
ocrFileInputEl.addEventListener('change', async (event) => {
|
||||||
const files = (event.target as HTMLInputElement).files;
|
const files = (event.target as HTMLInputElement).files;
|
||||||
if (files) {
|
if (files) {
|
||||||
console.log("Selected file:", files[0].name);
|
console.log('Selected file:', files[0].name);
|
||||||
ocrFileInputEl.src = URL.createObjectURL(files[0]);
|
// Assuming you have an img element to display the selected file
|
||||||
(async () => {
|
const imageDisplayEl = document.getElementById('imageDisplay') as HTMLImageElement;
|
||||||
// TODO: change ocr language in settings
|
if (imageDisplayEl) {
|
||||||
const worker = await createWorker(
|
imageDisplayEl.src = URL.createObjectURL(files[0]);
|
||||||
settings ? settings.ocrLanguage : "eng"
|
}
|
||||||
);
|
|
||||||
|
const worker = await createWorker('eng');
|
||||||
const ret = await worker.recognize(files[0]);
|
const ret = await worker.recognize(files[0]);
|
||||||
console.log(ret.data.text);
|
console.log(ret.data.text);
|
||||||
if (createNoteContentEl) [(createNoteContentEl.value += ret.data.text)];
|
if (createNoteContentEl) {
|
||||||
|
createNoteContentEl.value += ret.data.text;
|
||||||
|
}
|
||||||
await worker.terminate();
|
await worker.terminate();
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resizable Sidebar
|
|
||||||
const sidebar = document.querySelector(".sidebar") as HTMLDivElement;
|
|
||||||
const resizableHandle = document.querySelector(
|
|
||||||
".resizable-handle"
|
|
||||||
) as HTMLDivElement;
|
|
||||||
|
|
||||||
let isResizing = false;
|
|
||||||
|
|
||||||
resizableHandle.addEventListener("mousedown", () => {
|
|
||||||
isResizing = true;
|
|
||||||
document.body.style.cursor = "ew-resize";
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener("mousemove", (e) => {
|
|
||||||
if (!isResizing) return;
|
|
||||||
const newWidth = e.clientX - sidebar.getBoundingClientRect().left;
|
|
||||||
sidebar.style.width = `${newWidth}px`;
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener("mouseup", () => {
|
|
||||||
isResizing = false;
|
|
||||||
document.body.style.cursor = "default";
|
|
||||||
});
|
|
||||||
|
|
||||||
refreshContextMenuElements();
|
refreshContextMenuElements();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function loadSettings(): Promise<Settings> {
|
async function loadSettings(): Promise<Settings> {
|
||||||
const defaultSettings: Settings = {
|
const defaultSettings: Settings = {
|
||||||
fontSize: "16px",
|
fontSize: "16px"
|
||||||
ocrLanguage: "eng",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -317,13 +255,12 @@ async function loadSettings(): Promise<Settings> {
|
||||||
* We need to add new event listeners every time we refresh the note list
|
* We need to add new event listeners every time we refresh the note list
|
||||||
*/
|
*/
|
||||||
function refreshContextMenuElements() {
|
function refreshContextMenuElements() {
|
||||||
const elements: NodeListOf<HTMLElement> = document.querySelectorAll(
|
const elements: NodeListOf<HTMLElement> = document.querySelectorAll(".rightclick-element")
|
||||||
".rightclick-element"
|
const contextMenu = document.getElementById('contextMenu');
|
||||||
);
|
|
||||||
const contextMenu = document.getElementById("contextMenu");
|
|
||||||
|
|
||||||
if (contextMenu) {
|
if (contextMenu) {
|
||||||
elements.forEach((element) => {
|
elements.forEach(element => {
|
||||||
|
|
||||||
element.addEventListener("contextmenu", (e: MouseEvent) => {
|
element.addEventListener("contextmenu", (e: MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
@ -337,16 +274,15 @@ function refreshContextMenuElements() {
|
||||||
const viewportWidth = window.innerWidth;
|
const viewportWidth = window.innerWidth;
|
||||||
const viewportHeight = window.innerHeight;
|
const viewportHeight = window.innerHeight;
|
||||||
|
|
||||||
let posX =
|
let posX = mouseX + menuWidth > viewportWidth ? mouseX - menuWidth : mouseX;
|
||||||
mouseX + menuWidth > viewportWidth ? mouseX - menuWidth : mouseX;
|
let posY = mouseY + menuHeight > viewportHeight ? mouseY - menuHeight : mouseY;
|
||||||
let posY =
|
|
||||||
mouseY + menuHeight > viewportHeight ? mouseY - menuHeight : mouseY;
|
|
||||||
|
|
||||||
contextMenu.style.display = "block";
|
|
||||||
|
contextMenu.style.display = 'block';
|
||||||
contextMenu.style.left = `${posX}px`;
|
contextMenu.style.left = `${posX}px`;
|
||||||
contextMenu.style.top = `${posY}px`;
|
contextMenu.style.top = `${posY}px`;
|
||||||
|
|
||||||
const noteIdElement = element.querySelector(".sidebar-note-id");
|
const noteIdElement = element.querySelector('.sidebar-note-id');
|
||||||
if (noteIdElement) {
|
if (noteIdElement) {
|
||||||
const noteIdStr = noteIdElement.textContent;
|
const noteIdStr = noteIdElement.textContent;
|
||||||
if (noteIdStr) {
|
if (noteIdStr) {
|
||||||
|
@ -354,14 +290,16 @@ function refreshContextMenuElements() {
|
||||||
showNoteSidebarContextMenu(noteId);
|
showNoteSidebarContextMenu(noteId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error(".sidebar-note-id element not found within the note.");
|
console.error('.sidebar-note-id element not found within the note.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillNoteSidebar(noteArray: Note[], reverse: boolean) {
|
function fillNoteSidebar(noteArray: Note[], reverse: boolean) {
|
||||||
|
|
||||||
noteSidebarContainerEl = document.querySelector("#note-sidebar-container");
|
noteSidebarContainerEl = document.querySelector("#note-sidebar-container");
|
||||||
|
|
||||||
if (noteSidebarContainerEl) {
|
if (noteSidebarContainerEl) {
|
||||||
|
@ -372,50 +310,40 @@ function fillNoteSidebar(noteArray: Note[], reverse: boolean) {
|
||||||
|
|
||||||
noteArray.forEach((note) => {
|
noteArray.forEach((note) => {
|
||||||
// Create HTML elements for each note
|
// Create HTML elements for each note
|
||||||
const noteEl: HTMLDivElement = document.createElement("div");
|
const noteEl: HTMLDivElement = document.createElement('div');
|
||||||
noteEl.classList.add("sidebar-note");
|
noteEl.classList.add('sidebar-note');
|
||||||
noteEl.classList.add("rightclick-element");
|
noteEl.classList.add('rightclick-element');
|
||||||
noteEl.addEventListener(
|
noteEl.addEventListener("click", () => handleSidebarNoteClick(note.id), false);
|
||||||
"click",
|
|
||||||
() => handleSidebarNoteClick(note.id),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
const idSpan: HTMLSpanElement = document.createElement("span");
|
const idSpan: HTMLSpanElement = document.createElement('span');
|
||||||
idSpan.classList.add("sidebar-note-id");
|
idSpan.classList.add('sidebar-note-id');
|
||||||
idSpan.textContent = note.id.toString();
|
idSpan.textContent = note.id.toString();
|
||||||
|
|
||||||
const contentSpan: HTMLSpanElement = document.createElement("span");
|
const contentSpan: HTMLSpanElement = document.createElement('span');
|
||||||
contentSpan.classList.add("sidebar-note-content");
|
contentSpan.classList.add('sidebar-note-content');
|
||||||
|
|
||||||
// Show ... when text is too long
|
// Show ... when text is too long
|
||||||
contentSpan.textContent =
|
contentSpan.textContent = note.content.length > 20 ? note.content.substring(0, 20) + "..." : note.content as string;
|
||||||
note.content.length > 80
|
|
||||||
? note.content.substring(0, 80) + "..."
|
|
||||||
: (note.content as string);
|
|
||||||
contentSpan.title = note.content as string;
|
contentSpan.title = note.content as string;
|
||||||
|
|
||||||
const tagSpan: HTMLSpanElement = document.createElement("span");
|
const tagSpan: HTMLSpanElement = document.createElement('span');
|
||||||
tagSpan.classList.add("sidebar-note-tag");
|
tagSpan.classList.add('sidebar-note-tag');
|
||||||
tagSpan.textContent =
|
tagSpan.textContent = note.tag as string;
|
||||||
note.tag.length > 9
|
|
||||||
? note.tag.substring(0, 11) + ".."
|
|
||||||
: (note.tag as string);
|
|
||||||
|
|
||||||
noteEl.appendChild(idSpan);
|
noteEl.appendChild(idSpan);
|
||||||
noteEl.appendChild(contentSpan);
|
noteEl.appendChild(contentSpan);
|
||||||
noteEl.appendChild(tagSpan);
|
noteEl.appendChild(tagSpan);
|
||||||
|
|
||||||
// Append noteEl to the container, if it still exists?
|
// Append noteEl to the container, if it still exists?
|
||||||
noteSidebarContainerEl
|
noteSidebarContainerEl ? noteSidebarContainerEl.appendChild(noteEl) : null;
|
||||||
? noteSidebarContainerEl.appendChild(noteEl)
|
|
||||||
: null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
refreshContextMenuElements();
|
refreshContextMenuElements();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleSidebarNoteClick(id: Number): any {
|
function handleSidebarNoteClick(id: Number): any {
|
||||||
console.log("clicked note " + id);
|
console.log("clicked note " + id);
|
||||||
if (createNoteContentEl && createNoteTagEl) {
|
if (createNoteContentEl && createNoteTagEl) {
|
||||||
|
@ -424,10 +352,10 @@ function handleSidebarNoteClick(id: Number): any {
|
||||||
id: 0,
|
id: 0,
|
||||||
content: "undefined",
|
content: "undefined",
|
||||||
date: "undefined",
|
date: "undefined",
|
||||||
tag: "undefined",
|
tag: "undefined"
|
||||||
};
|
};
|
||||||
|
|
||||||
noteArray.forEach((note) => {
|
noteArray.forEach(note => {
|
||||||
if (note.id === id) {
|
if (note.id === id) {
|
||||||
n = note;
|
n = note;
|
||||||
}
|
}
|
||||||
|
@ -445,28 +373,29 @@ function handleSidebarNoteClick(id: Number): any {
|
||||||
// don't destory currently editing note if this fails
|
// don't destory currently editing note if this fails
|
||||||
console.error("Error fetching note");
|
console.error("Error fetching note");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showNoteSidebarContextMenu(noteId: Number) {
|
function showNoteSidebarContextMenu(noteId: Number) {
|
||||||
const contextMenu = document.getElementById("contextMenu");
|
const contextMenu = document.getElementById('contextMenu');
|
||||||
const deleteButton = document.getElementById("deleteButton");
|
const deleteButton = document.getElementById('deleteButton');
|
||||||
|
|
||||||
if (contextMenu && deleteButton) {
|
if (contextMenu && deleteButton) {
|
||||||
deleteButton.addEventListener("click", async function () {
|
deleteButton.addEventListener('click', async function () {
|
||||||
console.log("Deleting...");
|
console.log('Deleting...');
|
||||||
await invoke("delete_specific_note", {
|
await invoke("delete_specific_note", {
|
||||||
id: noteId,
|
id: noteId
|
||||||
});
|
});
|
||||||
// hide after delete
|
// hide after delete
|
||||||
contextMenu.style.display = "none";
|
contextMenu.style.display = 'none';
|
||||||
showNotes();
|
showNotes();
|
||||||
});
|
});
|
||||||
|
|
||||||
// hide when clicking outside of it
|
// hide when clicking outside of it
|
||||||
document.addEventListener("click", function (event) {
|
document.addEventListener('click', function (event) {
|
||||||
if (!contextMenu.contains(event.target as Node)) {
|
if (!contextMenu.contains(event.target as Node)) {
|
||||||
contextMenu.style.display = "none";
|
contextMenu.style.display = 'none';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -500,45 +429,29 @@ function clearEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for global key presses
|
// Listen for global key presses
|
||||||
document.addEventListener("keydown", (e) => handleKeyboardShortcuts(e));
|
document.addEventListener('keydown', (e) => handleKeyboardShortcuts(e));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle global keyboard shortcuts like save, search, new
|
* Handle global keyboard shortcuts like save, search, new
|
||||||
*/
|
*/
|
||||||
function handleKeyboardShortcuts(event: KeyboardEvent) {
|
function handleKeyboardShortcuts(event: KeyboardEvent) {
|
||||||
// save
|
// save
|
||||||
if (event.ctrlKey && event.key === "s") {
|
if (event.ctrlKey && event.key === 's') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
saveNote();
|
saveNote();
|
||||||
}
|
}
|
||||||
// new
|
// new
|
||||||
if (event.ctrlKey && event.key === "n") {
|
if (event.ctrlKey && event.key === 'n') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
clearEditor();
|
clearEditor();
|
||||||
}
|
}
|
||||||
// refresh
|
// refresh
|
||||||
if (event.ctrlKey && event.key === "r") {
|
if (event.ctrlKey && event.key === 'r') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
showNotes();
|
showNotes();
|
||||||
}
|
}
|
||||||
// focus editor
|
|
||||||
if (event.ctrlKey && event.key === "h") {
|
|
||||||
event.preventDefault();
|
|
||||||
if (createNoteContentEl) {
|
|
||||||
createNoteContentEl.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// focus tags
|
|
||||||
if (event.ctrlKey && event.key === "j") {
|
|
||||||
event.preventDefault();
|
|
||||||
if (createNoteTagEl) {
|
|
||||||
createNoteTagEl.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: if we're focused the searchbox, arrow down will focus on the first result in the list
|
|
||||||
|
|
||||||
// focus searchbox
|
// focus searchbox
|
||||||
if (event.ctrlKey && event.key === "p") {
|
if (event.ctrlKey && event.key === 'f') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (searchbarEl) {
|
if (searchbarEl) {
|
||||||
searchbarEl.focus();
|
searchbarEl.focus();
|
||||||
|
@ -547,11 +460,11 @@ function handleKeyboardShortcuts(event: KeyboardEvent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// open by id: open modal
|
// open by id: open modal
|
||||||
if (event.ctrlKey && event.key === "t") {
|
if (event.ctrlKey && event.key === 't') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const modalBg = document.getElementById("id-modal-bg");
|
const modalBg = document.getElementById("id-modal-bg");
|
||||||
const modal = document.getElementById("id-modal-container");
|
const modal = document.getElementById("id-modal-container");
|
||||||
const idSearchBar = document.getElementById("id-search");
|
const idSearchBar = document.getElementById("id-search")
|
||||||
if (modalBg && modal && idSearchBar) {
|
if (modalBg && modal && idSearchBar) {
|
||||||
modalBg.style.display = "block";
|
modalBg.style.display = "block";
|
||||||
modal.style.display = "block";
|
modal.style.display = "block";
|
||||||
|
@ -563,7 +476,7 @@ function handleKeyboardShortcuts(event: KeyboardEvent) {
|
||||||
modal.style.display = "none";
|
modal.style.display = "none";
|
||||||
modalBg.style.display = "none";
|
modalBg.style.display = "none";
|
||||||
idModalActive = false;
|
idModalActive = false;
|
||||||
});
|
})
|
||||||
|
|
||||||
idSearchBar.addEventListener("keydown", async (event: KeyboardEvent) => {
|
idSearchBar.addEventListener("keydown", async (event: KeyboardEvent) => {
|
||||||
if (event.key === "Enter" && idModalActive) {
|
if (event.key === "Enter" && idModalActive) {
|
||||||
|
@ -575,8 +488,7 @@ function handleKeyboardShortcuts(event: KeyboardEvent) {
|
||||||
idModalActive = false;
|
idModalActive = false;
|
||||||
} else {
|
} else {
|
||||||
(idSearchBar as HTMLInputElement).value = "";
|
(idSearchBar as HTMLInputElement).value = "";
|
||||||
(idSearchBar as HTMLInputElement).placeholder =
|
(idSearchBar as HTMLInputElement).placeholder = "no Note found for ID";
|
||||||
"no Note found for ID";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.key === "Escape" && idModalActive) {
|
if (event.key === "Escape" && idModalActive) {
|
||||||
|
@ -585,234 +497,12 @@ function handleKeyboardShortcuts(event: KeyboardEvent) {
|
||||||
idModalActive = false;
|
idModalActive = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
console.error("failed to get modal");
|
} else { console.error("failed to get modal"); }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// quick switch note 1-9
|
// quick switch note 1-9
|
||||||
if (event.ctrlKey && event.key === "f") {
|
|
||||||
openSearchModal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
interface SearchResult {
|
|
||||||
text: string;
|
|
||||||
startIndex: number;
|
|
||||||
endIndex: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: when clicked should it close the search results?
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function openSearchModal() {
|
|
||||||
const createNoteContentEl = document.querySelector(
|
|
||||||
"textarea"
|
|
||||||
) as HTMLTextAreaElement;
|
|
||||||
if (!createNoteContentEl) return;
|
|
||||||
|
|
||||||
const modalBg = document.createElement("div");
|
|
||||||
modalBg.id = "search-modal-bg";
|
|
||||||
modalBg.style.cssText = `
|
|
||||||
display: block;
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-color: rgba(0,0,0,0.5);
|
|
||||||
z-index: 1000;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const modal = document.createElement("div");
|
|
||||||
modal.id = "search-modal";
|
|
||||||
modal.style.cssText = `
|
|
||||||
display: block;
|
|
||||||
position: fixed;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
background-color: ${BACKGROUND_COLOR};
|
|
||||||
padding: 1rem;
|
|
||||||
box-shadow: 0 0 10px rgba(0,0,0,0.3);
|
|
||||||
z-index: 1001;
|
|
||||||
width: 80%;
|
|
||||||
max-width: 600px;
|
|
||||||
border-radius: 4px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const searchInput = document.createElement("input");
|
|
||||||
searchInput.type = "text";
|
|
||||||
searchInput.placeholder = "Search this note...";
|
|
||||||
searchInput.style.cssText = `
|
|
||||||
width: 100%;
|
|
||||||
padding: .5rem;
|
|
||||||
box-sizing: border-box;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
border-radius: .25rem;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const resultContainer = document.createElement("div");
|
|
||||||
resultContainer.id = "search-results";
|
|
||||||
resultContainer.style.cssText = `
|
|
||||||
width: 100%;
|
|
||||||
max-height: 300px;
|
|
||||||
overflow-y: auto;
|
|
||||||
border-top: 1px solid #ccc;
|
|
||||||
background-color: ${BACKGROUND_COLOR};
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Close button
|
|
||||||
const closeButton = document.createElement("button");
|
|
||||||
closeButton.textContent = "×";
|
|
||||||
closeButton.style.cssText = `
|
|
||||||
position: absolute;
|
|
||||||
top: 10px;
|
|
||||||
right: 10px;
|
|
||||||
border: none;
|
|
||||||
background: none;
|
|
||||||
font-size: 20px;
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 5px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Append elements to the modal
|
|
||||||
modal.appendChild(closeButton);
|
|
||||||
modal.appendChild(searchInput);
|
|
||||||
modal.appendChild(resultContainer);
|
|
||||||
|
|
||||||
// Append the modal to the body
|
|
||||||
document.body.appendChild(modalBg);
|
|
||||||
document.body.appendChild(modal);
|
|
||||||
|
|
||||||
// Add focus
|
|
||||||
searchInput.focus();
|
|
||||||
|
|
||||||
function findSearchResults(searchTerm: string): SearchResult[] {
|
|
||||||
const content = createNoteContentEl.value;
|
|
||||||
const results: SearchResult[] = [];
|
|
||||||
|
|
||||||
if (!searchTerm) return results;
|
|
||||||
|
|
||||||
const lines = content.split("\n");
|
|
||||||
let currentIndex = 0;
|
|
||||||
|
|
||||||
for (const line of lines) {
|
|
||||||
const lowerLine = line.toLowerCase();
|
|
||||||
const searchTermLower = searchTerm.toLowerCase();
|
|
||||||
let position = lowerLine.indexOf(searchTermLower);
|
|
||||||
|
|
||||||
while (position !== -1) {
|
|
||||||
results.push({
|
|
||||||
text: line,
|
|
||||||
startIndex: currentIndex + position,
|
|
||||||
endIndex: currentIndex + position + searchTerm.length,
|
|
||||||
});
|
|
||||||
position = lowerLine.indexOf(searchTermLower, position + 1);
|
|
||||||
}
|
|
||||||
currentIndex += line.length + 1; // +1 for the newline character
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter content
|
|
||||||
searchInput.addEventListener("input", () => {
|
|
||||||
const searchTerm = searchInput.value;
|
|
||||||
const results = findSearchResults(searchTerm);
|
|
||||||
|
|
||||||
// Display results
|
|
||||||
resultContainer.innerHTML = "";
|
|
||||||
results.forEach((result) => {
|
|
||||||
const p = document.createElement("p");
|
|
||||||
|
|
||||||
// Highlight matches
|
|
||||||
const beforeMatch = result.text.substring(
|
|
||||||
0,
|
|
||||||
result.text.toLowerCase().indexOf(searchTerm.toLowerCase())
|
|
||||||
);
|
|
||||||
const match = result.text.substring(
|
|
||||||
result.text.toLowerCase().indexOf(searchTerm.toLowerCase()),
|
|
||||||
result.text.toLowerCase().indexOf(searchTerm.toLowerCase()) +
|
|
||||||
searchTerm.length
|
|
||||||
);
|
|
||||||
const afterMatch = result.text.substring(
|
|
||||||
result.text.toLowerCase().indexOf(searchTerm.toLowerCase()) +
|
|
||||||
searchTerm.length
|
|
||||||
);
|
|
||||||
|
|
||||||
p.innerHTML = `${beforeMatch}<mark>${match}</mark>${afterMatch}`;
|
|
||||||
p.style.cssText = `
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
padding: 0.5rem;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 4px;
|
|
||||||
transition: background-color 0.2s;
|
|
||||||
`;
|
|
||||||
p.addEventListener("mouseover", () => {
|
|
||||||
p.style.backgroundColor = BACKGROUND_COLOR_HOVER;
|
|
||||||
});
|
|
||||||
p.addEventListener("mouseout", () => {
|
|
||||||
p.style.backgroundColor = "transparent";
|
|
||||||
});
|
|
||||||
p.addEventListener("click", () => selectResult(result));
|
|
||||||
resultContainer.appendChild(p);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function closeModal() {
|
|
||||||
modal.remove();
|
|
||||||
modalBg.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close modal
|
|
||||||
modalBg.addEventListener("click", closeModal);
|
|
||||||
closeButton.addEventListener("click", closeModal);
|
|
||||||
modal.addEventListener("click", (e) => e.stopPropagation());
|
|
||||||
document.addEventListener("keydown", (e) => {
|
|
||||||
if (e.key === "Escape") {
|
|
||||||
closeModal();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scroll to and focus on the clicked result in the Editor
|
|
||||||
*
|
|
||||||
* @param result the search result
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function selectResult(result: SearchResult) {
|
|
||||||
const createNoteContentEl = document.querySelector(
|
|
||||||
"textarea"
|
|
||||||
) as HTMLTextAreaElement;
|
|
||||||
if (!createNoteContentEl) return;
|
|
||||||
|
|
||||||
createNoteContentEl.focus();
|
|
||||||
createNoteContentEl.setSelectionRange(result.startIndex, result.endIndex);
|
|
||||||
|
|
||||||
// Calculate the position of the selection
|
|
||||||
const textBeforeSelection = createNoteContentEl.value.substring(
|
|
||||||
0,
|
|
||||||
result.startIndex
|
|
||||||
);
|
|
||||||
const lines = textBeforeSelection.split("\n");
|
|
||||||
const lineNumber = lines.length;
|
|
||||||
|
|
||||||
// Get the line height (fallback to 20 if computation fails)
|
|
||||||
const computedLineHeight =
|
|
||||||
parseInt(getComputedStyle(createNoteContentEl).lineHeight) || 20;
|
|
||||||
|
|
||||||
// Calculate scroll position to center the selection in the viewport
|
|
||||||
const targetPosition = (lineNumber - 1) * computedLineHeight;
|
|
||||||
const textareaHeight = createNoteContentEl.clientHeight;
|
|
||||||
const scrollPosition = Math.max(0, targetPosition - textareaHeight / 2);
|
|
||||||
|
|
||||||
createNoteContentEl.scrollTo({
|
|
||||||
top: scrollPosition,
|
|
||||||
behavior: "smooth",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Searches for note and displays the results accordingly
|
* Searches for note and displays the results accordingly
|
||||||
*/
|
*/
|
||||||
|
@ -824,7 +514,7 @@ async function searchNote(input: string) {
|
||||||
id: jsonObj.id,
|
id: jsonObj.id,
|
||||||
content: jsonObj.content,
|
content: jsonObj.content,
|
||||||
date: jsonObj.date,
|
date: jsonObj.date,
|
||||||
tag: jsonObj.tag,
|
tag: jsonObj.tag
|
||||||
}));
|
}));
|
||||||
|
|
||||||
fillNoteSidebar(noteArray, reversed);
|
fillNoteSidebar(noteArray, reversed);
|
||||||
|
@ -833,7 +523,7 @@ async function searchNote(input: string) {
|
||||||
|
|
||||||
async function getSearchResults(input: string): Promise<Array<JSON>> {
|
async function getSearchResults(input: string): Promise<Array<JSON>> {
|
||||||
const resultsString: string = await invoke("search_notes", {
|
const resultsString: string = await invoke("search_notes", {
|
||||||
query: input,
|
query: input
|
||||||
});
|
});
|
||||||
const resultsJson = JSON.parse(resultsString);
|
const resultsJson = JSON.parse(resultsString);
|
||||||
return resultsJson;
|
return resultsJson;
|
||||||
|
@ -855,28 +545,14 @@ async function refreshSidebarAndOpenLatestNote() {
|
||||||
id: noteJson[0].id,
|
id: noteJson[0].id,
|
||||||
content: noteJson[0].content,
|
content: noteJson[0].content,
|
||||||
date: noteJson[0].date,
|
date: noteJson[0].date,
|
||||||
tag: noteJson[0].tag,
|
tag: noteJson[0].tag
|
||||||
};
|
}
|
||||||
|
|
||||||
openNote(latestNote);
|
openNote(latestNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleReverse(
|
function toggleReverse(val: boolean) {
|
||||||
reverseIconAscEl: HTMLImageElement | null,
|
reversed = val;
|
||||||
reverseIconDescEl: HTMLImageElement | null
|
|
||||||
) {
|
|
||||||
reversed = !reversed;
|
|
||||||
|
|
||||||
if (reverseIconAscEl && reverseIconDescEl) {
|
|
||||||
if (reverseIconAscEl.style.display !== "none") {
|
|
||||||
reverseIconAscEl.style.display = "none";
|
|
||||||
reverseIconDescEl.style.display = "block";
|
|
||||||
} else {
|
|
||||||
reverseIconAscEl.style.display = "block";
|
|
||||||
reverseIconDescEl.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
showNotes();
|
showNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -884,10 +560,10 @@ async function openNoteById(value: string): Promise<boolean> {
|
||||||
const id: Number | null = parseInt(value);
|
const id: Number | null = parseInt(value);
|
||||||
if (id) {
|
if (id) {
|
||||||
const noteString = await invoke("get_note_by_id", {
|
const noteString = await invoke("get_note_by_id", {
|
||||||
id: id,
|
id: id
|
||||||
});
|
});
|
||||||
console.log("id called: " + id);
|
console.log("id called: " + id)
|
||||||
console.log("note string: " + noteString);
|
console.log("note string: " + noteString)
|
||||||
const noteJson = JSON.parse(noteString as string);
|
const noteJson = JSON.parse(noteString as string);
|
||||||
|
|
||||||
if (noteJson.length == 0) {
|
if (noteJson.length == 0) {
|
||||||
|
@ -898,138 +574,11 @@ async function openNoteById(value: string): Promise<boolean> {
|
||||||
id: noteJson[0].id,
|
id: noteJson[0].id,
|
||||||
content: noteJson[0].content,
|
content: noteJson[0].content,
|
||||||
date: noteJson[0].date,
|
date: noteJson[0].date,
|
||||||
tag: noteJson[0].tag,
|
tag: noteJson[0].tag
|
||||||
};
|
}
|
||||||
|
|
||||||
openNote(foundNote);
|
openNote(foundNote);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exportNote(contents: string | null) {
|
|
||||||
if (contents) {
|
|
||||||
const title =
|
|
||||||
contents.replace(/\n/g, " ").length < 30
|
|
||||||
? contents.replace(/\n/g, " ").trim()
|
|
||||||
: contents.replace(/\n/g, " ").slice(0, 30).trim();
|
|
||||||
const filePath = await save({
|
|
||||||
defaultPath: (await homeDir()) + "/" + title + ".md",
|
|
||||||
filters: [
|
|
||||||
{
|
|
||||||
name: "Text",
|
|
||||||
extensions: ["txt", "md"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
if (filePath) {
|
|
||||||
await writeTextFile(filePath, contents);
|
|
||||||
} else {
|
|
||||||
console.error("Failed to get filePath");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO: have some kind of error banner at the bottom for
|
|
||||||
// these notifications
|
|
||||||
console.error("Export note: failed to get note contents");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function exportAllNotes() {
|
|
||||||
let res = await invoke("export_all_notes");
|
|
||||||
console.log(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleOpenSettingsModal() {
|
|
||||||
// insert app version
|
|
||||||
const appVersionEl = document.getElementById("app-version");
|
|
||||||
if (appVersionEl) {
|
|
||||||
const VERSION_STR = await invoke("get_app_version");
|
|
||||||
appVersionEl.textContent = "version " + VERSION_STR;
|
|
||||||
} else {
|
|
||||||
console.error("Failed to get app version element.");
|
|
||||||
}
|
|
||||||
// open modal
|
|
||||||
const modalBg = document.getElementById("id-modal-bg");
|
|
||||||
const settingsModalContainer = document.getElementById(
|
|
||||||
"settings-modal-container"
|
|
||||||
);
|
|
||||||
const settingsFontsizeInput = document.getElementById(
|
|
||||||
"fontsize-setting-input"
|
|
||||||
) as HTMLInputElement;
|
|
||||||
const settingsOcrLanguageInput = document.getElementById(
|
|
||||||
"ocr-language-setting-input"
|
|
||||||
) as HTMLInputElement;
|
|
||||||
const settingsSaveButton = document.getElementById("save-settings-button");
|
|
||||||
if (modalBg && settingsModalContainer && settingsFontsizeInput) {
|
|
||||||
modalBg.style.display = "block";
|
|
||||||
settingsModalContainer.style.display = "block";
|
|
||||||
settingsModalContainer.style.backgroundColor = BACKGROUND_COLOR;
|
|
||||||
settingsFontsizeInput.focus();
|
|
||||||
settingsFontsizeInput.value = settings ? settings.fontSize : "16";
|
|
||||||
settingsOcrLanguageInput.value = settings ? settings.ocrLanguage : "eng";
|
|
||||||
|
|
||||||
modalBg.addEventListener("click", () => {
|
|
||||||
settingsModalContainer.style.display = "none";
|
|
||||||
modalBg.style.display = "none";
|
|
||||||
});
|
|
||||||
|
|
||||||
settingsFontsizeInput.addEventListener(
|
|
||||||
"keydown",
|
|
||||||
async (event: KeyboardEvent) => {
|
|
||||||
if (event.key === "Enter") {
|
|
||||||
console.log("saving settings..");
|
|
||||||
settings = {
|
|
||||||
fontSize: settingsFontsizeInput.value,
|
|
||||||
ocrLanguage:
|
|
||||||
settingsOcrLanguageInput.value === ""
|
|
||||||
? "eng"
|
|
||||||
: settingsOcrLanguageInput.value,
|
|
||||||
};
|
|
||||||
await invoke("save_settings", {
|
|
||||||
settings: JSON.stringify(settings),
|
|
||||||
});
|
|
||||||
if (createNoteContentEl) {
|
|
||||||
createNoteContentEl.style.fontSize =
|
|
||||||
settingsFontsizeInput.value + "px";
|
|
||||||
} else {
|
|
||||||
console.error("failed to get createNoteContentEl");
|
|
||||||
}
|
|
||||||
settingsModalContainer.style.display = "none";
|
|
||||||
modalBg.style.display = "none";
|
|
||||||
}
|
|
||||||
if (event.key === "Escape") {
|
|
||||||
settingsModalContainer.style.display = "none";
|
|
||||||
modalBg.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (settingsSaveButton) {
|
|
||||||
settingsSaveButton.addEventListener("click", async () => {
|
|
||||||
console.log("saving settings..");
|
|
||||||
settings = {
|
|
||||||
fontSize: settingsFontsizeInput.value,
|
|
||||||
ocrLanguage:
|
|
||||||
settingsOcrLanguageInput.value === ""
|
|
||||||
? "eng"
|
|
||||||
: settingsOcrLanguageInput.value,
|
|
||||||
};
|
|
||||||
await invoke("save_settings", {
|
|
||||||
settings: JSON.stringify(settings),
|
|
||||||
});
|
|
||||||
if (createNoteContentEl) {
|
|
||||||
createNoteContentEl.style.fontSize =
|
|
||||||
settingsFontsizeInput.value + "px";
|
|
||||||
} else {
|
|
||||||
console.error("failed to get createNoteContentEl");
|
|
||||||
}
|
|
||||||
settingsModalContainer.style.display = "none";
|
|
||||||
modalBg.style.display = "none";
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.error("Failed to get Settings Modal save button.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.error("Failed to get Settings Modal elements.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,6 +6,5 @@ export type Note = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Settings = {
|
export type Settings = {
|
||||||
fontSize: string,
|
fontSize: string
|
||||||
ocrLanguage: string,
|
|
||||||
};
|
};
|
||||||
|
|
133
src/styles.css
133
src/styles.css
|
@ -13,22 +13,18 @@
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
-webkit-text-size-adjust: 100%;
|
-webkit-text-size-adjust: 100%;
|
||||||
|
|
||||||
margin-top: 0.25em;
|
margin-top: 0.5em;
|
||||||
|
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-bar {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#button-row {
|
#button-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
flex-flow: wrap;
|
|
||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
|
@ -43,27 +39,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor {
|
.editor {
|
||||||
background-color: #1f1f1f;
|
background-color: #41005a;
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: calc(100vh - 1vh);
|
height: 100%;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
justify-content: flex-end;
|
||||||
|
|
||||||
#create-input {
|
|
||||||
flex-grow: 1;
|
|
||||||
margin: 0.5em;
|
|
||||||
font-size: 16px;
|
|
||||||
line-height: 1.5;
|
|
||||||
padding: 10px;
|
|
||||||
border: 1px solid #3b3b3b;
|
|
||||||
border-radius: 5px;
|
|
||||||
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
|
|
||||||
resize: none;
|
|
||||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
|
||||||
background-color: #252525;
|
|
||||||
color: #f6f6f6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.row {
|
.row {
|
||||||
|
@ -101,26 +84,19 @@ button {
|
||||||
|
|
||||||
button {
|
button {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover {
|
button:hover {
|
||||||
border-color: #c539d8;
|
border-color: #396cd8;
|
||||||
box-shadow: 0 0 5px #c539d8, 0 0 10px #c539d8, 0 0 15px #c539d8, 0 0 20px #c539d8;
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button:active {
|
button:active {
|
||||||
border-color: #ab39d8;
|
border-color: #396cd8;
|
||||||
background-color: #44003e;
|
background-color: #e8e8e8;
|
||||||
}
|
}
|
||||||
|
|
||||||
#create-tag {
|
#create-tag {
|
||||||
margin: 0.5em;
|
margin: 0.5em;
|
||||||
|
|
||||||
background-color: #252525;
|
|
||||||
color: #f6f6f6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#create-input {
|
#create-input {
|
||||||
|
@ -172,20 +148,7 @@ button {
|
||||||
.sidebar {
|
.sidebar {
|
||||||
background-color: #0f0f0f;
|
background-color: #0f0f0f;
|
||||||
width: 35%;
|
width: 35%;
|
||||||
padding: 0 20px;
|
padding: 20px;
|
||||||
|
|
||||||
border-radius: 15px;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.resizable-handle {
|
|
||||||
width: 5px;
|
|
||||||
background-color: #0f0f0f;
|
|
||||||
cursor: ew-resize;
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.note-sidebar-container {
|
.note-sidebar-container {
|
||||||
|
@ -205,58 +168,20 @@ button {
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-note-id {
|
.sidebar-note-id {
|
||||||
margin-right: 30px;
|
margin-right: 10px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-note-content {
|
.sidebar-note-content {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
|
||||||
text-align: left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-note-tag {
|
.sidebar-note-tag {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
padding: 2px 6px;
|
padding: 2px 6px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
|
|
||||||
flex-shrink: 0;
|
|
||||||
flex-grow: 0;
|
|
||||||
|
|
||||||
overflow: hidden;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
|
|
||||||
#reverse-icon-asc {
|
|
||||||
display: blocK;
|
|
||||||
|
|
||||||
width: 1.5em;
|
|
||||||
height: 1.5em;
|
|
||||||
|
|
||||||
color: white;
|
|
||||||
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
margin-right: 1.5em;
|
|
||||||
margin-left: -0.8em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#reverse-icon-desc {
|
|
||||||
display: none;
|
|
||||||
|
|
||||||
width: 1.5em;
|
|
||||||
height: 1.5em;
|
|
||||||
|
|
||||||
color: white;
|
|
||||||
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
margin-right: 1.5em;
|
|
||||||
margin-left: -0.8em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* CONTEXT MENU */
|
/* CONTEXT MENU */
|
||||||
|
@ -271,8 +196,6 @@ button {
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
|
||||||
background-color: #252525;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu button {
|
.menu button {
|
||||||
|
@ -290,10 +213,7 @@ button {
|
||||||
/* Searchbar */
|
/* Searchbar */
|
||||||
|
|
||||||
.searchbar-container {
|
.searchbar-container {
|
||||||
margin: 0.8em 0.5em 0.5em 0.5em;
|
margin: 0.5em;
|
||||||
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#note-searchbar {
|
#note-searchbar {
|
||||||
|
@ -304,11 +224,6 @@ button {
|
||||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||||
outline: none;
|
outline: none;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
line-height: 1.5;
|
|
||||||
margin: 0 -0.6em;
|
|
||||||
|
|
||||||
background-color: #252525;
|
|
||||||
color: #f6f6f6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#note-searchbar::placeholder {}
|
#note-searchbar::placeholder {}
|
||||||
|
@ -343,24 +258,6 @@ button {
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
#settings-modal-container {
|
|
||||||
display: none;
|
|
||||||
|
|
||||||
position: fixed;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
|
|
||||||
padding: 2em;
|
|
||||||
|
|
||||||
z-index: 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
#save-settings-button {
|
|
||||||
margin: 1em;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MISC */
|
/* MISC */
|
||||||
|
|
||||||
/* Fancier Scrollbar */
|
/* Fancier Scrollbar */
|
||||||
|
@ -384,9 +281,3 @@ button {
|
||||||
::-webkit-scrollbar-thumb:hover {
|
::-webkit-scrollbar-thumb:hover {
|
||||||
background: #555;
|
background: #555;
|
||||||
}
|
}
|
||||||
|
|
||||||
.unselectable {
|
|
||||||
-webkit-user-select: none; /* Safari */
|
|
||||||
-ms-user-select: none; /* IE 10 and IE 11 */
|
|
||||||
user-select: none; /* Standard syntax */
|
|
||||||
}
|
|
Loading…
Reference in New Issue