Skip to content

Commit 3cf70f4

Browse files
committed
更新应用版本号至 1.0.7,优化了悬浮球功能的异常处理,简化了日志输出。
1 parent e2fd4b3 commit 3cf70f4

File tree

4 files changed

+41
-27
lines changed

4 files changed

+41
-27
lines changed

index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66
<title>BPM Sniffer</title>
77
</head>
88
<body>
9+
<style>
10+
html, body { height: 100%; margin: 0; padding: 0; }
11+
</style>
12+
<script>
13+
(function(){
14+
function applyBg(){
15+
var isFloat = location.hash === '#float';
16+
var elHtml = document.documentElement, elBody = document.body;
17+
if (isFloat) {
18+
elHtml.style.background = 'transparent';
19+
elBody.style.background = 'transparent';
20+
} else {
21+
var isDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
22+
var dark = '#14060a', light = '#fff4f7';
23+
var bg = isDark ? dark : light;
24+
elHtml.style.background = bg;
25+
elBody.style.background = bg;
26+
}
27+
}
28+
applyBg();
29+
window.addEventListener('hashchange', applyBg);
30+
})();
31+
</script>
932
<div id="root"></div>
1033
<script type="module" src="/src/main.tsx"></script>
1134
</body>

src-tauri/src/main.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,7 @@ fn set_always_on_top(app: AppHandle, on_top: bool) -> Result<(), String> {
195195
#[tauri::command]
196196
fn enter_floating(app: AppHandle) -> Result<(), String> {
197197
// 创建悬浮球窗口(透明、无边框、置顶、隐藏任务栏)
198-
append_log_line("[FLOAT] enter_floating invoked");
199-
eprintln!("[FLOAT] enter_floating invoked");
200198
// 切回“独立透明窗口”方案:新建 float 窗口 + 透明 + 无边框 + 置顶
201-
eprintln!("[FLOAT] creating dedicated transparent window");
202199
// 使用 App 协议,dev 模式会自动映射到 dev 服务器
203200
// 如果在配置中已声明 float 窗口,则直接获取并显示
204201
if let Some(w) = app.get_webview_window("float") {
@@ -220,12 +217,9 @@ fn enter_floating(app: AppHandle) -> Result<(), String> {
220217
let _ = w.navigate(Url::parse("tauri://localhost/index.html#float").unwrap_or_else(|_| Url::parse("tauri://localhost/#float").unwrap()));
221218
let _ = w.show();
222219
let _ = w.set_focus();
223-
eprintln!("[FLOAT] show float window");
224-
append_log_line("[FLOAT] show float window");
225220
} else {
226221
// 理论上不会发生(预声明的 float 始终存在且我们不再关闭它)
227-
eprintln!("[FLOAT] WARN: float window not found (should be pre-declared)");
228-
append_log_line("[FLOAT] WARN: float window not found (should be pre-declared)");
222+
// 静默处理:若未找到浮窗,跳过
229223
}
230224
// 隐藏主窗口,避免任务栏占位(如果主窗口尚未创建则忽略)
231225
if let Some(main) = app.get_webview_window("main") {
@@ -237,29 +231,33 @@ fn enter_floating(app: AppHandle) -> Result<(), String> {
237231

238232
#[tauri::command]
239233
fn exit_floating(app: AppHandle) -> Result<(), String> {
240-
append_log_line("[FLOAT] exit_floating invoked");
241-
eprintln!("[FLOAT] exit_floating invoked");
242234
// 不再关闭浮窗,改为仅隐藏
243235
if let Some(f) = app.get_webview_window("float") { let _ = f.hide(); }
244236
if let Some(main) = app.get_webview_window("main") {
245-
append_log_line("[FLOAT] restore MAIN from floating style");
246-
eprintln!("[FLOAT] restore MAIN from floating style");
247237
let _ = main.set_decorations(true);
248238
let _ = main.set_resizable(true);
249239
let _ = main.set_skip_taskbar(false);
250240
let _ = main.set_always_on_top(false);
251241
let _ = main.set_min_size(Some(Size::Logical(LogicalSize::new(220.0, 120.0))));
252242
let _ = main.set_max_size(Some(Size::Logical(LogicalSize::new(560.0, 560.0))));
253243
let _ = main.set_size(Size::Logical(LogicalSize::new(390.0, 390.0)));
254-
#[cfg(debug_assertions)]
255-
{ let _ = main.navigate(Url::parse("tauri://localhost/").unwrap()); }
256-
#[cfg(not(debug_assertions))]
257-
{ let _ = main.navigate(Url::parse("tauri://localhost/index.html").unwrap()); }
258244
let _ = main.show();
245+
// 尝试通过 1px 尺寸抖动强制 WebView2 重绘,缓解偶发黑/白屏
246+
if let (Ok(sz), Ok(sf)) = (main.inner_size(), main.scale_factor()) {
247+
let w_log = (sz.width as f64) / sf;
248+
let h_log = (sz.height as f64) / sf;
249+
let _ = main.set_size(Size::Logical(LogicalSize::new(w_log + 1.0, h_log)));
250+
let app2 = app.clone();
251+
std::thread::spawn(move || {
252+
std::thread::sleep(Duration::from_millis(30));
253+
if let Some(win2) = app2.get_webview_window("main") {
254+
let _ = win2.set_size(Size::Logical(LogicalSize::new(w_log, h_log)));
255+
}
256+
});
257+
}
259258
let _ = main.set_focus();
260259
} else {
261-
append_log_line("[FLOAT] ERROR: main window not found on exit");
262-
eprintln!("[FLOAT] ERROR: main window not found on exit");
260+
// 静默处理:若未找到主窗口,跳过
263261
}
264262
Ok(())
265263
}

src-tauri/tauri.conf.json

Lines changed: 1 addition & 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": "BPM Sniffer",
4-
"version": "1.0.6",
4+
"version": "1.0.7",
55
"identifier": "com.renlu.bpm-sniffer",
66
"build": {
77
"beforeBuildCommand": "pnpm web:build",

src/App.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,8 @@ export default function App() {
445445
<button
446446
onClick={async () => {
447447
try {
448-
console.log('[UI] enter_floating clicked')
449448
await invoke('enter_floating')
450-
console.log('[UI] enter_floating invoked OK')
451-
} catch (e) {
452-
console.error('[UI] enter_floating failed', e)
453-
}
449+
} catch (e) { }
454450
}}
455451
title={t('enter_floating')}
456452
style={{
@@ -599,16 +595,13 @@ function FloatBall({ themeName, bpm, conf, viz, onExit }: { themeName: 'dark'|'l
599595
const win = getCurrentWebviewWindow()
600596
// 双保险:先尝试系统拖动;若失败则手动移动到光标附近(需要 window 权限)
601597
try { await win.startDragging() } catch (e) {
602-
console.warn('[Float] startDragging failed, fallback to setPosition', e)
603598
try {
604599
const x = Math.max(0, ev.screenX - Math.floor(ballSize/2))
605600
const y = Math.max(0, ev.screenY - Math.floor(ballSize/2))
606601
// @ts-ignore 支持 Tauri v2 setPosition(Position)
607602
await (win as any).setPosition({ x, y })
608603
try { await (window as any).__TAURI_INVOKE__('save_float_pos', { x, y }) } catch {}
609-
} catch (e2) {
610-
console.error('[Float] setPosition fallback failed', e2)
611-
}
604+
} catch (e2) { }
612605
}
613606
} catch {}
614607
window.removeEventListener('pointermove', onMove)

0 commit comments

Comments
 (0)