Skip to content

Commit de2be28

Browse files
committed
main update
1 parent eac9f6e commit de2be28

File tree

20 files changed

+1380
-2432
lines changed

20 files changed

+1380
-2432
lines changed

apps/backend/Cargo.lock

Lines changed: 89 additions & 273 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/backend/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust
99

1010

1111
[profile.dev]
12-
opt-level = "z"
12+
opt-level = 0
1313
debug = true
1414
split-debuginfo = "unpacked"
1515
debug-assertions = true
1616
overflow-checks = true
17-
lto = true
18-
strip = true
17+
lto = false
18+
strip = false
1919
panic = "abort"
2020
incremental = true
21-
codegen-units = 256
21+
codegen-units = 16
2222
rpath = false
2323

2424
[profile.release]

apps/backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"cargo:remove": "cargo remove"
1212
},
1313
"devDependencies": {
14-
"@tauri-apps/cli": "2.3.1"
14+
"@tauri-apps/cli": "2.4.0"
1515
}
1616
}

apps/backend/tauri/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ name = "tab_clip_manager_lib"
1010
crate-type = ["staticlib", "cdylib", "rlib"]
1111

1212
[build-dependencies]
13-
tauri-build = { version = "2.0.6", features = [] }
13+
tauri-build = { version = "2.1.0", features = [] }
1414

1515
[dependencies]
1616
anyhow = "1"
17-
tauri = { version = "2.3.1", default-features = false, features = ["tray-icon"] }
17+
tauri = { version = "2.4.0", default-features = false, features = ["tray-icon"] }
1818
tauri-plugin-clipboard-manager = "2.2.2"
1919
prisma-cli = { path = "../prisma-cli" }
2020
serde = { workspace = true }

apps/backend/tauri/src/lib.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::sync::{Arc, Mutex};
22

3-
use tauri::{App, AppHandle, Emitter, State};
4-
use tauri_plugin_clipboard_manager::ClipboardExt;
5-
use tokio::time::{self, Duration};
3+
use tauri::{AppHandle, Emitter, State, WindowEvent};
64

75
// use prisma::PrismaClient;
86

