mirror of
https://github.com/nimbold/Firelink.git
synced 2026-09-11 02:05:45 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ca87fd6a4 |
@@ -308,16 +308,18 @@ async fn download_handler(
|
|||||||
None => return Err(StatusCode::BAD_REQUEST),
|
None => return Err(StatusCode::BAD_REQUEST),
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_hidden = state
|
if let Some(window) = state.app_handle.get_webview_window("main") {
|
||||||
.app_handle
|
let is_visible = window.is_visible().unwrap_or(true);
|
||||||
.get_webview_window("main")
|
if !is_visible {
|
||||||
.and_then(|window| window.is_visible().ok())
|
let _ = window.show();
|
||||||
.is_some_and(|is_visible| !is_visible);
|
let _ = window.set_focus();
|
||||||
crate::restore_main_window(&state.app_handle);
|
// Sleep briefly to let the webview wake up from macOS App Nap
|
||||||
if is_hidden {
|
// otherwise the IPC event emitted immediately after is dropped.
|
||||||
// Sleep briefly to let the webview wake up from macOS App Nap
|
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
|
||||||
// otherwise the IPC event emitted immediately after is dropped.
|
} else {
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
|
let _ = window.show();
|
||||||
|
let _ = window.set_focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !wait_for_frontend(&state.frontend_ready).await {
|
if !wait_for_frontend(&state.frontend_ready).await {
|
||||||
|
|||||||
+1
-57
@@ -3659,7 +3659,6 @@ pub struct AppState {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct MainWindowRestoreState {
|
struct MainWindowRestoreState {
|
||||||
requested: AtomicBool,
|
requested: AtomicBool,
|
||||||
startup_complete: AtomicBool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
@@ -3955,26 +3954,7 @@ where
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn restore_main_window(app_handle: &tauri::AppHandle) {
|
fn restore_main_window(app_handle: &tauri::AppHandle) {
|
||||||
let startup_complete = app_handle
|
|
||||||
.try_state::<MainWindowRestoreState>()
|
|
||||||
.is_none_or(|state| state.startup_complete.load(Ordering::Acquire));
|
|
||||||
if !startup_complete {
|
|
||||||
if let Some(state) = app_handle.try_state::<MainWindowRestoreState>() {
|
|
||||||
// The first window can be requested by a single-instance callback
|
|
||||||
// or an opened .torrent path while the native host is still being
|
|
||||||
// constructed. Do not touch the HWND until RunEvent::Ready.
|
|
||||||
state.requested.store(true, Ordering::Release);
|
|
||||||
// Ready may have won the transition between the first load and
|
|
||||||
// the request store. Re-check before returning so that request is
|
|
||||||
// serviced by this call instead of being left pending forever.
|
|
||||||
if !state.startup_complete.load(Ordering::Acquire) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let Some(window) = app_handle.get_webview_window("main") else {
|
let Some(window) = app_handle.get_webview_window("main") else {
|
||||||
if let Some(state) = app_handle.try_state::<MainWindowRestoreState>() {
|
if let Some(state) = app_handle.try_state::<MainWindowRestoreState>() {
|
||||||
state.requested.store(true, Ordering::Release);
|
state.requested.store(true, Ordering::Release);
|
||||||
@@ -3987,24 +3967,6 @@ pub(crate) fn restore_main_window(app_handle: &tauri::AppHandle) {
|
|||||||
let _ = window.set_focus();
|
let _ = window.set_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_main_window_startup_complete(app_handle: &tauri::AppHandle) {
|
|
||||||
if let Some(state) = app_handle.try_state::<MainWindowRestoreState>() {
|
|
||||||
state.startup_complete.store(true, Ordering::Release);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn reveal_main_window(app_handle: &tauri::AppHandle) {
|
|
||||||
if let Some(window) = app_handle.get_webview_window("main") {
|
|
||||||
if let Err(error) = window.set_focusable(true) {
|
|
||||||
log::warn!("Could not make the main window focusable: {error}");
|
|
||||||
}
|
|
||||||
if let Err(error) = window.show() {
|
|
||||||
eprintln!("Failed to reveal the main window: {error}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn restore_pending_main_window(app_handle: &tauri::AppHandle) {
|
fn restore_pending_main_window(app_handle: &tauri::AppHandle) {
|
||||||
if app_handle
|
if app_handle
|
||||||
.try_state::<MainWindowRestoreState>()
|
.try_state::<MainWindowRestoreState>()
|
||||||
@@ -18550,17 +18512,6 @@ pub fn run() {
|
|||||||
main_window_builder = main_window_builder
|
main_window_builder = main_window_builder
|
||||||
.inner_size(startup_size.width as f64, startup_size.height as f64)
|
.inner_size(startup_size.width as f64, startup_size.height as f64)
|
||||||
.prevent_overflow();
|
.prevent_overflow();
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
// Wry installs its parent WM_SETFOCUS handler while WebView2
|
|
||||||
// is still being initialized. Keep the host hidden and
|
|
||||||
// non-activatable until RunEvent::Ready so Windows cannot
|
|
||||||
// re-enter that handler during native construction.
|
|
||||||
main_window_builder = main_window_builder
|
|
||||||
.visible(false)
|
|
||||||
.focused(false)
|
|
||||||
.focusable(false);
|
|
||||||
}
|
|
||||||
main_window_builder
|
main_window_builder
|
||||||
.build()
|
.build()
|
||||||
.map_err(|error| format!("failed to create main window: {error}"))?;
|
.map_err(|error| format!("failed to create main window: {error}"))?;
|
||||||
@@ -19896,13 +19847,6 @@ pub fn run() {
|
|||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while building tauri application")
|
.expect("error while building tauri application")
|
||||||
.run(|app_handle, event| match event {
|
.run(|app_handle, event| match event {
|
||||||
tauri::RunEvent::Ready => {
|
|
||||||
mark_main_window_startup_complete(app_handle);
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
reveal_main_window(app_handle);
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
restore_pending_main_window(app_handle);
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
tauri::RunEvent::Opened { urls } => {
|
tauri::RunEvent::Opened { urls } => {
|
||||||
let paths = collect_opened_torrent_paths(
|
let paths = collect_opened_torrent_paths(
|
||||||
|
|||||||
@@ -439,7 +439,6 @@ pub fn open_download_properties_window(
|
|||||||
.visible(false)
|
.visible(false)
|
||||||
// A hidden WebView2 must not request focus during construction. The
|
// A hidden WebView2 must not request focus during construction. The
|
||||||
// native reveal path focuses it after the window is visible.
|
// native reveal path focuses it after the window is visible.
|
||||||
.focused(false)
|
|
||||||
.transparent(true);
|
.transparent(true);
|
||||||
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
|
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
|
||||||
let builder = builder.decorations(false);
|
let builder = builder.decorations(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user