Added next.js example (#191)

This commit is contained in:
Dale Inverarity 2019-12-20 16:28:11 -06:00 committed by nothingismagick
parent 0298a78726
commit adaef1a3d7
30 changed files with 6109 additions and 0 deletions

25
examples/react/next.js/.gitignore vendored Normal file
View File

@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
.env*
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@ -0,0 +1,25 @@
## Running Example
Ensure you have setup and installed all the project dependencies.
```
npm install -g tauri
git clone https://github.com/tauri-apps/tauri
cd examples/react/next.js
yarn
cargo install tauri-cli
```
### Development
```
yarn dev & tauri dev
```
### Production
```
yarn build
yarn next export
tauri build
```

View File

@ -0,0 +1,56 @@
import React from 'react'
import Link from 'next/link'
const links = [
{ href: 'https://zeit.co/now', label: 'ZEIT' },
{ href: 'https://github.com/zeit/next.js', label: 'GitHub' },
].map(link => {
link.key = `nav-link-${link.href}-${link.label}`
return link
})
const Nav = () => (
<nav>
<ul>
<li>
<Link href="/">
<a>Home</a>
</Link>
</li>
{links.map(({ key, href, label }) => (
<li key={key}>
<a href={href}>{label}</a>
</li>
))}
</ul>
<style jsx>{`
:global(body) {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Avenir Next, Avenir,
Helvetica, sans-serif;
}
nav {
text-align: center;
}
ul {
display: flex;
justify-content: space-between;
}
nav > ul {
padding: 4px 16px;
}
li {
display: flex;
padding: 6px 8px;
}
a {
color: #067df7;
text-decoration: none;
font-size: 13px;
}
`}</style>
</nav>
)
export default Nav

View File

@ -0,0 +1,15 @@
{
"name": "next.js",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "9.1.6",
"react": "16.12.0",
"react-dom": "16.12.0"
}
}

View File

@ -0,0 +1,88 @@
import React from 'react'
import Head from 'next/head'
import Nav from '../components/nav'
const Home = () => (
<div>
<Head>
<title>Home</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Nav />
<div className="hero">
<h1 className="title">Welcome to Next.js!</h1>
<p className="description">
To get started, edit <code>pages/index.js</code> and save to reload.
</p>
<div className="row">
<a href="https://nextjs.org/docs" className="card">
<h3>Documentation &rarr;</h3>
<p>Learn more about Next.js in the documentation.</p>
</a>
<a href="https://nextjs.org/learn" className="card">
<h3>Next.js Learn &rarr;</h3>
<p>Learn about Next.js by following an interactive tutorial!</p>
</a>
<a
href="https://github.com/zeit/next.js/tree/master/examples"
className="card"
>
<h3>Examples &rarr;</h3>
<p>Find other example boilerplates on the Next.js GitHub.</p>
</a>
</div>
</div>
<style jsx>{`
.hero {
width: 100%;
color: #333;
}
.title {
margin: 0;
width: 100%;
padding-top: 80px;
line-height: 1.15;
font-size: 48px;
}
.title,
.description {
text-align: center;
}
.row {
max-width: 880px;
margin: 80px auto 40px;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.card {
padding: 18px 18px 24px;
width: 220px;
text-align: left;
text-decoration: none;
color: #434343;
border: 1px solid #9b9b9b;
}
.card:hover {
border-color: #067df7;
}
.card h3 {
margin: 0;
color: #067df7;
font-size: 18px;
}
.card p {
margin: 0;
padding: 12px 0 0;
font-size: 13px;
color: #333;
}
`}</style>
</div>
)
export default Home

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,14 @@
# Generated by Cargo
# 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
tauri.js
config.json
bundle.json

View File

