Merge pull request #2 from JonasKruckenberg/feat/window
feat: add window module
42
.github/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
name: Test
|
||||||
|
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- '.github/workflows/test.yml'
|
||||||
|
- 'src/**'
|
||||||
|
- 'examples/test/**'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- '.github/workflows/test.yml'
|
||||||
|
- 'src/**'
|
||||||
|
- 'examples/test/**'
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Install stable toolchain
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
- uses: Swatinem/rust-cache@v1
|
||||||
|
- name: Install native deps
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y webkit2gtk-4.0
|
||||||
|
wget -qO- https://github.com/tauri-apps/tauri/releases/download/cli.rs-v1.1.1/cargo-tauri-x86_64-unknown-linux-gnu.tgz | tar -xzf-
|
||||||
|
- name: Run test app
|
||||||
|
run: |
|
||||||
|
cd examples/test
|
||||||
|
cargo tauri dev --exit-on-panic --config ./src-tauri/ci.tauri.conf.json
|
3572
Cargo.lock
generated
11
Cargo.toml
|
@ -18,11 +18,20 @@ semver = { version = "1.0.14", optional = true }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
wasm-bindgen-test = "0.3.33"
|
wasm-bindgen-test = "0.3.33"
|
||||||
tauri-sys = { path = ".", features = ["all"] }
|
tauri-sys = { path = ".", features = ["all"] }
|
||||||
|
tauri = "1.1.1"
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
all = ["app", "clipboard", "event", "mocks", "tauri"]
|
all = ["app", "clipboard", "event", "mocks", "tauri", "window", "process"]
|
||||||
app = ["dep:semver"]
|
app = ["dep:semver"]
|
||||||
clipboard = []
|
clipboard = []
|
||||||
event = []
|
event = []
|
||||||
mocks = []
|
mocks = []
|
||||||
tauri = ["dep:url"]
|
tauri = ["dep:url"]
|
||||||
|
window = []
|
||||||
|
process = []
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = ["examples/test", "examples/test/src-tauri"]
|
8
build.rs
|
@ -2,7 +2,7 @@ use std::process::Command;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
/* Shared arguments */
|
/* Shared arguments */
|
||||||
let sargs: [&str; 8] = [
|
let sargs: &[&str] = &[
|
||||||
"--outdir=dist",
|
"--outdir=dist",
|
||||||
"--format=esm",
|
"--format=esm",
|
||||||
"--bundle",
|
"--bundle",
|
||||||
|
@ -11,18 +11,20 @@ fn main() {
|
||||||
"tauri/tooling/api/src/tauri.ts",
|
"tauri/tooling/api/src/tauri.ts",
|
||||||
"tauri/tooling/api/src/event.ts",
|
"tauri/tooling/api/src/event.ts",
|
||||||
"tauri/tooling/api/src/mocks.ts",
|
"tauri/tooling/api/src/mocks.ts",
|
||||||
|
"tauri/tooling/api/src/window.ts",
|
||||||
|
"tauri/tooling/api/src/process.ts"
|
||||||
];
|
];
|
||||||
|
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
/* Use cmd if the target is windows */
|
/* Use cmd if the target is windows */
|
||||||
Command::new("cmd")
|
Command::new("cmd")
|
||||||
.args(&["/C", "esbuild"])
|
.args(&["/C", "esbuild"])
|
||||||
.args(&sargs)
|
.args(sargs)
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
} else if cfg!(unix) {
|
} else if cfg!(unix) {
|
||||||
Command::new("esbuild")
|
Command::new("esbuild")
|
||||||
.args(&sargs)
|
.args(sargs)
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
|
65
dist/process.js
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// tauri/tooling/api/src/tauri.ts
|
||||||
|
function uid() {
|
||||||
|
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||||
|
}
|
||||||
|
function transformCallback(callback, once = false) {
|
||||||
|
const identifier = uid();
|
||||||
|
const prop = `_${identifier}`;
|
||||||
|
Object.defineProperty(window, prop, {
|
||||||
|
value: (result) => {
|
||||||
|
if (once) {
|
||||||
|
Reflect.deleteProperty(window, prop);
|
||||||
|
}
|
||||||
|
return callback?.(result);
|
||||||
|
},
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
async function invoke(cmd, args = {}) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const callback = transformCallback((e) => {
|
||||||
|
resolve(e);
|
||||||
|
Reflect.deleteProperty(window, `_${error}`);
|
||||||
|
}, true);
|
||||||
|
const error = transformCallback((e) => {
|
||||||
|
reject(e);
|
||||||
|
Reflect.deleteProperty(window, `_${callback}`);
|
||||||
|
}, true);
|
||||||
|
window.__TAURI_IPC__({
|
||||||
|
cmd,
|
||||||
|
callback,
|
||||||
|
error,
|
||||||
|
...args
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/helpers/tauri.ts
|
||||||
|
async function invokeTauriCommand(command) {
|
||||||
|
return invoke("tauri", command);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/process.ts
|
||||||
|
async function exit(exitCode = 0) {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "Process",
|
||||||
|
message: {
|
||||||
|
cmd: "exit",
|
||||||
|
exitCode
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function relaunch() {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "Process",
|
||||||
|
message: {
|
||||||
|
cmd: "relaunch"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export {
|
||||||
|
exit,
|
||||||
|
relaunch
|
||||||
|
};
|
1004
dist/window.js
vendored
Normal file
3
examples/api/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
||||||
/dist/
|
|
||||||
/target/
|
|
||||||
/Cargo.lock
|
|
|
@ -1,3 +0,0 @@
|
||||||
/src
|
|
||||||
/public
|
|
||||||
/Cargo.toml
|
|
|
@ -1,21 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "tauri-app-ui"
|
|
||||||
version = "0.0.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
[dependencies]
|
|
||||||
tauri-sys = { path = "../../", features = ["all"] }
|
|
||||||
serde = { version = "1.0.140", features = ["derive"] }
|
|
||||||
sycamore = { git = "https://github.com/sycamore-rs/sycamore", rev = "abd556cbc02047042dad2ebd04405e455a9b11b2", features = ["suspense", "hydrate"] }
|
|
||||||
sycamore-router = { git = "https://github.com/sycamore-rs/sycamore", rev = "abd556cbc02047042dad2ebd04405e455a9b11b2" }
|
|
||||||
log = "0.4.17"
|
|
||||||
wasm-logger = "0.2.0"
|
|
||||||
gloo-timers = "0.2.4"
|
|
||||||
shared = { path = "shared" }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
ssg = ["sycamore/ssr"]
|
|
||||||
|
|
||||||
[workspace]
|
|
||||||
members = ["src-tauri", "shared"]
|
|
|
@ -1,16 +0,0 @@
|
||||||
[build]
|
|
||||||
target = "./index.html"
|
|
||||||
|
|
||||||
[watch]
|
|
||||||
ignore = ["./src-tauri"]
|
|
||||||
|
|
||||||
[serve]
|
|
||||||
address = "127.0.0.1"
|
|
||||||
port = 1420
|
|
||||||
open = false
|
|
||||||
|
|
||||||
# [[hooks]]
|
|
||||||
# # Runs SSG on production builds
|
|
||||||
# stage = "post_build"
|
|
||||||
# command = "bash"
|
|
||||||
# command_arguments = ["-c", "if [[ $TRUNK_PROFILE == \"release\" ]]; then cargo run --release --features ssg -- $TRUNK_STAGING_DIR; fi"]
|
|
|
@ -1,12 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>Tauri + Yew App</title>
|
|
||||||
<link data-trunk rel="css" href="style.css" />
|
|
||||||
<link data-trunk rel="copy-dir" href="public" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<!--app-html-->
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Before Width: | Height: | Size: 2.7 KiB |
|
@ -1,9 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "shared"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
serde = { version = "1.0.140", features = ["derive"] }
|
|
|
@ -1,12 +0,0 @@
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct Reply<'a> {
|
|
||||||
pub data: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct RequestBody<'a> {
|
|
||||||
pub id: i32,
|
|
||||||
pub name: &'a str,
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
#![cfg_attr(
|
|
||||||
all(not(debug_assertions), target_os = "windows"),
|
|
||||||
windows_subsystem = "windows"
|
|
||||||
)]
|
|
||||||
|
|
||||||
use shared::{Reply, RequestBody};
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn log_operation(event: String, payload: Option<String>) {
|
|
||||||
println!("{} {:?}", event, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn perform_request(endpoint: String, body: RequestBody) -> String {
|
|
||||||
println!("{} {:?}", endpoint, body);
|
|
||||||
"message response".into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
tauri::Builder::default()
|
|
||||||
.invoke_handler(tauri::generate_handler![log_operation, perform_request])
|
|
||||||
.on_page_load(|window, _| {
|
|
||||||
let window_ = window.clone();
|
|
||||||
window.listen("js-event", move |event| {
|
|
||||||
println!("got js-event with message '{:?}'", event.payload());
|
|
||||||
let reply = Reply {
|
|
||||||
data: "something else",
|
|
||||||
};
|
|
||||||
|
|
||||||
window_
|
|
||||||
.emit("rust-event", Some(reply))
|
|
||||||
.expect("failed to emit");
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.run(tauri::generate_context!())
|
|
||||||
.expect("error while running tauri application");
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
mod views;
|
|
||||||
|
|
||||||
use sycamore::prelude::*;
|
|
||||||
#[cfg(not(feature = "ssg"))]
|
|
||||||
use sycamore_router::{Router, HistoryIntegration};
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
fn Header<G: Html>(cx: Scope) -> View<G> {
|
|
||||||
view! { cx,
|
|
||||||
header(style="display: flex; gap: 1em; margin-bottom: 1em;") {
|
|
||||||
a(href="/") {
|
|
||||||
"Welcome"
|
|
||||||
}
|
|
||||||
a(href="/app") {
|
|
||||||
"App"
|
|
||||||
}
|
|
||||||
a(href="/clipboard") {
|
|
||||||
"Clipboard"
|
|
||||||
}
|
|
||||||
a(href="/communication") {
|
|
||||||
"Communication"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(not(debug_assertions), not(feature = "ssg")))]
|
|
||||||
fn main() {
|
|
||||||
wasm_logger::init(wasm_logger::Config::default());
|
|
||||||
|
|
||||||
sycamore::hydrate(|cx| view! { cx,
|
|
||||||
Header
|
|
||||||
Router(
|
|
||||||
integration=HistoryIntegration::new(),
|
|
||||||
view=views::switch
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(debug_assertions, not(feature = "ssg")))]
|
|
||||||
fn main() {
|
|
||||||
use sycamore::view;
|
|
||||||
|
|
||||||
wasm_logger::init(wasm_logger::Config::default());
|
|
||||||
|
|
||||||
sycamore::render(|cx| view! { cx,
|
|
||||||
Header
|
|
||||||
Router(
|
|
||||||
integration=HistoryIntegration::new(),
|
|
||||||
view=views::switch
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "ssg")]
|
|
||||||
fn main() {
|
|
||||||
use sycamore_router::StaticRouter;
|
|
||||||
|
|
||||||
let out_dir = std::env::args().nth(1).unwrap();
|
|
||||||
|
|
||||||
println!("out_dir {}", out_dir);
|
|
||||||
|
|
||||||
let template = std::fs::read_to_string(format!("{}/index.html", out_dir)).unwrap();
|
|
||||||
|
|
||||||
let html = sycamore::render_to_string(|cx| view! { cx,
|
|
||||||
Header
|
|
||||||
StaticRouter(
|
|
||||||
route=route.clone(),
|
|
||||||
view=views::switch
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let html = template.replace("<!--app-html-->\n", &html);
|
|
||||||
|
|
||||||
let path = format!("{}/index.html", out_dir);
|
|
||||||
|
|
||||||
println!("Writing html to file \"{}\"", path);
|
|
||||||
std::fs::write(path, html).unwrap();
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
use gloo_timers::callback::Timeout;
|
|
||||||
use sycamore::prelude::*;
|
|
||||||
use tauri_sys::app;
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn App<G: Html>(cx: Scope) -> View<G> {
|
|
||||||
let show_app = |_| {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
let res = app::hide().await;
|
|
||||||
|
|
||||||
log::debug!("app hide res {:?}", res);
|
|
||||||
|
|
||||||
let timeout = Timeout::new(2_000, move || {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
let res = app::show().await;
|
|
||||||
|
|
||||||
log::debug!("app show res {:?}", res);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
timeout.forget();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let hide_app = |_| {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
let res = app::hide().await;
|
|
||||||
|
|
||||||
log::debug!("app hide res {:?}", res);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let get_name = |_| {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
let res = app::get_name().await;
|
|
||||||
|
|
||||||
log::debug!("app name {:?}", res);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let get_version = |_| {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
let res = app::get_version().await;
|
|
||||||
|
|
||||||
log::debug!("app version {:?}", res);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let get_tauri_version = |_| {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
let res = app::get_tauri_version().await;
|
|
||||||
|
|
||||||
log::debug!("tauri version {:?}", res);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
view! { cx,
|
|
||||||
div {
|
|
||||||
button(class="btn",id="get_name",on:click=get_name) {
|
|
||||||
"Get App Name"
|
|
||||||
}
|
|
||||||
button(class="btn",id="get_version",on:click=get_version) {
|
|
||||||
"Get App Version"
|
|
||||||
}
|
|
||||||
button(class="btn",id="get_tauri_version",on:click=get_tauri_version) {
|
|
||||||
"Get Tauri Version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
div {
|
|
||||||
button(class="btn",id="show",title="Hides and shows the app after 2 seconds",on:click=show_app) {
|
|
||||||
"Show"
|
|
||||||
}
|
|
||||||
button(class="btn",id="hide",on:click=hide_app) {
|
|
||||||
"Hide"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
use sycamore::prelude::*;
|
|
||||||
use tauri_sys::clipboard::{read_text, write_text};
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Clipboard<G: Html>(cx: Scope) -> View<G> {
|
|
||||||
let text = create_signal(cx, "clipboard message".to_string());
|
|
||||||
|
|
||||||
let write = move |_| {
|
|
||||||
sycamore::futures::spawn_local_scoped(cx, async move {
|
|
||||||
write_text(&text.get()).await
|
|
||||||
// .then(() => {
|
|
||||||
// onMessage('Wrote to the clipboard')
|
|
||||||
// })
|
|
||||||
// .catch(onMessage)
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let read = |_| {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
let text = read_text().await;
|
|
||||||
|
|
||||||
log::info!("Read text from clipboard {:?}", text);
|
|
||||||
// readText()
|
|
||||||
// .then((contents) => {
|
|
||||||
// onMessage(`Clipboard contents: ${contents}`)
|
|
||||||
// })
|
|
||||||
// .catch(onMessage)
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
view! { cx,
|
|
||||||
div(class="flex gap-1") {
|
|
||||||
input(class="grow input",placeholder="Text to write to the clipboard",bind:value=text)
|
|
||||||
button(class="btn",type="button",on:click=write) {
|
|
||||||
"Write"
|
|
||||||
}
|
|
||||||
button(class="btn",type="button",on:click=read) {
|
|
||||||
"Read"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use sycamore::prelude::*;
|
|
||||||
use tauri_sys::event::{emit, listen};
|
|
||||||
use tauri_sys::tauri::invoke;
|
|
||||||
use shared::RequestBody;
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Communication<'a, G: Html>(cx: Scope<'a>) -> View<G> {
|
|
||||||
let unlisten = create_signal::<Option<Box<&dyn FnOnce()>>>(cx, None);
|
|
||||||
|
|
||||||
// on_mount(cx, move || {
|
|
||||||
|
|
||||||
// sycamore::futures::spawn_local_scoped(cx, async move {
|
|
||||||
// let unlisten_raw = listen::<Reply>("rust-event", &|reply| log::debug!("got reply {:?}", reply)).await;
|
|
||||||
|
|
||||||
// unlisten.set(Some(Box::new(&unlisten_raw)));
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// on_cleanup(cx, || {
|
|
||||||
// if let Some(unlisten) = unlisten .take().as_deref() {
|
|
||||||
// (unlisten)()
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
let log = |_| {
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct Payload<'a> {
|
|
||||||
event: &'a str,
|
|
||||||
payload: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
let res = invoke::<_, ()>(
|
|
||||||
"log_operation",
|
|
||||||
&Payload {
|
|
||||||
event: "tauri-click",
|
|
||||||
payload: "this payload is optional because we used Option in Rust",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
log::debug!("Emitted event, response {:?}", res);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let perform_request = |_| {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct Payload<'a> {
|
|
||||||
endpoint: &'a str,
|
|
||||||
body: RequestBody<'a>
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = invoke::<_, String>(
|
|
||||||
"perform_request",
|
|
||||||
&Payload {
|
|
||||||
endpoint: "dummy endpoint arg",
|
|
||||||
body: RequestBody {
|
|
||||||
id: 5,
|
|
||||||
name: "test",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
log::debug!("Got reply {:?}", res);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let emit_event = |_| {
|
|
||||||
sycamore::futures::spawn_local(async move {
|
|
||||||
emit("js-event", &"this is the payload string").await;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
view! { cx,
|
|
||||||
div {
|
|
||||||
button(class="btn",id="log",on:click=log) {
|
|
||||||
"Call Log API"
|
|
||||||
}
|
|
||||||
button(class="btn",mid="request",on:click=perform_request) {
|
|
||||||
"Call Request (async) API"
|
|
||||||
}
|
|
||||||
button(class="btn",id="event",on:click=emit_event) {
|
|
||||||
"Send event to Rust"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
mod app;
|
|
||||||
mod clipboard;
|
|
||||||
mod communication;
|
|
||||||
mod welcome;
|
|
||||||
|
|
||||||
use sycamore::view::View;
|
|
||||||
use sycamore_router::Route;
|
|
||||||
use sycamore::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Route)]
|
|
||||||
pub enum Page {
|
|
||||||
#[to("/app")]
|
|
||||||
App,
|
|
||||||
#[to("/clipboard")]
|
|
||||||
Clipboard,
|
|
||||||
#[to("/communication")]
|
|
||||||
Communication,
|
|
||||||
#[not_found]
|
|
||||||
NotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn switch<G: Html>(cx: Scope, route: &ReadSignal<Page>) -> View<G> {
|
|
||||||
match route.get().as_ref() {
|
|
||||||
Page::App => app::App(cx),
|
|
||||||
Page::Clipboard => clipboard::Clipboard(cx),
|
|
||||||
Page::Communication => communication::Communication(cx),
|
|
||||||
Page::NotFound => welcome::Welcome(cx)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
use sycamore::prelude::*;
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Welcome<G: Html>(cx: Scope) -> View<G> {
|
|
||||||
view! { cx,
|
|
||||||
h1 {
|
|
||||||
"Welcome"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
.logo.yew:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #20a88a);
|
|
||||||
}
|
|
||||||
.logo.sycamore {
|
|
||||||
color: #0000;
|
|
||||||
font-size: 3rem;
|
|
||||||
line-height: 1;
|
|
||||||
font-weight: 800;
|
|
||||||
-webkit-background-clip: text;
|
|
||||||
background-clip: text;
|
|
||||||
background-image: linear-gradient(to right,#fdba74, #f87171);
|
|
||||||
font-family: Inter,system-ui,sans-serif;
|
|
||||||
}
|
|
||||||
.logo.sycamore:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #f87171);
|
|
||||||
}
|
|
||||||
|
|
||||||
:root {
|
|
||||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
|
||||||
font-size: 16px;
|
|
||||||
line-height: 24px;
|
|
||||||
font-weight: 400;
|
|
||||||
|
|
||||||
color: #0f0f0f;
|
|
||||||
background-color: #f6f6f6;
|
|
||||||
|
|
||||||
font-synthesis: none;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
-webkit-text-size-adjust: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
margin: 0;
|
|
||||||
padding-top: 10vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
|
||||||
height: 6em;
|
|
||||||
padding: 1.5em;
|
|
||||||
will-change: filter;
|
|
||||||
transition: 0.75s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo.tauri:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #24c8db);
|
|
||||||
}
|
|
||||||
|
|
||||||
.row {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-weight: 500;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
color: #535bf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
input,
|
|
||||||
button {
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
padding: 0.6em 1.2em;
|
|
||||||
font-size: 1em;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: inherit;
|
|
||||||
color: #0f0f0f;
|
|
||||||
background-color: #ffffff;
|
|
||||||
transition: border-color 0.25s;
|
|
||||||
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
button:hover {
|
|
||||||
border-color: #396cd8;
|
|
||||||
}
|
|
||||||
|
|
||||||
input,
|
|
||||||
button {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#greet-input {
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:root {
|
|
||||||
color: #f6f6f6;
|
|
||||||
background-color: #2f2f2f;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
color: #24c8db;
|
|
||||||
}
|
|
||||||
|
|
||||||
input,
|
|
||||||
button {
|
|
||||||
color: #ffffff;
|
|
||||||
background-color: #0f0f0f98;
|
|
||||||
}
|
|
||||||
}
|
|
1
examples/test/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
target
|
3894
examples/test/Cargo.lock
generated
Normal file
17
examples/test/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[package]
|
||||||
|
name = "tauri-sys-test-ui"
|
||||||
|
version = "0.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[dependencies]
|
||||||
|
tauri-sys = { path = "../../", features = ["all"] }
|
||||||
|
sycamore = { git = "https://github.com/sycamore-rs/sycamore", rev = "abd556cbc02047042dad2ebd04405e455a9b11b2", features = ["suspense"] }
|
||||||
|
anyhow = "1.0.66"
|
||||||
|
console_error_panic_hook = "0.1.7"
|
||||||
|
wasm-bindgen-futures = "0.4.32"
|
||||||
|
futures-util = "0.3.25"
|
||||||
|
serde = { version = "1.0.147", features = ["derive"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
ci = []
|
10
examples/test/Trunk.toml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[build]
|
||||||
|
target = "./index.html"
|
||||||
|
|
||||||
|
[watch]
|
||||||
|
ignore = ["./src-tauri"]
|
||||||
|
|
||||||
|
[serve]
|
||||||
|
address = "127.0.0.1"
|
||||||
|
port = 1420
|
||||||
|
open = false
|
35
examples/test/dist/index.html
vendored
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<!DOCTYPE html><html><head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Tauri + Yew App</title>
|
||||||
|
|
||||||
|
<link rel="preload" href="/tauri-sys-test-ui-3eb704384493bbf2_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
|
||||||
|
<link rel="modulepreload" href="/tauri-sys-test-ui-3eb704384493bbf2.js"></head>
|
||||||
|
<body>
|
||||||
|
<script type="module">import init from '/tauri-sys-test-ui-3eb704384493bbf2.js';init('/tauri-sys-test-ui-3eb704384493bbf2_bg.wasm');</script><script>(function () {
|
||||||
|
var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
var url = protocol + '//' + window.location.host + '/_trunk/ws';
|
||||||
|
var poll_interval = 5000;
|
||||||
|
var reload_upon_connect = () => {
|
||||||
|
window.setTimeout(
|
||||||
|
() => {
|
||||||
|
// when we successfully reconnect, we'll force a
|
||||||
|
// reload (since we presumably lost connection to
|
||||||
|
// trunk due to it being killed, so it will have
|
||||||
|
// rebuilt on restart)
|
||||||
|
var ws = new WebSocket(url);
|
||||||
|
ws.onopen = () => window.location.reload();
|
||||||
|
ws.onclose = reload_upon_connect;
|
||||||
|
},
|
||||||
|
poll_interval);
|
||||||
|
};
|
||||||
|
|
||||||
|
var ws = new WebSocket(url);
|
||||||
|
ws.onmessage = (ev) => {
|
||||||
|
const msg = JSON.parse(ev.data);
|
||||||
|
if (msg.reload) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.onclose = reload_upon_connect;
|
||||||
|
})()
|
||||||
|
</script></body></html>
|
91
examples/test/dist/snippets/tauri-sys-91bd50ded94e0ed7/dist/app.js
vendored
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
// tauri/tooling/api/src/tauri.ts
|
||||||
|
function uid() {
|
||||||
|
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||||
|
}
|
||||||
|
function transformCallback(callback, once = false) {
|
||||||
|
const identifier = uid();
|
||||||
|
const prop = `_${identifier}`;
|
||||||
|
Object.defineProperty(window, prop, {
|
||||||
|
value: (result) => {
|
||||||
|
if (once) {
|
||||||
|
Reflect.deleteProperty(window, prop);
|
||||||
|
}
|
||||||
|
return callback?.(result);
|
||||||
|
},
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
async function invoke(cmd, args = {}) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const callback = transformCallback((e) => {
|
||||||
|
resolve(e);
|
||||||
|
Reflect.deleteProperty(window, `_${error}`);
|
||||||
|
}, true);
|
||||||
|
const error = transformCallback((e) => {
|
||||||
|
reject(e);
|
||||||
|
Reflect.deleteProperty(window, `_${callback}`);
|
||||||
|
}, true);
|
||||||
|
window.__TAURI_IPC__({
|
||||||
|
cmd,
|
||||||
|
callback,
|
||||||
|
error,
|
||||||
|
...args
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/helpers/tauri.ts
|
||||||
|
async function invokeTauriCommand(command) {
|
||||||
|
return invoke("tauri", command);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/app.ts
|
||||||
|
async function getVersion() {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "App",
|
||||||
|
message: {
|
||||||
|
cmd: "getAppVersion"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function getName() {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "App",
|
||||||
|
message: {
|
||||||
|
cmd: "getAppName"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function getTauriVersion() {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "App",
|
||||||
|
message: {
|
||||||
|
cmd: "getTauriVersion"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function show() {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "App",
|
||||||
|
message: {
|
||||||
|
cmd: "show"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function hide() {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "App",
|
||||||
|
message: {
|
||||||
|
cmd: "hide"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export {
|
||||||
|
getName,
|
||||||
|
getTauriVersion,
|
||||||
|
getVersion,
|
||||||
|
hide,
|
||||||
|
show
|
||||||
|
};
|
66
examples/test/dist/snippets/tauri-sys-91bd50ded94e0ed7/dist/clipboard.js
vendored
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
// tauri/tooling/api/src/tauri.ts
|
||||||
|
function uid() {
|
||||||
|
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||||
|
}
|
||||||
|
function transformCallback(callback, once = false) {
|
||||||
|
const identifier = uid();
|
||||||
|
const prop = `_${identifier}`;
|
||||||
|
Object.defineProperty(window, prop, {
|
||||||
|
value: (result) => {
|
||||||
|
if (once) {
|
||||||
|
Reflect.deleteProperty(window, prop);
|
||||||
|
}
|
||||||
|
return callback?.(result);
|
||||||
|
},
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
async function invoke(cmd, args = {}) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const callback = transformCallback((e) => {
|
||||||
|
resolve(e);
|
||||||
|
Reflect.deleteProperty(window, `_${error}`);
|
||||||
|
}, true);
|
||||||
|
const error = transformCallback((e) => {
|
||||||
|
reject(e);
|
||||||
|
Reflect.deleteProperty(window, `_${callback}`);
|
||||||
|
}, true);
|
||||||
|
window.__TAURI_IPC__({
|
||||||
|
cmd,
|
||||||
|
callback,
|
||||||
|
error,
|
||||||
|
...args
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/helpers/tauri.ts
|
||||||
|
async function invokeTauriCommand(command) {
|
||||||
|
return invoke("tauri", command);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/clipboard.ts
|
||||||
|
async function writeText(text) {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "Clipboard",
|
||||||
|
message: {
|
||||||
|
cmd: "writeText",
|
||||||
|
data: text
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function readText() {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "Clipboard",
|
||||||
|
message: {
|
||||||
|
cmd: "readText",
|
||||||
|
data: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export {
|
||||||
|
readText,
|
||||||
|
writeText
|
||||||
|
};
|
123
examples/test/dist/snippets/tauri-sys-91bd50ded94e0ed7/dist/event.js
vendored
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
// tauri/tooling/api/src/tauri.ts
|
||||||
|
function uid() {
|
||||||
|
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||||
|
}
|
||||||
|
function transformCallback(callback, once3 = false) {
|
||||||
|
const identifier = uid();
|
||||||
|
const prop = `_${identifier}`;
|
||||||
|
Object.defineProperty(window, prop, {
|
||||||
|
value: (result) => {
|
||||||
|
if (once3) {
|
||||||
|
Reflect.deleteProperty(window, prop);
|
||||||
|
}
|
||||||
|
return callback?.(result);
|
||||||
|
},
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
async function invoke(cmd, args = {}) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const callback = transformCallback((e) => {
|
||||||
|
resolve(e);
|
||||||
|
Reflect.deleteProperty(window, `_${error}`);
|
||||||
|
}, true);
|
||||||
|
const error = transformCallback((e) => {
|
||||||
|
reject(e);
|
||||||
|
Reflect.deleteProperty(window, `_${callback}`);
|
||||||
|
}, true);
|
||||||
|
window.__TAURI_IPC__({
|
||||||
|
cmd,
|
||||||
|
callback,
|
||||||
|
error,
|
||||||
|
...args
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/helpers/tauri.ts
|
||||||
|
async function invokeTauriCommand(command) {
|
||||||
|
return invoke("tauri", command);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/helpers/event.ts
|
||||||
|
async function _unlisten(event, eventId) {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "Event",
|
||||||
|
message: {
|
||||||
|
cmd: "unlisten",
|
||||||
|
event,
|
||||||
|
eventId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function emit(event, windowLabel, payload) {
|
||||||
|
await invokeTauriCommand({
|
||||||
|
__tauriModule: "Event",
|
||||||
|
message: {
|
||||||
|
cmd: "emit",
|
||||||
|
event,
|
||||||
|
windowLabel,
|
||||||
|
payload
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function listen(event, windowLabel, handler) {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "Event",
|
||||||
|
message: {
|
||||||
|
cmd: "listen",
|
||||||
|
event,
|
||||||
|
windowLabel,
|
||||||
|
handler: transformCallback(handler)
|
||||||
|
}
|
||||||
|
}).then((eventId) => {
|
||||||
|
return async () => _unlisten(event, eventId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function once(event, windowLabel, handler) {
|
||||||
|
return listen(event, windowLabel, (eventData) => {
|
||||||
|
handler(eventData);
|
||||||
|
_unlisten(event, eventData.id).catch(() => {
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/event.ts
|
||||||
|
var TauriEvent = /* @__PURE__ */ ((TauriEvent2) => {
|
||||||
|
TauriEvent2["WINDOW_RESIZED"] = "tauri://resize";
|
||||||
|
TauriEvent2["WINDOW_MOVED"] = "tauri://move";
|
||||||
|
TauriEvent2["WINDOW_CLOSE_REQUESTED"] = "tauri://close-requested";
|
||||||
|
TauriEvent2["WINDOW_CREATED"] = "tauri://window-created";
|
||||||
|
TauriEvent2["WINDOW_DESTROYED"] = "tauri://destroyed";
|
||||||
|
TauriEvent2["WINDOW_FOCUS"] = "tauri://focus";
|
||||||
|
TauriEvent2["WINDOW_BLUR"] = "tauri://blur";
|
||||||
|
TauriEvent2["WINDOW_SCALE_FACTOR_CHANGED"] = "tauri://scale-change";
|
||||||
|
TauriEvent2["WINDOW_THEME_CHANGED"] = "tauri://theme-changed";
|
||||||
|
TauriEvent2["WINDOW_FILE_DROP"] = "tauri://file-drop";
|
||||||
|
TauriEvent2["WINDOW_FILE_DROP_HOVER"] = "tauri://file-drop-hover";
|
||||||
|
TauriEvent2["WINDOW_FILE_DROP_CANCELLED"] = "tauri://file-drop-cancelled";
|
||||||
|
TauriEvent2["MENU"] = "tauri://menu";
|
||||||
|
TauriEvent2["CHECK_UPDATE"] = "tauri://update";
|
||||||
|
TauriEvent2["UPDATE_AVAILABLE"] = "tauri://update-available";
|
||||||
|
TauriEvent2["INSTALL_UPDATE"] = "tauri://update-install";
|
||||||
|
TauriEvent2["STATUS_UPDATE"] = "tauri://update-status";
|
||||||
|
TauriEvent2["DOWNLOAD_PROGRESS"] = "tauri://update-download-progress";
|
||||||
|
return TauriEvent2;
|
||||||
|
})(TauriEvent || {});
|
||||||
|
async function listen2(event, handler) {
|
||||||
|
return listen(event, null, handler);
|
||||||
|
}
|
||||||
|
async function once2(event, handler) {
|
||||||
|
return once(event, null, handler);
|
||||||
|
}
|
||||||
|
async function emit2(event, payload) {
|
||||||
|
return emit(event, void 0, payload);
|
||||||
|
}
|
||||||
|
export {
|
||||||
|
TauriEvent,
|
||||||
|
emit2 as emit,
|
||||||
|
listen2 as listen,
|
||||||
|
once2 as once
|
||||||
|
};
|
30
examples/test/dist/snippets/tauri-sys-91bd50ded94e0ed7/dist/mocks.js
vendored
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// tauri/tooling/api/src/mocks.ts
|
||||||
|
function mockIPC(cb) {
|
||||||
|
window.__TAURI_IPC__ = async ({
|
||||||
|
cmd,
|
||||||
|
callback,
|
||||||
|
error,
|
||||||
|
...args
|
||||||
|
}) => {
|
||||||
|
try {
|
||||||
|
window[`_${callback}`](await cb(cmd, args));
|
||||||
|
} catch (err) {
|
||||||
|
window[`_${error}`](err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function mockWindows(current, ...additionalWindows) {
|
||||||
|
window.__TAURI_METADATA__ = {
|
||||||
|
__windows: [current, ...additionalWindows].map((label) => ({ label })),
|
||||||
|
__currentWindow: { label: current }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function clearMocks() {
|
||||||
|
delete window.__TAURI_IPC__;
|
||||||
|
delete window.__TAURI_METADATA__;
|
||||||
|
}
|
||||||
|
export {
|
||||||
|
clearMocks,
|
||||||
|
mockIPC,
|
||||||
|
mockWindows
|
||||||
|
};
|
65
examples/test/dist/snippets/tauri-sys-91bd50ded94e0ed7/dist/process.js
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// tauri/tooling/api/src/tauri.ts
|
||||||
|
function uid() {
|
||||||
|
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||||
|
}
|
||||||
|
function transformCallback(callback, once = false) {
|
||||||
|
const identifier = uid();
|
||||||
|
const prop = `_${identifier}`;
|
||||||
|
Object.defineProperty(window, prop, {
|
||||||
|
value: (result) => {
|
||||||
|
if (once) {
|
||||||
|
Reflect.deleteProperty(window, prop);
|
||||||
|
}
|
||||||
|
return callback?.(result);
|
||||||
|
},
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
async function invoke(cmd, args = {}) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const callback = transformCallback((e) => {
|
||||||
|
resolve(e);
|
||||||
|
Reflect.deleteProperty(window, `_${error}`);
|
||||||
|
}, true);
|
||||||
|
const error = transformCallback((e) => {
|
||||||
|
reject(e);
|
||||||
|
Reflect.deleteProperty(window, `_${callback}`);
|
||||||
|
}, true);
|
||||||
|
window.__TAURI_IPC__({
|
||||||
|
cmd,
|
||||||
|
callback,
|
||||||
|
error,
|
||||||
|
...args
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/helpers/tauri.ts
|
||||||
|
async function invokeTauriCommand(command) {
|
||||||
|
return invoke("tauri", command);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tauri/tooling/api/src/process.ts
|
||||||
|
async function exit(exitCode = 0) {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "Process",
|
||||||
|
message: {
|
||||||
|
cmd: "exit",
|
||||||
|
exitCode
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function relaunch() {
|
||||||
|
return invokeTauriCommand({
|
||||||
|
__tauriModule: "Process",
|
||||||
|
message: {
|
||||||
|
cmd: "relaunch"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export {
|
||||||
|
exit,
|
||||||
|
relaunch
|
||||||
|
};
|
46
examples/test/dist/snippets/tauri-sys-91bd50ded94e0ed7/dist/tauri.js
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// tauri/tooling/api/src/tauri.ts
|
||||||
|
function uid() {
|
||||||
|
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||||
|
}
|
||||||
|
function transformCallback(callback, once = false) {
|
||||||
|
const identifier = uid();
|
||||||
|
const prop = `_${identifier}`;
|
||||||
|
Object.defineProperty(window, prop, {
|
||||||
|
value: (result) => {
|
||||||
|
if (once) {
|
||||||
|
Reflect.deleteProperty(window, prop);
|
||||||
|
}
|
||||||
|
return callback?.(result);
|
||||||
|
},
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
async function invoke(cmd, args = {}) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const callback = transformCallback((e) => {
|
||||||
|
resolve(e);
|
||||||
|
Reflect.deleteProperty(window, `_${error}`);
|
||||||
|
}, true);
|
||||||
|
const error = transformCallback((e) => {
|
||||||
|
reject(e);
|
||||||
|
Reflect.deleteProperty(window, `_${callback}`);
|
||||||
|
}, true);
|
||||||
|
window.__TAURI_IPC__({
|
||||||
|
cmd,
|
||||||
|
callback,
|
||||||
|
error,
|
||||||
|
...args
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function convertFileSrc(filePath, protocol = "asset") {
|
||||||
|
const path = encodeURIComponent(filePath);
|
||||||
|
return navigator.userAgent.includes("Windows") ? `https://${protocol}.localhost/${path}` : `${protocol}://localhost/${path}`;
|
||||||
|
}
|
||||||
|
export {
|
||||||
|
convertFileSrc,
|
||||||
|
invoke,
|
||||||
|
transformCallback
|
||||||
|
};
|
1004
examples/test/dist/snippets/tauri-sys-91bd50ded94e0ed7/dist/window.js
vendored
Normal file
644
examples/test/dist/tauri-sys-test-ui-3eb704384493bbf2.js
vendored
Normal file
|
@ -0,0 +1,644 @@
|
||||||
|
import { getName, getTauriVersion, getVersion } from './snippets/tauri-sys-91bd50ded94e0ed7/dist/app.js';
|
||||||
|
import { readText, writeText } from './snippets/tauri-sys-91bd50ded94e0ed7/dist/clipboard.js';
|
||||||
|
import { emit } from './snippets/tauri-sys-91bd50ded94e0ed7/dist/event.js';
|
||||||
|
import { invoke } from './snippets/tauri-sys-91bd50ded94e0ed7/dist/tauri.js';
|
||||||
|
|
||||||
|
let wasm;
|
||||||
|
|
||||||
|
const heap = new Array(32).fill(undefined);
|
||||||
|
|
||||||
|
heap.push(undefined, null, true, false);
|
||||||
|
|
||||||
|
function getObject(idx) { return heap[idx]; }
|
||||||
|
|
||||||
|
let WASM_VECTOR_LEN = 0;
|
||||||
|
|
||||||
|
let cachedUint8Memory0 = new Uint8Array();
|
||||||
|
|
||||||
|
function getUint8Memory0() {
|
||||||
|
if (cachedUint8Memory0.byteLength === 0) {
|
||||||
|
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachedUint8Memory0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cachedTextEncoder = new TextEncoder('utf-8');
|
||||||
|
|
||||||
|
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
||||||
|
? function (arg, view) {
|
||||||
|
return cachedTextEncoder.encodeInto(arg, view);
|
||||||
|
}
|
||||||
|
: function (arg, view) {
|
||||||
|
const buf = cachedTextEncoder.encode(arg);
|
||||||
|
view.set(buf);
|
||||||
|
return {
|
||||||
|
read: arg.length,
|
||||||
|
written: buf.length
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
function passStringToWasm0(arg, malloc, realloc) {
|
||||||
|
|
||||||
|
if (realloc === undefined) {
|
||||||
|
const buf = cachedTextEncoder.encode(arg);
|
||||||
|
const ptr = malloc(buf.length);
|
||||||
|
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||||
|
WASM_VECTOR_LEN = buf.length;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
let len = arg.length;
|
||||||
|
let ptr = malloc(len);
|
||||||
|
|
||||||
|
const mem = getUint8Memory0();
|
||||||
|
|
||||||
|
let offset = 0;
|
||||||
|
|
||||||
|
for (; offset < len; offset++) {
|
||||||
|
const code = arg.charCodeAt(offset);
|
||||||
|
if (code > 0x7F) break;
|
||||||
|
mem[ptr + offset] = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset !== len) {
|
||||||
|
if (offset !== 0) {
|
||||||
|
arg = arg.slice(offset);
|
||||||
|
}
|
||||||
|
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
||||||
|
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
||||||
|
const ret = encodeString(arg, view);
|
||||||
|
|
||||||
|
offset += ret.written;
|
||||||
|
}
|
||||||
|
|
||||||
|
WASM_VECTOR_LEN = offset;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isLikeNone(x) {
|
||||||
|
return x === undefined || x === null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cachedInt32Memory0 = new Int32Array();
|
||||||
|
|
||||||
|
function getInt32Memory0() {
|
||||||
|
if (cachedInt32Memory0.byteLength === 0) {
|
||||||
|
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachedInt32Memory0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let heap_next = heap.length;
|
||||||
|
|
||||||
|
function addHeapObject(obj) {
|
||||||
|
if (heap_next === heap.length) heap.push(heap.length + 1);
|
||||||
|
const idx = heap_next;
|
||||||
|
heap_next = heap[idx];
|
||||||
|
|
||||||
|
heap[idx] = obj;
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||||
|
|
||||||
|
cachedTextDecoder.decode();
|
||||||
|
|
||||||
|
function getStringFromWasm0(ptr, len) {
|
||||||
|
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
||||||
|
}
|
||||||
|
|
||||||
|
let cachedFloat64Memory0 = new Float64Array();
|
||||||
|
|
||||||
|
function getFloat64Memory0() {
|
||||||
|
if (cachedFloat64Memory0.byteLength === 0) {
|
||||||
|
cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachedFloat64Memory0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function dropObject(idx) {
|
||||||
|
if (idx < 36) return;
|
||||||
|
heap[idx] = heap_next;
|
||||||
|
heap_next = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeObject(idx) {
|
||||||
|
const ret = getObject(idx);
|
||||||
|
dropObject(idx);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function debugString(val) {
|
||||||
|
// primitive types
|
||||||
|
const type = typeof val;
|
||||||
|
if (type == 'number' || type == 'boolean' || val == null) {
|
||||||
|
return `${val}`;
|
||||||
|
}
|
||||||
|
if (type == 'string') {
|
||||||
|
return `"${val}"`;
|
||||||
|
}
|
||||||
|
if (type == 'symbol') {
|
||||||
|
const description = val.description;
|
||||||
|
if (description == null) {
|
||||||
|
return 'Symbol';
|
||||||
|
} else {
|
||||||
|
return `Symbol(${description})`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type == 'function') {
|
||||||
|
const name = val.name;
|
||||||
|
if (typeof name == 'string' && name.length > 0) {
|
||||||
|
return `Function(${name})`;
|
||||||
|
} else {
|
||||||
|
return 'Function';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// objects
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
const length = val.length;
|
||||||
|
let debug = '[';
|
||||||
|
if (length > 0) {
|
||||||
|
debug += debugString(val[0]);
|
||||||
|
}
|
||||||
|
for(let i = 1; i < length; i++) {
|
||||||
|
debug += ', ' + debugString(val[i]);
|
||||||
|
}
|
||||||
|
debug += ']';
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
// Test for built-in
|
||||||
|
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
||||||
|
let className;
|
||||||
|
if (builtInMatches.length > 1) {
|
||||||
|
className = builtInMatches[1];
|
||||||
|
} else {
|
||||||
|
// Failed to match the standard '[object ClassName]'
|
||||||
|
return toString.call(val);
|
||||||
|
}
|
||||||
|
if (className == 'Object') {
|
||||||
|
// we're a user defined class or Object
|
||||||
|
// JSON.stringify avoids problems with cycles, and is generally much
|
||||||
|
// easier than looping through ownProperties of `val`.
|
||||||
|
try {
|
||||||
|
return 'Object(' + JSON.stringify(val) + ')';
|
||||||
|
} catch (_) {
|
||||||
|
return 'Object';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// errors
|
||||||
|
if (val instanceof Error) {
|
||||||
|
return `${val.name}: ${val.message}\n${val.stack}`;
|
||||||
|
}
|
||||||
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
||||||
|
return className;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeMutClosure(arg0, arg1, dtor, f) {
|
||||||
|
const state = { a: arg0, b: arg1, cnt: 1, dtor };
|
||||||
|
const real = (...args) => {
|
||||||
|
// First up with a closure we increment the internal reference
|
||||||
|
// count. This ensures that the Rust closure environment won't
|
||||||
|
// be deallocated while we're invoking it.
|
||||||
|
state.cnt++;
|
||||||
|
const a = state.a;
|
||||||
|
state.a = 0;
|
||||||
|
try {
|
||||||
|
return f(a, state.b, ...args);
|
||||||
|
} finally {
|
||||||
|
if (--state.cnt === 0) {
|
||||||
|
wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
state.a = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
real.original = state;
|
||||||
|
|
||||||
|
return real;
|
||||||
|
}
|
||||||
|
function __wbg_adapter_28(arg0, arg1, arg2) {
|
||||||
|
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h45f286b32445b0b2(arg0, arg1, addHeapObject(arg2));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCachedStringFromWasm0(ptr, len) {
|
||||||
|
if (ptr === 0) {
|
||||||
|
return getObject(len);
|
||||||
|
} else {
|
||||||
|
return getStringFromWasm0(ptr, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleError(f, args) {
|
||||||
|
try {
|
||||||
|
return f.apply(this, args);
|
||||||
|
} catch (e) {
|
||||||
|
wasm.__wbindgen_exn_store(addHeapObject(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(module, imports) {
|
||||||
|
if (typeof Response === 'function' && module instanceof Response) {
|
||||||
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
||||||
|
try {
|
||||||
|
return await WebAssembly.instantiateStreaming(module, imports);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
if (module.headers.get('Content-Type') != 'application/wasm') {
|
||||||
|
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bytes = await module.arrayBuffer();
|
||||||
|
return await WebAssembly.instantiate(bytes, imports);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const instance = await WebAssembly.instantiate(module, imports);
|
||||||
|
|
||||||
|
if (instance instanceof WebAssembly.Instance) {
|
||||||
|
return { instance, module };
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getImports() {
|
||||||
|
const imports = {};
|
||||||
|
imports.wbg = {};
|
||||||
|
imports.wbg.__wbg_readText_d6aa69a1d055ebfb = function() {
|
||||||
|
const ret = readText();
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_writeText_98a927b6ebdc847f = function(arg0, arg1) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg0, arg1);
|
||||||
|
const ret = writeText(v0);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_invoke_575077e3d547074e = function() { return handleError(function (arg0, arg1, arg2) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg0, arg1);
|
||||||
|
const ret = invoke(v0, takeObject(arg2));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_getVersion_13e166788d7097c8 = function() {
|
||||||
|
const ret = getVersion();
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_getTauriVersion_62b3cf54af008ea9 = function() {
|
||||||
|
const ret = getTauriVersion();
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_getName_d3872e5e2b652485 = function() {
|
||||||
|
const ret = getName();
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_emit_128d56f37ce5403a = function(arg0, arg1, arg2) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg0, arg1);
|
||||||
|
const ret = emit(v0, takeObject(arg2));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_boolean_get = function(arg0) {
|
||||||
|
const v = getObject(arg0);
|
||||||
|
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
||||||
|
const obj = getObject(arg1);
|
||||||
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
||||||
|
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||||
|
var len0 = WASM_VECTOR_LEN;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
||||||
|
const ret = getObject(arg0);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_nodeId_bbf0efafa303e805 = function(arg0, arg1) {
|
||||||
|
const ret = getObject(arg1).$$$nodeId;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 1] = isLikeNone(ret) ? 0 : ret;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_setnodeId_433ef8ed15bd1612 = function(arg0, arg1) {
|
||||||
|
getObject(arg0).$$$nodeId = arg1 >>> 0;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_createTextNode_a7d5f5b956acda97 = function(arg0, arg1) {
|
||||||
|
const ret = getObject(arg0).createTextNode(arg1);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
||||||
|
const ret = getStringFromWasm0(arg0, arg1);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_instanceof_Window_acc97ff9f5d2c7b4 = function(arg0) {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = getObject(arg0) instanceof Window;
|
||||||
|
} catch {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
const ret = result;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_document_3ead31dbcad65886 = function(arg0) {
|
||||||
|
const ret = getObject(arg0).document;
|
||||||
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_body_3cb4b4042b9a632b = function(arg0) {
|
||||||
|
const ret = getObject(arg0).body;
|
||||||
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_createComment_0df3a4d0d91032e7 = function(arg0, arg1, arg2) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg1, arg2);
|
||||||
|
const ret = getObject(arg0).createComment(v0);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_createElement_976dbb84fe1661b5 = function() { return handleError(function (arg0, arg1, arg2) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg1, arg2);
|
||||||
|
const ret = getObject(arg0).createElement(v0);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_createElementNS_1561aca8ee3693c0 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg1, arg2);
|
||||||
|
var v1 = getCachedStringFromWasm0(arg3, arg4);
|
||||||
|
const ret = getObject(arg0).createElementNS(v0, v1);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_createTextNode_300f845fab76642f = function(arg0, arg1, arg2) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg1, arg2);
|
||||||
|
const ret = getObject(arg0).createTextNode(v0);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_instanceof_Comment_1758f7164ca9ea81 = function(arg0) {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = getObject(arg0) instanceof Comment;
|
||||||
|
} catch {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
const ret = result;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_instanceof_Text_6855016c7825859b = function(arg0) {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = getObject(arg0) instanceof Text;
|
||||||
|
} catch {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
const ret = result;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_instanceof_Element_33bd126d58f2021b = function(arg0) {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = getObject(arg0) instanceof Element;
|
||||||
|
} catch {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
const ret = result;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_outerHTML_bf662bdff92e5910 = function(arg0, arg1) {
|
||||||
|
const ret = getObject(arg1).outerHTML;
|
||||||
|
const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||||
|
const len0 = WASM_VECTOR_LEN;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_parentNode_e397bbbe28be7b28 = function(arg0) {
|
||||||
|
const ret = getObject(arg0).parentNode;
|
||||||
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_nextSibling_62338ec2a05607b4 = function(arg0) {
|
||||||
|
const ret = getObject(arg0).nextSibling;
|
||||||
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_textContent_77bd294928962f93 = function(arg0, arg1) {
|
||||||
|
const ret = getObject(arg1).textContent;
|
||||||
|
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||||
|
var len0 = WASM_VECTOR_LEN;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_settextContent_538ceb17614272d8 = function(arg0, arg1, arg2) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg1, arg2);
|
||||||
|
getObject(arg0).textContent = v0;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_appendChild_e513ef0e5098dfdd = function() { return handleError(function (arg0, arg1) {
|
||||||
|
const ret = getObject(arg0).appendChild(getObject(arg1));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_insertBefore_9f2d2defb9471006 = function() { return handleError(function (arg0, arg1, arg2) {
|
||||||
|
const ret = getObject(arg0).insertBefore(getObject(arg1), getObject(arg2));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_removeChild_6751e9ca5d9aaf00 = function() { return handleError(function (arg0, arg1) {
|
||||||
|
const ret = getObject(arg0).removeChild(getObject(arg1));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_replaceChild_4793d6269c04dd25 = function() { return handleError(function (arg0, arg1, arg2) {
|
||||||
|
const ret = getObject(arg0).replaceChild(getObject(arg1), getObject(arg2));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
||||||
|
const ret = getObject(arg0) === undefined;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
|
||||||
|
const obj = getObject(arg1);
|
||||||
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
||||||
|
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
||||||
|
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
|
||||||
|
const ret = getObject(arg0) == getObject(arg1);
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_cb_drop = function(arg0) {
|
||||||
|
const obj = takeObject(arg0).original;
|
||||||
|
if (obj.cnt-- == 1) {
|
||||||
|
obj.a = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const ret = false;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_instanceof_ArrayBuffer_e5e48f4762c5610b = function(arg0) {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = getObject(arg0) instanceof ArrayBuffer;
|
||||||
|
} catch {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
const ret = result;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_newnoargs_b5b063fc6c2f0376 = function(arg0, arg1) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg0, arg1);
|
||||||
|
const ret = new Function(v0);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_call_97ae9d8645dc388b = function() { return handleError(function (arg0, arg1) {
|
||||||
|
const ret = getObject(arg0).call(getObject(arg1));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_is_40a66842732708e7 = function(arg0, arg1) {
|
||||||
|
const ret = Object.is(getObject(arg0), getObject(arg1));
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_toString_7be108a12ef03bc2 = function(arg0) {
|
||||||
|
const ret = getObject(arg0).toString();
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_resolve_99fe17964f31ffc0 = function(arg0) {
|
||||||
|
const ret = Promise.resolve(getObject(arg0));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_then_11f7a54d67b4bfad = function(arg0, arg1) {
|
||||||
|
const ret = getObject(arg0).then(getObject(arg1));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_then_cedad20fbbd9418a = function(arg0, arg1, arg2) {
|
||||||
|
const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_globalThis_7f206bda628d5286 = function() { return handleError(function () {
|
||||||
|
const ret = globalThis.globalThis;
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_self_6d479506f72c6a71 = function() { return handleError(function () {
|
||||||
|
const ret = self.self;
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_window_f2557cc78490aceb = function() { return handleError(function () {
|
||||||
|
const ret = window.window;
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_global_ba75c50d1cf384f4 = function() { return handleError(function () {
|
||||||
|
const ret = global.global;
|
||||||
|
return addHeapObject(ret);
|
||||||
|
}, arguments) };
|
||||||
|
imports.wbg.__wbg_instanceof_Uint8Array_971eeda69eb75003 = function(arg0) {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = getObject(arg0) instanceof Uint8Array;
|
||||||
|
} catch {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
const ret = result;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_new_8c3f0052272a457a = function(arg0) {
|
||||||
|
const ret = new Uint8Array(getObject(arg0));
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_length_9e1ae1900cb0fbd5 = function(arg0) {
|
||||||
|
const ret = getObject(arg0).length;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_set_83db9690f9353e79 = function(arg0, arg1, arg2) {
|
||||||
|
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_buffer_3f3d764d4747d564 = function(arg0) {
|
||||||
|
const ret = getObject(arg0).buffer;
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
|
||||||
|
var v0 = getCachedStringFromWasm0(arg0, arg1);
|
||||||
|
if (arg0 !== 0) { wasm.__wbindgen_free(arg0, arg1); }
|
||||||
|
console.error(v0);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
|
||||||
|
const ret = new Error();
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
|
||||||
|
const ret = getObject(arg1).stack;
|
||||||
|
const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||||
|
const len0 = WASM_VECTOR_LEN;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
||||||
|
const ret = debugString(getObject(arg1));
|
||||||
|
const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||||
|
const len0 = WASM_VECTOR_LEN;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
||||||
|
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
||||||
|
takeObject(arg0);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
||||||
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_memory = function() {
|
||||||
|
const ret = wasm.memory;
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
imports.wbg.__wbindgen_closure_wrapper5822 = function(arg0, arg1, arg2) {
|
||||||
|
const ret = makeMutClosure(arg0, arg1, 295, __wbg_adapter_28);
|
||||||
|
return addHeapObject(ret);
|
||||||
|
};
|
||||||
|
|
||||||
|
return imports;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initMemory(imports, maybe_memory) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function finalizeInit(instance, module) {
|
||||||
|
wasm = instance.exports;
|
||||||
|
init.__wbindgen_wasm_module = module;
|
||||||
|
cachedFloat64Memory0 = new Float64Array();
|
||||||
|
cachedInt32Memory0 = new Int32Array();
|
||||||
|
cachedUint8Memory0 = new Uint8Array();
|
||||||
|
|
||||||
|
wasm.__wbindgen_start();
|
||||||
|
return wasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initSync(module) {
|
||||||
|
const imports = getImports();
|
||||||
|
|
||||||
|
initMemory(imports);
|
||||||
|
|
||||||
|
if (!(module instanceof WebAssembly.Module)) {
|
||||||
|
module = new WebAssembly.Module(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = new WebAssembly.Instance(module, imports);
|
||||||
|
|
||||||
|
return finalizeInit(instance, module);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function init(input) {
|
||||||
|
if (typeof input === 'undefined') {
|
||||||
|
input = new URL('tauri-sys-test-ui-3eb704384493bbf2_bg.wasm', import.meta.url);
|
||||||
|
}
|
||||||
|
const imports = getImports();
|
||||||
|
|
||||||
|
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
||||||
|
input = fetch(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
initMemory(imports);
|
||||||
|
|
||||||
|
const { instance, module } = await load(await input, imports);
|
||||||
|
|
||||||
|
return finalizeInit(instance, module);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { initSync }
|
||||||
|
export default init;
|
BIN
examples/test/dist/tauri-sys-test-ui-3eb704384493bbf2_bg.wasm
vendored
Normal file
7
examples/test/index.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Tauri + Yew App</title>
|
||||||
|
</head>
|
||||||
|
</html>
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tauri-app"
|
name = "tauri-sys-test"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
description = "A Tauri App"
|
description = "A Tauri App"
|
||||||
authors = ["you"]
|
authors = ["you"]
|
||||||
|
@ -11,13 +11,12 @@ rust-version = "1.57"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-build = { git = "https://github.com/tauri-apps/tauri", features = [] }
|
tauri-build = { version = "1.1", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { git = "https://github.com/tauri-apps/tauri", features = ["api-all"] }
|
tauri = { version = "1.1", features = ["api-all"] }
|
||||||
shared = { path = "../shared" }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# by default Tauri runs in production mode
|
# by default Tauri runs in production mode
|
6
examples/test/src-tauri/ci.tauri.conf.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"build": {
|
||||||
|
"beforeDevCommand": "trunk serve --features ci",
|
||||||
|
"beforeBuildCommand": "trunk build --release --features ci"
|
||||||
|
}
|
||||||
|
}
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 974 B After Width: | Height: | Size: 974 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 903 B After Width: | Height: | Size: 903 B |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 85 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
38
examples/test/src-tauri/src/main.rs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#![cfg_attr(
|
||||||
|
all(not(debug_assertions), target_os = "windows"),
|
||||||
|
windows_subsystem = "windows"
|
||||||
|
)]
|
||||||
|
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
|
use tauri::{State, Manager};
|
||||||
|
|
||||||
|
struct Received(AtomicBool);
|
||||||
|
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||||
|
#[tauri::command]
|
||||||
|
fn verify_receive(emitted: State<Received>) -> bool {
|
||||||
|
emitted.0.load(Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn exit_with_error(e: &str) -> bool {
|
||||||
|
eprintln!("{}", e);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
tauri::Builder::default()
|
||||||
|
.invoke_handler(tauri::generate_handler![verify_receive, exit_with_error])
|
||||||
|
.setup(|app| {
|
||||||
|
app.manage(Received(AtomicBool::new(false)));
|
||||||
|
|
||||||
|
let app_handle = app.handle();
|
||||||
|
app.listen_global("foo", move |_| {
|
||||||
|
app_handle.state::<Received>().0.store(true, Ordering::Relaxed);
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.run(tauri::generate_context!())
|
||||||
|
.expect("error while running tauri application");
|
||||||
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
"withGlobalTauri": true
|
"withGlobalTauri": true
|
||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "tauri-app",
|
"productName": "tauri-sys-test",
|
||||||
"version": "0.0.0"
|
"version": "0.0.0"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
34
examples/test/src/app.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use anyhow::ensure;
|
||||||
|
use tauri_sys::app;
|
||||||
|
|
||||||
|
pub async fn get_name() -> anyhow::Result<()> {
|
||||||
|
let name = app::get_name().await;
|
||||||
|
|
||||||
|
ensure!(name == "tauri-sys-test");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_version() -> anyhow::Result<()> {
|
||||||
|
let version = app::get_version().await;
|
||||||
|
|
||||||
|
ensure!(version.major == 0);
|
||||||
|
ensure!(version.minor == 0);
|
||||||
|
ensure!(version.patch == 0);
|
||||||
|
ensure!(version.build.is_empty());
|
||||||
|
ensure!(version.pre.is_empty());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_tauri_version() -> anyhow::Result<()> {
|
||||||
|
let version = app::get_tauri_version().await;
|
||||||
|
|
||||||
|
ensure!(version.major == 1);
|
||||||
|
ensure!(version.minor == 1);
|
||||||
|
ensure!(version.patch == 1);
|
||||||
|
ensure!(version.build.is_empty());
|
||||||
|
ensure!(version.pre.is_empty());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
12
examples/test/src/clipboard.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
use anyhow::ensure;
|
||||||
|
use tauri_sys::clipboard;
|
||||||
|
|
||||||
|
pub async fn test() -> anyhow::Result<()> {
|
||||||
|
clipboard::write_text("foobar").await;
|
||||||
|
|
||||||
|
let text = clipboard::read_text().await;
|
||||||
|
|
||||||
|
ensure!(text == Some("foobar".to_string()));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
10
examples/test/src/event.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use anyhow::ensure;
|
||||||
|
use tauri_sys::{event, tauri};
|
||||||
|
|
||||||
|
pub async fn emit() -> anyhow::Result<()> {
|
||||||
|
event::emit("foo", &"bar").await;
|
||||||
|
|
||||||
|
ensure!(tauri::invoke::<_, bool>("verify_receive", &()).await.unwrap());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
86
examples/test/src/main.rs
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
mod app;
|
||||||
|
mod clipboard;
|
||||||
|
mod event;
|
||||||
|
mod window;
|
||||||
|
|
||||||
|
extern crate console_error_panic_hook;
|
||||||
|
use std::future::Future;
|
||||||
|
use std::panic;
|
||||||
|
use sycamore::prelude::*;
|
||||||
|
use sycamore::suspense::Suspense;
|
||||||
|
|
||||||
|
#[cfg(feature = "ci")]
|
||||||
|
async fn exit_with_error(e: String) {
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct Args {
|
||||||
|
e: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
tauri_sys::tauri::invoke::<_, ()>("exit_with_error", &Args { e }).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Props)]
|
||||||
|
pub struct TestProps<'a, F>
|
||||||
|
where
|
||||||
|
F: Future<Output = anyhow::Result<()>> + 'a,
|
||||||
|
{
|
||||||
|
name: &'a str,
|
||||||
|
test: F,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub async fn Test<'a, G: Html, F>(cx: Scope<'a>, props: TestProps<'a, F>) -> View<G>
|
||||||
|
where
|
||||||
|
F: Future<Output = anyhow::Result<()>> + 'a,
|
||||||
|
{
|
||||||
|
let res = props.test.await;
|
||||||
|
|
||||||
|
view! { cx,
|
||||||
|
tr {
|
||||||
|
td { code { (props.name.to_string()) } }
|
||||||
|
td { (if let Err(e) = &res {
|
||||||
|
#[cfg(feature = "ci")]
|
||||||
|
{
|
||||||
|
wasm_bindgen_futures::spawn_local(exit_with_error(e.to_string()));
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "ci"))]
|
||||||
|
format!("❌ {:?}", e)
|
||||||
|
} else {
|
||||||
|
format!("✅")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
panic::set_hook(Box::new(|info| {
|
||||||
|
console_error_panic_hook::hook(info);
|
||||||
|
|
||||||
|
#[cfg(feature = "ci")]
|
||||||
|
wasm_bindgen_futures::spawn_local(exit_with_error(format!("{}", info)));
|
||||||
|
}));
|
||||||
|
|
||||||
|
sycamore::render(|cx| {
|
||||||
|
view! { cx,
|
||||||
|
table {
|
||||||
|
tbody {
|
||||||
|
Suspense(fallback=view!{ cx, "Running Tests..." }) {
|
||||||
|
Test(name="app::get_name",test=app::get_name())
|
||||||
|
Test(name="app::get_version",test=app::get_version())
|
||||||
|
Test(name="app::get_tauri_version",test=app::get_tauri_version())
|
||||||
|
Test(name="clipboard::read_text | clipboard::write_text",test=clipboard::test())
|
||||||
|
Test(name="event::emit",test=event::emit())
|
||||||
|
// Test(name="window::WebviewWindow::new",test=window::create_window())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
#[cfg(feature = "ci")]
|
||||||
|
tauri_sys::process::exit(0);
|
||||||
|
}
|
13
examples/test/src/window.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
use anyhow::ensure;
|
||||||
|
use tauri_sys::window;
|
||||||
|
|
||||||
|
pub async fn create_window() -> anyhow::Result<()> {
|
||||||
|
let win = window::WebviewWindow::new("foo", ());
|
||||||
|
|
||||||
|
ensure!(win.is_visible().await);
|
||||||
|
// ensure!(win.label() == "foo".to_string());
|
||||||
|
|
||||||
|
win.close().await;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -10,6 +10,10 @@ pub mod event;
|
||||||
pub mod mocks;
|
pub mod mocks;
|
||||||
#[cfg(feature = "tauri")]
|
#[cfg(feature = "tauri")]
|
||||||
pub mod tauri;
|
pub mod tauri;
|
||||||
|
#[cfg(feature = "window")]
|
||||||
|
pub mod window;
|
||||||
|
#[cfg(feature = "process")]
|
||||||
|
pub mod process;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
|
18
src/process.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
pub fn exit(exit_code: u32) -> ! {
|
||||||
|
inner::exit(exit_code);
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn relaunch() {
|
||||||
|
inner::relaunch();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner {
|
||||||
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/process.js")]
|
||||||
|
extern "C" {
|
||||||
|
pub fn exit(exitCode: u32);
|
||||||
|
pub fn relaunch();
|
||||||
|
}
|
||||||
|
}
|
750
src/window.rs
Normal file
|
@ -0,0 +1,750 @@
|
||||||
|
use crate::event::Event;
|
||||||
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
use std::fmt::Display;
|
||||||
|
use wasm_bindgen::{prelude::Closure, JsCast, JsValue};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum Theme {
|
||||||
|
Light,
|
||||||
|
Dark,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum TitleBarStyle {
|
||||||
|
Visible,
|
||||||
|
Transparent,
|
||||||
|
Overlay,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum UserAttentionType {
|
||||||
|
Critical = 1,
|
||||||
|
Informational,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum Position {
|
||||||
|
Physical(PhysicalPosition),
|
||||||
|
Logical(LogicalPosition),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum Size {
|
||||||
|
Physical(PhysicalSize),
|
||||||
|
Logical(LogicalSize),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum CursorIcon {
|
||||||
|
Default,
|
||||||
|
Crosshair,
|
||||||
|
Hand,
|
||||||
|
Arrow,
|
||||||
|
Move,
|
||||||
|
Text,
|
||||||
|
Wait,
|
||||||
|
Help,
|
||||||
|
Progress,
|
||||||
|
// something cannot be done
|
||||||
|
NotAllowed,
|
||||||
|
ContextMenu,
|
||||||
|
Cell,
|
||||||
|
VerticalText,
|
||||||
|
Alias,
|
||||||
|
Copy,
|
||||||
|
NoDrop,
|
||||||
|
// something can be grabbed
|
||||||
|
Grab,
|
||||||
|
/// something is grabbed
|
||||||
|
Grabbing,
|
||||||
|
AllScroll,
|
||||||
|
ZoomIn,
|
||||||
|
ZoomOut,
|
||||||
|
// edge is to be moved
|
||||||
|
EResize,
|
||||||
|
NResize,
|
||||||
|
NeResize,
|
||||||
|
NwResize,
|
||||||
|
SResize,
|
||||||
|
SeResize,
|
||||||
|
SwResize,
|
||||||
|
WResize,
|
||||||
|
EwResize,
|
||||||
|
NsResize,
|
||||||
|
NeswResize,
|
||||||
|
NwseResize,
|
||||||
|
ColResize,
|
||||||
|
RowResize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for CursorIcon {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
CursorIcon::Default => write!(f, "default"),
|
||||||
|
CursorIcon::Crosshair => write!(f, "crosshair"),
|
||||||
|
CursorIcon::Hand => write!(f, "hand"),
|
||||||
|
CursorIcon::Arrow => write!(f, "arrow"),
|
||||||
|
CursorIcon::Move => write!(f, "move"),
|
||||||
|
CursorIcon::Text => write!(f, "text"),
|
||||||
|
CursorIcon::Wait => write!(f, "wait"),
|
||||||
|
CursorIcon::Help => write!(f, "help"),
|
||||||
|
CursorIcon::Progress => write!(f, "progress"),
|
||||||
|
CursorIcon::NotAllowed => write!(f, "notAllowed"),
|
||||||
|
CursorIcon::ContextMenu => write!(f, "contextMenu"),
|
||||||
|
CursorIcon::Cell => write!(f, "cell"),
|
||||||
|
CursorIcon::VerticalText => write!(f, "verticalText"),
|
||||||
|
CursorIcon::Alias => write!(f, "alias"),
|
||||||
|
CursorIcon::Copy => write!(f, "copy"),
|
||||||
|
CursorIcon::NoDrop => write!(f, "noDrop"),
|
||||||
|
CursorIcon::Grab => write!(f, "grab"),
|
||||||
|
CursorIcon::Grabbing => write!(f, "grabbing"),
|
||||||
|
CursorIcon::AllScroll => write!(f, "allScroll"),
|
||||||
|
CursorIcon::ZoomIn => write!(f, "zoomIn"),
|
||||||
|
CursorIcon::ZoomOut => write!(f, "zoomOut"),
|
||||||
|
CursorIcon::EResize => write!(f, "eResize"),
|
||||||
|
CursorIcon::NResize => write!(f, "nResize"),
|
||||||
|
CursorIcon::NeResize => write!(f, "neResize"),
|
||||||
|
CursorIcon::NwResize => write!(f, "nwResize"),
|
||||||
|
CursorIcon::SResize => write!(f, "sResize"),
|
||||||
|
CursorIcon::SeResize => write!(f, "seResize"),
|
||||||
|
CursorIcon::SwResize => write!(f, "swResize"),
|
||||||
|
CursorIcon::WResize => write!(f, "wResize"),
|
||||||
|
CursorIcon::EwResize => write!(f, "ewResize"),
|
||||||
|
CursorIcon::NsResize => write!(f, "nsResize"),
|
||||||
|
CursorIcon::NeswResize => write!(f, "neswResize"),
|
||||||
|
CursorIcon::NwseResize => write!(f, "nwseResize"),
|
||||||
|
CursorIcon::ColResize => write!(f, "colResize"),
|
||||||
|
CursorIcon::RowResize => write!(f, "rowResize"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct WebviewWindow(inner::WebviewWindow);
|
||||||
|
|
||||||
|
impl WebviewWindow {
|
||||||
|
pub fn new(label: &str, options: ()) -> Self {
|
||||||
|
Self(inner::WebviewWindow::new(label, options))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_by_label(label: &str) -> Option<Self> {
|
||||||
|
inner::WebviewWindow::getByLabel(label).map(Self)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn label(&self) -> String {
|
||||||
|
self.0.label()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn scale_factor(&self) -> f64 {
|
||||||
|
self.0.scaleFactor().await.as_f64().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn inner_position(&self) -> PhysicalPosition {
|
||||||
|
PhysicalPosition(self.0.innerPosition().await.unchecked_into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn outer_position(&self) -> PhysicalPosition {
|
||||||
|
PhysicalPosition(self.0.outerPosition().await.unchecked_into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn inner_size(&self) -> PhysicalSize {
|
||||||
|
PhysicalSize(self.0.innerSize().await.unchecked_into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn outer_size(&self) -> PhysicalSize {
|
||||||
|
PhysicalSize(self.0.outerSize().await.unchecked_into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_fullscreen(&self) -> bool {
|
||||||
|
self.0.isFullscreen().await.as_bool().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_maximized(&self) -> bool {
|
||||||
|
self.0.isMaximized().await.as_bool().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_decorated(&self) -> bool {
|
||||||
|
self.0.isDecorated().await.as_bool().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_resizable(&self) -> bool {
|
||||||
|
self.0.isResizable().await.as_bool().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_visible(&self) -> bool {
|
||||||
|
self.0.isVisible().await.as_bool().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn theme(&self) -> Theme {
|
||||||
|
match self.0.theme().await.as_string().unwrap().as_str() {
|
||||||
|
"light" => Theme::Light,
|
||||||
|
"dark" => Theme::Dark,
|
||||||
|
_ => panic!("Unknown theme"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn center(&self) {
|
||||||
|
self.0.center().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn request_user_attention(&self, request_type: UserAttentionType) {
|
||||||
|
self.0.requestUserAttention(request_type as u32).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_resizable(&self, resizable: bool) {
|
||||||
|
self.0.setResizable(resizable).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_title(&self, title: impl AsRef<str>) {
|
||||||
|
self.0.setTitle(title.as_ref()).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn maximize(&self) {
|
||||||
|
self.0.maximize().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn unmaximize(&self) {
|
||||||
|
self.0.unmaximize().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn toggle_maximize(&self) {
|
||||||
|
self.0.toggleMaximize().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn minimize(&self) {
|
||||||
|
self.0.minimize().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn unminimize(&self) {
|
||||||
|
self.0.unminimize().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn show(&self) {
|
||||||
|
self.0.show().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn hide(&self) {
|
||||||
|
self.0.hide().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn close(&self) {
|
||||||
|
self.0.close().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_decorations(&self, decorations: bool) {
|
||||||
|
self.0.setDecorations(decorations).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_always_on_top(&self, always_on_top: bool) {
|
||||||
|
self.0.setAlwaysOnTop(always_on_top).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_size(&self, size: Size) {
|
||||||
|
match size {
|
||||||
|
Size::Physical(size) => self.0.setSizePhysical(size.0).await,
|
||||||
|
Size::Logical(size) => self.0.setSizeLogical(size.0).await,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_min_size(&self, size: Option<Size>) {
|
||||||
|
match size {
|
||||||
|
None => self.0.setMinSizePhysical(None).await,
|
||||||
|
Some(Size::Physical(size)) => self.0.setMinSizePhysical(Some(size.0)).await,
|
||||||
|
Some(Size::Logical(size)) => self.0.setMinSizeLogical(Some(size.0)).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_max_size(&self, size: Option<Size>) {
|
||||||
|
match size {
|
||||||
|
None => self.0.setMaxSizePhysical(None).await,
|
||||||
|
Some(Size::Physical(size)) => self.0.setMaxSizePhysical(Some(size.0)).await,
|
||||||
|
Some(Size::Logical(size)) => self.0.setMaxSizeLogical(Some(size.0)).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_position(&self, position: Position) {
|
||||||
|
match position {
|
||||||
|
Position::Physical(pos) => self.0.setPositionPhysical(pos.0).await,
|
||||||
|
Position::Logical(pos) => self.0.setPositionLogical(pos.0).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_fullscreen(&self, fullscreen: bool) {
|
||||||
|
self.0.setFullscreen(fullscreen).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_focus(&self) {
|
||||||
|
self.0.setFocus().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_icon(&self, icon: &[u8]) {
|
||||||
|
self.0.setIcon(icon).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_skip_taskbar(&self, skip: bool) {
|
||||||
|
self.0.setSkipTaskbar(skip).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_cursor_grab(&self, grab: bool) {
|
||||||
|
self.0.setCursorGrab(grab).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_cursor_visible(&self, visible: bool) {
|
||||||
|
self.0.setCursorVisible(visible).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_cursor_icon(&self, icon: CursorIcon) {
|
||||||
|
self.0.setCursorIcon(&icon.to_string()).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_cursor_position(&self, position: Position) {
|
||||||
|
match position {
|
||||||
|
Position::Physical(pos) => self.0.setCursorPositionPhysical(pos.0).await,
|
||||||
|
Position::Logical(pos) => self.0.setCursorPositionLogical(pos.0).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_ignore_cursor_events(&self, ignore: bool) {
|
||||||
|
self.0.setIgnoreCursorEvents(ignore).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_dragging(&self) {
|
||||||
|
self.0.startDragging().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub async fn emit<T: Serialize>(&self, event: &str, payload: &T) {
|
||||||
|
self.0
|
||||||
|
.emit(event, serde_wasm_bindgen::to_value(payload).unwrap())
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub async fn listen<T, H>(&self, event: &str, mut handler: H) -> impl FnOnce()
|
||||||
|
where
|
||||||
|
T: DeserializeOwned,
|
||||||
|
H: FnMut(Event<T>) + 'static,
|
||||||
|
{
|
||||||
|
let closure = Closure::<dyn FnMut(JsValue)>::new(move |raw| {
|
||||||
|
(handler)(serde_wasm_bindgen::from_value(raw).unwrap())
|
||||||
|
});
|
||||||
|
|
||||||
|
let unlisten = self.0.listen(event, &closure).await;
|
||||||
|
|
||||||
|
closure.forget();
|
||||||
|
|
||||||
|
let unlisten = js_sys::Function::from(unlisten);
|
||||||
|
move || {
|
||||||
|
unlisten.call0(&wasm_bindgen::JsValue::NULL).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub async fn once<T, H>(&self, event: &str, mut handler: H) -> impl FnOnce()
|
||||||
|
where
|
||||||
|
T: DeserializeOwned,
|
||||||
|
H: FnMut(Event<T>) + 'static,
|
||||||
|
{
|
||||||
|
let closure = Closure::<dyn FnMut(JsValue)>::new(move |raw| {
|
||||||
|
(handler)(serde_wasm_bindgen::from_value(raw).unwrap())
|
||||||
|
});
|
||||||
|
|
||||||
|
let unlisten = self.0.once(event, &closure).await;
|
||||||
|
|
||||||
|
closure.forget();
|
||||||
|
|
||||||
|
let unlisten = js_sys::Function::from(unlisten);
|
||||||
|
move || {
|
||||||
|
unlisten.call0(&wasm_bindgen::JsValue::NULL).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct LogicalPosition(inner::LogicalPosition);
|
||||||
|
|
||||||
|
impl LogicalPosition {
|
||||||
|
pub fn new(x: u32, y: u32) -> Self {
|
||||||
|
Self(inner::LogicalPosition::new(x, y))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn x(&self) -> u32 {
|
||||||
|
self.0.x()
|
||||||
|
}
|
||||||
|
pub fn set_x(&self, x: u32) {
|
||||||
|
self.0.set_x(x)
|
||||||
|
}
|
||||||
|
pub fn y(&self) -> u32 {
|
||||||
|
self.0.y()
|
||||||
|
}
|
||||||
|
pub fn set_y(&self, y: u32) {
|
||||||
|
self.0.set_y(y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct PhysicalPosition(inner::PhysicalPosition);
|
||||||
|
|
||||||
|
impl PhysicalPosition {
|
||||||
|
pub fn new(x: u32, y: u32) -> Self {
|
||||||
|
Self(inner::PhysicalPosition::new(x, y))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_logical(self, scale_factor: u32) -> LogicalPosition {
|
||||||
|
LogicalPosition(self.0.toLogical(scale_factor))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn x(&self) -> u32 {
|
||||||
|
self.0.x()
|
||||||
|
}
|
||||||
|
pub fn set_x(&self, x: u32) {
|
||||||
|
self.0.set_x(x)
|
||||||
|
}
|
||||||
|
pub fn y(&self) -> u32 {
|
||||||
|
self.0.y()
|
||||||
|
}
|
||||||
|
pub fn set_y(&self, y: u32) {
|
||||||
|
self.0.set_y(y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct LogicalSize(inner::LogicalSize);
|
||||||
|
|
||||||
|
impl LogicalSize {
|
||||||
|
pub fn new(x: u32, y: u32) -> Self {
|
||||||
|
Self(inner::LogicalSize::new(x, y))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn width(&self) -> u32 {
|
||||||
|
self.0.width()
|
||||||
|
}
|
||||||
|
pub fn set_width(&self, x: u32) {
|
||||||
|
self.0.set_width(x)
|
||||||
|
}
|
||||||
|
pub fn height(&self) -> u32 {
|
||||||
|
self.0.height()
|
||||||
|
}
|
||||||
|
pub fn set_height(&self, y: u32) {
|
||||||
|
self.0.set_height(y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct PhysicalSize(inner::PhysicalSize);
|
||||||
|
|
||||||
|
impl PhysicalSize {
|
||||||
|
pub fn new(x: u32, y: u32) -> Self {
|
||||||
|
Self(inner::PhysicalSize::new(x, y))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_logical(self, scale_factor: u32) -> LogicalSize {
|
||||||
|
LogicalSize(self.0.toLogical(scale_factor))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn width(&self) -> u32 {
|
||||||
|
self.0.width()
|
||||||
|
}
|
||||||
|
pub fn set_width(&self, x: u32) {
|
||||||
|
self.0.set_width(x)
|
||||||
|
}
|
||||||
|
pub fn height(&self) -> u32 {
|
||||||
|
self.0.height()
|
||||||
|
}
|
||||||
|
pub fn set_height(&self, y: u32) {
|
||||||
|
self.0.set_height(y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct Monitor(JsValue);
|
||||||
|
|
||||||
|
impl Monitor {
|
||||||
|
pub fn name(&self) -> Option<String> {
|
||||||
|
let raw = js_sys::Reflect::get(&self.0, &JsValue::from_str("name")).unwrap();
|
||||||
|
|
||||||
|
raw.as_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size(&self) -> PhysicalSize {
|
||||||
|
let raw = js_sys::Reflect::get(&self.0, &JsValue::from_str("size")).unwrap();
|
||||||
|
|
||||||
|
PhysicalSize(raw.unchecked_into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn position(&self) -> PhysicalPosition {
|
||||||
|
let raw = js_sys::Reflect::get(&self.0, &JsValue::from_str("position")).unwrap();
|
||||||
|
|
||||||
|
PhysicalPosition(raw.unchecked_into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scale_factor(&self) -> u32 {
|
||||||
|
let raw = js_sys::Reflect::get(&self.0, &JsValue::from_str("size"))
|
||||||
|
.unwrap()
|
||||||
|
.as_f64()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
raw as u32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current_window() -> WebviewWindow {
|
||||||
|
WebviewWindow(inner::getCurrent())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn all_windows() -> Vec<WebviewWindow> {
|
||||||
|
inner::getAll().into_iter().map(WebviewWindow).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn current_monitor() -> Monitor {
|
||||||
|
Monitor(inner::currentMonitor().await)
|
||||||
|
}
|
||||||
|
pub async fn primary_monitor() -> Monitor {
|
||||||
|
Monitor(inner::primaryMonitor().await)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct AvailableMonitors {
|
||||||
|
idx: u32,
|
||||||
|
array: js_sys::Array,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for AvailableMonitors {
|
||||||
|
type Item = Monitor;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
let raw = self.array.get(self.idx);
|
||||||
|
|
||||||
|
if raw.is_undefined() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let monitor = Monitor(raw);
|
||||||
|
self.idx += 1;
|
||||||
|
|
||||||
|
Some(monitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn available_monitors() -> AvailableMonitors {
|
||||||
|
AvailableMonitors {
|
||||||
|
idx: 0,
|
||||||
|
array: inner::availableMonitors().await.unchecked_into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner {
|
||||||
|
use wasm_bindgen::{
|
||||||
|
prelude::{wasm_bindgen, Closure},
|
||||||
|
JsValue,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/window.js")]
|
||||||
|
extern "C" {
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub type LogicalPosition;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(x: u32, y: u32) -> LogicalPosition;
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn x(this: &LogicalPosition) -> u32;
|
||||||
|
#[wasm_bindgen(method, setter)]
|
||||||
|
pub fn set_x(this: &LogicalPosition, x: u32);
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn y(this: &LogicalPosition) -> u32;
|
||||||
|
#[wasm_bindgen(method, setter)]
|
||||||
|
pub fn set_y(this: &LogicalPosition, y: u32);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/window.js")]
|
||||||
|
extern "C" {
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub type PhysicalPosition;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(x: u32, y: u32) -> PhysicalPosition;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn toLogical(this: &PhysicalPosition, scaleFactor: u32) -> LogicalPosition;
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn x(this: &PhysicalPosition) -> u32;
|
||||||
|
#[wasm_bindgen(method, setter)]
|
||||||
|
pub fn set_x(this: &PhysicalPosition, x: u32);
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn y(this: &PhysicalPosition) -> u32;
|
||||||
|
#[wasm_bindgen(method, setter)]
|
||||||
|
pub fn set_y(this: &PhysicalPosition, y: u32);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/window.js")]
|
||||||
|
extern "C" {
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub type LogicalSize;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(width: u32, height: u32) -> LogicalSize;
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn width(this: &LogicalSize) -> u32;
|
||||||
|
#[wasm_bindgen(method, setter)]
|
||||||
|
pub fn set_width(this: &LogicalSize, width: u32);
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn height(this: &LogicalSize) -> u32;
|
||||||
|
#[wasm_bindgen(method, setter)]
|
||||||
|
pub fn set_height(this: &LogicalSize, height: u32);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/window.js")]
|
||||||
|
extern "C" {
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub type PhysicalSize;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(width: u32, height: u32) -> PhysicalSize;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn toLogical(this: &PhysicalSize, scaleFactor: u32) -> LogicalSize;
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn width(this: &PhysicalSize) -> u32;
|
||||||
|
#[wasm_bindgen(method, setter)]
|
||||||
|
pub fn set_width(this: &PhysicalSize, width: u32);
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn height(this: &PhysicalSize) -> u32;
|
||||||
|
#[wasm_bindgen(method, setter)]
|
||||||
|
pub fn set_height(this: &PhysicalSize, height: u32);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/window.js")]
|
||||||
|
extern "C" {
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub type WebviewWindowHandle;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(label: &str) -> WebviewWindowHandle;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn listen(
|
||||||
|
this: &WebviewWindowHandle,
|
||||||
|
event: &str,
|
||||||
|
handler: &Closure<dyn FnMut(JsValue)>,
|
||||||
|
) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn once(
|
||||||
|
this: &WebviewWindowHandle,
|
||||||
|
event: &str,
|
||||||
|
handler: &Closure<dyn FnMut(JsValue)>,
|
||||||
|
) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn emit(this: &WebviewWindowHandle, event: &str, payload: JsValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/window.js")]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(extends = WebviewWindowHandle)]
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub type WindowManager;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(label: &str) -> WindowManager;
|
||||||
|
#[wasm_bindgen(method, getter)]
|
||||||
|
pub fn label(this: &WindowManager) -> String;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn scaleFactor(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn innerPosition(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn outerPosition(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn innerSize(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn outerSize(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn isFullscreen(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn isMaximized(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn isDecorated(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn isResizable(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn isVisible(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn theme(this: &WindowManager) -> JsValue;
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn center(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn requestUserAttention(this: &WindowManager, requestType: u32);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setResizable(this: &WindowManager, resizable: bool);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setTitle(this: &WindowManager, title: &str);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn maximize(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn unmaximize(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn toggleMaximize(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn minimize(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn unminimize(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn show(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn hide(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn close(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setDecorations(this: &WindowManager, decorations: bool);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setAlwaysOnTop(this: &WindowManager, alwaysOnTop: bool);
|
||||||
|
#[wasm_bindgen(method, js_name = setSize)]
|
||||||
|
pub async fn setSizePhysical(this: &WindowManager, size: PhysicalSize);
|
||||||
|
#[wasm_bindgen(method, js_name = setSize)]
|
||||||
|
pub async fn setSizeLogical(this: &WindowManager, size: LogicalSize);
|
||||||
|
#[wasm_bindgen(method, js_name = setMinSize)]
|
||||||
|
pub async fn setMinSizePhysical(this: &WindowManager, size: Option<PhysicalSize>);
|
||||||
|
#[wasm_bindgen(method, js_name = setMinSize)]
|
||||||
|
pub async fn setMinSizeLogical(this: &WindowManager, size: Option<LogicalSize>);
|
||||||
|
#[wasm_bindgen(method, js_name = setMaxSize)]
|
||||||
|
pub async fn setMaxSizePhysical(this: &WindowManager, size: Option<PhysicalSize>);
|
||||||
|
#[wasm_bindgen(method, js_name = setMinSize)]
|
||||||
|
pub async fn setMaxSizeLogical(this: &WindowManager, size: Option<LogicalSize>);
|
||||||
|
#[wasm_bindgen(method, js_name = setPosition)]
|
||||||
|
pub async fn setPositionPhysical(this: &WindowManager, position: PhysicalPosition);
|
||||||
|
#[wasm_bindgen(method, js_name = setPosition)]
|
||||||
|
pub async fn setPositionLogical(this: &WindowManager, position: LogicalPosition);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setFullscreen(this: &WindowManager, fullscreen: bool);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setFocus(this: &WindowManager);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setIcon(this: &WindowManager, icon: &[u8]);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setSkipTaskbar(this: &WindowManager, skip: bool);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setCursorGrab(this: &WindowManager, grab: bool);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setCursorVisible(this: &WindowManager, visible: bool);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setCursorIcon(this: &WindowManager, icon: &str);
|
||||||
|
#[wasm_bindgen(method, js_name = setCursorPosition)]
|
||||||
|
pub async fn setCursorPositionPhysical(this: &WindowManager, position: PhysicalPosition);
|
||||||
|
#[wasm_bindgen(method, js_name = setCursorPosition)]
|
||||||
|
pub async fn setCursorPositionLogical(this: &WindowManager, position: LogicalPosition);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn setIgnoreCursorEvents(this: &WindowManager, ignore: bool);
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub async fn startDragging(this: &WindowManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/window.js")]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(extends = WindowManager)]
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub type WebviewWindow;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(label: &str, options: ()) -> WebviewWindow;
|
||||||
|
#[wasm_bindgen(static_method_of = WebviewWindow)]
|
||||||
|
pub fn getByLabel(label: &str) -> Option<WebviewWindow>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(module = "/dist/window.js")]
|
||||||
|
extern "C" {
|
||||||
|
pub fn getCurrent() -> WebviewWindow;
|
||||||
|
pub fn getAll() -> Vec<WebviewWindow>;
|
||||||
|
pub async fn currentMonitor() -> JsValue;
|
||||||
|
pub async fn primaryMonitor() -> JsValue;
|
||||||
|
pub async fn availableMonitors() -> JsValue;
|
||||||
|
}
|
||||||
|
}
|