refactor: rebuild desktop app with Tauri

This commit is contained in:
leookun committed 2026-08-24 02:49:00 +08:00
1 parent a3ec2a0dfc
commit 4053a7fb20
808 files changed
+87359 -181491

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
const integerFormatter = new Intl.NumberFormat("en-US");
const compactUnits = [
{ value: 1_000_000_000_000, suffix: "T" },
{ value: 1_000_000_000, suffix: "B" },
{ value: 1_000_000, suffix: "M" },
{ value: 1_000, suffix: "K" },
] as const;
function normalizeInteger(value: number) {
return Number.isFinite(value) ? Math.round(value) : 0;
}
function trimTrailingZeros(value: string) {
return value.replace(/\.0$/, "").replace(/(\.\d*[1-9])0+$/, "$1");
}
export function formatInteger(value: number) {
return integerFormatter.format(normalizeInteger(value));
}
export function formatCompactInteger(value: number) {
const number = normalizeInteger(value);
const unit = compactUnits.find(({ value: threshold }) => Math.abs(number) >= threshold);
if (!unit) return formatInteger(number);
const scaled = number / unit.value;
const fractionDigits = Math.abs(scaled) < 100 ? 1 : 0;
return `${trimTrailingZeros(scaled.toFixed(fractionDigits))}${unit.suffix}`;
}
+77
View File
@@ -0,0 +1,77 @@
const RELATIVE_UNIT_MS: Record<string, number> = {
分: 60_000,
分钟: 60_000,
min: 60_000,
mins: 60_000,
minute: 60_000,
minutes: 60_000,
小时: 60 * 60_000,
h: 60 * 60_000,
hour: 60 * 60_000,
hours: 60 * 60_000,
天: 24 * 60 * 60_000,
d: 24 * 60 * 60_000,
day: 24 * 60 * 60_000,
days: 24 * 60 * 60_000,
周: 7 * 24 * 60 * 60_000,
w: 7 * 24 * 60 * 60_000,
week: 7 * 24 * 60 * 60_000,
weeks: 7 * 24 * 60 * 60_000,
};
function localDate(parts: RegExpMatchArray) {
const [, year, month, day, hour = "0", minute = "0", second = "0"] = parts;
const value = new Date(+year, +month - 1, +day, +hour, +minute, +second);
return value.getFullYear() === +year
&& value.getMonth() === +month - 1
&& value.getDate() === +day
&& value.getHours() === +hour
&& value.getMinutes() === +minute
&& value.getSeconds() === +second
? value.getTime()
: null;
}
export function parseTimeInput(input: string, now = new Date()): number | null {
const value = input.trim().toLowerCase();
if (!value) return null;
if (value === "现在" || value === "now") return now.getTime();
if (value === "今天" || value === "today") {
const start = new Date(now);
start.setHours(0, 0, 0, 0);
return start.getTime();
}
if (value === "昨天" || value === "yesterday") {
const start = new Date(now);
start.setDate(start.getDate() - 1);
start.setHours(0, 0, 0, 0);
return start.getTime();
}
const relative = value.match(/^(\d+(?:\.\d+)?)\s*(分钟|分|mins?|minutes?|min|小时|hours?|h|天|days?|d|周|weeks?|w)\s*(?:前|ago)$/);
if (relative) return now.getTime() - Number(relative[1]) * RELATIVE_UNIT_MS[relative[2]];
if (/^\d{10}$/.test(value)) return Number(value) * 1_000;
if (/^\d{13}$/.test(value)) return Number(value);
const normalized = value
.replace(/年|\//g, "-")
.replace(/月/g, "-")
.replace(/日/g, " ")
.replace(/时/g, ":")
.replace(/分(?=\d)/g, ":")
.replace(/分/g, "")
.replace(/秒/g, "")
.trim();
const local = normalized.match(/^(\d{4})[-.](\d{1,2})[-.](\d{1,2})(?:[ t]+(\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2}))?)?$/);
if (local) return localDate(local);
const parsed = Date.parse(value);
return Number.isFinite(parsed) ? parsed : null;
}
export function formatTimeInput(date: Date) {
const part = (number: number) => String(number).padStart(2, "0");
return `${date.getFullYear()}-${part(date.getMonth() + 1)}-${part(date.getDate())} ${part(date.getHours())}:${part(date.getMinutes())}`;
}
@@ -0,0 +1,6 @@
export const defaultCustomHeaders = {
"User-Agent": "claude-cli/2.1.177 (external, cli)",
"anthropic-beta": "claude-code-20250219,context-1m-2025-08-07,interleaved-thinking-2025-05-14,redact-thinking-2026-02-12,context-management-2025-06-27,prompt-caching-scope-2026-01-05,mid-conversation-system-2026-04-07,effort-2025-11-24",
};
export const defaultCustomHeadersText = JSON.stringify(defaultCustomHeaders, null, 2);