perf: add write config

dev_config
SONGE9B3\song_pd_win11 2 years ago
parent aab8f0d387
commit a6d9a6ae09

@ -287,6 +287,7 @@ namespace STranslate
/// <param name="e"></param>
private void Exit_Click(object sender, EventArgs e)
{
vm.Dispose();
notifyIcon.Dispose();
Environment.Exit(0);
}

@ -18,8 +18,8 @@ namespace STranslate.Model
return new ConfigModel
{
IsBright = true,
SourceLanguage = LanguageEnum.AUTO,
TargetLanguage = LanguageEnum.AUTO,
SourceLanguage = LanguageEnum.AUTO.GetDescription(),
TargetLanguage = LanguageEnum.AUTO.GetDescription(),
SelectServer = 0,
Servers = new Server[]
{
@ -49,10 +49,10 @@ namespace STranslate.Model
public bool IsBright { get; set; }
[JsonProperty("sourceLanguage")]
public LanguageEnum SourceLanguage { get; set; }
public string SourceLanguage { get; set; }
[JsonProperty("targetLanguage")]
public LanguageEnum TargetLanguage { get; set; }
public string TargetLanguage { get; set; }
[JsonProperty("selectServer")]
public int SelectServer { get; set; }

@ -14,12 +14,12 @@ using STranslate.Util;
namespace STranslate.ViewModel
{
public class MainVM : BaseVM
public class MainVM : BaseVM, IDisposable
{
public MainVM()
{
if (!InitialConfig())
if (!ReadConfig())
{
Task.Delay(3000);
Environment.Exit(-1);
@ -75,7 +75,7 @@ namespace STranslate.ViewModel
/// 初始化配置文件
/// </summary>
/// <returns></returns>
private bool InitialConfig()
private bool ReadConfig()
{
try
{
@ -98,8 +98,8 @@ namespace STranslate.ViewModel
}
//从配置读取source target
InputComboSelected = GlobalConfig.SourceLanguage.GetDescription();
OutputComboSelected = GlobalConfig.TargetLanguage.GetDescription();
InputComboSelected = GlobalConfig.SourceLanguage;
OutputComboSelected = GlobalConfig.TargetLanguage;
return true;
}
@ -109,6 +109,25 @@ namespace STranslate.ViewModel
return false;
}
}
private void WriteConfig()
{
try
{
ConfigHelper.Instance.WriteConfig(new ConfigModel
{
IsBright = true,
SourceLanguage = InputComboSelected,
TargetLanguage = OutputComboSelected,
SelectServer = TranslationInterface.FindIndex(x => x == SelectedTranslationInterface),
Servers = GlobalConfig.Servers,
});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
/// <summary>
/// 自动识别语种
/// </summary>
@ -206,6 +225,11 @@ namespace STranslate.ViewModel
OutputTxt = ex.Message;
}
}
public void Dispose()
{
WriteConfig();
}
#endregion handle
#region Params

Loading…
Cancel
Save