diff --git a/index.html b/index.html index 5feac4f..51946f2 100644 --- a/index.html +++ b/index.html @@ -26,9 +26,10 @@
- + +
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0d721aa..3a4bcfb 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1701,6 +1701,17 @@ dependencies = [ "objc_exception", ] +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -2225,6 +2236,30 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "rfd" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0149778bd99b6959285b0933288206090c50e2327f47a9c463bfdbf45c8823ea" +dependencies = [ + "block", + "dispatch", + "glib-sys", + "gobject-sys", + "gtk-sys", + "js-sys", + "lazy_static", + "log", + "objc", + "objc-foundation", + "objc_id", + "raw-window-handle", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows 0.37.0", +] + [[package]] name = "rusqlite" version = "0.31.0" @@ -2727,6 +2762,7 @@ dependencies = [ "rand 0.8.5", "raw-window-handle", "regex", + "rfd", "semver", "serde", "serde_json", @@ -3300,6 +3336,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.92" @@ -3329,6 +3377,16 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webkit2gtk" version = "0.18.2" @@ -3445,6 +3503,19 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647" +dependencies = [ + "windows_aarch64_msvc 0.37.0", + "windows_i686_gnu 0.37.0", + "windows_i686_msvc 0.37.0", + "windows_x86_64_gnu 0.37.0", + "windows_x86_64_msvc 0.37.0", +] + [[package]] name = "windows" version = "0.39.0" @@ -3599,6 +3670,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +[[package]] +name = "windows_aarch64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a" + [[package]] name = "windows_aarch64_msvc" version = "0.39.0" @@ -3623,6 +3700,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +[[package]] +name = "windows_i686_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1" + [[package]] name = "windows_i686_gnu" version = "0.39.0" @@ -3647,6 +3730,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +[[package]] +name = "windows_i686_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c" + [[package]] name = "windows_i686_msvc" version = "0.39.0" @@ -3671,6 +3760,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +[[package]] +name = "windows_x86_64_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d" + [[package]] name = "windows_x86_64_gnu" version = "0.39.0" @@ -3713,6 +3808,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +[[package]] +name = "windows_x86_64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" + [[package]] name = "windows_x86_64_msvc" version = "0.39.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3d214f2..e0fd7ec 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" tauri-build = { version = "1", features = [] } [dependencies] -tauri = { version = "1", features = ["shell-open"] } +tauri = { version = "1", features = [ "path-all", "fs-read-file", "fs-write-file", "fs-read-dir", "dialog-all", "shell-open"] } serde = { version = "1", features = ["derive"] } serde_json = "1" libsnotes = { path = "../libsnotes" } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 0282379..e3e88b2 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -16,6 +16,25 @@ "shell": { "all": false, "open": true + }, + "dialog": { + "all": true + }, + "fs": { + "all": false, + "copyFile": false, + "createDir": false, + "exists": false, + "readDir": true, + "readFile": true, + "removeDir": false, + "removeFile": false, + "renameFile": false, + "scope": [], + "writeFile": true + }, + "path": { + "all": true } }, "windows": [ diff --git a/src/main.ts b/src/main.ts index fc11ace..d6d9d36 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,9 @@ import { invoke } from "@tauri-apps/api/tauri"; +import { save } from "@tauri-apps/api/dialog"; import { Note, Settings } from "./model"; import { createWorker } from 'tesseract.js'; +import { writeTextFile } from "@tauri-apps/api/fs"; +import { homeDir } from "@tauri-apps/api/path"; let notesMsgEl: HTMLElement | null; @@ -23,6 +26,11 @@ let idModalActive = false; let typingTimer: number | null = null; const AUTOSAVE_DELAY = 5000; +const exportFileOptions = { + //defaultPath: "/path/to/your/default/directory", + filters: [{ name: "Text Files", extensions: ["txt"] }], +}; + enum EditorState { NEW, @@ -139,6 +147,10 @@ window.addEventListener("DOMContentLoaded", async () => { e.preventDefault(); showNotes(); }); + document.querySelector('#export-button')?.addEventListener("click", (e) => { + e.preventDefault(); + exportNote(createNoteContentEl ? createNoteContentEl.value : null); + }) // Pressing TAB should insert intends in the editor. // This could potentially cause issues later... @@ -582,3 +594,26 @@ async function openNoteById(value: string): Promise { } return false; } + +async function exportNote(contents: string | null) { + if (contents) { + const title = contents.slice(0, 10); + 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"); + } +} +