Struct tauri::CloseRequestApi
source · pub struct CloseRequestApi(_);
Expand description
Api exposed on the CloseRequested
event.
Implementations§
source§impl CloseRequestApi
impl CloseRequestApi
sourcepub fn prevent_close(&self)
pub fn prevent_close(&self)
Prevents the window from being closed.
Examples found in repository?
src/manager.rs (line 1339)
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
fn on_window_event<R: Runtime>(
window: &Window<R>,
manager: &WindowManager<R>,
event: &WindowEvent,
) -> crate::Result<()> {
match event {
WindowEvent::Resized(size) => window.emit(WINDOW_RESIZED_EVENT, size)?,
WindowEvent::Moved(position) => window.emit(WINDOW_MOVED_EVENT, position)?,
WindowEvent::CloseRequested { api } => {
if window.has_js_listener(Some(window.label().into()), WINDOW_CLOSE_REQUESTED_EVENT) {
api.prevent_close();
}
window.emit(WINDOW_CLOSE_REQUESTED_EVENT, ())?;
}
WindowEvent::Destroyed => {
window.emit(WINDOW_DESTROYED_EVENT, ())?;
let label = window.label();
let windows_map = manager.inner.windows.lock().unwrap();
let windows = windows_map.values();
for window in windows {
window.eval(&format!(
r#"window.__TAURI_METADATA__.__windows = window.__TAURI_METADATA__.__windows.filter(w => w.label !== "{}");"#,
label
))?;
}
}
WindowEvent::Focused(focused) => window.emit(
if *focused {
WINDOW_FOCUS_EVENT
} else {
WINDOW_BLUR_EVENT
},
(),
)?,
WindowEvent::ScaleFactorChanged {
scale_factor,
new_inner_size,
..
} => window.emit(
WINDOW_SCALE_FACTOR_CHANGED_EVENT,
ScaleFactorChanged {
scale_factor: *scale_factor,
size: *new_inner_size,
},
)?,
WindowEvent::FileDrop(event) => match event {
FileDropEvent::Hovered(paths) => window.emit(WINDOW_FILE_DROP_HOVER_EVENT, paths)?,
FileDropEvent::Dropped(paths) => {
let scopes = window.state::<Scopes>();
for path in paths {
if path.is_file() {
let _ = scopes.allow_file(path);
} else {
let _ = scopes.allow_directory(path, false);
}
}
window.emit(WINDOW_FILE_DROP_EVENT, paths)?
}
FileDropEvent::Cancelled => window.emit(WINDOW_FILE_DROP_CANCELLED_EVENT, ())?,
_ => unimplemented!(),
},
WindowEvent::ThemeChanged(theme) => window.emit(WINDOW_THEME_CHANGED, theme.to_string())?,
}
Ok(())
}
Trait Implementations§
source§impl Clone for CloseRequestApi
impl Clone for CloseRequestApi
source§fn clone(&self) -> CloseRequestApi
fn clone(&self) -> CloseRequestApi
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more