Added next.js example (#191)
25
examples/react/next.js/.gitignore
vendored
Normal 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*
|
25
examples/react/next.js/README.md
Normal 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
|
||||
```
|
56
examples/react/next.js/components/nav.js
Normal 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
|
15
examples/react/next.js/package.json
Normal 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"
|
||||
}
|
||||
}
|
88
examples/react/next.js/pages/index.js
Normal 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 →</h3>
|
||||
<p>Learn more about Next.js in the documentation.</p>
|
||||
</a>
|
||||
<a href="https://nextjs.org/learn" className="card">
|
||||
<h3>Next.js Learn →</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 →</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
|
BIN
examples/react/next.js/public/favicon.ico
Normal file
After Width: | Height: | Size: 15 KiB |
14
examples/react/next.js/src-tauri/.gitignore
vendored
Normal 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
|
39
examples/react/next.js/src-tauri/Cargo.toml
Normal 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"
|
BIN
examples/react/next.js/src-tauri/icons/128x128.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
examples/react/next.js/src-tauri/icons/128x128@2x.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
examples/react/next.js/src-tauri/icons/32x32.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square107x107Logo.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square142x142Logo.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square150x150Logo.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square284x284Logo.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square30x30Logo.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square310x310Logo.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square44x44Logo.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square71x71Logo.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
examples/react/next.js/src-tauri/icons/Square89x89Logo.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
examples/react/next.js/src-tauri/icons/StoreLogo.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
examples/react/next.js/src-tauri/icons/icon.icns
Normal file
BIN
examples/react/next.js/src-tauri/icons/icon.ico
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
examples/react/next.js/src-tauri/icons/icon.png
Normal file
After Width: | Height: | Size: 76 KiB |
13
examples/react/next.js/src-tauri/rustfmt.toml
Normal 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
|
8
examples/react/next.js/src-tauri/src/cmd.rs
Normal 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 },
|
||||
}
|
26
examples/react/next.js/src-tauri/src/main.rs
Normal 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();
|
||||
}
|
69
examples/react/next.js/src-tauri/src/updater.rs
Normal 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),
|
||||
};
|
||||
}
|
35
examples/react/next.js/tauri.conf.js
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|