first commit
No files matched your search
@@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
@@ -0,0 +1,35 @@
|
||||
[package]
|
||||
name = "test"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2024"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
# The `_lib` suffix may seem redundant but it is necessary
|
||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||
name = "test_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
rusqlite = { version = "0.41.1", features = ["bundled"] }
|
||||
chrono = "0.4.45"
|
||||
|
||||
|
||||
# Read the optimization guideline for more details: https://tauri.app/concept/size/#cargo-configuration
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = 3
|
||||
panic = "abort"
|
||||
strip = true
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default"
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 567 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 536 B |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 777 B |
|
After Width: | Height: | Size: 1020 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 848 B |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
@@ -0,0 +1,48 @@
|
||||
use rusqlite::Connection;
|
||||
|
||||
#[path = "note.rs"]
|
||||
mod note;
|
||||
use note::Note;
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_notes_list(search: &str) -> Vec<Note> {
|
||||
let conn = Connection::open("notes.db").expect("Failed to open database");
|
||||
|
||||
conn.execute(
|
||||
"CREATE TABLE IF NOT EXISTS notes
|
||||
(id INTEGER PRIMARY KEY, title TEXT, text TEXT, created_at TEXT)",
|
||||
[],
|
||||
)
|
||||
.expect("Failed to create table");
|
||||
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT id, title, text, created_at FROM notes WHERE title LIKE ? OR text LIKE ? ORDER BY created_at DESC")
|
||||
.expect("Failed to prepare statement");
|
||||
let note_iter = stmt.query_map([format!("%{}%", search), format!("%{}%", search)], |row| {
|
||||
Ok(Note {
|
||||
id: row.get(0)?,
|
||||
title: row.get(1)?,
|
||||
text: row.get(2)?,
|
||||
created_at: row.get(3)?,
|
||||
})
|
||||
});
|
||||
|
||||
let mut notes = Vec::new();
|
||||
for note in note_iter.expect("Failed to query notes") {
|
||||
let mut _note = note.expect("Failed to get note");
|
||||
_note.text = _note.text.replace("\n", "<br>").chars().take(57).collect();
|
||||
|
||||
if _note.text.len() >= 57 {
|
||||
_note.text.push_str("...");
|
||||
}
|
||||
|
||||
_note.title = _note.title.replace("\n", "<br>").chars().take(17).collect();
|
||||
|
||||
if _note.title.len() >= 17 {
|
||||
_note.title.push_str("...");
|
||||
}
|
||||
|
||||
notes.push(_note);
|
||||
}
|
||||
return notes;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#[path = "data.rs"]
|
||||
mod data;
|
||||
use data::get_notes_list;
|
||||
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![greet, get_notes_list])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
test_lib::run();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct Note {
|
||||
pub id: u32,
|
||||
pub title: String,
|
||||
pub text: String,
|
||||
pub created_at: String
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "notesapp",
|
||||
"version": "0.1.0",
|
||||
"identifier": "com.jonas.notesapp",
|
||||
"build": {
|
||||
"frontendDist": "../src"
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": true,
|
||||
"windows": [
|
||||
{
|
||||
"title": "Notizion",
|
||||
"transparent": true,
|
||||
"width": 950,
|
||||
"height": 600,
|
||||
"minWidth": 800,
|
||||
"minHeight": 500
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||