mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-17 03:40:23 +03:00
fix(core): Announce new webviews and windows (#9211)
* fix(core): Announce new webviews and windows fixes #9200 fixes #8144 * fix js import in example * emit created events to all listeners. * remove duplicate event
This commit is contained in:
parent
e7cd973123
commit
c33f6e6cf3
5
.changes/api-readd-window-created-event.md
Normal file
5
.changes/api-readd-window-created-event.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@tauri-apps/api': 'patch:bug'
|
||||||
|
---
|
||||||
|
|
||||||
|
Re-added the `TauriEvent.WINDOW_CREATED` (`tauri://window-created`) event.
|
5
.changes/core-emit-created-events.md
Normal file
5
.changes/core-emit-created-events.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
tauri: 'patch:bug'
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed an issue preventing webview/window creation events to not be emitted. This also fixed the `getByLabel` and `getAll` JavaScript functions.
|
File diff suppressed because one or more lines are too long
@ -610,6 +610,19 @@ impl<R: Runtime> WebviewManager<R> {
|
|||||||
.expect("failed to run on_webview_created hook");
|
.expect("failed to run on_webview_created hook");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Ok(webview_labels_array) = serde_json::to_string(&webview.manager.webview.labels()) {
|
||||||
|
let _ = webview.manager.webview.eval_script_all(format!(
|
||||||
|
"window.__TAURI_INTERNALS__.metadata.webviews = {webview_labels_array}.map(function (label) {{ return {{ label: label }} }})",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = webview.manager.emit(
|
||||||
|
"tauri://webview-created",
|
||||||
|
Some(crate::webview::CreatedEvent {
|
||||||
|
label: webview.label().into(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
webview
|
webview
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ pub(crate) type OnPageLoad<R> = dyn Fn(Webview<R>, PageLoadPayload<'_>) + Send +
|
|||||||
pub(crate) type DownloadHandler<R> = dyn Fn(Webview<R>, DownloadEvent<'_>) -> bool + Send + Sync;
|
pub(crate) type DownloadHandler<R> = dyn Fn(Webview<R>, DownloadEvent<'_>) -> bool + Send + Sync;
|
||||||
|
|
||||||
#[derive(Clone, Serialize)]
|
#[derive(Clone, Serialize)]
|
||||||
struct CreatedEvent {
|
pub(crate) struct CreatedEvent {
|
||||||
label: String,
|
pub(crate) label: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Download event for the [`WebviewBuilder#method.on_download`] hook.
|
/// Download event for the [`WebviewBuilder#method.on_download`] hook.
|
||||||
@ -624,22 +624,6 @@ tauri::Builder::default()
|
|||||||
}
|
}
|
||||||
.map(|webview| app_manager.webview.attach_webview(window.clone(), webview))?;
|
.map(|webview| app_manager.webview.attach_webview(window.clone(), webview))?;
|
||||||
|
|
||||||
app_manager.webview.eval_script_all(format!(
|
|
||||||
"window.__TAURI_INTERNALS__.metadata.windows = {window_labels_array}.map(function (label) {{ return {{ label: label }} }})",
|
|
||||||
window_labels_array = serde_json::to_string(&app_manager.webview.labels())?,
|
|
||||||
))?;
|
|
||||||
|
|
||||||
app_manager.emit_filter(
|
|
||||||
"tauri://webview-created",
|
|
||||||
Some(CreatedEvent {
|
|
||||||
label: webview.label().into(),
|
|
||||||
}),
|
|
||||||
|s| match s {
|
|
||||||
EventTarget::Webview { label } => label == webview.label(),
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(webview)
|
Ok(webview)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,6 +425,18 @@ tauri::Builder::default()
|
|||||||
crate::vibrancy::set_window_effects(&window, Some(effects))?;
|
crate::vibrancy::set_window_effects(&window, Some(effects))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app_manager.webview.eval_script_all(format!(
|
||||||
|
"window.__TAURI_INTERNALS__.metadata.windows = {window_labels_array}.map(function (label) {{ return {{ label: label }} }})",
|
||||||
|
window_labels_array = serde_json::to_string(&app_manager.window.labels())?,
|
||||||
|
))?;
|
||||||
|
|
||||||
|
app_manager.emit(
|
||||||
|
"tauri://window-created",
|
||||||
|
Some(crate::webview::CreatedEvent {
|
||||||
|
label: window.label().into(),
|
||||||
|
}),
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(window)
|
Ok(window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<div id="response"></div>
|
<div id="response"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const WebviewWindow = window.__TAURI__.webview.WebviewWindow
|
const WebviewWindow = window.__TAURI__.webviewWindow.WebviewWindow
|
||||||
const appWindow = window.__TAURI__.window.getCurrent()
|
const appWindow = window.__TAURI__.window.getCurrent()
|
||||||
const windowLabel = appWindow.label
|
const windowLabel = appWindow.label
|
||||||
const windowLabelContainer = document.getElementById('window-label')
|
const windowLabelContainer = document.getElementById('window-label')
|
||||||
|
@ -55,6 +55,7 @@ enum TauriEvent {
|
|||||||
WINDOW_BLUR = 'tauri://blur',
|
WINDOW_BLUR = 'tauri://blur',
|
||||||
WINDOW_SCALE_FACTOR_CHANGED = 'tauri://scale-change',
|
WINDOW_SCALE_FACTOR_CHANGED = 'tauri://scale-change',
|
||||||
WINDOW_THEME_CHANGED = 'tauri://theme-changed',
|
WINDOW_THEME_CHANGED = 'tauri://theme-changed',
|
||||||
|
WINDOW_CREATED = 'tauri://window-created',
|
||||||
WEBVIEW_CREATED = 'tauri://webview-created',
|
WEBVIEW_CREATED = 'tauri://webview-created',
|
||||||
FILE_DROP = 'tauri://file-drop',
|
FILE_DROP = 'tauri://file-drop',
|
||||||
FILE_DROP_HOVER = 'tauri://file-drop-hover',
|
FILE_DROP_HOVER = 'tauri://file-drop-hover',
|
||||||
|
Loading…
Reference in New Issue
Block a user