Skip to content

Commit

Permalink
custom plugin example
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Sep 7, 2023
1 parent c879faa commit 921363d
Show file tree
Hide file tree
Showing 80 changed files with 1,702 additions and 63 deletions.
46 changes: 34 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
default = []
javascript = []
javascript = ["specta/typescript"]
typescript = ["specta/typescript"]

[dependencies]
specta = { workspace = true, features = ["functions", "tauri"] }
tauri-specta-macros = { path = "./macros" }
serde = "1.0.152"
serde = { workspace = true }
serde_json = "1.0.93"
tauri = "1.2.4"
tauri = { workspace = true }
thiserror = "1.0.38"
heck = "0.4.1"
indoc = "2.0.0"
Expand All @@ -36,11 +36,14 @@ doc-comment = "0.3.3"

[workspace]
members = [
"example/src-tauri",
"examples/app/src-tauri",
"examples/custom-plugin/app/src-tauri",
"examples/custom-plugin/plugin",
"macros"
]


[workspace.dependencies]
# specta = { version = "=2.0.0-rc.1" }
serde = "1.0.152"
specta = { git = "https://github.com/oscartbeaumont/specta", rev = "5948d80f2551780eda2c7bf38450fc796c74cfbf" }
tauri = "1.2.4"
File renamed without changes.
2 changes: 1 addition & 1 deletion example/package.json → examples/app/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "example",
"name": "tauri-specta-app",
"private": true,
"version": "0.0.0",
"type": "module",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "example"
name = "tauri-specta-example-app"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
Expand All @@ -17,7 +17,7 @@ serde_json = "1.0"
specta.workspace = true
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.3.0", features = ["api-all"] }
tauri-specta = { path = "../../", features = ["typescript", "javascript"] }
tauri-specta = { path = "../../../", features = ["typescript", "javascript"] }

[features]
default = [ "custom-protocol" ]
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions examples/custom-plugin/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
3 changes: 3 additions & 0 deletions examples/custom-plugin/app/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
}
7 changes: 7 additions & 0 deletions examples/custom-plugin/app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Tauri + Solid + Typescript

This template should help get you started developing with Tauri, Solid and Typescript in Vite.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
17 changes: 17 additions & 0 deletions examples/custom-plugin/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel="icon" type="image/svg+xml" href="/src/assets/logo.svg" />
<title>Tauri + Solid + Typescript App</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<script src="/src/index.tsx" type="module"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions examples/custom-plugin/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "tauri-specta-example-custom-plugin-app",
"version": "0.0.0",
"description": "",
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"tauri": "tauri"
},
"license": "MIT",
"dependencies": {
"solid-js": "^1.7.8",
"@tauri-apps/api": "^1.4.0",
"tauri-specta-custom-plugin": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.2",
"vite": "^4.4.4",
"vite-plugin-solid": "^2.7.0",
"@tauri-apps/cli": "^1.4.0"
}
}
6 changes: 6 additions & 0 deletions examples/custom-plugin/app/public/tauri.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/custom-plugin/app/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions examples/custom-plugin/app/src-tauri/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/

24 changes: 24 additions & 0 deletions examples/custom-plugin/app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "tauri-specta-example-custom-plugin-app"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "1.4", features = [] }

[dependencies]
tauri = { version = "1.4", features = ["shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri-specta-example-custom-plugin = { path = "../../plugin" }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
3 changes: 3 additions & 0 deletions examples/custom-plugin/app/src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/custom-plugin/app/src-tauri/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions examples/custom-plugin/app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
tauri::Builder::default()
.plugin(tauri_specta_example_custom_plugin::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
46 changes: 46 additions & 0 deletions examples/custom-plugin/app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"build": {
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": false
},
"package": {
"productName": "app",
"version": "0.0.0"
},
"tauri": {
"allowlist": {
"all": false,
"shell": {
"all": false,
"open": true
}
},
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.tauri.dev",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/[email protected]",
"icons/icon.icns",
"icons/icon.ico"
]
},
"security": {
"csp": null
},
"windows": [
{
"fullscreen": false,
"resizable": true,
"title": "app",
"width": 800,
"height": 600
}
]
}
}
50 changes: 50 additions & 0 deletions examples/custom-plugin/app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Match, Switch, createSignal, onCleanup } from "solid-js";
import { events, addNumbers } from "tauri-specta-custom-plugin";

function App() {
const [latestNumber, setLatestNumber] = createSignal<number | null>(null);

const [generatedNumber, setGeneratedNumber] = createSignal<
{ type: "loading" } | { type: "loaded"; value: number } | null
>(null);

events.randomNumber
.listen((e) => setLatestNumber(e.payload))
.then((unlisten) => onCleanup(unlisten));

return (
<div>
<p>Latest Random Number: {latestNumber()}</p>
<button
disabled={generatedNumber()?.type === "loading"}
onClick={() => {
setGeneratedNumber({ type: "loading" });

addNumbers(
Math.floor(Math.random() * 10),
Math.floor(Math.random() * 10)
)
.then((value) => setGeneratedNumber({ type: "loaded", value }))
.catch(() => setGeneratedNumber(null));
}}
>
Generate Random Number
</button>
<Switch fallback="Generate a number!">
<Match when={generatedNumber()?.type === "loading"}>
Loading number...
</Match>
<Match
when={(() => {
const n = generatedNumber();
return n?.type === "loaded" && n.value;
})()}
>
{(value) => value()}
</Match>
</Switch>
</div>
);
}

export default App;
6 changes: 6 additions & 0 deletions examples/custom-plugin/app/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* @refresh reload */
import { render } from "solid-js/web";

import App from "./App";

render(() => <App />, document.getElementById("root") as HTMLElement);
28 changes: 28 additions & 0 deletions examples/custom-plugin/app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,

"checkJs": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions examples/custom-plugin/app/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
1 change: 1 addition & 0 deletions examples/custom-plugin/app/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
20 changes: 20 additions & 0 deletions examples/custom-plugin/app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";

// https://vitejs.dev/config/
export default defineConfig(async () => ({
plugins: [solidPlugin()],

// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
},
// 3. to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ["VITE_", "TAURI_"],
}));
Loading

0 comments on commit 921363d

Please sign in to comment.