perf: no local api no local serve

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

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

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

Loading…
Cancel
Save