#Is it possible to load local HTML files, or is that against the concept of Tauri?
18 messages · Page 1 of 1 (latest)
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
});
Oh I just assumed you wanted from JS because of the JS you sent
Yea you can do it in Rust
https://docs.rs/tauri/latest/tauri/window/struct.WindowBuilder.html
tauri::Builder::default()
.setup(|app| {
let window = tauri::WindowBuilder::new(app, "label", tauri::WindowUrl::App("index.html".into()))
.build()?;
Ok(())
});
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
as long as the html file was inside your devPath & distDir you can use the standard apis like window.location.replace
but I would need to do that from within js right?
yeah
well, you can also do it in rust by invoking js: ```rs
window.eval("window.location.replace(...)")
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
GlobalShortcutManager is a trait so you may have to import it before you can use its functions via use tauri::GlobalShortcutManager;
thanks, that was it
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?
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.
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?