Skip to content

Commit

Permalink
Provide simple command-based tauri app
Browse files Browse the repository at this point in the history
  • Loading branch information
Yassen Damyanov committed Jul 20, 2021
1 parent 00bf39c commit b30fc79
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# .gitignore for tauri-events-minimal

# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Front-end-specific exclusions
node_modules/
yarn.lock
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "tauri-events-minimal",
"version": "0.1.0",
"description": "Minimal Tauri events example",
"main": "index.html",
"repository": "https://github.com/yassen-damyanov/tauri-events-minimal.git",
"author": "Yassen Damyanov <[email protected]>",
"license": "Apache-2.0",
"private": false,
"devDependencies": {
"@tauri-apps/api": "^1.0.0-beta.5",
"@tauri-apps/cli": "^1.0.0-beta.6"
}
}
7 changes: 7 additions & 0 deletions src-tauri/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
WixTools

# Exclude the auto-genrated icons for now
/icons/
24 changes: 24 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
default-run = "app"
edition = "2018"
build = "src/build.rs"

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

[build-dependencies]
tauri-build = { version = "1.0.0-beta.3" }

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-beta.5", features = ["api-all"] }

[features]
default = [ "custom-protocol" ]
custom-protocol = [ "tauri/custom-protocol" ]
14 changes: 14 additions & 0 deletions src-tauri/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
max_width = 99
hard_tabs = false
tab_spaces = 3
newline_style = "Auto"
use_small_heuristics = "Default"
reorder_imports = true
reorder_modules = true
remove_nested_parens = true
edition = "2018"
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
imports_granularity = "Crate"
3 changes: 3 additions & 0 deletions src-tauri/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
19 changes: 19 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

#[tauri::command]
fn say_hello(name: String) -> String {
let response = format!("Hello, {}!", name);
println!("{:?}", response);
response.into()
}

fn main() {
println!("** Tauri app about to start");
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![say_hello,])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
68 changes: 68 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"package": {
"productName": "tauri-events-minimal",
"version": "0.1.0"
},
"build": {
"distDir": "../www",
"devPath": "../www",
"beforeDevCommand": "",
"beforeBuildCommand": "",
"withGlobalTauri": true
},
"tauri": {
"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"
],
"resources": [],
"externalBin": [],
"copyright": "",
"category": "DeveloperTool",
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
},
"macOS": {
"frameworks": [],
"minimumSystemVersion": "",
"useBootstrapper": false,
"exceptionDomain": "",
"signingIdentity": null,
"entitlements": null
},
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"updater": {
"active": false
},
"allowlist": {
"all": true
},
"windows": [
{
"title": "Tauri Events (Minimal Sample App)",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false
}
],
"security": {
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'"
}
}
}
30 changes: 30 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Tauri Events (Minimal Example)</title>
<link href="/styles.css" rel="stylesheet" />

<script type="text/javascript">
var Tauri = null;
import('/invoke.js').then(imported => {
Tauri = imported;
});

const sayHello = () => {
console.log('sayHello() called')
let name = 'Alice';
Tauri.invoke_cmd('say_hello', {'name': name}).then(ret => {
console.log(`say_hello('${name}') returned '${ret}'`);
});
};
</script>

</head>

<body>
<h2>Tauri Events (Minimal Example)</h2>
<p>Minimal example for a Tauri events-based application.</p>
<button onclick="sayHello();">Say Hello!</button>
</body>
</html>
11 changes: 11 additions & 0 deletions www/invoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Setup the bridge for invoking rust functions.
* (See https://tauri.studio/en/docs/usage/guides/command)
*/

// With the Tauri API npm package:
import { invoke } from '/modules/@tauri-apps/api/tauri.js';

// With the Tauri global script, enabled when
// `tauri.conf.json > build > withGlobalTauri` is set to true:
export const invoke_cmd = window.__TAURI__.invoke;
1 change: 1 addition & 0 deletions www/modules
5 changes: 5 additions & 0 deletions www/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
background-color: #eee;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
font-size: 1.4em;
}

0 comments on commit b30fc79

Please sign in to comment.