experimentation with tauri api

This commit is contained in:
Vomitblood 2024-07-30 18:03:06 +08:00
parent 5294b46e64
commit e3da8ce18d
8 changed files with 195 additions and 14 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"tauri": "tauri"
},
"dependencies": {
"@emotion/cache": "^11.13.1",
@ -14,6 +15,7 @@
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.13.0",
"@mui/material": "^5.16.5",
"@tauri-apps/api": "^1.6.0",
"next": "14.2.5",
"react": "^18",
"react-dom": "^18"

101
src-tauri/Cargo.lock generated
View file

@ -1619,6 +1619,17 @@ dependencies = [
"objc_exception",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc_exception"
version = "0.1.2"
@ -2138,6 +2149,30 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
name = "rfd"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0149778bd99b6959285b0933288206090c50e2327f47a9c463bfdbf45c8823ea"
dependencies = [
"block",
"dispatch",
"glib-sys",
"gobject-sys",
"gtk-sys",
"js-sys",
"lazy_static",
"log",
"objc",
"objc-foundation",
"objc_id",
"raw-window-handle",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"windows 0.37.0",
]
[[package]]
name = "rustc-demangle"
version = "0.1.24"
@ -2614,6 +2649,7 @@ dependencies = [
"percent-encoding",
"rand 0.8.5",
"raw-window-handle",
"rfd",
"semver",
"serde",
"serde_json",
@ -3170,6 +3206,18 @@ dependencies = [
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0"
dependencies = [
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.92"
@ -3199,6 +3247,16 @@ version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
[[package]]
name = "web-sys"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "webkit2gtk"
version = "0.18.2"
@ -3315,6 +3373,19 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647"
dependencies = [
"windows_aarch64_msvc 0.37.0",
"windows_i686_gnu 0.37.0",
"windows_i686_msvc 0.37.0",
"windows_x86_64_gnu 0.37.0",
"windows_x86_64_msvc 0.37.0",
]
[[package]]
name = "windows"
version = "0.39.0"
@ -3449,6 +3520,12 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a"
[[package]]
name = "windows_aarch64_msvc"
version = "0.39.0"
@ -3467,6 +3544,12 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1"
[[package]]
name = "windows_i686_gnu"
version = "0.39.0"
@ -3491,6 +3574,12 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c"
[[package]]
name = "windows_i686_msvc"
version = "0.39.0"
@ -3509,6 +3598,12 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d"
[[package]]
name = "windows_x86_64_gnu"
version = "0.39.0"
@ -3539,6 +3634,12 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.39.0"

View file

@ -17,7 +17,7 @@ tauri-build = { version = "1.5.3", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.7.0", features = [] }
tauri = { version = "1.7.0", features = [ "dialog-all"] }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.

View file

@ -1,8 +1,14 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#[tauri::command]
fn hello(content: &str) -> String {
format!("Hello {}, what is your name?!", content)
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![hello])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View file

@ -1,8 +1,8 @@
{
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "npm run build",
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "bun run build",
"beforeDevCommand": "bun run dev",
"devPath": "http://localhost:3000",
"distDir": "../out"
},
@ -12,7 +12,14 @@
},
"tauri": {
"allowlist": {
"all": false
"dialog": {
"all": true,
"ask": true,
"confirm": true,
"message": true,
"open": true,
"save": true
}
},
"bundle": {
"active": true,

View file

@ -64,7 +64,7 @@ export const userPalette = {
export const UserThemeProvider: FC<UserThemeProviderProps> = ({ children }) => {
// font family settings
// TODO: figure out how to bundle fonts in tauri
let fontFamily = "JetBrains Mono";
let fontFamily = "GoogleSans";
// switch (settings.display.font_family) {
// case "sans_serif":
// fontFamily = "GoogleSans, sans-serif";

View file

@ -1,10 +1,75 @@
import { Box, Button } from "@mui/material";
import { Box, Button, TextField, Typography } from "@mui/material";
import { getName } from "@tauri-apps/api/app";
import { readText, writeText } from "@tauri-apps/api/clipboard";
import {
ask,
ConfirmDialogOptions,
DialogFilter,
MessageDialogOptions,
open,
OpenDialogOptions,
} from "@tauri-apps/api/dialog";
import { useState } from "react";
export default function Home() {
const [content, setContent] = useState("Please enter your name");
const confirmDialogOptions: ConfirmDialogOptions = {
cancelLabel: "fuck no",
okLabel: "fuck yes",
title: "this is a title",
type: "error",
};
const dialogFilter: DialogFilter = {
extensions: ["png", "jpeg"],
name: "this is a name",
};
const messageDialogOptions: MessageDialogOptions = {
okLabel: "fuck yes",
title: "this is a title",
type: "warning",
};
const openDialogOptions: OpenDialogOptions = {
defaultPath: "/home/vomitblood/Downloads",
directory: false,
filters: [dialogFilter],
multiple: true,
};
const bruh = async () => {
const selected = await open(openDialogOptions);
if (Array.isArray(selected)) {
console.log(selected);
} else if (selected === null) {
// user cancelled the selection
console.log(selected);
} else {
// user selected a single file
console.log(selected);
}
};
async function handleClick() {
bruh();
}
return (
<Box>
<h1>WhensApp</h1>
<Button>hello</Button>
<TextField
label="Name"
onChange={(e) => setContent(e.target.value)}
size="small"
variant="outlined"
/>
<Button variant="contained" onClick={handleClick}>
Submit
</Button>
<Typography>
<b>Response:</b> {content}
</Typography>
</Box>
);
}