diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 602d3c8..21dfc9d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -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 } diff --git a/src/App.svelte b/src/App.svelte index d97f7cd..a79addc 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -21,6 +21,14 @@

Settings go here

+ +

+ Default ComicInfo.xml save location +

+ +

+ Default Metadata Settings (genre, age rating) +

{/if} diff --git a/src/lib/MetadataInput.svelte b/src/lib/MetadataInput.svelte index 08c75b9..310420e 100644 --- a/src/lib/MetadataInput.svelte +++ b/src/lib/MetadataInput.svelte @@ -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();
@@ -131,14 +171,24 @@ - +
- +
+
+ + +
+ + +
+ {#if doBundle} + + {/if}

{returnMessage}

diff --git a/src/lib/PathInput.svelte b/src/lib/PathInput.svelte new file mode 100644 index 0000000..ed38668 --- /dev/null +++ b/src/lib/PathInput.svelte @@ -0,0 +1,35 @@ + + +
+ + {#if path != ""} +

{path}

+ {:else} +

Select Save Location...

+ {/if} +
+ + \ No newline at end of file