@@ -14,55 +12,58 @@ struct ClipboardState {
1412
mod prisma;
1513
mod shortcuts;
1614
mod tray_menu;
15+
mod watcher;
1716

1817
#[tauri::command]
1918
fn get_recent_clipboard_entries(
2019
clipboard_state: State<'_, Arc<Mutex<ClipboardState>>>,
2120
) -> Vec<String> {
2221
let state = clipboard_state.lock().unwrap();
23-
println!("Returning recent clipboard entries: {:?}", state.recent);
2422
state.recent.clone()
2523
}
2624

2725
#[cfg_attr(mobile, tauri::mobile_entry_point)]
28-
pub async fn run() -> anyhow::Result<()> {
26+
pub fn run() {
2927
let clipboard_state = Arc::new(Mutex::new(ClipboardState::default()));
30-
let app = tauri::Builder::default()
28+
tauri::Builder::default()
3129
.manage(clipboard_state.clone())
3230
.setup(|app| {
33-
let app_handle = app.handle().clone();
31+
let app_handle = app.handle();
32+
start_app(&app_handle)?;
33+
34+
let app_handle_clone = app_handle.clone();
3435
tauri::async_runtime::spawn(async move {
35-
start_app(&app_handle).await.unwrap();
36+
watcher::run(app_handle_clone).await;
3637
});
3738
Ok(())
3839
})
3940
.on_menu_event(|app, event| tray_menu::on_menu_event(app, event))
4041
.on_window_event(|window, event| match event {
41-
tauri::WindowEvent::Focused(focused) => {
42+
WindowEvent::CloseRequested { api, .. } => {
43+
if let Err(e) = window.hide() {
44+
eprintln!("Failed to hide window: {:?}", e);
45+
}
46+
api.prevent_close();
47+
}
48+
WindowEvent::Focused(focused) => {
4249
if window.label() == "Tab_Clip_Manager_main" {
4350
if *focused {
4451
window.emit("window_open", ()).unwrap();
4552
} else {
46-
window.hide().unwrap();
53+
if let Err(e) = window.hide() {
54+
eprintln!("Failed to hide window: {:?}", e);
55+
}
4756
}
4857
}
4958
}
5059
_ => {}
5160
})
5261
.invoke_handler(tauri::generate_handler![get_recent_clipboard_entries])
53-
.build(tauri::generate_context!())?;
54-
55-
app.run(|_app_handle, event| match event {
56-
tauri::RunEvent::ExitRequested { api, .. } => {
57-
api.prevent_exit();
58-
}
59-
_ => {}
60-
});
61-
62-
Ok(())
62+
.run(tauri::generate_context!())
63+
.expect("error while running tauri application");
6364
}
6465

65-
async fn start_app(app: &AppHandle) -> anyhow::Result<()> {
66+
fn start_app(app: &AppHandle) -> anyhow::Result<()> {
6667
tray_menu::setup_tray_menu(app)?;
6768
shortcuts::add_shortcuts(app)?;
6869

apps/backend/tauri/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

4-
#[tokio::main]
5-
async fn main() {
6-
let _ = tab_clip_manager_lib::run().await;
4+
fn main() {
5+
tab_clip_manager_lib::run();
76
}

apps/backend/tauri/src/shortcuts.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ fn main_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event: ShortcutEv
5656
match event.state() {
5757
ShortcutState::Pressed => {}
5858
ShortcutState::Released => {
59-
app.get_webview_window("Tab_Clip_Manager_main")
60-
.unwrap()
61-
.show()
62-
.unwrap();
59+
app.get_webview_window("Tab_Clip_Manager_main").and_then(|window| {
60+
window
61+
.show()
62+
.map_err(|e| {
63+
eprintln!("Failed to show window: {:?}", e);
64+
e
65+
})
66+
.ok()
67+
});
6368
}
6469
}
6570
}
6671

67-
// fn copy_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event: ShortcutEvent) {
68-
// if shortcut != &copy_shortcut() {
72+
// fn copy_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event:
73+
// ShortcutEvent) { if shortcut != &copy_shortcut() {
6974
// return;
7075
// }
7176
// match event.state() {
@@ -74,8 +79,8 @@ fn main_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event: ShortcutEv
7479
// }
7580
// }
7681

77-
// fn cut_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event: ShortcutEvent) {
78-
// if shortcut != &cut_shortcut() {
82+
// fn cut_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event:
83+
// ShortcutEvent) { if shortcut != &cut_shortcut() {
7984
// return;
8085
// }
8186
// match event.state() {
@@ -87,8 +92,8 @@ fn main_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event: ShortcutEv
8792
// }
8893
// }
8994

90-
// fn paste_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event: ShortcutEvent) {
91-
// if shortcut != &paste_shortcut() {
95+
// fn paste_shortcut_handler(app: &AppHandle, shortcut: &Shortcut, event:
96+
// ShortcutEvent) { if shortcut != &paste_shortcut() {
9297
// return;
9398
// }
9499
// match event.state() {
Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
use tauri::{
2+
AppHandle, Error, Manager,
23
menu::{Menu, MenuEvent, MenuItem},
34
tray::TrayIconBuilder,
4-
AppHandle, Error, Manager,
55
};
66

77
pub fn setup_tray_menu(app: &AppHandle) -> Result<(), Error> {
8-
let open = MenuItem::with_id(app, "open", "Open", true, None::<&str>)?;
9-
let hide = MenuItem::with_id(app, "hide", "Hide", true, None::<&str>)?;
108
let settings = MenuItem::with_id(app, "settings", "Settings", true, None::<&str>)?;
119
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
1210

13-
let menu = Menu::with_items(app, &[&open, &hide, &settings, &quit])?;
11+
let menu = Menu::with_items(app, &[&settings, &quit])?;
1412

1513
let _tray = TrayIconBuilder::new()
1614
.icon(app.default_window_icon().unwrap().clone())
@@ -22,29 +20,20 @@ pub fn setup_tray_menu(app: &AppHandle) -> Result<(), Error> {
2220

2321
pub fn on_menu_event(app: &AppHandle, event: MenuEvent) {
2422
match event.id.as_ref() {
25-
"open" => {
26-
app.get_webview_window("Tab_Clip_Manager_main")
27-
.unwrap()
28-
.show()
29-
.unwrap();
30-
}
31-
"hide" => {
32-
app.get_webview_window("Tab_Clip_Manager_main")
33-
.unwrap()
34-
.hide()
35-
.unwrap();
36-
}
3723
"settings" => {
38-
app.get_webview_window("Tab_Clip_Manager_settings")
39-
.unwrap()
40-
.show()
41-
.unwrap();
24+
app.get_webview_window("Tab_Clip_Manager_settings").and_then(|window| {
25+
window
26+
.show()
27+
.map_err(|e| {
28+
eprintln!("Failed to show window: {:?}", e);
29+
e
30+
})
31+
.ok()
32+
});
4233
}
4334
"quit" => {
4435
app.exit(0);
4536
}
46-
_ => {
47-
println!("menu item {:?} not handled", event.id);
48-
}
37+
_ => {}
4938
}
5039
}

apps/backend/tauri/src/watcher.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use std::{
2+
sync::{Arc, Mutex},
3+
time::Duration,
4+
};
5+
6+
use tauri::{AppHandle, Manager, async_runtime::spawn};
7+
use tauri_plugin_clipboard_manager::ClipboardExt;
8+
use tokio::{sync::watch, time::sleep};
9+
10+
use crate::ClipboardState;
11+
12+
pub async fn run(app_handle: AppHandle) {
13+
let (tx, mut rx) = watch::channel(String::new());
14+
15+
let app_handle_clone = app_handle.clone();
16+
spawn(async move {
17+
let mut last_content = String::new();
18+
19+
loop {
20+
match app_handle_clone.clipboard().read_text() {
21+
Ok(content) => {
22+
if content != last_content {
23+
last_content = content.clone();
24+
let _ = tx.send(content);
25+
}
26+
}
27+
Err(e) => {
28+
eprintln!("Clipboard read error: {:?}", e);
29+
}
30+
}
31+
sleep(Duration::from_millis(500)).await;
32+
}
33+
});
34+
35+
36+
let app_handle_clone = app_handle.clone();
37+
spawn(async move {
38+
while rx.changed().await.is_ok() {
39+
let new_content = rx.borrow().clone();
40+
41+
if let Some(state) = app_handle_clone.try_state::<Arc<Mutex<ClipboardState>>>() {
42+
let mut clipboard_state = state.lock().unwrap();
43+
clipboard_state.recent.insert(0, new_content);
44+
}
45+
}
46+
});
47+
}

apps/frontend/package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,21 @@
2727
"devDependencies": {
2828
"@repo/linter": "workspace:*",
2929
"@repo/tsconfig": "workspace:*",
30-
"@tailwindcss/nesting": "0.0.0-insiders.565cd3e",
3130
"@types/node": "22.13.13",
3231
"@types/react": "19.0.12",
3332
"@types/react-dom": "19.0.4",
3433
"@vitejs/plugin-react": "^4.3.4",
3534
"@vitejs/plugin-react-swc": "3.8.1",
36-
"autoprefixer": "10.4.21",
3735
"eslint": "9.23.0",
3836
"jiti": "^2.4.2",
3937
"path": "^0.12.7",
40-
"postcss": "8.5.3",
41-
"postcss-import": "^16.1.0",
42-
"postcss-nesting": "^13.0.1",
43-
"sass-embedded": "1.86.0",
44-
"tailwind-merge": "3.0.2",
45-
"tailwindcss": "4.0.15",
46-
"tailwindcss-animate": "^1.0.7",
38+
"tailwind-merge": "^3.0.2",
39+
"tailwindcss": "^4.0.15",
40+
"tw-animate-css": "^1.2.4",
4741
"typescript": "5.8.2",
4842
"vite": "6.2.3",
43+
"eslint-plugin-react-hooks": "^5.1.0",
44+
"eslint-plugin-react-refresh": "^0.4.19",
4945
"vite-tsconfig-paths": "^5.1.4"
5046
}
5147
}

0 commit comments

Comments
 (0)