perf: no local api no local serve

dev_without_third_libraries
DESKTOP-3BO4HSG\ksat 2 years ago
parent 5cd1f04799
commit c0b666f4f9

@ -21,6 +21,8 @@ namespace STranslate
{
InitializeComponent();
vm = (MainVM)DataContext;
InitView();
InitialTray();
@ -31,7 +33,6 @@ namespace STranslate
//{
// MessageBox.Show("全局快捷键有冲突,请您到设置中重新设置");
//}
vm = (MainVM)DataContext;
}
private void InitialTray()
@ -272,6 +273,7 @@ namespace STranslate
/// </summary>
private void DeepLStart()
{
if (!string.IsNullOrEmpty(vm.config.deepl?.url) && vm.config.deepl?.url != vm.defaultApi) return;
string strPathExe = AppDomain.CurrentDomain.BaseDirectory + "\\Static\\deepl-x86_64-pc-windows-gnu.exe";
process.StartInfo.FileName = strPathExe;
process.StartInfo.Arguments = null;//-s -t 可以用来关机、开机或重启
@ -288,6 +290,7 @@ namespace STranslate
/// </summary>
private void DeepLStop()
{
if (!string.IsNullOrEmpty(vm.config.deepl?.url) && vm.config.deepl?.url != vm.defaultApi) return;
process.Kill();//等待退出。
}
}

@ -18,9 +18,9 @@ namespace STranslate.ViewModel
//[System.Runtime.InteropServices.DllImport("deepl.dll", EntryPoint = "run")]
//extern static void run();
private static string ConfigPath => $"{AppDomain.CurrentDomain.BaseDirectory}STranslate.yml";
public static ConfigModel config = new ConfigModel();
public string defaultApi = "http://127.0.0.1:8000/translate";
private string ConfigPath => $"{AppDomain.CurrentDomain.BaseDirectory}STranslate.yml";
public ConfigModel config = new ConfigModel();
private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); }
public MainVM()
@ -34,7 +34,6 @@ namespace STranslate.ViewModel
OutputCombo = LanguageEnumDict.Keys.ToList();
OutputComboSelected = LanguageEnum.EN.GetDescription();
//TODO: fix no config
config = ConfigUtil.ReadConfig(ConfigPath);
//复制输入
@ -94,12 +93,14 @@ namespace STranslate.ViewModel
{
try
{
//清空输入框
OutputTxt = "翻译中...";
//获取结果
var translateResp = await TranslateUtil.TranslateDeepLAsync(config.deepl.url, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
//DeepL Api
var translateResp = await TranslateUtil.TranslateDeepLAsync(config.deepl?.url ?? defaultApi, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
//百度 Api
//var translateResp = await TranslateUtil.TranslateBaiduAsync(config.baidu.appid, config.baidu.secretKey, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
if (translateResp == string.Empty)

Loading…
Cancel
Save