Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tauriReady function to core #12586

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions crates/tauri/src/manager/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ impl<R: Runtime> WebviewManager<R> {
}
}

all_initialization_scripts.push(
r#"
Object.defineProperty(window.__TAURI_INTERNALS__, 'ready', { value: true });
window.dispatchEvent(new Event("tauriReady"));
"#
.to_string(),
);

webview_attributes
.initialization_scripts
.splice(0..0, all_initialization_scripts);
Expand Down
13 changes: 12 additions & 1 deletion packages/api/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ function isTauri(): boolean {
return 'isTauri' in window && !!window.isTauri
}

function tauriReady(): Promise<void> {
if (window.__TAURI_INTERNALS__?.ready) {
return Promise.resolve()
} else {
return new Promise((resolve) => {
window.addEventListener('tauriReady', () => resolve())
})
}
}

export type { InvokeArgs, InvokeOptions }

export {
Expand All @@ -318,5 +328,6 @@ export {
requestPermissions,
invoke,
convertFileSrc,
isTauri
isTauri,
tauriReady
}
1 change: 1 addition & 0 deletions packages/api/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare global {
delimiter: string
}
}
ready: boolean
}
}
}
Expand Down
Loading