#Is it possible to load local HTML files, or is that against the concept of Tauri?

18 messages · Page 1 of 1 (latest)

hushed sierra
#

So I am trying to convert an electron app to tauri. And in electron I used to do stuff like this (not 100% accurate):

new BrowserWindow({...}).loadFile(path.join(__dirname, 'src/login/login.html'));

is something like that possible with Tauri, or how would I approach something like this using Tauri?

ripe lodge
# hushed sierra So I am trying to convert an electron app to tauri. And in electron I used to do...

You can do it like this 🙂
https://tauri.app/v1/api/js/window#webviewwindow

import { WebviewWindow } from '@tauri-apps/api/window';
const webview = new WebviewWindow('my-label', {
  url: 'https://github.com/tauri-apps/tauri'
});
webview.once('tauri://created', function () {
 // webview window successfully created
});
webview.once('tauri://error', function (e) {
 // an error happened creating the webview window
});
hushed sierra
#

I rather meant from within rust

ripe lodge
hushed sierra
#

Is it also possible to chamge the url afterwards again

#

like a button is pressed, which causes another html file to load, without making a new window

west elbow
#

as long as the html file was inside your devPath & distDir you can use the standard apis like window.location.replace

hushed sierra
#

but I would need to do that from within js right?

west elbow
#

yeah

#

well, you can also do it in rust by invoking js: ```rs
window.eval("window.location.replace(...)")

hushed sierra
#

I see thanks

#

kinda off-topic, but how do I use a GlobalShortcutManagerHandle to register a new global shortcut, I only found register on GlobalShortcutManager but I can't seem to find a way to go from the handle to the main thing

west elbow
#

GlobalShortcutManager is a trait so you may have to import it before you can use its functions via use tauri::GlobalShortcutManager;

hushed sierra
#

thanks, that was it

hushed sierra
#

Another random thing: Is there a way to bridge between the JS file type (https://developer.mozilla.org/en-US/docs/Web/API/File) and the rust file type?
i.e. can I use:

<input type="file" ...>

to let the user select a file and pass the resulting file object to tauri, or do I need to use the fs dialog from tauri itself, which I would trigger with a button or something?

supple parrot
#

The recommended way is to use Tauri's dialog API because it will extend the scope automatically and is already in a compatible format. You can use the native JS API if you wish but you can't pass it directly to Rust because it is an opaque type that doesn't have a JSON equivalent; you will have to extract the data manually into a new object.

hushed sierra
#

Is the js drop event blocked by tauri / does it the js event get skipped, cause there is the tauri interal event for file drag / drop?