Primitive Backend Communication

This commit is contained in:
Neshura 2023-11-01 20:21:59 +01:00
parent 2b5a19fdd6
commit 9a8f2198f1
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
7 changed files with 373 additions and 18 deletions

44
src-tauri/Cargo.lock generated
View file

@ -347,10 +347,14 @@ dependencies = [
[[package]]
name = "comicinfo-editor-v2"
version = "0.0.0"
version = "0.1.0"
dependencies = [
"quick-xml",
"serde",
"serde-xml-rs",
"serde_json",
"strum",
"strum_macros",
"tauri",
"tauri-build",
]
@ -1996,6 +2000,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81b9228215d82c7b61490fec1de287136b5de6f5700f6e58ea9ad61a7964ca51"
dependencies = [
"memchr",
"serde",
]
[[package]]
@ -2272,6 +2277,18 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-xml-rs"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb3aa78ecda1ebc9ec9847d5d3aba7d618823446a049ba2491940506da6e2782"
dependencies = [
"log",
"serde",
"thiserror",
"xml-rs",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
@ -2497,6 +2514,25 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "strum"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
[[package]]
name = "strum_macros"
version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0"
dependencies = [
"heck 0.4.1",
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.38",
]
[[package]]
name = "syn"
version = "1.0.109"
@ -3651,3 +3687,9 @@ checksum = "f4686009f71ff3e5c4dbcf1a282d0a44db3f021ba69350cd42086b3e5f1c6985"
dependencies = [
"libc",
]
[[package]]
name = "xml-rs"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a"

View file

@ -1,8 +1,8 @@
[package]
name = "comicinfo-editor-v2"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
version = "0.1.0"
description = "App for creating Comicinfo.xml files"
authors = ["Neshura"]
license = ""
repository = ""
edition = "2021"
@ -14,8 +14,12 @@ tauri-build = { version = "1.4", features = [] }
[dependencies]
tauri = { version = "1.4", features = ["shell-open"] }
quick-xml = { version = "0.29.0", features = ["serde", "serialize"] }
serde = { version = "1.0", features = ["derive"] }
serde-xml-rs = "0.6.0"
serde_json = "1.0"
strum = "0.25.0"
strum_macros = "0.25.0"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem

View file

@ -1,6 +1,11 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use serde::{Deserialize, Serialize};
use crate::metadata::{*};
mod metadata;
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
@ -9,7 +14,12 @@ fn greet(name: &str) -> String {
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.invoke_handler(tauri::generate_handler![greet, test])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[tauri::command]
fn test(message: metadata::Metadata) -> String {
format!("Series: '{}' | Title: '{}'", message.series_title, message.title)
}

View file

@ -0,0 +1,198 @@
use std::{fs::File, io::{Write, Cursor}};
use quick_xml::{se::Serializer, events::BytesStart};
use serde::{Serialize, Deserialize};
use serde::ser::{SerializeSeq, SerializeStruct};
use serde_xml_rs::{to_string, to_writer};
#[derive(Debug, Deserialize, PartialEq, Clone)]
pub(crate) struct Metadata {
pub(crate) title: String,
pub(crate) series_title: String,
pub(crate) chapter_number: u16,
pub(crate) total_chapter_count: i16,
pub(crate) volume_number: i16,
pub(crate) summary: Option<String>,
pub(crate) year: i16,
pub(crate) month: i8,
pub(crate) day: i8,
pub(crate) writer: Option<String>,
pub(crate) translator: Option<String>,
pub(crate) letterer: Option<String>,
pub(crate) editor: Option<String>,
pub(crate) publisher: Option<String>,
pub(crate) genre: String,
pub(crate) tags: Vec<String>,
pub(crate) page_count: u16,
pub(crate) language: String,
pub(crate) characters: Vec<String>,
pub(crate) age_rating: String
}
impl Default for Metadata {
fn default() -> Self {
Self {
title: "".into(),
series_title: "".into(),
chapter_number: 0,
total_chapter_count: -1,
volume_number: 1,
summary: None,
year: -1,
month: -1,
day: -1,
writer: None,
letterer: None,
editor: None,
translator: None,
publisher: None,
genre: "".into(),
tags: vec![],
page_count: 0,
language: "en".into(),
characters: vec![],
age_rating: "Unknown".into()
}
}
}
impl Serialize for Metadata {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
let mut out_state = serializer.serialize_struct("Metadata", 22)?;
out_state.serialize_field("@xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")?;
out_state.serialize_field("@xsi:noNamespaceSchemaLocation", "ComicInfo.xsd")?;
out_state.serialize_field("Title", &self.title)?;
out_state.serialize_field("Series", &self.series_title)?;
out_state.serialize_field("Number", &self.chapter_number)?;
out_state.serialize_field("Count", &self.total_chapter_count)?;
out_state.serialize_field("Volume", &self.volume_number)?;
if self.summary.is_some() {
out_state.serialize_field("Summary", &self.summary)?;
}
out_state.serialize_field("Year", &self.year)?;
out_state.serialize_field("Month", &self.month)?;
out_state.serialize_field("Day", &self.day)?;
if self.writer.is_some() {
out_state.serialize_field("Writer", &self.writer)?;
}
if self.letterer.is_some() {
out_state.serialize_field("Letterer", &self.letterer)?;
}
if self.editor.is_some() {
out_state.serialize_field("Editor", &self.editor)?;
}
if self.translator.is_some() {
out_state.serialize_field("Translator", &self.translator)?;
}
if self.publisher.is_some() {
out_state.serialize_field("Publisher", &self.publisher)?;
}
out_state.serialize_field("Genre", &self.genre)?;
if self.tags.len() != 0 {
out_state.serialize_field("Tags", &self.tags.join(", "))?;
}
out_state.serialize_field("PageCount", &self.page_count)?;
out_state.serialize_field("LanguageISO", &self.language)?;
if self.characters.len() != 0 {
out_state.serialize_field("Characters", &self.characters.join(", "))?;
}
out_state.serialize_field("AgeRating", &self.age_rating)?;
out_state.end()
}
}
impl Metadata {
pub(crate) fn save_to_xml(&self, path: &str) {
let mut file = File::create(path).unwrap();
let mut buffer = String::new();
let root = "ComicInfo";
let mut ser = Serializer::with_root(&mut buffer, Some(root)).unwrap();
ser.indent(' ', 4);
self.serialize(ser).unwrap();
file.write(buffer.as_bytes()).unwrap();
}
}
/*#[derive(strum_macros::Display, Debug, PartialEq, strum_macros::EnumIter, Serialize, Deserialize, Clone)]
#[serde(tag = "AgeRating")]
pub(crate) enum AgeRating {
#[strum(serialize="Unknown")]
Unknown,
#[strum(serialize="Adults Only 18+")]
#[serde(rename="Adults Only 18+")]
AdultsOnly,
#[strum(serialize="Early Childhood")]
#[serde(rename="Early Childhood")]
EarlyChildhood,
#[strum(serialize="Everyone")]
Everyone,
#[strum(serialize="Everyone 10+")]
#[serde(rename="Everyone 10+")]
Everyone10,
#[strum(serialize="G")]
G,
#[strum(serialize="Kids to Adults")]
#[serde(rename="Kids to Adults")]
KidsAdults,
#[strum(serialize="M")]
M,
#[strum(serialize="MA15+")]
#[serde(rename="MA15+")]
MA15,
#[strum(serialize="Mature 17+")]
#[serde(rename="Mature 17+")]
Mature,
#[strum(serialize="PG")]
PG,
#[strum(serialize="R18+")]
#[serde(rename="R18+")]
R18,
#[strum(serialize="Rating Pending")]
#[serde(rename="Rating Pending")]
RatingPending,
#[strum(serialize="Teen")]
Teen,
#[strum(serialize="X18+")]
#[serde(rename="X18+")]
X18
}
#[derive(strum_macros::Display, Debug, PartialEq, strum_macros::EnumIter, Serialize, Deserialize, Clone)]
#[serde(tag = "LanguageISO")]
pub(crate) enum LanguageISO {
#[strum(serialize="en")]
#[serde(rename="en")]
EN,
#[strum(serialize="jp")]
#[serde(rename="jp")]
JP
}*/

View file

@ -8,7 +8,7 @@
},
"package": {
"productName": "comicinfo-editor-v2",
"version": "0.0.0"
"version": "0.1.0"
},
"tauri": {
"allowlist": {

View file

@ -1,10 +1,12 @@
<script lang="ts">
import {writable} from "svelte/store";
import type {Writable} from "svelte/store";
import IntegerInput from "./IntegerInput.svelte";
import TextInput from "./TextInput.svelte";
import NewListTextInput from "./ListTextInput/NewListTextInput.svelte";
import ListTextInputElement from "./ListTextInput/ListTextInputElement.svelte";
import {invoke} from "@tauri-apps/api/tauri";
import {AgeRating, LanguageISO, type Metadata} from "./metadata";
let returnMessage = "";
let seriesTitle = "";
let volumeTitle = "";
@ -23,8 +25,8 @@
let publisher: string;
let tags: Array<string> = [];
let genre = "Hentai";
let lang = "en";
let ageRating = "18+";
let lang = LanguageISO.EN;
let ageRating = AgeRating.R18;
$: {
if (releaseYear < 0) {
@ -40,9 +42,49 @@
tags.splice(event.detail.tagId, 1);
tags = tags;
}
async function saveMetadata() {
let message: Metadata = {
title: volumeTitle,
series_title: seriesTitle,
chapter_number: 0,
total_chapter_count: -1,
volume_number: -1,
summary: "",
year: 2023,
month: -1,
day: -1,
writer: "",
translator: "",
letterer: "",
editor: "",
publisher: "",
genre: "",
tags: [],
page_count: 10,
language: LanguageISO.EN,
characters: [],
age_rating: AgeRating.R18,
}
console.log(message);
returnMessage = await invoke("test", { message })
}
</script>
<div class="metadataInput">
<form class="metadataInput" on:submit|preventDefault={saveMetadata}>
<h1>Metadata</h1>
<label for="series">Series:</label>
@ -78,15 +120,15 @@
<label for="author">Author:</label>
<TextInput id="author" bind:value={author} placeholder="Author" /><br>
<label for="translator">Translator:</label>
<TextInput id="translator" bind:value={translator} placeholder="Translator" /><br>
<label for="typesetter">Typesetter:</label>
<TextInput id="typesetter" bind:value={typesetter} placeholder="Typesetter" /><br>
<label for="editor">Editor:</label>
<TextInput id="editor" bind:value={editor} placeholder="Editor" /><br>
<label for="translator">Translator:</label>
<TextInput id="translator" bind:value={translator} placeholder="Translator" /><br>
<label for="publisher">Publisher:</label>
<TextInput id="publisher" bind:value={publisher} placeholder="Publisher" /><br>
@ -97,17 +139,18 @@
{/each}
<NewListTextInput id="new-tag" bind:value={tags[tags.length]}/><br>
<label for="genre">Genre</label>
<label for="genre">Genre:</label>
<TextInput id="genre" bind:value={genre} placeholder="Genre" />
<label for="lang">Language</label>
<label for="lang">Language:</label>
<input id="lang" type="text"><br>
<label for="age_rating">Age Rating</label>
<label for="age_rating">Age Rating:</label>
<input id="age_rating" type="text"><br>
<input type="submit" value="Save"/>
</div>
<p>{returnMessage}</p>
</form>
<style>
.metadataInput {

58
src/lib/metadata.ts Normal file
View file

@ -0,0 +1,58 @@
type Metadata = {
title: string,
series_title: string,
chapter_number: number,
total_chapter_count: number,
volume_number: number,
summary: string,
year: number,
month: number,
day: number,
writer: string,
translator: string,
letterer: string
editor: string,
publisher: string,
genre: string,
tags: string[],
page_count: number,
language: LanguageISO,
characters: string[]
age_rating: AgeRating
}
enum AgeRating {
Unknown = "Unknown",
AdultsOnly = "Adults Only 18+",
EarlyChildhood = "Early Childhood",
Everyone = "Everyone",
Everyone10 = "Everyone 10+",
G = "G",
KidsAdults = "Kids to Adults",
M = "M",
MA15 = "MA15+",
Mature = "Mature 17+",
PG = "PG",
R18 = "R18+",
RatingPending = "Rating Pending",
X18 = "X18+"
}
enum LanguageISO {
EN = "en",
JP = "jp"
}
export { LanguageISO, AgeRating}
export type {Metadata}