|
@@ -13,10 +13,7 @@ const Log = require('ee-core/log');
|
|
|
|
|
|
|
|
const { readConfigFile } = require('../utils/config');
|
|
const { readConfigFile } = require('../utils/config');
|
|
|
const configDeault = readConfigFile();
|
|
const configDeault = readConfigFile();
|
|
|
-const errData = {
|
|
|
|
|
- msg :'请求失败,请联系管理员',
|
|
|
|
|
- code:999
|
|
|
|
|
-}
|
|
|
|
|
|
|
+const { t } = require('../config/i18n');
|
|
|
const sharp = require('sharp'); // 确保安装:npm install sharp
|
|
const sharp = require('sharp'); // 确保安装:npm install sharp
|
|
|
|
|
|
|
|
|
|
|
|
@@ -40,7 +37,7 @@ class UtilsController extends Controller {
|
|
|
const targetName = exePath || exeName;
|
|
const targetName = exePath || exeName;
|
|
|
|
|
|
|
|
if (!targetName) {
|
|
if (!targetName) {
|
|
|
- throw new Error('缺少可执行文件名称');
|
|
|
|
|
|
|
+ throw new Error(t('utils.missingExeName'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const isPackaged = app.isPackaged;
|
|
const isPackaged = app.isPackaged;
|
|
@@ -82,7 +79,7 @@ class UtilsController extends Controller {
|
|
|
const resolvedPath = candidates.find((filePath) => filePath && fs.existsSync(filePath));
|
|
const resolvedPath = candidates.find((filePath) => filePath && fs.existsSync(filePath));
|
|
|
|
|
|
|
|
if (!resolvedPath) {
|
|
if (!resolvedPath) {
|
|
|
- throw new Error(`未找到工具:${targetName}`);
|
|
|
|
|
|
|
+ throw new Error(t('utils.toolNotFound', { name: targetName }));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 如果已经有正在运行的子进程,则先关闭旧进程,再重新启动新的(保证始终只有一个进程,同时刷新页面参数)
|
|
// 如果已经有正在运行的子进程,则先关闭旧进程,再重新启动新的(保证始终只有一个进程,同时刷新页面参数)
|
|
@@ -121,7 +118,7 @@ class UtilsController extends Controller {
|
|
|
console.error('runExternalTool error:', error);
|
|
console.error('runExternalTool error:', error);
|
|
|
return {
|
|
return {
|
|
|
code: 1,
|
|
code: 1,
|
|
|
- msg: error.message || '运行外部工具失败'
|
|
|
|
|
|
|
+ msg: error.message || t('utils.runExternalToolFailed')
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -196,10 +193,10 @@ class UtilsController extends Controller {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async openDirectory(optiops={
|
|
async openDirectory(optiops={
|
|
|
- title:"选择文件夹"
|
|
|
|
|
|
|
+ title: t('utils.selectFolder')
|
|
|
}){
|
|
}){
|
|
|
const filePaths = dialog.showOpenDialogSync({
|
|
const filePaths = dialog.showOpenDialogSync({
|
|
|
- title:optiops.title || '选择文件夹',
|
|
|
|
|
|
|
+ title:optiops.title || t('utils.selectFolder'),
|
|
|
properties: ['openDirectory']
|
|
properties: ['openDirectory']
|
|
|
})
|
|
})
|
|
|
if(filePaths[0]) return filePaths[0];
|
|
if(filePaths[0]) return filePaths[0];
|
|
@@ -237,18 +234,18 @@ class UtilsController extends Controller {
|
|
|
|
|
|
|
|
async openImage(
|
|
async openImage(
|
|
|
optiops= {
|
|
optiops= {
|
|
|
- title:"选择图片",
|
|
|
|
|
|
|
+ title: t('utils.selectImage'),
|
|
|
filters:[
|
|
filters:[
|
|
|
- { name: '支持JPG,png,gif', extensions: ['jpg','jpeg','png'] },
|
|
|
|
|
|
|
+ { name: t('utils.supportImageFormats'), extensions: ['jpg','jpeg','png'] },
|
|
|
],
|
|
],
|
|
|
}
|
|
}
|
|
|
){
|
|
){
|
|
|
|
|
|
|
|
const filePaths = dialog.showOpenDialogSync({
|
|
const filePaths = dialog.showOpenDialogSync({
|
|
|
- title:optiops.title || '选择图片',
|
|
|
|
|
|
|
+ title:optiops.title || t('utils.selectImage'),
|
|
|
properties:['openFile'],
|
|
properties:['openFile'],
|
|
|
filters:optiops.filters || [
|
|
filters:optiops.filters || [
|
|
|
- { name: '支持JPG,png,gif', extensions: ['jpg','jpeg','png'] },
|
|
|
|
|
|
|
+ { name: t('utils.supportImageFormats'), extensions: ['jpg','jpeg','png'] },
|
|
|
]
|
|
]
|
|
|
})
|
|
})
|
|
|
const filePath = filePaths[0];
|
|
const filePath = filePaths[0];
|
|
@@ -292,7 +289,7 @@ class UtilsController extends Controller {
|
|
|
const { app } = require('electron');
|
|
const { app } = require('electron');
|
|
|
const bundles = payload.bundles || [];
|
|
const bundles = payload.bundles || [];
|
|
|
if (!Array.isArray(bundles) || !bundles.length) {
|
|
if (!Array.isArray(bundles) || !bundles.length) {
|
|
|
- return { code: 1, msg: '无可保存的图片数据' };
|
|
|
|
|
|
|
+ return { code: 1, msg: t('utils.noImageData') };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 运行目录:打包后为 EXE 所在目录,开发环境为项目根目录
|
|
// 运行目录:打包后为 EXE 所在目录,开发环境为项目根目录
|
|
@@ -355,22 +352,22 @@ class UtilsController extends Controller {
|
|
|
console.error('saveGeneratedImages error:', error);
|
|
console.error('saveGeneratedImages error:', error);
|
|
|
return {
|
|
return {
|
|
|
code: 1,
|
|
code: 1,
|
|
|
- msg: error.message || '保存生成图片失败',
|
|
|
|
|
|
|
+ msg: error.message || t('utils.saveImageFailed'),
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
async openFile(optiops= {
|
|
async openFile(optiops= {
|
|
|
- title:"选择文件",
|
|
|
|
|
|
|
+ title: t('utils.selectFile'),
|
|
|
filters:[
|
|
filters:[
|
|
|
- { name: '支持JPG', extensions: ['jpg','jpeg'] },
|
|
|
|
|
|
|
+ { name: t('utils.supportImageFormats'), extensions: ['jpg','jpeg'] },
|
|
|
],
|
|
],
|
|
|
}){
|
|
}){
|
|
|
|
|
|
|
|
const filePaths = dialog.showOpenDialogSync({
|
|
const filePaths = dialog.showOpenDialogSync({
|
|
|
- title:optiops.title || '选择文件',
|
|
|
|
|
|
|
+ title:optiops.title || t('utils.selectFile'),
|
|
|
properties: ['openFile'],
|
|
properties: ['openFile'],
|
|
|
filters: optiops.filters || [
|
|
filters: optiops.filters || [
|
|
|
- { name: '选择文件' },
|
|
|
|
|
|
|
+ { name: t('utils.selectFile') },
|
|
|
]
|
|
]
|
|
|
})
|
|
})
|
|
|
if(filePaths[0]) return filePaths[0];
|
|
if(filePaths[0]) return filePaths[0];
|
|
@@ -510,6 +507,30 @@ class UtilsController extends Controller {
|
|
|
return { success: true, message: 'IPC is working', args }
|
|
return { success: true, message: 'IPC is working', args }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 设置语言(由前端调用,保持 Electron 和前端语言同步)
|
|
|
|
|
+ async setLanguage(args, event) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const { language } = args;
|
|
|
|
|
+ const fs = require('fs');
|
|
|
|
|
+
|
|
|
|
|
+ // 将语言设置写入缓存文件
|
|
|
|
|
+ const userDataPath = app.getPath('userData');
|
|
|
|
|
+ const langCachePath = path.join(userDataPath, 'language.json');
|
|
|
|
|
+
|
|
|
|
|
+ fs.writeFileSync(langCachePath, JSON.stringify({ language }), 'utf-8');
|
|
|
|
|
+
|
|
|
|
|
+ // 重新加载 i18n
|
|
|
|
|
+ const i18n = require('../config/i18n');
|
|
|
|
|
+ i18n.reloadTranslations();
|
|
|
|
|
+
|
|
|
|
|
+ console.log('Language set to:', language);
|
|
|
|
|
+ return { success: true, language };
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Failed to set language:', error);
|
|
|
|
|
+ return { success: false, error: error.message };
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async readFileImageForPath(filePath,maxWidth=1500){
|
|
async readFileImageForPath(filePath,maxWidth=1500){
|
|
|
|
|
|
|
|
const getMimeType = (fileName)=>{
|
|
const getMimeType = (fileName)=>{
|