feat(examples): add navigation example (#1690)

This commit is contained in:
Lucas Fernandes Nogueira 2021-05-03 14:42:40 -03:00 committed by GitHub
parent 8845487f9d
commit 26c6a832bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 207 additions and 6 deletions

View File

@ -14,6 +14,7 @@ members = [
"examples/commands/src-tauri",
"examples/splashscreen/src-tauri/",
"examples/state/src-tauri/",
"examples/navigation/src-tauri/",
# used to build updater artifacts
"examples/updater/src-tauri",
]

View File

@ -7,14 +7,8 @@
windows_subsystem = "windows"
)]
#[tauri::command]
fn my_custom_command(argument: String) {
println!("{}", argument);
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![my_custom_command])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -0,0 +1,7 @@
{
"name": "navigation",
"version": "1.0.0",
"scripts": {
"tauri": "node ../../tooling/cli.js/bin/tauri"
}
}

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri</title>
</head>
<body>
<h1>index.html</h1>
<select id="route">
<option value="secondary.html">secondary.html</option>
<option value="nested/index.html">nested/index.html</option>
<option value="nested/secondary.html">nested/secondary.html</option>
</select>
<button id="go">Go</button>
<a id="link" href="secondary.html">Go</a>
<script src="index.js"></script>
</body>
</html>

View File

@ -0,0 +1,10 @@
const routeSelect = document.querySelector('#route')
const link = document.querySelector('#link')
routeSelect.addEventListener('change', (event) => {
link.href = event.target.value
})
document.querySelector('#go').addEventListener('click', () => {
window.location.href = (window.location.origin + '/' + routeSelect.value)
})

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri</title>
</head>
<body>
<h1></h1>
<button onclick="window.history.back()">Back</button>
<script src="index.js"></script>
</body>
</html>

View File

@ -0,0 +1 @@
document.querySelector('h1').innerHTML = 'nested/index.html'

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri</title>
</head>
<body>
<h1></h1>
<button onclick="window.history.back()">Back</button>
<script src="secondary.js"></script>
</body>
</html>

View File

@ -0,0 +1 @@
document.querySelector('h1').innerHTML = 'nested/secondary.html'

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri</title>
</head>
<body>
<h1></h1>
<button onclick="window.history.back()">Back</button>
<script src="secondary.js"></script>
</body>
</html>

View File

@ -0,0 +1 @@
document.querySelector('h1').innerHTML = 'secondary.html'

View File

@ -0,0 +1,10 @@
# Generated by Cargo
# will have compiled files and executables
/target/
WixTools
# These are backup files generated by rustfmt
**/*.rs.bk
config.json
bundle.json

View File

@ -0,0 +1 @@
../../../.license_template

View File

@ -0,0 +1,17 @@
[package]
name = "navigation"
version = "0.1.0"
description = "A very simple Tauri Appplication with navigation"
edition = "2018"
[build-dependencies]
tauri-build = { path = "../../../core/tauri-build", features = [ "codegen" ] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = [ "derive" ] }
tauri = { path = "../../../core/tauri", features = ["api-all"] }
[features]
default = [ "custom-protocol" ]
custom-protocol = [ "tauri/custom-protocol" ]

View File

@ -0,0 +1,14 @@
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use tauri_build::{try_build, Attributes, WindowsAttributes};
fn main() {
if let Err(error) = try_build(
Attributes::new()
.windows_attributes(WindowsAttributes::new().window_icon_path("../../.icons/icon.ico")),
) {
panic!("error found during tauri-build: {}", error);
}
}

View File

@ -0,0 +1,14 @@
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -0,0 +1,56 @@
{
"build": {
"distDir": "../public",
"devPath": "../public",
"beforeDevCommand": "",
"beforeBuildCommand": ""
},
"tauri": {
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.tauri.dev",
"icon": [
"../../.icons/32x32.png",
"../../.icons/128x128.png",
"../../.icons/128x128@2x.png",
"../../.icons/icon.icns",
"../../.icons/icon.ico"
],
"resources": [],
"externalBin": [],
"copyright": "",
"category": "DeveloperTool",
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
},
"macOS": {
"frameworks": [],
"minimumSystemVersion": "",
"useBootstrapper": false,
"exceptionDomain": ""
}
},
"allowlist": {
"all": true
},
"windows": [
{
"title": "Welcome to Tauri!",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false
}
],
"security": {
"csp": "default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'"
},
"updater": {
"active": false
}
}
}