Skip to content

Commit 5925ae3

Browse files
committed
update
1 parent 051d2bb commit 5925ae3

File tree

7 files changed

+55
-6
lines changed

7 files changed

+55
-6
lines changed

crates/rs-tauri-vue/Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ tasks:
6363
dir: "src-tauri"
6464
ignore_error: true
6565

66+
kill:
67+
cmds:
68+
- fig run kill-all-processes-at-port --port 7173
6669

6770
test:
6871
cmds:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
pub mod calc;
22
pub mod todo;
3+
4+
pub use todo::*;
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
#![cfg_attr(all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows")]
2+
3+
use tracing::info;
4+
5+
use crate::{proto::TodoEntity, service::AppService};
6+
17
#[tauri::command]
2-
pub fn add_todo(title: String, description: String) -> bool {
3-
// AppService::new().ctx.sql.
4-
false
8+
pub async fn add_todo(title: String, description: String) -> i64 {
9+
let s = AppService::new().await;
10+
11+
let ret = s
12+
.storage
13+
.sql
14+
.todo
15+
.add_todo(&TodoEntity { id: 0, title, description, done: false, completed: false })
16+
.await;
17+
18+
info!("add todo: {:?}", ret);
19+
20+
ret.unwrap()
521
}

crates/rs-tauri-vue/src-tauri/src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use window_shadows::set_shadow;
1313

1414
use command::calc::backend_add;
1515

16+
use crate::ctx::AppContext;
17+
1618
mod command;
1719
mod config;
1820
mod ctx;
@@ -37,6 +39,8 @@ fn main() {
3739
// tips:
3840
info!("tauri main started");
3941

42+
init_app();
43+
4044
// todo x: 系统托盘菜单
4145
let tray = SystemTray::new().with_menu(menu::tray_menu());
4246

@@ -88,7 +92,7 @@ fn main() {
8892
},
8993
_ => {},
9094
})
91-
.invoke_handler(tauri::generate_handler![backend_add])
95+
.invoke_handler(tauri::generate_handler![backend_add, command::add_todo,])
9296
.setup(|app| {
9397
#[cfg(debug_assertions)]
9498
{
@@ -123,6 +127,11 @@ fn main() {
123127
.expect("error while running tauri application");
124128
}
125129

130+
fn init_app() {
131+
// init sqlite
132+
AppContext::global();
133+
}
134+
126135
pub trait WindowExt {
127136
#[cfg(target_os = "macos")]
128137
fn set_transparent_title_bar(&self, title_transparent: bool, remove_toolbar: bool);

crates/rs-tauri-vue/src-tauri/src/storage/sql/db.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ impl Clone for SqlConn {
4141

4242
impl SqlConn {
4343
pub async fn default() -> Self {
44-
let conn = new_sql_conn("app.db").await;
45-
Self { conn }
44+
Self::new("app.db").await
4645
}
4746

4847
pub async fn new(db_name: &str) -> Self {

crates/rs-tauri-vue/src-tauri/src/storage/sql/todo.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use sqlx::{Acquire, Executor, Statement};
2+
use tracing::info;
23

34
use crate::{proto::TodoEntity, storage::db::SqlConn};
45

@@ -27,6 +28,8 @@ impl TodoSqlScope {
2728
.await?
2829
.last_insert_rowid();
2930

31+
info!("add todo: {:?}", todo);
32+
3033
Ok(id)
3134
}
3235

crates/rs-tauri-vue/src/components/demo/Hello.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ import {invoke} from '@tauri-apps/api/tauri'
44
defineProps<{ msg: string }>()
55
66
const count = ref(0)
7+
const addRet = ref(0)
8+
79
810
async function backendAdd() {
911
count.value = await invoke('backend_add', {number: count.value})
1012
}
13+
14+
async function addTodo() {
15+
// todo x: sqlite crud
16+
addRet.value = await invoke('add_todo', {title: "test from fe", description: "test from fe"})
17+
console.log("addTodo", addRet)
18+
}
19+
20+
1121
</script>
1222

1323
<template>
@@ -34,6 +44,13 @@ async function backendAdd() {
3444
</n-grid-item>
3545

3646

47+
<n-grid-item>
48+
<n-button style="background-color: orange" type="error" @click="addTodo">
49+
Add Todo (call rust in backend)
50+
</n-button>
51+
</n-grid-item>
52+
53+
3754
</n-grid>
3855

3956

0 commit comments

Comments
 (0)