mirror of
https://github.com/System-End/hackatime-desktop.git
synced 2026-04-19 19:45:09 +00:00
fix: solve crash on resize #56
This commit is contained in:
parent
ce7dcfa2da
commit
3b57b270af
4 changed files with 44 additions and 55 deletions
|
|
@ -170,31 +170,44 @@ pub fn run() {
|
|||
use objc2::runtime::AnyObject;
|
||||
use objc2_app_kit::NSColor;
|
||||
use objc2::msg_send;
|
||||
use std::panic;
|
||||
|
||||
if let Err(e) = window.set_title_bar_style(TitleBarStyle::Transparent) {
|
||||
push_log("error", "backend", format!("Failed to set title bar style: {}", e));
|
||||
}
|
||||
|
||||
// Apply macOS-specific window styling with proper error handling
|
||||
if let Ok(ns_win) = window.ns_window() {
|
||||
let ns_window = ns_win as *mut AnyObject;
|
||||
unsafe {
|
||||
let clear_color = NSColor::clearColor();
|
||||
let _: () = msg_send![ns_window, setBackgroundColor: &*clear_color];
|
||||
let _: () = msg_send![ns_window, setOpaque: false];
|
||||
|
||||
let content_view: *mut AnyObject = msg_send![ns_window, contentView];
|
||||
let _: () = msg_send![content_view, setWantsLayer: true];
|
||||
|
||||
let layer: *mut AnyObject = msg_send![content_view, layer];
|
||||
let _: () = msg_send![layer, setCornerRadius: 12.0f64];
|
||||
let _: () = msg_send![layer, setMasksToBounds: true];
|
||||
|
||||
let _: () = msg_send![layer, setNeedsDisplayOnBoundsChange: true];
|
||||
let styling_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
if let Ok(ns_win) = window.ns_window() {
|
||||
let ns_window = ns_win as *mut AnyObject;
|
||||
unsafe {
|
||||
let clear_color = NSColor::clearColor();
|
||||
let _: () = msg_send![ns_window, setBackgroundColor: &*clear_color];
|
||||
let _: () = msg_send![ns_window, setOpaque: false];
|
||||
|
||||
let content_view: *mut AnyObject = msg_send![ns_window, contentView];
|
||||
let _: () = msg_send![content_view, setWantsLayer: true];
|
||||
|
||||
let layer: *mut AnyObject = msg_send![content_view, layer];
|
||||
let _: () = msg_send![layer, setCornerRadius: 12.0f64];
|
||||
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Failed to get NSWindow")
|
||||
}
|
||||
}));
|
||||
|
||||
match styling_result {
|
||||
Ok(Ok(())) => {
|
||||
push_log("info", "backend", "✅ macOS window styling applied".to_string());
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
push_log("error", "backend", format!("Failed to apply window styling: {}", e));
|
||||
}
|
||||
Err(_) => {
|
||||
push_log("error", "backend", "Panic occurred while applying window styling".to_string());
|
||||
}
|
||||
push_log("info", "backend", "✅ macOS window styling applied".to_string());
|
||||
} else {
|
||||
push_log("error", "backend", "Failed to get NSWindow".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,12 @@ pub fn setup_tray(app: &AppHandle) -> Result<(), Box<dyn std::error::Error>> {
|
|||
])?;
|
||||
|
||||
|
||||
let icon = app.default_window_icon()
|
||||
.ok_or("No default window icon found")?
|
||||
.clone();
|
||||
|
||||
let _tray_icon = TrayIconBuilder::new()
|
||||
.icon(app.default_window_icon().unwrap().clone())
|
||||
.icon(icon)
|
||||
.menu(&menu)
|
||||
.show_menu_on_left_click(true)
|
||||
.on_menu_event(|app, event| {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@
|
|||
"minimizable": true,
|
||||
"maximizable": true,
|
||||
"closable": true,
|
||||
"hiddenTitle": true,
|
||||
"transparent": true
|
||||
"hiddenTitle": true
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
<button
|
||||
class="traffic-light maximize-light"
|
||||
@click="toggleMaximize"
|
||||
:title="isMaximized ? 'Restore' : 'Maximize'"
|
||||
title="Maximize"
|
||||
aria-label="Maximize"
|
||||
>
|
||||
<svg width="8" height="8" viewBox="0 0 8 8" class="traffic-light-icon">
|
||||
|
|
@ -52,15 +52,11 @@
|
|||
<button
|
||||
class="titlebar-button maximize-button"
|
||||
@click="toggleMaximize"
|
||||
:title="isMaximized ? 'Restore' : 'Maximize'"
|
||||
title="Maximize"
|
||||
>
|
||||
<svg v-if="!isMaximized" width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect x="1" y="1" width="10" height="10" stroke="currentColor" stroke-width="1" fill="none"/>
|
||||
</svg>
|
||||
<svg v-else width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect x="2" y="2" width="8" height="8" stroke="currentColor" stroke-width="1" fill="none"/>
|
||||
<rect x="1" y="1" width="8" height="8" stroke="currentColor" stroke-width="1" fill="none"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- Close button -->
|
||||
|
|
@ -92,37 +88,16 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
|
||||
const isMaximized = ref(false);
|
||||
const isMacOS = ref(false);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
|
||||
isMacOS.value = navigator.userAgent.includes('Mac');
|
||||
|
||||
const { getCurrentWindow } = await import('@tauri-apps/api/window');
|
||||
const window = getCurrentWindow();
|
||||
isMaximized.value = await window.isMaximized();
|
||||
|
||||
|
||||
const unlisten = await window.onResized(async () => {
|
||||
isMaximized.value = await window.isMaximized();
|
||||
});
|
||||
|
||||
|
||||
return unlisten;
|
||||
} catch (error) {
|
||||
console.error('Failed to setup window state:', error);
|
||||
}
|
||||
onMounted(() => {
|
||||
isMacOS.value = navigator.userAgent.includes('Mac');
|
||||
});
|
||||
|
||||
|
||||
const handleDoubleClick = async () => {
|
||||
try {
|
||||
const { getCurrentWindow } = await import('@tauri-apps/api/window');
|
||||
const window = getCurrentWindow();
|
||||
await window.toggleMaximize();
|
||||
isMaximized.value = await window.isMaximized();
|
||||
await getCurrentWindow().toggleMaximize();
|
||||
} catch (error) {
|
||||
console.error('Failed to toggle maximize:', error);
|
||||
}
|
||||
|
|
@ -140,9 +115,7 @@ const minimizeWindow = async () => {
|
|||
const toggleMaximize = async () => {
|
||||
try {
|
||||
const { getCurrentWindow } = await import('@tauri-apps/api/window');
|
||||
const window = getCurrentWindow();
|
||||
await window.toggleMaximize();
|
||||
isMaximized.value = await window.isMaximized();
|
||||
await getCurrentWindow().toggleMaximize();
|
||||
} catch (error) {
|
||||
console.error('Failed to toggle maximize:', error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue