Skip to content

Commit

Permalink
feat: 在没有服务器配置会自动创建一个
Browse files Browse the repository at this point in the history
chore: 简化代码
  • Loading branch information
Zaitonn committed Dec 3, 2024
1 parent 72a8352 commit 8b09e77
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 110 deletions.
1 change: 1 addition & 0 deletions src/Serein.Core/Services/Servers/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ private void LoadAll()
if (!Directory.Exists(PathConstants.ServerConfigDirectory))
{
Directory.CreateDirectory(PathConstants.ServerConfigDirectory);
Add("myserver", new());
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Serein.Lite/Serein.Lite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
<ApplicationIcon>../Sources/logo.ico</ApplicationIcon>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<DefineConstants>LITE;</DefineConstants>
</PropertyGroup>


<ItemGroup>
<Resource Include="../Sources/logo.ico" />
<Compile Include="../Shared/Utils/DialogFactory.cs" />
<EmbeddedResource Include="../Sources/console/index.html" />
<EmbeddedResource Include="../Sources/console/custom.css" />

Expand Down
4 changes: 2 additions & 2 deletions src/Serein.Lite/Ui/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 3 additions & 52 deletions src/Serein.Plus/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Ookii.Dialogs.Wpf;

using Serein.Core;
using Serein.Core.Models.Output;
using Serein.Core.Services;
using Serein.Core.Utils;
using Serein.Core.Utils.Extensions;
using Serein.Plus.Pages;
using Serein.Plus.Pages.Settings;
using Serein.Plus.Services;
using Serein.Plus.Services.Loggers;
using Serein.Plus.Utils;
using Serein.Plus.ViewModels;

namespace Serein.Plus;
Expand All @@ -27,9 +24,9 @@ public partial class App : Application
public App()
{
ShutdownMode = ShutdownMode.OnMainWindowClose;
DispatcherUnhandledException += static (_, e) => ShowErrorDialog(e.Exception);
DispatcherUnhandledException += static (_, e) => DialogFactory.ShowErrorDialog(e.Exception);
AppDomain.CurrentDomain.UnhandledException += static (_, e) =>
ShowErrorDialog((Exception)e.ExceptionObject);
DialogFactory.ShowErrorDialog((Exception)e.ExceptionObject);
}

private static IHost Build()
Expand Down Expand Up @@ -82,50 +79,4 @@ private void Application_Exit(object sender, ExitEventArgs e)
{
_app.StopAsync();
}

private static void ShowErrorDialog(Exception e)
{
try
{
var fileName = CrashHelper.CreateLog(e);
var button1 = new TaskDialogButton("GitHub Issue")
{
CommandLinkNote = "【推荐】在GitHub上反馈,方便作者定位和跟踪问题",
};
var button2 = new TaskDialogButton("交流群")
{
CommandLinkNote = "通过共同讨论分析和确定问题,但效率可能较低",
};

var dialog = new TaskDialog
{
Buttons = { new(ButtonType.Ok), button1, button2 },
CenterParent = true,
Content =
$"{e.GetType().FullName}: {e.Message} \r\n\r\n"
+ $"完整崩溃日志已保存在 {fileName},请先善用搜索引擎寻找解决方案。\r\n"
+ "在确定不是自身问题(如文件语法不正确、文件缺失等)后,你可以通过以下方式反馈此问题,帮助我们更好的改进 Serein!",
EnableHyperlinks = true,
Footer = "反馈问题时你应该上传崩溃日志文件,而不是此窗口的截图",
FooterIcon = TaskDialogIcon.Warning,
ExpandedInformation = e.StackTrace,
MainIcon = TaskDialogIcon.Error,
MainInstruction = "唔……崩溃了(っ °Д °;)っ",
WindowTitle = "Serein.Plus",
ButtonStyle = TaskDialogButtonStyle.CommandLinks,
};

var btn = dialog.ShowDialog();

if (btn == button1)
{
UrlConstants.Issues.OpenInBrowser();
}
else if (btn == button2)
{
UrlConstants.Group.OpenInBrowser();
}
}
catch { }
}
}
2 changes: 1 addition & 1 deletion src/Serein.Plus/Dialogs/WelcomeDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
官网文档:
</Run>
<Hyperlink NavigateUri="https://sereindev.github.io/" RequestNavigate="OnRequestNavigate">
serein.cc
sereindev.github.io
</Hyperlink>
</Paragraph>
</ListItem>
Expand Down
23 changes: 16 additions & 7 deletions src/Serein.Plus/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
using Serein.Core.Services.Servers;
using Serein.Core.Utils;
using Serein.Plus.Commands;
using Serein.Plus.Dialogs;
using Serein.Plus.Models;
using Serein.Plus.Pages;
using Serein.Plus.Services;
using Serein.Plus.Utils;

