remove api example

This commit is contained in:
Jonas Kruckenberg 2022-11-03 18:52:06 +01:00
parent 6bd4dd0489
commit b3e477ed18
37 changed files with 0 additions and 732 deletions

View file

@ -1,3 +0,0 @@
/dist/
/target/
/Cargo.lock

View file

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

View file

@ -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"]

View file

@ -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"]

View file

@ -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>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

View file

@ -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"] }

View file

@ -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,
}

View file

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

View file

@ -1,28 +0,0 @@
[package]
name = "tauri-app"
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 = { git = "https://github.com/tauri-apps/tauri", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { git = "https://github.com/tauri-apps/tauri", features = ["api-all"] }
shared = { path = "../shared" }
[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

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View file

@ -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");
}

View file

@ -1,66 +0,0 @@
{
"build": {
"beforeDevCommand": "trunk serve",
"beforeBuildCommand": "trunk build --release",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": true
},
"package": {
"productName": "tauri-app",
"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": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "tauri-app",
"width": 800
}
]
}
}

View file

@ -1,82 +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"
}
a(href="/window") {
"Window"
}
}
}
}
#[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();
}

View file

@ -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"
}
}
}
}

View file

@ -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"
}
}
}
}

View file

@ -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"
}
}
}
}

View file

@ -1,33 +0,0 @@
mod app;
mod clipboard;
mod communication;
mod welcome;
mod window;
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,
#[to("/window")]
Window,
#[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::Window => window::Window(cx),
Page::NotFound => welcome::Welcome(cx)
}
}

View file

@ -1,10 +0,0 @@
use sycamore::prelude::*;
#[component]
pub fn Welcome<G: Html>(cx: Scope) -> View<G> {
view! { cx,
h1 {
"Welcome"
}
}
}

View file

@ -1,63 +0,0 @@
use sycamore::prelude::*;
use tauri_sys::window;
#[component]
pub fn Window<G: Html>(cx: Scope) -> View<G> {
let get_current = |_| {
let win = window::current_window();
log::debug!("{:?}", win);
};
let get_all = |_| {
let windows = window::all_windows();
log::debug!("{:?}", windows);
};
let get_current_monitor = |_| {
sycamore::futures::spawn_local(async move {
let monitor = window::current_monitor().await;
log::debug!("{:?}", monitor);
});
};
let get_primary_monitor = |_| {
sycamore::futures::spawn_local(async move {
let monitor = window::primary_monitor().await;
log::debug!("{:?}", monitor);
});
};
let get_all_monitors = |_| {
sycamore::futures::spawn_local(async move {
let monitors = window::available_monitors().await.collect::<Vec<_>>();
log::debug!("{:?}", monitors);
});
};
view! { cx,
div {
button(class="btn",id="get_name",on:click=get_current) {
"Get Current Window"
}
button(class="btn",id="get_version",on:click=get_all) {
"Get All Windows"
}
}
div {
button(class="btn",id="get_tauri_version",on:click=get_current_monitor) {
"Get Current Monitor"
}
button(class="btn",id="get_tauri_version",on:click=get_primary_monitor) {
"Get Primary Monitor"
}
button(class="btn",id="get_tauri_version",on:click=get_all_monitors) {
"Get All Monitors"
}
}
}
}

View file

@ -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;
}
}