Skip to content

Commit

Permalink
feat: add API example (tauri-apps#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored May 5, 2023
1 parent be1c775 commit 5015132
Show file tree
Hide file tree
Showing 98 changed files with 10,335 additions and 157 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["plugins/*"]
exclude = ["plugins/fs", "plugins/http"]
members = ["plugins/*", "examples/*/src-tauri"]
exclude = ["plugins/fs", "plugins/http", "examples/api/src-tauri"]
resolver = "2"

[workspace.dependencies]
Expand Down
4 changes: 4 additions & 0 deletions examples/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
/.vscode/
.DS_Store
.cargo
5 changes: 5 additions & 0 deletions examples/api/.setup-cross.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

export ICONS_VOLUME="$(realpath icons)"
export DIST_VOLUME="$(realpath dist)"
export ISOLATION_VOLUME="$(realpath isolation-dist)"
3 changes: 3 additions & 0 deletions examples/api/.taurignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src-tauri/locales/
src-tauri/Cross.toml
src-tauri/.gitignore
28 changes: 28 additions & 0 deletions examples/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# API example

This example demonstrates Tauri's API capabilities using the plugins from this repository. It's used as the main validation app, serving as the testbed of our development process.
In the future, this app will be used on Tauri's integration tests.

![App screenshot](./screenshot.png?raw=true)

## Running the example

- Install dependencies and build packages (Run inside of the repository root)

```bash
$ pnpm install
$ pnpm build
```

- Run the app in development mode (Run inside of this folder `examples/api/`)

```bash
$ pnpm tauri dev
```

- Build an run the release app (Run inside of this folder `examples/api/`)

```bash
$ pnpm tauri build
$ ./src-tauri/target/release/app
```
13 changes: 13 additions & 0 deletions examples/api/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en" theme="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Svelte + Vite App</title>
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions examples/api/isolation-dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Isolation Secure Script</title>
</head>
<body>
<script src="index.js"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions examples/api/isolation-dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

window.__TAURI_ISOLATION_HOOK__ = (payload) => {
return payload;
};
34 changes: 34 additions & 0 deletions examples/api/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"moduleResolution": "node",
"target": "esnext",
"module": "esnext",
/**
* svelte-preprocess cannot figure out whether you have
* a value or a type, so tell TypeScript to enforce using
* `import type` instead of `import` for Types.
*/
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"resolveJsonModule": true,
/**
* To have warnings / errors of the Svelte compiler at the
* correct position, enable source maps by default.
*/
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable this if you'd like to use dynamic types.
*/
"checkJs": true
},
/**
* Use global.d.ts instead of compilerOptions.types
* to avoid limiting type declarations.
*/
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}
32 changes: 32 additions & 0 deletions examples/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "svelte-app",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite --clearScreen false",
"build": "vite build",
"serve": "vite preview"
},
"dependencies": {
"@tauri-apps/api": "2.0.0-alpha.3",
"@tauri-apps/cli": "2.0.0-alpha.8",
"@zerodevx/svelte-json-view": "0.2.1",
"tauri-plugin-cli-api": "0.0.0",
"tauri-plugin-clipboard-api": "0.0.0",
"tauri-plugin-dialog-api": "0.0.0",
"tauri-plugin-fs-api": "0.0.0",
"tauri-plugin-global-shortcut-api": "0.0.0",
"tauri-plugin-http-api": "0.0.0",
"tauri-plugin-notification-api": "0.0.0",
"tauri-plugin-shell-api": "0.0.0"
},
"devDependencies": {
"@iconify-json/codicon": "^1.1.10",
"@iconify-json/ph": "^1.1.1",
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"internal-ip": "^7.0.0",
"svelte": "^3.49.0",
"unocss": "^0.39.3",
"vite": "^3.0.9"
}
}
Binary file added examples/api/public/tauri_logo.png
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/api/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/api/src-tauri/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# cargo-mobile
.cargo/
1 change: 1 addition & 0 deletions examples/api/src-tauri/.taurignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tauri-plugin-sample/
Loading

0 comments on commit 5015132

Please sign in to comment.