first commit
4
src-tauri/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
3197
src-tauri/Cargo.lock
generated
Normal file
29
src-tauri/Cargo.toml
Normal 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
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
BIN
src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 974 B |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
1
src-tauri/rustfmt.toml
Normal file
@@ -0,0 +1 @@
|
||||
tab_spaces = 2
|
||||
135
src-tauri/src/main.rs
Normal 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
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||