namespace Serein.Plus;

Expand Down Expand Up @@ -90,7 +90,14 @@ TitleUpdater titleUpdater
{
if (_updateChecker.Newest is not null)
{
Dispatcher.Invoke(() => ShowBalloonTip("发现新版本", _updateChecker.Newest.TagName, BalloonIcon.Info));
Dispatcher.Invoke(
() =>
ShowBalloonTip(
"发现新版本",
_updateChecker.Newest.TagName,
BalloonIcon.Info
)
);
}
};
}
Expand Down Expand Up @@ -156,7 +163,7 @@ private void Window_ContentRendered(object sender, EventArgs e)
{
if (SereinAppBuilder.StartForTheFirstTime)
{
new WelcomeDialog().ShowAsync();
DialogFactory.ShowWelcomeDialog();
}

if (FileLoggerProvider.IsEnabled)
Expand All @@ -167,9 +174,9 @@ private void Window_ContentRendered(object sender, EventArgs e)
Content = new TextBlock
{
Text =
$"在此模式下,应用程序会将完整的调试日志保存在\"{PathConstants.LogDirectory}/app\"目录下(可能很大很大很大,并对硬盘的读写速度产生一定影响)\r\n"
+ "除非你知道你在干什么 / 是开发者要求的,请不要在此模式下运行Serein!!\r\n\r\n"
+ "当然你也不需要太担心,若要退出此模式只需要重新启动就行啦 :D",
$"在此模式下,应用程序会将完整的调试日志保存在\"{PathConstants.LogDirectory}/app\"目录下(可能很大很大很大,并对硬盘的读写速度产生一定影响)\r\n"
+ "除非你知道你在干什么 / 是开发者要求的,请不要在此模式下运行Serein!!\r\n\r\n"
+ "当然你也不需要太担心,若要退出此模式只需要重新启动就行啦 :D",
},
CloseButtonText = "我知道了",
DefaultButton = ContentDialogButton.Close,
Expand Down Expand Up @@ -232,7 +239,9 @@ public void ShowInfoBar(InfoBarTask infoBarTask)
{
GlobalInfoBar.Title = infoBarTask.Title;
GlobalInfoBar.Content = infoBarTask.Content;
GlobalInfoBar.Message = string.IsNullOrEmpty(infoBarTask.Message) ? " " : infoBarTask.Message;
GlobalInfoBar.Message = string.IsNullOrEmpty(infoBarTask.Message)
? " "
: infoBarTask.Message;
GlobalInfoBar.Severity = infoBarTask.Severity;

var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
Expand Down
2 changes: 2 additions & 0 deletions src/Serein.Plus/Serein.Plus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
<UseWPF>true</UseWPF>
<ApplicationIcon>../Sources/logo.ico</ApplicationIcon>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<DefineConstants>PLUS;</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../Serein.Core/Serein.Core.csproj" />
<Resource Include="../Sources/logo.ico" />
<Compile Include="../Shared/Utils/DialogFactory.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/Serein.Tests/Services/NetPlugin/EventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public EventTests()
_netPluginLoader = _host.Services.GetRequiredService<NetPluginLoader>();

Directory.CreateDirectory(PathConstants.PluginsDirectory);
Directory.CreateDirectory(Path.Join(PathConstants.PluginsDirectory, "test"));
}

public void Dispose()
Expand All @@ -42,7 +43,7 @@ public void Dispose()
[Fact]
public async Task ShouldInvokePluginLoadedEvent()
{
CSharpCompilationOptionsHelper.Compile(
CSharpCompilationHelper.Compile(
"""
using System;
using System.Threading.Tasks;
Expand Down Expand Up @@ -92,7 +93,7 @@ protected override Task OnPluginsLoaded()
[Fact]
public async Task ShouldInvokeServerEvent()
{
CSharpCompilationOptionsHelper.Compile(
CSharpCompilationHelper.Compile(
"""
using System;
using System.Collections.Generic;
Expand Down
9 changes: 4 additions & 5 deletions src/Serein.Tests/Services/NetPlugin/LoadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public LoadTests()
_host = HostFactory.BuildNew();
_netPluginLoader = _host.Services.GetRequiredService<NetPluginLoader>();

Directory.CreateDirectory(PathConstants.PluginsDirectory);
Directory.CreateDirectory(Path.Join(PathConstants.PluginsDirectory, "test"));
}

Expand All @@ -41,7 +40,7 @@ public void Dispose()
[Fact]
public async Task ShouldNotLoadNetPluginWithoutValidPluginClass()
{
CSharpCompilationOptionsHelper.Compile(
CSharpCompilationHelper.Compile(
"""
namespace EmptyPlugin;
public class EmptyClass{}
Expand Down Expand Up @@ -73,7 +72,7 @@ public class EmptyClass{}
[Fact]
public async Task ShouldNotLoadNetPluginWithTwoPluginClasses()
{
CSharpCompilationOptionsHelper.Compile(
CSharpCompilationHelper.Compile(
"""
using Serein.Core.Models.Plugins.Net;
Expand Down Expand Up @@ -120,7 +119,7 @@ public override void Dispose() { }
[Fact]
public async Task ShouldLoadNetPluginWithValidAssembly()
{
CSharpCompilationOptionsHelper.Compile(
CSharpCompilationHelper.Compile(
"""
using Serein.Core.Models.Plugins.Net;
Expand Down Expand Up @@ -158,7 +157,7 @@ public override void Dispose() { }
[Fact]
public async Task ShouldLoadNetPluginWithoutSpecifyingEntryFile()
{
CSharpCompilationOptionsHelper.Compile(
CSharpCompilationHelper.Compile(
"""
using System;
using Serein.Core.Models.Plugins.Net;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Serein.Tests.Utils;

#pragma warning disable IL3000

public static class CSharpCompilationOptionsHelper
public static class CSharpCompilationHelper
{
private static readonly CSharpCompilationOptions Default = new CSharpCompilationOptions(
OutputKind.DynamicallyLinkedLibrary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using System;

using Ookii.Dialogs.WinForms;

using Serein.Core.Utils;
using Serein.Core.Utils.Extensions;

#if LITE
using Ookii.Dialogs.WinForms;
namespace Serein.Lite.Utils;
#elif PLUS
using Ookii.Dialogs.Wpf;
namespace Serein.Plus.Utils;
#endif

public static class DialogFactory
{
public static void ShowWelcomeDialog()
Expand Down Expand Up @@ -98,6 +103,7 @@ public static void ShowErrorDialog(Exception e)
catch { }
}

#if LITE
public static void ShowWarningDialogOfLogMode()
{
var dialog = new TaskDialog
Expand All @@ -115,4 +121,5 @@ public static void ShowWarningDialogOfLogMode()

dialog.ShowDialog();
}
#endif
}
41 changes: 3 additions & 38 deletions src/Sources/console/custom.css
Original file line number Diff line number Diff line change
@@ -1,41 +1,6 @@
/*
用于自定义特殊高亮样式
- 需以 ".custom> " 开头
- 用".[NAME]"指定高亮对象
*/
.custom > .file {
color: #688292;
}

.custom > .server {
color: #8bd645;
}

.custom > .debug {
color: #865fc5;
}

.custom > .error {
color: #d16969;
}

.custom > .warn {
color: #aa5612;
}

.custom > .info {
color: #20b2aa;
}

.custom > .LiteLoader,
.custom > .LiteXLoader,
.custom > .LLMoney {
color: #5a93c2;
}

/*
颜色参考来源:https://en.wikipedia.org/wiki/ANSI_escape_code
*/
/**
* 颜色参考来源:https://en.wikipedia.org/wiki/ANSI_escape_code
*/
.ansi30 {
color: #0c0c0c;
}
Expand Down

0 comments on commit 8b09e77

Please sign in to comment.