i18n and UI fix

This commit is contained in:
2026-03-14 23:16:15 +08:00
parent 43289845fc
commit f7ad51b9ec
69 changed files with 5970 additions and 286 deletions

View File

@@ -15,6 +15,8 @@ import {
deleteVersion,
saveDownload,
saveBackup,
getLocale,
setLocale,
} from "./storage";
import { KintoneClient, createKintoneClient } from "./kintone-api";
import type { Result } from "@shared/types/ipc";
@@ -31,7 +33,9 @@ import type {
DownloadResult,
GetVersionsParams,
RollbackParams,
SetLocaleParams,
} from "@shared/types/ipc";
import type { LocaleCode } from "@shared/types/locale";
import type {
Domain,
DomainWithStatus,
@@ -45,6 +49,7 @@ import type {
} from "@shared/types/version";
import type { AppCustomizeParameter, AppDetail } from "@shared/types/kintone";
import { getDisplayName, getFileKey } from "@shared/utils/fileDisplay";
import { getErrorMessage } from "./errors";
// Cache for Kintone clients
const clientCache = new Map<string, KintoneClient>();
@@ -59,7 +64,7 @@ async function getClient(domainId: string): Promise<KintoneClient> {
const domainWithPassword = await getDomain(domainId);
if (!domainWithPassword) {
throw new Error(`Domain not found: ${domainId}`);
throw new Error(getErrorMessage("domainNotFound"));
}
const client = createKintoneClient(domainWithPassword);
@@ -81,7 +86,7 @@ function handle<P = void, T = unknown>(
const data = await handler(params as P);
return { success: true, data };
} catch (error) {
const message = error instanceof Error ? error.message : "Unknown error";
const message = error instanceof Error ? error.message : getErrorMessage("unknownError");
return { success: false, error: message };
}
});
@@ -114,7 +119,10 @@ function registerCreateDomain(): void {
if (duplicate) {
throw new Error(
`Domain "${params.domain}" with user "${params.username}" already exists. Please edit the existing domain instead.`,
getErrorMessage("domainDuplicate", {
domain: params.domain,
username: params.username,
}),
);
}
@@ -142,7 +150,7 @@ function registerUpdateDomain(): void {
const existing = domains.find((d) => d.id === params.id);
if (!existing) {
throw new Error(`Domain not found: ${params.id}`);
throw new Error(getErrorMessage("domainNotFound"));
}
const updated: Domain = {
@@ -188,7 +196,7 @@ function registerTestConnection(): void {
handle<string, DomainWithStatus>("testConnection", async (id) => {
const domainWithPassword = await getDomain(id);
if (!domainWithPassword) {
throw new Error(`Domain not found: ${id}`);
throw new Error(getErrorMessage("domainNotFound"));
}
const client = createKintoneClient(domainWithPassword);
@@ -223,7 +231,7 @@ function registerTestDomainConnection(): void {
const result = await client.testConnection();
if (!result.success) {
throw new Error(result.error || "Connection failed");
throw new Error(result.error || getErrorMessage("connectionFailed"));
}
return true;
@@ -320,7 +328,7 @@ function registerDeploy(): void {
const domainWithPassword = await getDomain(params.domainId);
if (!domainWithPassword) {
throw new Error(`Domain not found: ${params.domainId}`);
throw new Error(getErrorMessage("domainNotFound"));
}
// Get current app config for backup
@@ -410,7 +418,7 @@ function registerDownload(): void {
const domainWithPassword = await getDomain(params.domainId);
if (!domainWithPassword) {
throw new Error(`Domain not found: ${params.domainId}`);
throw new Error(getErrorMessage("domainNotFound"));
}
const appDetail = await client.getAppDetail(params.appId);
@@ -507,7 +515,27 @@ function registerRollback(): void {
handle<RollbackParams, DeployResult>("rollback", async (_params) => {
// This would read the version file and redeploy
// Simplified implementation - would need full implementation
throw new Error("Rollback not yet implemented");
throw new Error(getErrorMessage("rollbackNotImplemented"));
});
}
// ==================== Locale IPC Handlers ====================
/**
* Get the current locale
*/
function registerGetLocale(): void {
handle<void, LocaleCode>("getLocale", async () => {
return getLocale();
});
}
/**
* Set the locale
*/
function registerSetLocale(): void {
handle<SetLocaleParams, void>("setLocale", async (params) => {
setLocale(params.locale);
});
}
@@ -541,6 +569,10 @@ export function registerIpcHandlers(): void {
registerDeleteVersion();
registerRollback();
// Locale
registerGetLocale();
registerSetLocale();
console.log("IPC handlers registered");
}