From 17261c770696fbf1736bbf0ad87768ed5bb36468 Mon Sep 17 00:00:00 2001 From: Mossimo Date: Tue, 4 May 2021 23:40:52 +0800 Subject: [PATCH] fix tipsmsg --- .../Services/Mvvm/ProxyService.cs | 16 +++-- .../Pages/ProxyScriptManagePageViewModel.cs | 61 +++++++++++-------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs index 8a0a2125a..d79e848e6 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs @@ -316,7 +316,7 @@ namespace System.Application.Services var jspath = await DI.Get().DownloadScript(basicsInfo.Content.UpdateLink); if (jspath.state) { - var build = await DI.Get().AddScriptAsync(jspath.path, build: false, order: 1, deleteFile: true, pid: basicsInfo.Content.Id,ignoreCache:true); + var build = await DI.Get().AddScriptAsync(jspath.path, build: false, order: 1, deleteFile: true, pid: basicsInfo.Content.Id, ignoreCache: true); if (build.state) { if (build.model != null) @@ -389,7 +389,15 @@ namespace System.Application.Services public async Task AddNewScript(FileInfo fileInfo, ScriptDTO? info, ScriptDTO? oldInfo = null) { IsLoading = true; - var item = await DI.Get().AddScriptAsync(fileInfo, info, oldInfo); + bool isbuild = true; + int order = 10; + if (oldInfo != null) + { + isbuild = oldInfo.IsBuild; + order = oldInfo.Order; + + } + var item = await DI.Get().AddScriptAsync(fileInfo, info, oldInfo, build: isbuild, order: order); if (item.state) { if (item.model != null) @@ -404,11 +412,11 @@ namespace System.Application.Services public async void RefreshScript() { var scriptList = await DI.Get().GetAllScript(); - ProxyScripts.Clear(); + ProxyScripts.Clear(); if (ProxySettings.ScriptsStatus.Value.Any_Nullable() && scriptList.Any()) { foreach (var item in scriptList) - { + { if (ProxySettings.ScriptsStatus.Value.Contains(item.LocalId)) { item.Enable = true; diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs index 31c4d330b..1bf0b9494 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs @@ -142,42 +142,51 @@ namespace System.Application.UI.ViewModels public void DeleteNoFileScriptItemButton(ScriptDTO script) { - var result = MessageBoxCompat.ShowAsync(@AppResources.Script_NoFileDeleteItem , ThisAssembly.AssemblyTrademark, MessageBoxButtonCompat.OKCancel).ContinueWith(async (s) => - { - if (s.Result == MessageBoxResultCompat.OK) - { - var item = await DI.Get().DeleteScriptAsync(script); - if (item.state) - { - if (ProxyService.Current.ProxyScripts != null) - ProxyService.Current.ProxyScripts.Remove(script); + var result = MessageBoxCompat.ShowAsync(@AppResources.Script_NoFileDeleteItem, ThisAssembly.AssemblyTrademark, MessageBoxButtonCompat.OKCancel).ContinueWith(async (s) => + { + if (s.Result == MessageBoxResultCompat.OK) + { + var item = await DI.Get().DeleteScriptAsync(script); + if (item.state) + { + if (ProxyService.Current.ProxyScripts != null) + ProxyService.Current.ProxyScripts.Remove(script); - } - Toast.Show(item.msg); - } - }); + } + Toast.Show(item.msg); + } + }); } - + public void EditScriptItemButton(ScriptDTO script) { var url = Path.Combine(IOPath.AppDataDirectory, script.FilePath); - DI.Get().OpenFileByTextReader(url); - var result = MessageBoxCompat.ShowAsync(@AppResources.Script_EditTxt, ThisAssembly.AssemblyTrademark, MessageBoxButtonCompat.OKCancel).ContinueWith(async (s) => + var fileInfo = new FileInfo(url); + if (fileInfo.Exists) { - if (s.Result == MessageBoxResultCompat.OK) + DI.Get().OpenFileByTextReader(url); + var result = MessageBoxCompat.ShowAsync(@AppResources.Script_EditTxt, ThisAssembly.AssemblyTrademark, MessageBoxButtonCompat.OKCancel).ContinueWith(async (s) => { - var item = await DI.Get().AddScriptAsync(url, script,build: script.IsBuild,order:script.Order); - if (item.state) + if (s.Result == MessageBoxResultCompat.OK) { - if (ProxyService.Current.ProxyScripts.Items.Any() && item.model != null) + var item = await DI.Get().AddScriptAsync(url, script, build: script.IsBuild, order: script.Order, ignoreCache: true); + if (item.state) { - ProxyService.Current.ProxyScripts.Replace(script, item.model); - Toast.Show(AppResources.Success_.Format(AppResources.Script_Edit)); + if (ProxyService.Current.ProxyScripts.Items.Any() && item.model != null) + { + ProxyService.Current.ProxyScripts.Replace(script, item.model); + Toast.Show(AppResources.Success_.Format(AppResources.Script_Edit)); + } } } - } - }); + }); + } + else + { + DeleteNoFileScriptItemButton(script); + } + } public void OpenHomeScriptItemButton(ScriptDTO script) @@ -189,11 +198,11 @@ namespace System.Application.UI.ViewModels { if (script?.FilePath != null) { - var item = await DI.Get().AddScriptAsync(Path.Combine(IOPath.AppDataDirectory, script.FilePath),script,order:script.Order, build: script.IsBuild, ignoreCache:true); + var item = await DI.Get().AddScriptAsync(Path.Combine(IOPath.AppDataDirectory, script.FilePath), script, order: script.Order, build: script.IsBuild, ignoreCache: true); if (item.state) { if (item.model != null) - { + { ProxyService.Current.ProxyScripts.Replace(script, item.model); Toast.Show(AppResources.RefreshOK); }