Skip to content

Commit beaf555

Browse files
authored
Feat: Enhance popup, support qwen3 and thinking models (#26)
* Implement Compact Popup for translation functionality - Introduced a new `CompactPopupClient` component to handle translation and correction results. - Replaced the existing `TranslatePopup` with a more streamlined `CompactPopup` structure. - Updated event listeners to manage translation shortcuts and results effectively. - Enhanced UI with a copy-to-clipboard feature and loading indicators. - Updated settings to reflect new provider models and adjusted window management for the compact popup. - Removed deprecated `TranslatePopup` files and adjusted related configurations. * add qwen3 and trimout thinking block * bump version
1 parent e451ce0 commit beaf555

File tree

12 files changed

+335
-203
lines changed

12 files changed

+335
-203
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "refiner",
3-
"version": "0.1.0",
3+
"version": "0.1.3",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

src-tauri/capabilities/migrated.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"local": true,
55
"windows": [
66
"main",
7-
"translate-popup",
7+
"compact-popup",
88
"selection-icon"
99
],
1010
"permissions": [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main","translate-popup","selection-icon"],"permissions":["core:path:default","core:event:default","core:event:allow-emit","core:event:allow-listen","core:window:default","core:window:allow-create","core:window:allow-close","core:window:allow-hide","core:window:allow-show","core:window:allow-set-position","core:window:allow-set-size","core:window:allow-set-focus","core:window:allow-set-skip-taskbar","core:window:allow-set-cursor-grab","core:window:allow-set-cursor-visible","core:window:allow-set-cursor-icon","core:window:allow-set-always-on-top","core:window:allow-set-decorations","core:window:allow-set-title","core:app:default","core:resources:default","core:menu:default","core:tray:default","store:default","store:allow-set","store:allow-get","store:allow-save","global-shortcut:default","global-shortcut:allow-is-registered","global-shortcut:allow-register","global-shortcut:allow-unregister","shell:default"]}}
1+
{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main","compact-popup","selection-icon"],"permissions":["core:path:default","core:event:default","core:event:allow-emit","core:event:allow-listen","core:window:default","core:window:allow-create","core:window:allow-close","core:window:allow-hide","core:window:allow-show","core:window:allow-set-position","core:window:allow-set-size","core:window:allow-set-focus","core:window:allow-set-skip-taskbar","core:window:allow-set-cursor-grab","core:window:allow-set-cursor-visible","core:window:allow-set-cursor-icon","core:window:allow-set-always-on-top","core:window:allow-set-decorations","core:window:allow-set-title","core:app:default","core:resources:default","core:menu:default","core:tray:default","store:default","store:allow-set","store:allow-get","store:allow-save","global-shortcut:default","global-shortcut:allow-is-registered","global-shortcut:allow-register","global-shortcut:allow-unregister","shell:default"]}}

src-tauri/src/commands.rs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,47 @@ const DEFAULT_CORRECTION_PROMPT: &str =
1111
const DEFAULT_REFINE_PROMPT: &str =
1212
"You are an expert editor. Rewrite the following text in a more conversational style, in {target_lang}. Provide only the rewritten text, without any additional explanations or formatting.";
1313

14+
// Helper function to trim thinking blocks from model responses
15+
fn trim_thinking_blocks(response: &str) -> String {
16+
let mut result = response.to_string();
17+
18+
// Remove <think>...</think> blocks
19+
while let Some(start) = result.find("<think>") {
20+
if let Some(end) = result[start..].find("</think>") {
21+
let end_pos = start + end + 7; // 7 is length of "</think>"
22+
result.replace_range(start..end_pos, "");
23+
} else {
24+
// If no closing tag found, remove everything from <think> to the end
25+
result.truncate(start);
26+
}
27+
}
28+
29+
// Remove <thinking>...</thinking> blocks (alternative format)
30+
while let Some(start) = result.find("<thinking>") {
31+
if let Some(end) = result[start..].find("</thinking>") {
32+
let end_pos = start + end + 10; // 10 is length of "</thinking>"
33+
result.replace_range(start..end_pos, "");
34+
} else {
35+
// If no closing tag found, remove everything from <thinking> to the end
36+
result.truncate(start);
37+
}
38+
}
39+
40+
// Remove <reasoning>...</reasoning> blocks (another alternative format)
41+
while let Some(start) = result.find("<reasoning>") {
42+
if let Some(end) = result[start..].find("</reasoning>") {
43+
let end_pos = start + end + 11; // 11 is length of "</reasoning>"
44+
result.replace_range(start..end_pos, "");
45+
} else {
46+
// If no closing tag found, remove everything from <reasoning> to the end
47+
result.truncate(start);
48+
}
49+
}
50+
51+
// Trim whitespace from the result
52+
result.trim().to_string()
53+
}
54+
1455
// Helper function to get default settings from store
1556
async fn get_default_settings(app_handle: &tauri::AppHandle) -> Result<(String, String), String> {
1657
let store = app_handle.store("store.bin").map_err(|e| format!("Failed to get store: {}", e))?;
@@ -61,7 +102,7 @@ pub async fn translate(
61102
);
62103
} else {
63104
let res = res.unwrap();
64-
return Ok(res);
105+
return Ok(trim_thinking_blocks(&res));
65106
}
66107
}
67108

@@ -97,7 +138,7 @@ pub async fn correct(
97138
);
98139
} else {
99140
let res = res.unwrap();
100-
return Ok(res);
141+
return Ok(trim_thinking_blocks(&res));
101142
}
102143
}
103144