@ -0,0 +1,39 @@
workspace = { }
[package]
name = "app"
version = "0.1.0"
description = "A Tauri App"
author = [ "you" ]
license = ""
repository = ""
default-run = "app"
edition = "2018"
[package.metadata.bundle]
identifier = "com.tauri.dev"
icon = [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
[dependencies]
serde_json = "1.0.41"
serde = "1.0"
serde_derive = "1.0"
tiny_http = "0.6"
phf = "0.7.24"
includedir = "0.5.0"
tauri = { version = "0.2.0", features = [ "edge" ] }
[features]
dev-server = [ "tauri/dev-server" ]
embedded-server = [ "tauri/embedded-server" ]
no-server = [ "tauri/no-server" ]
[[bin]]
name = "app"
path = "src/main.rs"

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View File

@ -0,0 +1,13 @@
max_width = 100
hard_tabs = false
tab_spaces = 2
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

View File

@ -0,0 +1,8 @@
#[derive(Deserialize)]
#[serde(tag = "cmd", rename_all = "camelCase")]
pub enum Cmd {
// your custom commands
// multiple arguments are allowed
// note that rename_all = "camelCase": you need to use "myCustomCommand" on JS
MyCustomCommand { argument: String },
}

View File

@ -0,0 +1,26 @@
mod cmd;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
fn main() {
tauri::AppBuilder::new()
.invoke_handler(|_webview, arg| {
use cmd::Cmd::*;
match serde_json::from_str(arg) {
Err(_) => {}
Ok(command) => {
match command {
// definitions for your custom commands from Cmd here
MyCustomCommand { argument } => {
// your command code
println!("{}", argument);
}
}
}
}
})
.build()
.run();
}

View File

@ -0,0 +1,69 @@
use crate::tauri::process::{ProcessExt, Signal, SystemExt};
fn update() -> Result<(), String> {
let target = tauri::platform::target_triple().map_err(|_| "Could not determine target")?;
let github_release = tauri::updater::github::get_latest_release("jaemk", "self_update")
.map_err(|_| "Could not fetch latest release")?;
match github_release.asset_for(&target) {
Some(github_release_asset) => {
let release = tauri::updater::Release {
version: github_release.tag.trim_start_matches('v').to_string(),
download_url: github_release_asset.download_url,
asset_name: github_release_asset.name,
};
let status = tauri::updater::Update::configure()
.unwrap()
.release(release)
.bin_path_in_archive("github")
.bin_name("app")
.bin_install_path(&tauri::command::command_path("app".to_string()).unwrap())
.show_download_progress(true)
.current_version(env!("CARGO_PKG_VERSION"))
.build()
.unwrap()
.update()
.unwrap();
println!("found release: {}", status.version());
/*let tmp_dir = tauri::dir::with_temp_dir(|dir| {
let file_path = dir.path().join("my-temporary-note.pdf");
let mut tmp_archive = std::fs::File::create(file_path).unwrap();
tauri::http::download(&"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf".to_string(), &mut tmp_archive, true).unwrap();
});*/
Ok(())
}
None => Err(format!("Could not find release for target {}", target)),
}
}
fn restart_app(app_command: String) -> Result<(), String> {
let mut system = tauri::process::System::new();
let parent_process = tauri::process::get_parent_process(&mut system)
.map_err(|_| "Could not determine parent process")?;
if parent_process.name() == "app" {
parent_process.kill(Signal::Kill);
std::thread::sleep(std::time::Duration::from_secs(1));
std::process::Command::new(app_command)
.spawn()
.map_err(|_| "Could not start app")?;
}
Ok(())
}
fn run_updater() -> Result<(), String> {
let app_command = tauri::command::relative_command("app".to_string())
.map_err(|_| "Could not determine app path")?;
update()?;
restart_app(app_command)?;
Ok(())
}
fn main() {
match run_updater() {
Ok(_) => {}
Err(err) => panic!(err),
};
}

View File

@ -0,0 +1,35 @@
const path = require('path')
const distDir = path.resolve(__dirname, './out')
module.exports = function () {
return {
build: {
distDir: distDir,
devPath: 'http://localhost:3000' // devServer URL or html dir
},
ctx: {},
tauri: {
embeddedServer: {
active: true
},
bundle: {
active: true
},
whitelist: {
all: false
},
window: {
title: 'Tauri App'
},
security: {
csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\''
},
edge: {
active: true
},
automaticStart: {
active: true
}
}
}
}

File diff suppressed because it is too large Load Diff