Skip to content

Commit

Permalink
优化Desktop的日志展示内容,隐藏不影响主流程的错误提示内容;给房间列表删除和取消录制增加消息提示反馈
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKZL committed Jun 24, 2024
1 parent 6d511eb commit 601d699
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Desktop/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<ui:TitleBar Name="UI_TitleBar" Height="30" Title="DDTV5-Desktop" Grid.Row="0" Icon="pack://application:,,,/DDTV.ico" />
</Grid>
<Grid>
<ui:SnackbarPresenter Height="150" Name="ConfigSnackbar" VerticalAlignment="Bottom"></ui:SnackbarPresenter>
<ui:SnackbarPresenter Height="150" Name="MainSnackbar" VerticalAlignment="Bottom"></ui:SnackbarPresenter>
</Grid>
<ContentPresenter x:Name="RootContentDialogPresenter" />
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion Desktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Init()
Loaded += (_, _) => RootNavigation.Navigate(typeof(DefaultPage));
//初始化底部提示框
SnackbarService = Desktop.App._ServiceProvider.GetRequiredService<ISnackbarService>();
SnackbarService.SetSnackbarPresenter(ConfigSnackbar);
SnackbarService.SetSnackbarPresenter(MainSnackbar);
//初始化托盘
notify();
//初始化确认窗口
Expand Down
20 changes: 19 additions & 1 deletion Desktop/NetWork/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Desktop.NetWork
{
public class Get
{
static int GetErrorCount = 0;
static bool First = true;
public static T GetBody<T>(string url, Dictionary<string, string> _dic = null)
{
if (!string.IsNullOrEmpty(url) && url.Substring(0, 4) != "http")
Expand Down Expand Up @@ -59,8 +61,24 @@ public static T GetBody<T>(string url, Dictionary<string, string> _dic = null)
return A.data;
}
}
catch (Exception)
catch (Exception ex)
{
GetErrorCount++;
if (GetErrorCount > 30)
{
GetErrorCount = 0;
Log.Warn(nameof(GetBody), $"发起Get请求出错Conut达到50,如需查看详情,请查看sqlite日志文件");
}
if (First)
{
First = false;
Log.Warn(nameof(GetBody), $"发起Get请求出错,URL:[{url}],错误堆栈:\r\n{ex.ToString()}", ex);
}
else
{
Log.Warn(nameof(GetBody), $"发起Get请求出错,URL:[{url}],错误堆栈:\r\n{ex.ToString()}", ex, false);
}

return default;
}
}
Expand Down
20 changes: 18 additions & 2 deletions Desktop/NetWork/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Desktop.NetWork
{
public class Post
{
static int PostErrorCount = 0;
static bool First = true;
/// <summary>
/// 同步POST方法
/// </summary>
Expand Down Expand Up @@ -51,7 +53,7 @@ public static async Task<T> PostBody<T>(string url, Dictionary<string, string> _
dic.Remove("access_key_secret");
using (HttpClient client = new HttpClient())
{
client.Timeout = new TimeSpan(0,0,8);
client.Timeout = new TimeSpan(0, 0, 8);
var content = new FormUrlEncodedContent(dic);
var response = await client.PostAsync(url, content);
var responseString = response.Content.ReadAsStringAsync().Result;
Expand All @@ -61,7 +63,21 @@ public static async Task<T> PostBody<T>(string url, Dictionary<string, string> _
}
catch (Exception ex)
{
Log.Warn(nameof(PostBody),$"发起Post请求出错,URL:[{url}],错误堆栈:\r\n{ex.ToString()}",ex);
PostErrorCount++;
if (PostErrorCount > 30)
{
PostErrorCount = 0;
Log.Warn(nameof(PostBody), $"发起Post请求出错Conut达到50,如需查看详情,请查看sqlite日志文件");
}
if (First)
{
First = false;
Log.Warn(nameof(PostBody), $"发起Post请求出错,URL:[{url}],错误堆栈:\r\n{ex.ToString()}", ex);
}
else
{
Log.Warn(nameof(PostBody), $"发起Post请求出错,URL:[{url}],错误堆栈:\r\n{ex.ToString()}", ex, false);
}
return default;
}
}
Expand Down
21 changes: 21 additions & 0 deletions Desktop/Views/Control/CardControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ private void DelRoom_Click(object sender, RoutedEventArgs e)
if (State == null)
{
Log.Warn(nameof(DelRoom_Click), "调用Core的API[batch_delete_rooms]删除房间失败,返回的对象为Null,详情请查看Core日志", null, true);
Dispatcher.Invoke(() =>
{
MainWindow.SnackbarService.Show("删除房间失败", $"操作{dataCard.Nickname}({dataCard.Room_Id})时调用Core的API[batch_delete_rooms]删除房间失败", ControlAppearance.Danger, new SymbolIcon(SymbolRegular.ErrorCircle20), TimeSpan.FromSeconds(3));
});
return;
}
Dispatcher.Invoke(() =>
{
MainWindow.SnackbarService.Show("删除房间成功", $"{dataCard.Nickname}({dataCard.Room_Id})已从房间配置中删除", ControlAppearance.Success, new SymbolIcon(SymbolRegular.Checkmark20), TimeSpan.FromSeconds(3));
});
});

}
Expand All @@ -155,6 +165,17 @@ private void Cancel_Task_Click(object sender, RoutedEventArgs e)
if (State == false)
{
Log.Warn(nameof(DelRoom_Click), "调用Core的API[cancel_task]取消录制任务失败,详情请查看Core日志", null, true);
Dispatcher.Invoke(() =>
{
MainWindow.SnackbarService.Show("取消录制失败", $"操作{dataCard.Nickname}({dataCard.Room_Id})时调用Core的API[cancel_task]取消录制任务失败", ControlAppearance.Danger, new SymbolIcon(SymbolRegular.ErrorCircle20), TimeSpan.FromSeconds(3));
});
}
else
{
Dispatcher.Invoke(() =>
{
MainWindow.SnackbarService.Show("取消录制成功", $"已取消{dataCard.Nickname}({dataCard.Room_Id})的录制任务", ControlAppearance.Success, new SymbolIcon(SymbolRegular.Checkmark20), TimeSpan.FromSeconds(3));
});
}
});
}
Expand Down

0 comments on commit 601d699

Please sign in to comment.