Merge remote-tracking branch 'upstream/main' into updater

This commit is contained in:
Max Coppen 2022-11-15 19:07:41 +01:00
commit 8b9299ec1c
87 changed files with 15088 additions and 667 deletions

2
examples/test/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
target
dist

View file

@ -0,0 +1,3 @@
/src
/public
/Cargo.toml

3894
examples/test/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

19
examples/test/Cargo.toml Normal file
View file

@ -0,0 +1,19 @@
[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"] }
wasm-logger = "0.2.0"
log = "0.4.17"
[features]
ci = []

10
examples/test/Trunk.toml Normal file
View file

@ -0,0 +1,10 @@
[build]
target = "./index.html"
[watch]
ignore = ["./src-tauri"]
[serve]
address = "127.0.0.1"
port = 1420
open = false

7
examples/test/index.html Normal file
View file

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Tauri + Yew App</title>
</head>
</html>

4
examples/test/src-tauri/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/

View file

@ -0,0 +1,27 @@
[package]
name = "tauri-sys-test"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.57"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.2", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2", features = ["api-all"] }
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]

View file

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

View file

@ -0,0 +1,6 @@
{
"build": {
"beforeDevCommand": "trunk serve --features ci",
"beforeBuildCommand": "trunk build --release --features ci"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -0,0 +1,41 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{Manager, State, api::notification::Notification};
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");
}

View file

@ -0,0 +1,71 @@
{
"build": {
"beforeDevCommand": "trunk serve",
"beforeBuildCommand": "trunk build --release",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": true
},
"package": {
"productName": "tauri-sys-test",
"version": "0.0.0"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": true,
"endpoints": [
"https://releases.myapp.com/{{target}}/{{current_version}}"
],
"dialog": true,
"pubkey": "YOUR_UPDATER_SIGNATURE_PUBKEY_HERE"
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "tauri-sys testing suite",
"width": 800
}
]
}
}

34
examples/test/src/app.rs Normal file
View 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 == 2);
ensure!(version.patch == 0);
ensure!(version.build.is_empty());
ensure!(version.pre.is_empty());
Ok(())
}

View 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 == "foobar".to_string());
Ok(())
}

View file

@ -0,0 +1,97 @@
use anyhow::ensure;
use tauri_sys::dialog::{FileDialogBuilder, MessageDialogBuilder, MessageDialogType};
pub async fn ask() -> anyhow::Result<()> {
let mut builder = MessageDialogBuilder::new();
builder.set_title("Tauri");
builder.set_type(MessageDialogType::Warning);
let works = builder
.ask("Does this work? \n Click Yes to mark this test as passing")
.await?;
ensure!(works);
Ok(())
}
pub async fn confirm() -> anyhow::Result<()> {
let mut builder = MessageDialogBuilder::new();
builder.set_title("Tauri");
builder.set_type(MessageDialogType::Warning);
let works = builder
.confirm("Does this work? \n Click Ok to mark this test as passing")
.await?;
ensure!(works);
Ok(())
}
pub async fn message() -> anyhow::Result<()> {
let mut builder = MessageDialogBuilder::new();
builder.set_title("Tauri");
builder.set_type(MessageDialogType::Warning);
builder.message("This is a message just for you!").await?;
Ok(())
}
pub async fn pick_file() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a file to mark this test as passing");
let file = builder.pick_file().await?;
ensure!(file.is_some());
Ok(())
}
pub async fn pick_files() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a multiple files to mark this test as passing");
let file = builder.pick_files().await?;
ensure!(file.is_some());
ensure!(file.unwrap().len() > 1);
Ok(())
}
pub async fn pick_folder() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a folder to mark this test as passing");
let file = builder.pick_folder().await?;
ensure!(file.is_some());
Ok(())
}
pub async fn pick_folders() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a multiple folders to mark this test as passing");
let file = builder.pick_folders().await?;
ensure!(file.is_some());
ensure!(file.unwrap().len() > 1);
Ok(())
}
pub async fn save() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a file to mark this test as passing");
let file = builder.save().await?;
ensure!(file.is_some());
Ok(())
}

View 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?);
Ok(())
}

175
examples/test/src/main.rs Normal file
View file

