mirror of
https://github.com/nimbold/Firelink.git
synced 2026-09-10 09:45:44 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ca87fd6a4 |
@@ -30,7 +30,6 @@ const child = spawn(executable, [], {
|
||||
env: {
|
||||
...process.env,
|
||||
FIRELINK_SMOKE_TEST: '1',
|
||||
FIRELINK_SKIP_MAIN_WINDOW: '1',
|
||||
WEBKIT_DISABLE_COMPOSITING_MODE: '1',
|
||||
GDK_BACKEND: 'x11',
|
||||
},
|
||||
|
||||
@@ -308,16 +308,18 @@ async fn download_handler(
|
||||
None => return Err(StatusCode::BAD_REQUEST),
|
||||
};
|
||||
|
||||
let is_hidden = state
|
||||
.app_handle
|
||||
.get_webview_window("main")
|
||||
.and_then(|window| window.is_visible().ok())
|
||||
.is_some_and(|is_visible| !is_visible);
|
||||
crate::restore_main_window(&state.app_handle);
|
||||
if is_hidden {
|
||||
// Sleep briefly to let the webview wake up from macOS App Nap
|
||||
// otherwise the IPC event emitted immediately after is dropped.
|
||||
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
|
||||
if let Some(window) = state.app_handle.get_webview_window("main") {
|
||||
let is_visible = window.is_visible().unwrap_or(true);
|
||||
if !is_visible {
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
// Sleep briefly to let the webview wake up from macOS App Nap
|
||||
// otherwise the IPC event emitted immediately after is dropped.
|
||||
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
|
||||
} else {
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}
|
||||
|
||||
if !wait_for_frontend(&state.frontend_ready).await {
|
||||
|
||||
+4
-62
@@ -3659,7 +3659,6 @@ pub struct AppState {
|
||||
#[derive(Default)]
|
||||
struct MainWindowRestoreState {
|
||||
requested: AtomicBool,
|
||||
startup_complete: AtomicBool,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -3955,26 +3954,7 @@ where
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) 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;
|
||||
}
|
||||
}
|
||||
fn restore_main_window(app_handle: &tauri::AppHandle) {
|
||||
let Some(window) = app_handle.get_webview_window("main") else {
|
||||
if let Some(state) = app_handle.try_state::<MainWindowRestoreState>() {
|
||||
state.requested.store(true, Ordering::Release);
|
||||
@@ -3987,24 +3967,6 @@ pub(crate) fn restore_main_window(app_handle: &tauri::AppHandle) {
|
||||
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) {
|
||||
if app_handle
|
||||
.try_state::<MainWindowRestoreState>()
|
||||
@@ -18550,22 +18512,9 @@ pub fn run() {
|
||||
main_window_builder = main_window_builder
|
||||
.inner_size(startup_size.width as f64, startup_size.height as f64)
|
||||
.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);
|
||||
}
|
||||
if std::env::var_os("FIRELINK_SKIP_MAIN_WINDOW").is_none() {
|
||||
main_window_builder
|
||||
.build()
|
||||
.map_err(|error| format!("failed to create main window: {error}"))?;
|
||||
}
|
||||
main_window_builder
|
||||
.build()
|
||||
.map_err(|error| format!("failed to create main window: {error}"))?;
|
||||
restore_pending_main_window(app.handle());
|
||||
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
@@ -19898,13 +19847,6 @@ pub fn run() {
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building tauri application")
|
||||
.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")]
|
||||
tauri::RunEvent::Opened { urls } => {
|
||||
let paths = collect_opened_torrent_paths(
|
||||
|
||||
@@ -439,7 +439,6 @@ pub fn open_download_properties_window(
|
||||
.visible(false)
|
||||
// A hidden WebView2 must not request focus during construction. The
|
||||
// native reveal path focuses it after the window is visible.
|
||||
.focused(false)
|
||||
.transparent(true);
|
||||
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
|
||||
let builder = builder.decorations(false);
|
||||
|
||||
Reference in New Issue
Block a user