Skip to content

Commit bfecc58

Browse files
authored
Merge pull request #3 from seekrays/v0.1.1
add cpp support & fix time format
2 parents 5f1adb2 + 49bc5b5 commit bfecc58

File tree

10 files changed

+99
-18
lines changed

10 files changed

+99
-18
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "SeekCode",
33
"private": true,
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -14,6 +14,7 @@
1414
"@codemirror/autocomplete": "^6.18.6",
1515
"@codemirror/basic-setup": "^0.20.0",
1616
"@codemirror/commands": "^6.8.1",
17+
"@codemirror/lang-cpp": "^6.0.3",
1718
"@codemirror/lang-css": "^6.3.1",
1819
"@codemirror/lang-go": "^6.0.1",
1920
"@codemirror/lang-html": "^6.4.9",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "SeekCode"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "A Tauri App"
55
authors = ["you"]
66
license = ""

src-tauri/src/commands.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ func main() {
237237
/// 获取当前时间戳(本地时间格式)
238238
#[tauri::command]
239239
pub fn get_current_timestamp() -> String {
240-
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
240+
// 使用 ISO 8601 格式,确保在所有系统上都能正确解析
241+
chrono::Local::now().format("%Y-%m-%dT%H:%M:%S").to_string()
241242
}
242243

243244
/// 获取支持的编程语言列表

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "SeekCode",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"identifier": "com.seekrays.seekcode",
66
"build": {
77
"beforeDevCommand": "pnpm dev",

src/components/CodeEditor.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { sql } from "@codemirror/lang-sql";
3737
import { markdown } from "@codemirror/lang-markdown";
3838
import { xml } from "@codemirror/lang-xml";
3939
import { yaml } from "@codemirror/lang-yaml";
40+
import { cpp } from "@codemirror/lang-cpp";
4041
4142
// Legacy modes for additional languages
4243
import { StreamLanguage } from "@codemirror/language";
@@ -97,6 +98,8 @@ const languageMap: Record<string, any> = {
9798
go: go(),
9899
rust: rust(),
99100
php: php(),
101+
cpp: cpp(),
102+
c: cpp(), // C 语言使用 C++ 的语法高亮
100103
csharp: StreamLanguage.define(csharp),
101104
102105
// 数据库

src/services/tauri.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ export async function getCurrentTimestamp(): Promise<string> {
3434
return await invoke("get_current_timestamp");
3535
} catch (error) {
3636
console.error("Failed to get current timestamp:", error);
37-
// 回退到前端本地时间
37+
// 回退到前端本地时间,使用 ISO 8601 格式
3838
const now = new Date();
3939
const year = now.getFullYear();
4040
const month = String(now.getMonth() + 1).padStart(2, "0");
4141
const day = String(now.getDate()).padStart(2, "0");
4242
const hours = String(now.getHours()).padStart(2, "0");
4343
const minutes = String(now.getMinutes()).padStart(2, "0");
4444
const seconds = String(now.getSeconds()).padStart(2, "0");
45-
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
45+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
4646
}
4747
}
4848

src/utils/language.ts

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const languageIcons: Record<string, string> = {
99
html: "🌐",
1010
go: "🐹",
1111
java: "☕",
12+
cpp: "⚡",
13+
c: "🔵",
1214
php: "🐘",
1315
sql: "🗄️",
1416
shell: "🐚",
@@ -20,22 +22,24 @@ export const languageIcons: Record<string, string> = {
2022
};
2123

2224
export const languages = [
23-
"javascript",
24-
"typescript",
25-
"vue",
26-
"rust",
27-
"python",
25+
"c",
26+
"cpp",
2827
"css",
29-
"html",
3028
"go",
29+
"html",
3130
"java",
32-
"php",
33-
"sql",
34-
"shell",
31+
"javascript",
3532
"json",
3633
"markdown",
37-
"yaml",
34+
"php",
35+
"python",
36+
"rust",
37+
"shell",
38+
"sql",
39+
"typescript",
40+
"vue",
3841
"xml",
42+
"yaml",
3943
"text",
4044
];
4145

@@ -165,6 +169,48 @@ export function detectLanguage(content: string): string {
165169
return "java";
166170
}
167171

172+
// 检测 C++
173+
if (
174+
content.includes("#include") ||
175+
content.includes("std::") ||
176+
content.includes("namespace ") ||
177+
content.includes("class ") ||
178+
content.includes("template<") ||
179+
content.includes("cout <<") ||
180+
content.includes("cin >>") ||
181+
content.includes("vector<") ||
182+
content.includes("string ") ||
183+
content.includes("int main(") ||
184+
content.includes("void ") ||
185+
content.includes("const ") ||
186+
content.includes("&") ||
187+
content.includes("->")
188+
) {
189+
return "cpp";
190+
}
191+
192+
// 检测 C
193+
if (
194+
content.includes("#include") ||
195+
content.includes("stdio.h") ||
196+
content.includes("stdlib.h") ||
197+
content.includes("printf(") ||
198+
content.includes("scanf(") ||
199+
content.includes("malloc(") ||
200+
content.includes("free(") ||
201+
content.includes("struct ") ||
202+
content.includes("typedef ") ||
203+
content.includes("int main(") ||
204+
content.includes("void ") ||
205+
content.includes("char ") ||
206+
content.includes("int ") ||
207+
content.includes("float ") ||
208+
content.includes("double ") ||
209+
content.includes("return 0;")
210+
) {
211+
return "c";
212+
}
213+
168214
// 检测 PHP
169215
if (
170216
content.includes("<?php") ||

src/utils/time.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,34 @@ import { useI18n } from "vue-i18n";
22

33
export function formatTime(dateInput: Date | string): string {
44
const { t, locale } = useI18n();
5-
const date = typeof dateInput === "string" ? new Date(dateInput) : dateInput;
5+
6+
let date: Date;
7+
8+
if (typeof dateInput === "string") {
9+
// 尝试解析时间字符串
10+
let parsedDate: Date | null = null;
11+
12+
// 尝试直接解析
13+
try {
14+
parsedDate = new Date(dateInput);
15+
if (!isNaN(parsedDate.getTime())) {
16+
date = parsedDate;
17+
} else {
18+
// 尝试将空格替换为 T 来解析
19+
const isoStr = dateInput.replace(" ", "T");
20+
parsedDate = new Date(isoStr);
21+
if (!isNaN(parsedDate.getTime())) {
22+
date = parsedDate;
23+
} else {
24+
return t("time.invalid_date");
25+
}
26+
}
27+
} catch {
28+
return t("time.invalid_date");
29+
}
30+
} else {
31+
date = dateInput;
32+
}
633

734
// 检查日期是否有效
835
if (isNaN(date.getTime())) {

0 commit comments

Comments
 (0)