Browse Source

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

Lucas Fernandes Nogueira 4 years ago
parent
commit
26c6a832bf

+ 1 - 0
Cargo.toml

@@ -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",
 ]

+ 0 - 6
examples/helloworld/src-tauri/src/main.rs

@@ -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");
 }

+ 7 - 0
examples/navigation/package.json

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

+ 23 - 0
examples/navigation/public/index.html

@@ -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>

+ 10 - 0
examples/navigation/public/index.js

@@ -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)
+})

+ 17 - 0
examples/navigation/public/nested/index.html

@@ -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>

+ 1 - 0
examples/navigation/public/nested/index.js

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

+ 17 - 0
examples/navigation/public/nested/secondary.html

@@ -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>

+ 1 - 0
examples/navigation/public/nested/secondary.js

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

+ 17 - 0
examples/navigation/public/secondary.html

@@ -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>

+ 1 - 0
examples/navigation/public/secondary.js

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

+ 10 - 0
examples/navigation/src-tauri/.gitignore

@@ -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

+ 1 - 0
examples/navigation/src-tauri/.license_template

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

+ 17 - 0
examples/navigation/src-tauri/Cargo.toml

@@ -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" ]

+ 14 - 0
examples/navigation/src-tauri/build.rs

@@ -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);
+  }
+}

+ 14 - 0
examples/navigation/src-tauri/src/main.rs

@@ -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");
+}

+ 56 - 0
examples/navigation/src-tauri/tauri.conf.json

@@ -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
+    }
+  }
+}