Skip to content

Commit

Permalink
Merge pull request #43 from CKylinMC:dev
Browse files Browse the repository at this point in the history
Publish v1.2.3
  • Loading branch information
CKylinMC authored Mar 3, 2025
2 parents 107d685 + 9729d30 commit 8ea647d
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 123 deletions.
33 changes: 0 additions & 33 deletions components.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pasteme",
"private": true,
"version": "1.2.2",
"version": "1.2.3",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
21 changes: 20 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pasteme"
version = "1.2.2"
version = "1.2.3"
description = "A simple clipboard manager"
authors = ["CKylinMC"]
edition = "2021"
Expand Down Expand Up @@ -34,3 +34,4 @@ tauri-plugin-autostart = "2"
tauri-plugin-global-shortcut = "2"
tauri-plugin-single-instance = "2"
tauri-plugin-updater = "2"
tauri-plugin-cors-fetch = "3.1.0"
1 change: 1 addition & 0 deletions src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"clipboard-manager:allow-write-image",
"clipboard-manager:allow-write-text",
"process:default",
"cors-fetch:default",
"updater:default",
{
"identifier": "http:default",
Expand Down
177 changes: 165 additions & 12 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
mod tray;

use enigo::{Direction, Enigo, Key, Keyboard, Settings};
use tauri::{AppHandle, Manager, Runtime};
use enigo::{Direction, Enigo, Key, Keyboard, Mouse, Settings};
use tauri::{AppHandle, Manager, Monitor, PhysicalPosition, Runtime};
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
use tauri_plugin_store::StoreExt;
use window_vibrancy::{apply_acrylic, apply_mica};

use serde_json::json;

// 定义默认的Panel窗口大小
const DEFAULT_PANEL_WIDTH: i32 = 400;
const DEFAULT_PANEL_HEIGHT: i32 = 476;

#[tauri::command]
async fn input_text(text: &str) -> Result<(), String> {
let mut enigo = Enigo::new(&Settings::default()).unwrap();
Expand All @@ -27,7 +32,6 @@ async fn simulate_paste() -> Result<(), String> {
#[tauri::command]
async fn get_key_from_store<R: Runtime>(
app: tauri::AppHandle<R>,
_window: tauri::Window<R>,
key: String,
fallback: serde_json::Value,
) -> Result<serde_json::Value, String> {
Expand All @@ -49,7 +53,6 @@ async fn get_key_from_store<R: Runtime>(
#[tauri::command]
async fn set_key_to_store<R: Runtime>(
app: tauri::AppHandle<R>,
_window: tauri::Window<R>,
key: String,
value: serde_json::Value,
) -> Result<(), String> {
Expand All @@ -66,12 +69,150 @@ async fn set_key_to_store<R: Runtime>(
fn show_window(app: &AppHandle) {
let windows = app.webview_windows();

windows
.values()
.next()
.expect("Sorry, no window found")
.set_focus()
.expect("Can't Bring Window to Focus");
let window = windows.values().next().expect("Sorry, no window found");
window.show().expect("Can't Show Window");
window.set_focus().expect("Can't Bring Window to Focus");
}

fn show_window_with_name(app: &AppHandle<tauri::Wry>, name: &str) {
let windows = app.webview_windows();

let window = windows.get(name).expect("Sorry, no window found");
window.show().expect("Can't Show Window");
window.set_focus().expect("Can't Bring Window to Focus");
}

fn show_window_with_name_and_position(app: &AppHandle<tauri::Wry>, pos: PhysicalPosition<i32>) {
let windows = app.webview_windows();
let window = match windows.get("context") {
Some(win) => win.clone(),
None => return,
};

let monitors = match window.available_monitors() {
Ok(m) => m,
Err(_) => {
let _ = window.center();
let _ = window.show();
let _ = window.set_focus();
return;
}
};

if monitors.is_empty() {
let _ = window.center();
let _ = window.show();
let _ = window.set_focus();
return;
}

tauri::async_runtime::spawn(async move {
let panel_width = DEFAULT_PANEL_WIDTH;
let panel_height = DEFAULT_PANEL_HEIGHT;

let mut current_monitor: Option<Monitor> = None;
for monitor in monitors {
let size = monitor.size();
let position: &PhysicalPosition<i32> = monitor.position();

let monitor_x = position.x;
let monitor_y = position.y;
let monitor_width = size.width as i32;
let monitor_height = size.height as i32;

if pos.x >= monitor_x
&& pos.x < monitor_x + monitor_width
&& pos.y >= monitor_y
&& pos.y < monitor_y + monitor_height
{
current_monitor = Some(monitor);
break;
}
}

if let Some(monitor) = current_monitor {
let size = monitor.size();
let position = monitor.position();

let monitor_x = position.x;
let monitor_y = position.y;
let monitor_width = size.width as i32;
let monitor_height = size.height as i32;

let mut x = pos.x;
let mut y = pos.y;

if x + panel_width > monitor_x + monitor_width {
x = x - panel_width;
}

if y + panel_height > monitor_y + monitor_height {
y = y - panel_height;
}

x = std::cmp::max(
monitor_x,
std::cmp::min(x, monitor_x + monitor_width - panel_width),
);
y = std::cmp::max(
monitor_y,
std::cmp::min(y, monitor_y + monitor_height - panel_height),
);

let adjusted_pos = PhysicalPosition::new(x, y);

let _ = window.set_position(adjusted_pos);
let _ = window.show();
let _ = window.set_always_on_top(true);
let _ = window.set_focus();
return;
}

let _ = window.set_position(pos);
let _ = window.show();
let _ = window.set_always_on_top(true);
let _ = window.set_focus();

});
}

#[tauri::command]
async fn reregister_panel_shortcut(app: tauri::AppHandle<tauri::Wry>) -> Result<(), String> {
let _ = app.global_shortcut().unregister_all();
let mut shortcut_string = "CmdOrControl+Shift+V".to_string();
let stores = app.store("store.bin");
let _store = match stores {
Ok(store) => {
if let Some(value) = store.get("globalShortcut") {
if let Some(s) = value.as_str() {
shortcut_string = s.to_string();
}
}
}
Err(_) => return Err("Failed to read config".to_string()),
};
let shortcut = match shortcut_string.parse::<Shortcut>() {
Ok(s) => s,
Err(_) => return Err("Failed to parse shortcut".to_string()),
};

let _ = app
.global_shortcut()
.on_shortcut(shortcut, move |app_handle, _event, _shortcut| {
let enigo = Enigo::new(&Settings::default());
let mut location = PhysicalPosition::new(0, 0);

// 获取鼠标位置
if let Ok(enigo) = enigo {
if let Ok(pos) = enigo.location() {
location = PhysicalPosition::new(pos.0 as i32, pos.1 as i32);
}
}

show_window_with_name_and_position(app_handle, location);
});

Ok(())
}

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

let handle = app.handle();
let _ = tray::create_tray(handle);

let args: Vec<String> = std::env::args().collect();
if !args.contains(&"--autostart".to_string()) && !args.contains(&"--silent".to_string())
{
show_window_with_name(app.handle(), "main");
}
let app_handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
let _ = reregister_panel_shortcut(app_handle).await;
});
Ok(())
})
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_cors_fetch::init())
.invoke_handler(tauri::generate_handler![
input_text,
simulate_paste,
get_key_from_store,
set_key_to_store
set_key_to_store,
reregister_panel_shortcut
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "PasteMe",
"version": "1.2.2",
"version": "1.2.3",
"identifier": "in.ckyl.pasteme",
"build": {
"beforeDevCommand": "yarn dev",
Expand All @@ -19,6 +19,7 @@
"decorations": false,
"resizable": false,
"transparent": true,
"visible": false,
"url": "/"
},
{
Expand All @@ -35,6 +36,7 @@
"transparent": true
}
],
"withGlobalTauri": true,
"security": {
"csp": null
}
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ onBeforeUnmount(() => {
</script>

<template>
<n-config-provider :theme="usingTheme" class="size-full !bg-transparent">
<n-config-provider :theme="usingTheme" :class="['size-full !bg-transparent', isSystemDarkTheme ? 'dark' : '']">
<RouterView />
</n-config-provider>
</template>
Expand Down
2 changes: 1 addition & 1 deletion src/AppInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const AppInfo = {
version: "1.2.2",
version: "1.2.3",
};
4 changes: 2 additions & 2 deletions src/components/KeySelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ onBeforeUnmount(() => {
display: inline-block;
transition: 0.3s;
background: #b9b9b91a;
color: rgb(0, 0, 0);
color: black;
border: 2px solid rgba(128, 128, 128, 0.116);
}
.dark .keyBox {
background: #383838;
color: white;
color: white !important;
border: 2px solid rgba(128, 128, 128, 0.116);
}
.keyBox:hover {
Expand Down
Loading

0 comments on commit 8ea647d

Please sign in to comment.