first commit

This commit is contained in:
2023-01-09 16:21:31 +09:00
commit 8bd6c719ae
41 changed files with 6658 additions and 0 deletions

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

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

3197
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

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

@@ -0,0 +1,29 @@
[package]
name = "pokemon-data-displayer"
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.91"
serde = { version = "1.0.152", features = ["derive"] }
tauri = { version = "1.2", features = ["shell-open"] }
sqlite = "0.30.3"
wana_kana = "2.1.0"
[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

1
src-tauri/rustfmt.toml Normal file
View File

@@ -0,0 +1 @@
tab_spaces = 2

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

@@ -0,0 +1,135 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use serde::{Deserialize, Serialize};
use wana_kana::to_katakana::*;
#[derive(Serialize, Deserialize, Debug, Clone)]
struct SearchResult {
id: i64,
dex_index: String,
jap_name: String,
eng_name: String,
types: String,
hp: i64,
attack: i64,
defense: i64,
special_attack: i64,
special_defense: i64,
speed: i64,
thumb_small: String,
thumb_big: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
struct Autosearch {
id: i64,
name: String,
}
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
let connection = sqlite::open("./pokemon.db").unwrap();
let query = "SELECT types FROM pokemon WHERE eng_name = ?";
let mut result = "".to_string();
for row in connection
.prepare(query)
.unwrap()
.into_iter()
.bind((1, name))
.unwrap()
.map(|row| row.unwrap())
{
result = row.read::<&str, _>("types").to_string();
}
format!("Hello, {}! You've been greeted from Rust! {}", name, result)
}
#[tauri::command]
fn autosearch(keyword: &str) -> serde_json::Value {
let connection = sqlite::open("./pokemon.db").unwrap();
let query = "SELECT * FROM pokemon WHERE LOWER(eng_name) like ? or jap_name like ? or jap_name like ? or LOWER(dex_index) like ? LIMIT 5";
let mut result: Vec<Autosearch> = vec![];
let aste_keyword = format!("%{}%", keyword.to_lowercase());
let katakana = format!("%{}%", to_katakana(keyword));
println!("{}", katakana);
for row in connection
.prepare(query)
.unwrap()
.into_iter()
.bind((1, aste_keyword.as_str()))
.unwrap()
.bind((2, aste_keyword.as_str()))
.unwrap()
.bind((3, katakana.as_str()))
.unwrap()
.bind((4, aste_keyword.as_str()))
.unwrap()
.map(|row| row.unwrap())
{
let row_result = Autosearch {
id: row.read::<i64, _>("id"),
name: format!(
"{} - {} ({})",
row.read::<&str, _>("dex_index").to_string(),
row.read::<&str, _>("jap_name").to_string(),
row.read::<&str, _>("eng_name").to_string()
),
};
result.push(row_result);
}
println!("{:?}", result);
serde_json::to_value(result).unwrap_or(serde_json::json!("[]"))
}
#[tauri::command]
fn search(index: i64) -> SearchResult {
let connection = sqlite::open("./pokemon.db").unwrap();
let query = "SELECT * FROM pokemon WHERE id = ?";
for row in connection
.prepare(query)
.unwrap()
.into_iter()
.bind((1, index))
.unwrap()
.map(|row| row.unwrap())
{
let row_result = SearchResult {
id: row.read::<i64, _>("id"),
dex_index: row.read::<&str, _>("dex_index").to_string(),
eng_name: row.read::<&str, _>("eng_name").to_string(),
jap_name: row.read::<&str, _>("jap_name").to_string(),
types: row.read::<&str, _>("types").to_string(),
thumb_big: row.read::<&str, _>("thumb_big").to_string(),
thumb_small: row.read::<&str, _>("thumb_small").to_string(),
hp: row.read::<i64, _>("hp"),
attack: row.read::<i64, _>("attack"),
defense: row.read::<i64, _>("defense"),
special_attack: row.read::<i64, _>("special_attack"),
special_defense: row.read::<i64, _>("special_defense"),
speed: row.read::<i64, _>("speed"),
};
return row_result
}
return SearchResult {
id: 0,
dex_index: "#???".to_string(),
eng_name: "Missigno".to_string(),
jap_name: "Missigno".to_string(),
types: "[]".to_string(),
thumb_big: "".to_string(),
thumb_small: "".to_string(),
hp: 0,
attack: 0,
defense: 0,
special_attack: 0,
special_defense: 0,
speed: 0,
}
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, autosearch, search])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

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

@@ -0,0 +1,70 @@
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": false
},
"package": {
"productName": "pokemon-data-displayer",
"version": "0.0.1"
},
"tauri": {
"allowlist": {
"all": false,
"shell": {
"all": false,
"open": 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.pokemon.data.displayer.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": ["pokemon.db"],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 500,
"resizable": true,
"title": "pokemon-data-displayer",
"width": 1000
}
]
}
}