Skip to content
This repository was archived by the owner on Jan 3, 2026. It is now read-only.

Commit 8ea647d

Browse files
authored
Merge pull request #43 from CKylinMC:dev
Publish v1.2.3
2 parents 107d685 + 9729d30 commit 8ea647d

File tree

15 files changed

+271
-123
lines changed

15 files changed

+271
-123
lines changed

components.d.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pasteme",
33
"private": true,
4-
"version": "1.2.2",
4+
"version": "1.2.3",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src-tauri/Cargo.lock

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pasteme"
3-
version = "1.2.2"
3+
version = "1.2.3"
44
description = "A simple clipboard manager"
55
authors = ["CKylinMC"]
66
edition = "2021"
@@ -34,3 +34,4 @@ tauri-plugin-autostart = "2"
3434
tauri-plugin-global-shortcut = "2"
3535
tauri-plugin-single-instance = "2"
3636
tauri-plugin-updater = "2"
37+
tauri-plugin-cors-fetch = "3.1.0"

src-tauri/capabilities/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"clipboard-manager:allow-write-image",
4444
"clipboard-manager:allow-write-text",
4545
"process:default",
46+
"cors-fetch:default",
4647
"updater:default",
4748
{
4849
"identifier": "http:default",

src-tauri/src/lib.rs

Lines changed: 165 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
mod tray;
22

3-
use enigo::{Direction, Enigo, Key, Keyboard, Settings};
4-
use tauri::{AppHandle, Manager, Runtime};
3+
use enigo::{Direction, Enigo, Key, Keyboard, Mouse, Settings};
4+
use tauri::{AppHandle, Manager, Monitor, PhysicalPosition, Runtime};
55
use tauri_plugin_autostart::MacosLauncher;
6+
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
67
use tauri_plugin_store::StoreExt;
78
use window_vibrancy::{apply_acrylic, apply_mica};
89

910
use serde_json::json;
1011

12+
// 定义默认的Panel窗口大小
13+
const DEFAULT_PANEL_WIDTH: i32 = 400;
14+
const DEFAULT_PANEL_HEIGHT: i32 = 476;
15+
1116
#[tauri::command]
1217
async fn input_text(text: &str) -> Result<(), String> {
1318
let mut enigo = Enigo::new(&Settings::default()).unwrap();
@@ -27,7 +32,6 @@ async fn simulate_paste() -> Result<(), String> {
2732
#[tauri::command]
2833
async fn get_key_from_store<R: Runtime>(
2934
app: tauri::AppHandle<R>,
30-
_window: tauri::Window<R>,
3135
key: String,
3236
fallback: serde_json::Value,
3337
) -> Result<serde_json::Value, String> {
@@ -49,7 +53,6 @@ async fn get_key_from_store<R: Runtime>(
4953
#[tauri::command]
5054
async fn set_key_to_store<R: Runtime>(
5155
app: tauri::AppHandle<R>,
52-
_window: tauri::Window<R>,
5356
key: String,
5457
value: serde_json::Value,
5558
) -> Result<(), String> {
@@ -66,12 +69,150 @@ async fn set_key_to_store<R: Runtime>(
6669
fn show_window(app: &AppHandle) {
6770
let windows = app.webview_windows();
6871

69-
windows
70-
.values()
71-
.next()
72-
.expect("Sorry, no window found")
73-
.set_focus()
74-
.expect("Can't Bring Window to Focus");
72+
let window = windows.values().next().expect("Sorry, no window found");
73+
window.show().expect("Can't Show Window");
74+
window.set_focus().expect("Can't Bring Window to Focus");
75+
}
76+
77+
fn show_window_with_name(app: &AppHandle<tauri::Wry>, name: &str) {
78+
let windows = app.webview_windows();
79+
80+
let window = windows.get(name).expect("Sorry, no window found");
81+
window.show().expect("Can't Show Window");
82+
window.set_focus().expect("Can't Bring Window to Focus");
83+
}
84+
85+
fn show_window_with_name_and_position(app: &AppHandle<tauri::Wry>, pos: PhysicalPosition<i32>) {
86+
let windows = app.webview_windows();
87+
let window = match windows.get("context") {
88+
Some(win) => win.clone(),
89+
None => return,
90+
};
91+
92+
let monitors = match window.available_monitors() {
93+
Ok(m) => m,
94+
Err(_) => {
95+
let _ = window.center();
96+
let _ = window.show();
97+
let _ = window.set_focus();
98+
return;
99+
}
100+
};
101+
102+
if monitors.is_empty() {
103+
let _ = window.center();
104+
let _ = window.show();
105+
let _ = window.set_focus();
106+
return;
107+
}
108+
109+
tauri::async_runtime::spawn(async move {
110+
let panel_width = DEFAULT_PANEL_WIDTH;
111+
let panel_height = DEFAULT_PANEL_HEIGHT;
112+
113+
let mut current_monitor: Option<Monitor> = None;
114+
for monitor in monitors {
115+
let size = monitor.size();
116+
let position: &PhysicalPosition<i32> = monitor.position();
117+
118+
let monitor_x = position.x;
119+
let monitor_y = position.y;
120+
let monitor_width = size.width as i32;
121+
let monitor_height = size.height as i32;
122+
123+
if pos.x >= monitor_x
124+
&& pos.x < monitor_x + monitor_width
125+
&& pos.y >= monitor_y
126+
&& pos.y < monitor_y + monitor_height
127+
{
128+
current_monitor = Some(monitor);
129+
break;
130+
}
131+
}
132+
133+
if let Some(monitor) = current_monitor {
134+
let size = monitor.size();
135+
let position = monitor.position();
136+
137+
let monitor_x = position.x;
138+
let monitor_y = position.y;
139+
let monitor_width = size.width as i32;
140+
let monitor_height = size.height as i32;
141+
142+
let mut x = pos.x;
143+
let mut y = pos.y;
144+
145+
if x + panel_width > monitor_x + monitor_width {
146+
x = x - panel_width;
147+
}
148+
149+
if y + panel_height > monitor_y + monitor_height {
150+
y = y - panel_height;
151+
}
152+
153+
x = std::cmp::max(
154+
monitor_x,
155+
std::cmp::min(x, monitor_x + monitor_width - panel_width),
156+
);
157+
y = std::cmp::max(
158+
monitor_y,
159+
std::cmp::min(y, monitor_y + monitor_height - panel_height),
160+
);
161+
162+
let adjusted_pos = PhysicalPosition::new(x, y);
163+
164+
let _ = window.set_position(adjusted_pos);
165+
let _ = window.show();
166+
let _ = window.set_always_on_top(true);
167+
let _ = window.set_focus();
168+
return;
169+
}
170+
171+
let _ = window.set_position(pos);
172+
let _ = window.show();
173+
let _ = window.set_always_on_top(true);
174+
let _ = window.set_focus();
175+
176+
});
177+
}
178+
179+
#[tauri::command]
180+
async fn reregister_panel_shortcut(app: tauri::AppHandle<tauri::Wry>) -> Result<(), String> {
181+
let _ = app.global_shortcut().unregister_all();
182+
let mut shortcut_string = "CmdOrControl+Shift+V".to_string();
183+
let stores = app.store("store.bin");
184+
let _store = match stores {
185+
Ok(store) => {
186+
if let Some(value) = store.get("globalShortcut") {
187+
if let Some(s) = value.as_str() {
188+
shortcut_string = s.to_string();
189+
}
190+
}
191+
}
192+
Err(_) => return Err("Failed to read config".to_string()),
193+
};
194+
let shortcut = match shortcut_string.parse::<Shortcut>() {
195+
Ok(s) => s,
196+
Err(_) => return Err("Failed to parse shortcut".to_string()),
197+
};
198+
199+
let _ = app
200+
.global_shortcut()
201+
.on_shortcut(shortcut, move |app_handle, _event, _shortcut| {
202+
let enigo = Enigo::new(&Settings::default());
203+
let mut location = PhysicalPosition::new(0, 0);
204+
205+
// 获取鼠标位置
206+
if let Ok(enigo) = enigo {
207+
if let Ok(pos) = enigo.location() {
208+
location = PhysicalPosition::new(pos.0 as i32, pos.1 as i32);
209+
}
210+
}
211+
212+
show_window_with_name_and_position(app_handle, location);
213+
});
214+
215+
Ok(())
75216
}
76217

77218
#[cfg_attr(mobile, tauri::mobile_entry_point)]
@@ -82,7 +223,7 @@ pub fn run() {
82223
.plugin(tauri_plugin_process::init())
83224
.plugin(tauri_plugin_store::Builder::new().build())
84225
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
85-
let _ = show_window(app);
226+
let _ = show_window_with_name(app, "main");
86227
}))
87228
.plugin(tauri_plugin_autostart::init(
88229
MacosLauncher::LaunchAgent,
@@ -102,14 +243,26 @@ pub fn run() {
102243

103244
let handle = app.handle();
104245
let _ = tray::create_tray(handle);
246+
247+
let args: Vec<String> = std::env::args().collect();
248+
if !args.contains(&"--autostart".to_string()) && !args.contains(&"--silent".to_string())
249+
{
250+
show_window_with_name(app.handle(), "main");
251+
}
252+
let app_handle = app.handle().clone();
253+
tauri::async_runtime::spawn(async move {
254+
let _ = reregister_panel_shortcut(app_handle).await;
255+
});
105256
Ok(())
106257
})
107258
.plugin(tauri_plugin_opener::init())
259+
.plugin(tauri_plugin_cors_fetch::init())
108260
.invoke_handler(tauri::generate_handler![
109261
input_text,
110262
simulate_paste,
111263
get_key_from_store,
112-
set_key_to_store
264+
set_key_to_store,
265+
reregister_panel_shortcut
113266
])
114267
.run(tauri::generate_context!())
115268
.expect("error while running tauri application");

src-tauri/tauri.conf.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "PasteMe",
4-
"version": "1.2.2",
4+
"version": "1.2.3",
55
"identifier": "in.ckyl.pasteme",
66
"build": {
77
"beforeDevCommand": "yarn dev",
@@ -19,6 +19,7 @@
1919
"decorations": false,
2020
"resizable": false,
2121
"transparent": true,
22+
"visible": false,
2223
"url": "/"
2324
},
2425
{
@@ -35,6 +36,7 @@
3536
"transparent": true
3637
}
3738
],
39+
"withGlobalTauri": true,
3840
"security": {
3941
"csp": null
4042
}

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ onBeforeUnmount(() => {
2727
</script>
2828

2929
<template>
30-
<n-config-provider :theme="usingTheme" class="size-full !bg-transparent">
30+
<n-config-provider :theme="usingTheme" :class="['size-full !bg-transparent', isSystemDarkTheme ? 'dark' : '']">
3131
<RouterView />
3232
</n-config-provider>
3333
</template>

src/AppInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const AppInfo = {
2-
version: "1.2.2",
2+
version: "1.2.3",
33
};

src/components/KeySelector.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ onBeforeUnmount(() => {
210210
display: inline-block;
211211
transition: 0.3s;
212212
background: #b9b9b91a;
213-
color: rgb(0, 0, 0);
213+
color: black;
214214
border: 2px solid rgba(128, 128, 128, 0.116);
215215
}
216216
.dark .keyBox {
217217
background: #383838;
218-
color: white;
218+
color: white !important;
219219
border: 2px solid rgba(128, 128, 128, 0.116);
220220
}
221221
.keyBox:hover {

0 commit comments

Comments
 (0)