First commit: file selection

master
Dany Thach 2022-12-05 00:42:37 +01:00
commit aec5fa05c8
28 changed files with 3916 additions and 0 deletions

24
.gitignore vendored Normal file
View File

@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

3
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
}

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# Tauri + Vanilla
This template should help get you started developing with Tauri in vanilla HTML, CSS and Javascript.
## Recommended IDE Setup
- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)

4
src-tauri/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/

3645
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

27
src-tauri/Cargo.toml Normal file
View File

@ -0,0 +1,27 @@
[package]
name = "first-app"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.57"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = {version = "1.2", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = {version = "1.2", features = ["api-all"] }
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]

3
src-tauri/build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

53
src-tauri/src/main.rs Normal file
View File

@ -0,0 +1,53 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::io::Read;
use tauri::Manager;
#[derive(Clone, serde::Serialize)]
struct Payload {
message: String,
}
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn select_file(app: tauri::AppHandle) {
tauri::api::dialog::FileDialogBuilder::default()
.add_filter("iNES file (.nes)", &["nes"])
.pick_file(move |path_buf| match path_buf {
Some(path_buf) => {
app.emit_all("loading", Payload { message: "".into() }).unwrap();
if !path_buf.is_file() {
app.emit_all("error", Payload { message: "You must select a file".into() }).unwrap();
return;
}
if path_buf.extension().unwrap().ne("nes") {
app.emit_all("error", Payload { message: "The selected file must have a .nes extension".into() }).unwrap();
return;
}
let file_result = std::fs::File::open(&path_buf);
if file_result.is_err() {
app.emit_all("error", Payload { message: "Unable to open file".into() }).unwrap();
return;
}
let mut file = file_result.unwrap();
let mut contents = Vec::new();
let read_result = file.read_to_end(&mut contents);
if read_result.is_err() {
app.emit_all("error", Payload { message: "Unable to read file".into() }).unwrap();
return;
}
println!("{}", contents.len());
}
None => {}
});
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![select_file])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

66
src-tauri/tauri.conf.json Normal file
View File

@ -0,0 +1,66 @@
{
"build": {
"beforeDevCommand": "",
"beforeBuildCommand": "",
"devPath": "../src",
"distDir": "../src",
"withGlobalTauri": true
},
"package": {
"productName": "first-app",
"version": "0.0.0"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "iNES Helper",
"width": 800
}
]
}
}

26
src/index.html Normal file
View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<script src="script.js" defer></script>
<title>iNES Helper</title>
</head>
<body class="no-file-selected">
<header>
<h1>iNES Helper</h1>
</header>
<main>
<div class="select-file-wrapper" id="fileUploader">
<p>Click here to select a file</p>
</div>
<div class="loader">
<p>Loading...</p>
</div>
<div class="file-properties-wrapper">
</div>
</main>
</body>
</html>

16
src/script.js Normal file
View File

@ -0,0 +1,16 @@
const { listen } = window.__TAURI__.event;
const { invoke } = window.__TAURI__.tauri;
window.addEventListener("DOMContentLoaded", (e) => {
console.log(fileUploader);
fileUploader.addEventListener("click", (e) => {
invoke("select_file");
});
});
listen("loading", e => {
document.body.classList.remove([
"no-file-selected",
]);
document.body.classList.add(["is-loading"]);
});

42
src/style.css Normal file
View File

@ -0,0 +1,42 @@
* {
box-sizing: border-box;
}
body {
background-color: #212121;
color: #ffffff;
font-family: sans-serif;
}
h1 {
font-weight: 500;
text-align: center;
}
.select-file-wrapper {
display: none;
justify-content: center;
align-items: center;
width: 100%;
height: 200px;
border: 2px dashed #666666;
border-radius: 10px;
cursor: pointer;
}
body.no-file-selected .select-file-wrapper {
display: flex;
}
.loader {
display: none;
}
body.is-loading .loader {
display: block;
text-align: center;
}
main {
flex-grow: 1;
}