- Updated import paths for types and utilities in config-service, menu-service, script-execution-service, script-store-service, and window-service to reflect new structure. - Moved utility functions like debounce and cloneDeep to shared utilities. - Created new runtime and script types files to centralize type definitions. - Removed deprecated task-types and locale messages files. - Updated constants to use shared definitions and added new placeholders for providers. - Enhanced provider type information with additional placeholders for different languages.
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { CONFIG_KEYS } from '@runtime/lib/constants'
|
|
import logManager from '@electron/service/logger'
|
|
import configManager from '@electron/service/config-service'
|
|
import path from 'node:path'
|
|
import { app } from 'electron'
|
|
import { runtimeLocaleMessages, type RuntimeMessageTree } from '@electron/locales/messages'
|
|
|
|
const messages: Record<string, RuntimeMessageTree> = runtimeLocaleMessages
|
|
|
|
export function createTranslator() {
|
|
return (key?: string) => {
|
|
if (!key) return void 0;
|
|
try {
|
|
const keys = key?.split('.');
|
|
let result: any = messages[configManager.get(CONFIG_KEYS.LANGUAGE)] ?? messages.zh;
|
|
for (const _key of keys) {
|
|
result = result[_key];
|
|
}
|
|
return result as string;
|
|
} catch (e) {
|
|
logManager.error('failed to translate key:', key, e);
|
|
return key
|
|
}
|
|
}
|
|
}
|
|
|
|
let logo: string | void = void 0;
|
|
export function createLogo() {
|
|
if (logo != null) {
|
|
return logo;
|
|
}
|
|
// Use app.getAppPath() to get the application root directory
|
|
const appPath = app.getAppPath();
|
|
const iconPath = path.join(appPath, 'resources', 'icons', 'icon.ico');
|
|
logo = iconPath;
|
|
return logo;
|
|
}
|