|
@@ -93,7 +93,8 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
|
|
|
* Additionally, the `asset` must be allowlisted under `tauri.conf.json > tauri > allowlist > protocol`,
|
|
|
* and its access scope must be defined on the `assetScope` array on the same `protocol` object.
|
|
|
*
|
|
|
- * @param filePath the file path.
|
|
|
+ * @param filePath The file path.
|
|
|
+ * @param protocol The protocol to use. Defaults to `asset`. You only need to set this when using a custom protocol.
|
|
|
* @example
|
|
|
* ```typescript
|
|
|
* import { appDir, join } from '@tauri-apps/api/path'
|
|
@@ -102,18 +103,20 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
|
|
|
* const filePath = await join(appDir, 'assets/video.mp4')
|
|
|
* const assetUrl = convertFileSrc(filePath)
|
|
|
*
|
|
|
- * const video = document.getElementById('video_source')
|
|
|
- * const sources = video.getElementsByTagName('source')
|
|
|
- * sources[0].src = assetUrl
|
|
|
+ * const video = document.getElementById('my-video')
|
|
|
+ * const source = document.createElement('source')
|
|
|
+ * source.type = 'video/mp4'
|
|
|
+ * source.src = assetUrl
|
|
|
+ * video.appendChild(source)
|
|
|
* video.load()
|
|
|
* ```
|
|
|
*
|
|
|
* @return the URL that can be used as source on the webview.
|
|
|
*/
|
|
|
-function convertFileSrc(filePath: string): string {
|
|
|
+function convertFileSrc(filePath: string, protocol = 'asset'): string {
|
|
|
return navigator.userAgent.includes('Windows')
|
|
|
- ? `https://asset.localhost/${filePath}`
|
|
|
- : `asset://${filePath}`
|
|
|
+ ? `https://${protocol}.localhost/${filePath}`
|
|
|
+ : `${protocol}://${filePath}`
|
|
|
}
|
|
|
|
|
|
export type { InvokeArgs }
|