Skip to content

Commit

Permalink
tiny change.
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk569937453 committed Feb 26, 2024
1 parent b2a1430 commit 29e5c8c
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:

# ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main
runs-on: ${{ matrix.platform }}
# container:
# image: ${{ matrix.image }}
container:
image: ${{ matrix.image }}
steps:


Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## 主要功能
本地离线工具集合,包含以下功能:
- base64转码/解码:文本转base64,base64转文本,图片转base64,base64转图片
- 正则表达式
- 格式化:格式化json/yaml/xml
- urlEncode/urlDecode
- 摘要算法:计算文本的md5,sha256。计算多个文件的md5,sha256
Expand All @@ -10,6 +11,8 @@
- 调色板
- 文本对比工具
- 国密算法(SM2,SM3,SM4)
- 国际化:支持中文,英文
- 支持菜单项重排:将自己常用的功能置顶。

## relase 下载地址
https://github.com/lsk569937453/code-magic-public/releases
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"cmdk": "^0.2.0",
"date-fns": "^2.30.0",
"i18next": "^23.7.11",
"i18next-browser-languagedetector": "^7.2.0",
"lucide-react": "^0.263.1",
"next-themes": "^0.2.1",
"react": "^18.2.0",
Expand Down
11 changes: 10 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 44 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "code_magic"
version = "0.0.19"
version = "0.0.20"
description = "A development tools"
authors = ["lsk"]
license = "MIT"
Expand Down Expand Up @@ -45,6 +45,7 @@ hex = "0.4"
num = "0.4"
rusqlite = { version = "0.30.0", features = ["bundled"] }
serde_repr = "0.1.17"
sqlformat = "0.2.3"
[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
Expand Down
20 changes: 20 additions & 0 deletions src-tauri/src/common_tools/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::common_tools::crypto_algorithm::sm4_decrypt_with_error;
use crate::common_tools::crypto_algorithm::sm4_encrypt_with_error;
use crate::common_tools::crypto_algorithm::Sm2EncryptRequest;
use crate::common_tools::crypto_algorithm::Sm4EncryptRequest;
use crate::common_tools::format::foramt_pretty_sql_with_error;
use crate::common_tools::format::format_pretty_json_with_error;
use crate::common_tools::format::format_pretty_yaml_with_error;
use crate::common_tools::format::format_xml_with_error;
Expand Down Expand Up @@ -517,6 +518,25 @@ pub fn format_pretty_xml(source_string: String) -> String {
}
}
#[tauri::command]
pub fn foramt_pretty_sql(source_string: String) -> String {
match foramt_pretty_sql_with_error(source_string) {
Ok(item) => {
let res = BaseResponse {
response_code: 0,
response_msg: item,
};
serde_json::to_string(&res).unwrap()
}
Err(e) => {
let res = BaseResponse {
response_code: 1,
response_msg: e.to_string(),
};
serde_json::to_string(&res).unwrap()
}
}
}
#[tauri::command]
pub fn get_about_version() -> String {
match get_about_version_with_error() {
Ok(item) => {
Expand Down
10 changes: 9 additions & 1 deletion src-tauri/src/common_tools/format.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use quick_xml::events::Event;
use quick_xml::{Reader, Writer};

use sqlformat::*;
pub fn format_pretty_json_with_error(source_string: String) -> Result<String, anyhow::Error> {
let source: serde_json::value::Value =
serde_json::from_str(&source_string).map_err(|e| anyhow::anyhow!(e))?;
Expand All @@ -14,6 +14,14 @@ pub fn format_pretty_yaml_with_error(source_string: String) -> Result<String, an
let res = serde_yaml::to_string(&source)?;
Ok(res)
}
pub fn foramt_pretty_sql_with_error(source_string: String) -> Result<String, anyhow::Error> {
let res = format(
source_string.as_str(),
&QueryParams::None,
FormatOptions::default(),
);
Ok(res)
}
pub fn format_xml_with_error(source_string: String) -> Result<String, anyhow::Error> {
let mut buf = Vec::new();

Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn main() -> Result<(), anyhow::Error> {
format_pretty_json,
format_pretty_yaml,
format_pretty_xml,
foramt_pretty_sql,
get_about_version,
get_menu_config,
set_menu_index,
Expand Down
2 changes: 0 additions & 2 deletions src/dashboard/page/base64TextPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function Base64TextPage() {
const { toast } = useToast()

const base64Encode = async () => {
i18n.changeLanguage("zh");
if (currentInput === undefined || currentInput === "") {
toast({
variant: "destructive",
Expand All @@ -32,7 +31,6 @@ export function Base64TextPage() {
}
}
const base64Decode = async () => {
i18n.changeLanguage("en");

if (currentInput === undefined || currentInput === "") {
toast({
Expand Down
10 changes: 8 additions & 2 deletions src/dashboard/page/diffViewerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ export default function DiffViewerPage() {
setDifferValue(finalResult);
}
const differValueOnChange = (v: any) => {
console.log(v);
setDifferValue(v);
const [arr1,arr2]=v;
const newArr1=arr1.replaceAll('\r\n', '\n');
const newArr2=arr2.replaceAll('\r\n', '\n');
const newV=[];
newV.push(newArr1);
newV.push(newArr2);

setDifferValue(newV);
}
return (<div className="p-10 flex flex-col h-[calc(100vh-30px)]">
<div className="basis-11/12 mb-10">
Expand Down
7 changes: 4 additions & 3 deletions src/dashboard/page/formatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import FormatJsonPage from "./formatJsonPage";
import FormatYamlPage from './formatYamlPage';
import FormatXmlPage from "./formatXmlPage"


import FormatSqlPage from "./formatSqlPage";
export default function FormatPage() {
return (
<Tabs defaultValue="text" className="w-full h-full p-10 flex flex-col " >
<TabsList className="grid w-1/4 grid-cols-3 flex-initial" >
<TabsList className="grid w-1/4 grid-cols-4 flex-initial" >
<TabsTrigger value="text">JSON</TabsTrigger>
<TabsTrigger value="image">YAML</TabsTrigger>
<TabsTrigger value="xml">XML</TabsTrigger>
<TabsTrigger value="sql">SQL</TabsTrigger>

</TabsList>
<TabsContent value="text" className="w-full h-full"><FormatJsonPage/></TabsContent>
<TabsContent value="image" className="w-full h-full"><FormatYamlPage/></TabsContent>
<TabsContent value="xml" className="w-full h-full"><FormatXmlPage/></TabsContent>

<TabsContent value="sql" className="w-full h-full"><FormatSqlPage/></TabsContent>
</Tabs>
);
}
91 changes: 91 additions & 0 deletions src/dashboard/page/formatSqlPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Textarea } from "@/components/ui/textarea"
import { useState } from "react"
import { invoke } from "@tauri-apps/api/tauri";
import { Button } from "@/components/ui/button"
import { Card } from "@/components/ui/card"
import AceEditor from "react-ace";
import { useTheme } from "next-themes"
import { useToast } from "@/components/ui/use-toast"

import "ace-builds/src-noconflict/snippets/xml";
import "ace-builds/src-noconflict/mode-sql";
import "ace-builds/src-noconflict/theme-github";

import "ace-builds/src-noconflict/theme-monokai";

import "ace-builds/src-noconflict/ext-language_tools";
import { useTranslation, Trans } from "react-i18next";

export default function FormatSqlPage() {
const [currentInput, setCurrentInput] = useState();
const [validJson, setValidJson] = useState<object | null>(null);
const { setTheme, theme } = useTheme()
const { toast } = useToast()
const { t, i18n } = useTranslation();

const formatPrettyJson = async () => {
if (currentInput === undefined || currentInput === "") {
toast({
variant: "destructive",
title: t('toastMessage.errorMessageTile'),
description: t('jsonFormatPage.sourceNotEmptyMessageBody'),
})
return;
}
const { response_code, response_msg } = JSON.parse(await invoke("foramt_pretty_sql", { sourceString: currentInput }));
console.log(response_code);

if (response_code === 0) {
setCurrentInput(response_msg);
let json = JSON.parse(response_msg);
setValidJson(json);

} else {
toast({
variant: "destructive",
title: t('toastMessage.errorMessageTile'),
description: t('jsonFormatPage.sourceNotValidMessageBody'),
})
}
}

const handleValueChange = (e: any) => {
setCurrentInput(e);
}

return (
<div className="flex flex-col h-[calc(100vh-30px)]">
<div className="basis-8/12 mb-10">
<AceEditor
className="border-foreground/50 border rounded"
width="100%"
height="100%"
placeholder={t('formatToolsPage.formatInputPlaceHolder')}
mode="sql"
theme={theme === "dark" ? "monokai" : "github"}
name="blah2"
value={currentInput} onChange={handleValueChange}
fontSize={16}
editorProps={{ $blockScrolling: true }}

showPrintMargin={true}
showGutter={true}
highlightActiveLine={true}
setOptions={{
enableBasicAutocompletion: false,
enableLiveAutocompletion: false,
enableSnippets: false,
showLineNumbers: true,
tabSize: 2,
useWorker: false
}}

/>
</div>
<div className="1/12 mb-10">
<Button className="w-full" onClick={formatPrettyJson}>{t('formatToolsPage.buttonText')}</Button>
</div>

</div>
);
}
Loading

0 comments on commit 29e5c8c

Please sign in to comment.