Added: Path Selection (ComicInfo + Bundle Source), Bundle Checkbox

This commit is contained in:
Neshura 2023-11-15 23:59:09 +01:00
parent 87d703abe4
commit b5812fa32c
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
4 changed files with 108 additions and 7 deletions

View file

@ -2,6 +2,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use serde::{Deserialize, Serialize};
use std::path::MAIN_SEPARATOR_STR;
use crate::metadata::{*};
mod metadata;
@ -14,13 +15,20 @@ fn greet(name: &str) -> String {
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, test])
.invoke_handler(tauri::generate_handler![greet, save])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[tauri::command]
fn test(message: metadata::Metadata) -> String {
message.save_to_xml("/home/neshura/Repositories/comicinfo-editor-v2/ComicInfo.xml");
format!("Series: '{}' | Title: '{}'", message.series_title, message.title)
fn save(metadata: Metadata, path: String) -> String {
let file_path: String;
if path.ends_with(MAIN_SEPARATOR_STR) {
file_path = path + "ComicInfo.xml";
}
else {
file_path = path + MAIN_SEPARATOR_STR + "ComicInfo.xml";
}
metadata.save_to_xml(&file_path);
file_path
}

View file

@ -21,6 +21,14 @@
<p>
Settings go here
</p>
<p>
Default ComicInfo.xml save location
</p>
<p>
Default Metadata Settings (genre, age rating)
</p>
{/if}
</div>

View file

@ -6,6 +6,13 @@
import {invoke} from "@tauri-apps/api/tauri";
import {AgeRating, LanguageISO, type Metadata} from "./metadata";
import Dropdown from "./Dropdown/Dropdown.svelte";
import PathInput from "./PathInput.svelte";
import {tempdir} from "@tauri-apps/api/os";
import {downloadDir} from "@tauri-apps/api/path";
let tauriInitDone = false;
let downloadDirPath: string;
let tempDirPath: string;
let returnMessage = "";
@ -47,6 +54,11 @@
age_rating: AgeRating.Unknown
};
let saveDirectory = "";
let bundleDirectory = "";
let doBundle = false;
$: {
if (metadata.release_date.year < 0) {
metadata.release_date.month = -1;
@ -56,15 +68,43 @@
}
}
$: {
if (tauriInitDone) {
if (saveDirectory == "") {
saveDirectory = downloadDirPath;
}
if (bundleDirectory == "") {
bundleDirectory = downloadDirPath;
}
}
}
async function init() {
downloadDirPath = await downloadDir();
tempDirPath = await tempdir();
tauriInitDone = true;
}
function deleteTag(event: any) {
metadata.tags.splice(event.detail.tagId, 1);
metadata.tags = metadata.tags;
}
async function saveMetadata() {
while (!tauriInitDone) {
await new Promise( resolve => setTimeout(resolve, 100) );
}
console.log(metadata);
returnMessage = await invoke("test", { message: metadata })
if (bundleDirectory != "") {
}
else {
let comicInfoPath = await invoke("save", { message: metadata, path: saveDirectory })
returnMessage = "Saved '" + metadata.title + "' to '" + comicInfoPath + "'";
}
}
init();
</script>
<div class="metadataInputContainer">
@ -131,14 +171,24 @@
<TextInput id="genre" bind:value={metadata.genre} placeholder="Genre" />
<label for="language-select">Language:</label>
<Dropdown id="language-select" bind:activeElement={metadata.language} list={Object.values(LanguageISO)}></Dropdown>
<Dropdown id="language-select" bind:activeElement={metadata.language} list={Object.values(LanguageISO)} />
</div>
<div class="row-left">
<label for="age-rating">Age Rating:</label>
<Dropdown id="" bind:activeElement={metadata.age_rating} list={Object.values(AgeRating)}></Dropdown>
<Dropdown id="" bind:activeElement={metadata.age_rating} list={Object.values(AgeRating)} />
</div>
<hr>
<PathInput bind:path={saveDirectory}/>
<div class="row-left">
<label for="bundle-check">Bundle:</label>
<input id="bundle-check" type="checkbox" bind:checked={doBundle}>
</div>
{#if doBundle}
<PathInput bind:path={bundleDirectory}/>
{/if}
<input type="submit" value="Save"/>
<p>{returnMessage}</p>
</form>

35
src/lib/PathInput.svelte Normal file
View file

@ -0,0 +1,35 @@
<script lang="ts">
import { open } from '@tauri-apps/api/dialog';
export let path: string;
let buttonPrompt = "Select";
async function handleClick() {
const dirHandle = await open({
multiple: false,
directory: true,
defaultPath: path
});
if (Array.isArray(dirHandle)) {
path = dirHandle[0];
}
else if (dirHandle !== null) {
path = dirHandle;
}
}
</script>
<div>
<button on:click|preventDefault={handleClick}>{buttonPrompt}</button>
{#if path != ""}
<p>{path}</p>
{:else}
<p>Select Save Location...</p>
{/if}
</div>
<style>
</style>