Skip to content

Commit

Permalink
ready for first release
Browse files Browse the repository at this point in the history
  • Loading branch information
JPTomorrow committed Dec 13, 2022
1 parent 7ab30f1 commit 25f995a
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 14 deletions.
7 changes: 0 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
windows_subsystem = "windows"
)]

use serde_json::to_string;
use tauri::api::file;

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}

enum FileType {
TOML,
JSON,
Expand Down
19 changes: 12 additions & 7 deletions src/components/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { invoke } from "@tauri-apps/api/tauri";
import { open } from "@tauri-apps/api/dialog";
import { writeTextFile } from "@tauri-apps/api/fs";
import { useEffect, useState } from "react";
import { useState } from "react";
import { AiOutlineFileText } from "react-icons/ai";

type FileTextView = {
Expand Down Expand Up @@ -58,18 +58,17 @@ const FileUpload = ({ text }: { text?: string }) => {
err: err,
});
});
};

const writeOutputFiles = async () => {
var lastIndex = path.lastIndexOf("/");
var fileName = (ext: string) =>
path.slice(lastIndex + 1, path.length).split(".")[0] + "." + ext;
var newPath = path.slice(0, lastIndex + 1);

if (jsonView !== "")
await writeTextFile(newPath + fileName("json"), jsonView);
if (tomlView !== "")
await writeTextFile(newPath + fileName("toml"), tomlView);
if (yamlView !== "")
await writeTextFile(newPath + fileName("yaml"), yamlView);
if (jsonView) await writeTextFile(newPath + fileName("json"), jsonView);
if (tomlView) await writeTextFile(newPath + fileName("toml"), tomlView);
if (yamlView) await writeTextFile(newPath + fileName("yaml"), yamlView);
};
return (
<>
Expand Down Expand Up @@ -116,6 +115,12 @@ const FileUpload = ({ text }: { text?: string }) => {
</p>
) : null}
</div>
<br />
{jsonView || yamlView || tomlView ? (
<button onClick={writeOutputFiles} className="default-button mt-5">
Save Files
</button>
) : null}
</>
);
};
Expand Down
51 changes: 51 additions & 0 deletions test/Cargo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"build-dependencies": {
"tauri-build": {
"features": [],
"version": "1.2"
}
},
"dependencies": {
"serde_json": "1.0",
"tsu": "1.0.1",
"serde": {
"features": [
"derive"
],
"version": "1.0"
},
"tauri": {
"features": [
"dialog-open",
"dialog-save",
"fs-copy-file",
"fs-create-dir",
"fs-exists",
"fs-read-dir",
"fs-read-file",
"fs-write-file"
],
"version": "1.2"
}
},
"features": {
"custom-protocol": [
"tauri/custom-protocol"
],
"default": [
"custom-protocol"
]
},
"package": {
"authors": [
"you"
],
"description": "A Tauri App",
"edition": "2021",
"license": "",
"name": "tauri-desktop-app",
"repository": "",
"rust-version": "1.57",
"version": "0.0.0"
}
}
28 changes: 28 additions & 0 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "tauri-desktop-app"
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"
serde = { version = "1.0", features = ["derive"] }
tauri = {version = "1.2", features = ["dialog-open", "dialog-save", "fs-copy-file", "fs-create-dir", "fs-exists", "fs-read-dir", "fs-read-file", "fs-write-file"] }
tsu = "1.0.1"

[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" ]
37 changes: 37 additions & 0 deletions test/Cargo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
build-dependencies:
tauri-build:
features: []
version: '1.2'
dependencies:
serde_json: '1.0'
tsu: 1.0.1
serde:
features:
- derive
version: '1.0'
tauri:
features:
- dialog-open
- dialog-save
- fs-copy-file
- fs-create-dir
- fs-exists
- fs-read-dir
- fs-read-file
- fs-write-file
version: '1.2'
features:
custom-protocol:
- tauri/custom-protocol
default:
- custom-protocol
package:
authors:
- you
description: A Tauri App
edition: '2021'
license: ''
name: tauri-desktop-app
repository: ''
rust-version: '1.57'
version: 0.0.0

0 comments on commit 25f995a

Please sign in to comment.