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> /// <param name="e"></param>
private void Exit_Click(object sender, EventArgs e) private void Exit_Click(object sender, EventArgs e)
{ {
vm.Dispose();
notifyIcon.Dispose(); notifyIcon.Dispose();
Environment.Exit(0); Environment.Exit(0);
} }

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

@ -14,12 +14,12 @@ using STranslate.Util;
namespace STranslate.ViewModel namespace STranslate.ViewModel
{ {
public class MainVM : BaseVM public class MainVM : BaseVM, IDisposable
{ {
public MainVM() public MainVM()
{ {
if (!InitialConfig()) if (!ReadConfig())
{ {
Task.Delay(3000); Task.Delay(3000);
Environment.Exit(-1); Environment.Exit(-1);
@ -75,7 +75,7 @@ namespace STranslate.ViewModel
/// 初始化配置文件 /// 初始化配置文件
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private bool InitialConfig() private bool ReadConfig()
{ {
try try
{ {
@ -98,8 +98,8 @@ namespace STranslate.ViewModel
} }
//从配置读取source target //从配置读取source target
InputComboSelected = GlobalConfig.SourceLanguage.GetDescription(); InputComboSelected = GlobalConfig.SourceLanguage;
OutputComboSelected = GlobalConfig.TargetLanguage.GetDescription(); OutputComboSelected = GlobalConfig.TargetLanguage;
return true; return true;
} }
@ -109,6 +109,25 @@ namespace STranslate.ViewModel
return false; 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>
/// 自动识别语种 /// 自动识别语种
/// </summary> /// </summary>
@ -206,6 +225,11 @@ namespace STranslate.ViewModel
OutputTxt = ex.Message; OutputTxt = ex.Message;
} }
} }
public void Dispose()
{
WriteConfig();
}
#endregion handle #endregion handle
#region Params #region Params

Loading…
Cancel
Save