@ -0,0 +1,175 @@
mod app;
mod clipboard;
mod event;
mod window;
mod dialog;
mod notification;
mod os;
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!("")
})
}
}
}
}
#[cfg(not(feature = "ci"))]
#[component]
pub async fn InteractiveTest<'a, G: Html, F>(cx: Scope<'a>, props: TestProps<'a, F>) -> View<G>
where
F: Future<Output = anyhow::Result<()>> + 'a,
{
let mut test = Some(props.test);
let render_test = create_signal(cx, false);
let run_test = |_| {
render_test.set(true);
};
view! { cx,
(if *render_test.get() {
let test = test.take().unwrap();
let fallback = view! { cx,
tr {
td { code { (props.name.to_string()) } }
td {
"Running Test..."
}
}
};
view! { cx,
Suspense(fallback=fallback) {
Test(name=props.name, test=test)
}
}
} else {
view! { cx,
tr {
td { code { (props.name.to_string()) } }
td {
button(on:click=run_test) { "Run Interactive Test"}
}
}
}
})
}
}
#[cfg(feature = "ci")]
#[component]
pub async fn InteractiveTest<'a, G: Html, F>(cx: Scope<'a>, _props: TestProps<'a, F>) -> View<G>
where
F: Future<Output = anyhow::Result<()>> + 'a,
{
view! { cx, "Interactive tests are not run in CI mode" }
}
#[component]
pub async fn Terminate<'a, G: Html>(cx: Scope<'a>) -> View<G> {
#[cfg(feature = "ci")]
sycamore::suspense::await_suspense(cx, async {
tauri_sys::process::exit(0).await;
})
.await;
view! {
cx,
}
}
fn main() {
wasm_logger::init(wasm_logger::Config::default());
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())
InteractiveTest(name="dialog::message",test=dialog::message())
InteractiveTest(name="dialog::ask",test=dialog::ask())
InteractiveTest(name="dialog::confirm",test=dialog::confirm())
InteractiveTest(name="dialog::pick_file",test=dialog::pick_file())
InteractiveTest(name="dialog::pick_files",test=dialog::pick_files())
InteractiveTest(name="dialog::pick_folder",test=dialog::pick_folder())
InteractiveTest(name="dialog::pick_folders",test=dialog::pick_folders())
InteractiveTest(name="dialog::save",test=dialog::save())
Test(name="os::arch",test=os::arch())
Test(name="os::platform",test=os::platform())
Test(name="os::tempdir",test=os::tempdir())
Test(name="os::kind",test=os::kind())
Test(name="os::version",test=os::version())
Test(name="notification::is_permission_granted",test=notification::is_permission_granted())
Test(name="notification::request_permission",test=notification::request_permission())
InteractiveTest(name="notification::show_notification",test=notification::show_notification())
// Test(name="window::WebviewWindow::new",test=window::create_window())
Terminate
}
}
}
}
});
}

View file

@ -0,0 +1,28 @@
use anyhow::ensure;
use tauri_sys::notification::{self, Permission};
pub async fn is_permission_granted() -> anyhow::Result<()> {
let granted = notification::is_permission_granted().await?;
ensure!(granted);
Ok(())
}
pub async fn request_permission() -> anyhow::Result<()> {
let permission = notification::request_permission().await?;
ensure!(permission == Permission::Granted);
Ok(())
}
pub async fn show_notification() -> anyhow::Result<()> {
let mut n = notification::Notification::default();
n.set_title("TAURI");
n.set_body("Tauri is awesome!");
n.show()?;
Ok(())
}

41
examples/test/src/os.rs Normal file
View file

@ -0,0 +1,41 @@
use tauri_sys::os;
pub async fn arch() -> anyhow::Result<()> {
let arch = os::arch().await?;
log::debug!("{:?}", arch);
Ok(())
}
pub async fn platform() -> anyhow::Result<()> {
let platform = os::platform().await?;
log::debug!("{:?}", platform);
Ok(())
}
pub async fn tempdir() -> anyhow::Result<()> {
let tempdir = os::tempdir().await?;
log::debug!("{:?}", tempdir);
Ok(())
}
pub async fn kind() -> anyhow::Result<()> {
let kind = os::kind().await?;
log::debug!("{:?}", kind);
Ok(())
}
pub async fn version() -> anyhow::Result<()> {
let version = os::version().await?;
log::debug!("{:?}", version);
Ok(())
}

View 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(())
}