@@ -134,7 +175,7 @@ pub async fn refine(
134175
);
135176
} else {
136177
let res = res.unwrap();
137-
return Ok(res);
178+
return Ok(trim_thinking_blocks(&res));
138179
}
139180
}
140181

src-tauri/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ pub fn run() {
4848
tauri::WindowEvent::Focused(is_focused) => {
4949
if !is_focused {
5050
match window.label() {
51-
"translate-popup" => {
51+
"compact-popup" => {
5252
if let Err(e) = window.hide() {
53-
println!("Failed to hide translate popup on focus loss: {}", e);
53+
println!("Failed to hide compact popup on focus loss: {}", e);
5454
}
5555
}
5656
_ => {

src-tauri/src/window_management.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub async fn create_or_focus_compact_window(app: &tauri::AppHandle) -> Result<ta
1111
let position = get_mouse_position();
1212

1313
// Check if windows exist then just open it
14-
if let Some(window) = app.get_webview_window("translate-popup") {
14+
if let Some(window) = app.get_webview_window("compact-popup") {
1515
// Move the window to the mouse position
1616
#[cfg(target_os = "windows")]
1717
{
@@ -32,8 +32,8 @@ pub async fn create_or_focus_compact_window(app: &tauri::AppHandle) -> Result<ta
3232
} else {
3333
match WebviewWindowBuilder::new(
3434
app,
35-
"translate-popup",
36-
WebviewUrl::App("translate-popup".into())
35+
"compact-popup",
36+
WebviewUrl::App("compact-popup".into())
3737
).title("Quick Translate")
3838
.transparent(true)
3939
.decorations(false)
@@ -48,7 +48,7 @@ pub async fn create_or_focus_compact_window(app: &tauri::AppHandle) -> Result<ta
4848
Ok(window)
4949
},
5050
Err(e) => {
51-
Err(format!("Failed to create translate-popup window: {}", e))
51+
Err(format!("Failed to create compact-popup window: {}", e))
5252
}
5353
}
5454
}

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"productName": "Refiner",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"identifier": "dev.leehuwuj.refiner",
55
"build": {
66
"beforeDevCommand": "pnpm dev",

0 commit comments

Comments
 (0)