Skip to content

Commit

Permalink
Ver 2.4.0-Alpha.1
Browse files Browse the repository at this point in the history
Fully Compatible to API v2.2.0 and Added Some Performance Optimization.
  • Loading branch information
Shiroiame-Kusu committed Dec 25, 2024
1 parent e9111dd commit 7713610
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 203 deletions.
13 changes: 11 additions & 2 deletions Kairo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Security.Policy;
using System.Text.RegularExpressions;
using System.Text;
using Kairo.Components.OAuth;

namespace Kairo
{
Expand Down Expand Up @@ -54,10 +55,18 @@ protected override void OnStartup(StartupEventArgs e)
// 处理启动参数

string[] args = e.Args;

OAuthCallbackHandler.Init();
ProcessStartupParameters(args);
base.OnStartup(e);

Cef.Initialize(new CefSettings()
{
//BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CEF"),
//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
LogSeverity = LogSeverity.Verbose,
LogFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs\\CEF.log")
});

}
protected override void OnExit(ExitEventArgs e)
{
Expand Down
18 changes: 18 additions & 0 deletions Kairo/Components/OAuth/Controllers/MainController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Kairo.Utils;
using Microsoft.AspNetCore.Mvc;
using System;

namespace Kairo.Components.OAuth.Controllers
{
[ApiController]
[Route("oauth")]
public class MainController : Controller
{
[HttpGet("callback")]
public IActionResult Callback() {
Access.MainWindow.Login(Request.Query["refresh_token"]);
Console.WriteLine(Request.Query["refresh_token"]);
return Ok();
}
}
}
24 changes: 24 additions & 0 deletions Kairo/Components/OAuth/OAuthCallbackHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;

namespace Kairo.Components.OAuth
{
class OAuthCallbackHandler
{
public OAuthCallbackHandler() {

}
public static void Init()
{
Task.Run(() => {
WebApplicationBuilder builder = WebApplication.CreateBuilder(["--urls=http://localhost:16092"]);
builder.Services.AddControllers();
WebApplication app = builder.Build();
app.UseRouting();
app.MapControllers();
app.RunAsync();
});
}
}
}
1 change: 0 additions & 1 deletion Kairo/DashBoard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public bool CheckIfFrpcInstalled()
}
return false;
}
return false;
}
public void DownloadFrpc()
{
Expand Down
33 changes: 13 additions & 20 deletions Kairo/Dashboard/Home.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public Home()

private async void CheckIsSignedTodayOrNot()
{
using (var hc = new HttpClient())
using (HttpClient hc = new())
{
hc.DefaultRequestHeaders.Add("Authorization",$"Bearer {Global.Config.Token}");
var result = await hc.GetAsync($"{Global.API}/api/v2/sign?username={Global.Config.Username}").Await().Content.ReadAsStringAsync();
hc.DefaultRequestHeaders.Add("Authorization",$"Bearer {Global.Config.AccessToken}");
var result = await hc.GetAsync($"{Global.API}/sign?user_id={Global.Config.ID}").Await().Content.ReadAsStringAsync();
if (result == null) return;
var temp = JObject.Parse(result);
if (int.Parse(temp["status"].ToString()) == 200)
Expand All @@ -64,22 +64,20 @@ private async void CheckIsSignedTodayOrNot()
});
}
}
else
{
Console.WriteLine(temp["status"].ToString() + temp["message"].ToString());
}

}
}

private void InitializeCustomComponents()
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CEF"));
Cef.Initialize(new CefSettings()
{
BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CEF"),
//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
LogSeverity = LogSeverity.Verbose,
LogFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs\\CEF.log")
});

InitializeComponent();

DataContext = this;
title_username.Text += Global.Config.Username;
Resources["BorderColor"] = Global.isDarkThemeEnabled ? Colors.White : Colors.LightGray;
Expand All @@ -92,8 +90,7 @@ private async void FetchAnnouncement()
{
using (HttpClient client = new())
{
client.BaseAddress = new Uri($"{Global.API}/api/v2/notice");
var result = await client.GetAsync(client.BaseAddress).Await().Content.ReadAsStringAsync();
var result = await client.GetAsync($"{Global.API}/notice").Await().Content.ReadAsStringAsync();
var result2 = JObject.Parse(result);
if (result2 != null && int.Parse(result2["status"].ToString()) == 200) {
var html = Markdown.ToHtml(result2["data"]["broadcast"].ToString());
Expand Down Expand Up @@ -161,9 +158,7 @@ private async void RefreshAvatar()
{
using (var client = new HttpClient())
{

client.BaseAddress = new Uri(MainWindow.Avatar);
var Avatar = await client.GetAsync(client.BaseAddress).Await().Content.ReadAsStreamAsync();
var Avatar = await client.GetAsync(MainWindow.Avatar).Await().Content.ReadAsStreamAsync();
var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Avatar.png");
var ApplyAvatar = () =>
{
Expand Down Expand Up @@ -225,8 +220,8 @@ private void ToSign_Click(object sender, RoutedEventArgs e)
Task.Run(() => {
using (var hc = new HttpClient())
{
hc.DefaultRequestHeaders.Add("Authorization", $"Bearer {Global.Config.Token}");
HttpResponseMessage responseMessage = hc.PostAsync($"{Global.API}/api/v2/sign?username={Global.Config.Username}",new FormUrlEncodedContent(new List<KeyValuePair<string, string>>() { new("","")})).Result;
hc.DefaultRequestHeaders.Add("Authorization", $"Bearer {Global.Config.AccessToken}");
HttpResponseMessage responseMessage = hc.PostAsync($"{Global.API}/sign?user_id={Global.Config.ID}",null).Result;


var temp = JObject.Parse(responseMessage.Content.ReadAsStringAsync().Result);
Expand Down Expand Up @@ -270,5 +265,3 @@ private void ToSign_Click(object sender, RoutedEventArgs e)
}
}


//BreakAutoCompileBecauseTheRewriteIsNOTFinished
13 changes: 5 additions & 8 deletions Kairo/Dashboard/ProxyList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,14 @@ await Dispatcher.InvokeAsync(() =>
// 封装隧道获取,采用异步请求防止主线程卡死
private static async Task<ObservableCollection<string>> GetProxiesListAsync()
{
// 获取用户名和Token
string username = Global.Config.Username;
string token = Global.Config.Token;
// 实例化序列
GetProxiesResponseObject responseObject;
// 创建新的 HttpClient 实例
using (var client = new HttpClient())
{
// 定义API链接
string url = $"{Global.API}/api/v2/proxy/all?username={username}";
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
string url = $"{Global.API}/proxy/all?user_id={Global.Config.ID}";
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {Global.Config.AccessToken}");
// 防止API报错
try
{
Expand All @@ -139,7 +136,7 @@ private static async Task<ObservableCollection<string>> GetProxiesListAsync()
}

if (responseObject.Status != 200)
{
{
if(responseObject.Status == 404)
{
return null;
Expand Down Expand Up @@ -595,8 +592,8 @@ private async void DeleteProxy_Click(object sender, RoutedEventArgs e)
{
using (HttpClient httpClient = new HttpClient()) {

httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Global.Config.Token}");
var b = httpClient.DeleteAsync($"{Global.API}/api/v2/proxy?username={Global.Config.Username}&proxy_id={this.ID}").Await();
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Global.Config.AccessToken}");
var b = httpClient.DeleteAsync($"{Global.API}/proxy?user_id={Global.Config.ID}&proxy_id={this.ID}").Await();
var a = b.Content.ReadAsStringAsync().Await();

if (a == null )
Expand Down
5 changes: 3 additions & 2 deletions Kairo/Dashboard/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ private void SignOut_Click(object sender, RoutedEventArgs e)
Access.DashBoard.Close();

Global.Config.FrpToken = null;
Global.Config.Token = null;
Global.Config.LoginToken = null;
Global.Config.RefreshToken = null;
Global.Config.AccessToken = null;
Global.Password = null;
new ConfigManager(FileMode.Create);
MainWindow.islogin = false;
Access.MainWindow.Width = double.NaN;
Access.MainWindow.VisibilityChange(false);
Access.MainWindow.Show();
}

Expand Down
15 changes: 11 additions & 4 deletions Kairo/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ internal static class Global
public static readonly string PATH = AppDomain.CurrentDomain.BaseDirectory;
public static readonly DateTime StartTime = DateTime.Now;
public static bool LoginedByConsole = false;
public const string Version = "2.3.0";
public const string Version = "2.4.0";
public const string Branch = "Alpha";
public const int Revision = 5;
public const int Revision = 1;
public static readonly BuildInfo BuildInfo = new();
public const string Developer = "Shiroiame-Kusu & Daiyangcheng";
public const string Copyright = "Copyright © 2021 - 2024 杭州樱芸网络科技有限公司 All Rights Reserved";
public const string Copyright = "Copyright © 2021 - 2025 杭州樱芸网络科技有限公司 All Rights Reserved";
public static Config Config = new();
public static bool isDarkThemeEnabled;
public static SecureString Password = new();
Expand All @@ -37,6 +37,13 @@ internal static class Global
"Tips:再急, 再急就给你Crash了"

};
public const string API = "https://api-v2.locyanfrp.cn";
public const string API = "https://api-v2.locyanfrp.cn/api/v2";
public class APIList
{
public const string GetUserInfo = $"{API}/user/info";
public const string GetAccessToken = $"{API}/auth/oauth/access-token";
public const string GetFrpToken = $"{API}/user/frp/token";
}
public const int APPID = 9;
}
}
10 changes: 6 additions & 4 deletions Kairo/Kairo.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
Expand Down Expand Up @@ -44,11 +44,13 @@
<PackageReference Include="Markdig" Version="0.37.0" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="WPF-UI" Version="2.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Drawing.Common" Version="8.0.1" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<None Update="resource\BSODTrigger.sys">
Expand Down
27 changes: 9 additions & 18 deletions Kairo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="1" >

<Grid Height="420" VerticalAlignment="center">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="120"/>
<RowDefinition Height="20"/>
<RowDefinition Height="*"/>

</Grid.RowDefinitions>

<Grid Grid.Row="1">
Expand All @@ -144,7 +144,7 @@
<ScaleTransform ScaleX="0.6" ScaleY="0.6"/>
</ui:ProgressRing.LayoutTransform>
</ui:ProgressRing>
<TextBlock VerticalAlignment="Center" Margin="15,0" FontSize="16" Text="正在自动登录">
<TextBlock VerticalAlignment="Center" Margin="15,0" FontSize="16" Text="正在登录">
</TextBlock>
</StackPanel>
</Grid>
Expand All @@ -164,19 +164,11 @@
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Height="70" Margin="20,10,20,0" Header="用户名" FontSize="12">
<ui:TextBox Foreground="Black" Grid.Row="0" MinHeight="30" VerticalAlignment="Center" ToolTip="用户名" Name="Username"/>
</GroupBox>

<GroupBox Grid.Row="1" Height="70" Margin="20,10" Header="密码" FontSize="12">
<PasswordBox Foreground="Black" Grid.Row="1" MinHeight="30" VerticalAlignment="Center" HorizontalAlignment="Stretch" ToolTip="密码" Name="Password"/>
</GroupBox>

<ui:Button Grid.Row="2" Margin="20,10" Content="登录" Height="30" VerticalAlignment="Center" HorizontalAlignment="Stretch" Name="_Login" Click="Login_Click"/>
<TextBlock Margin="20,10" VerticalAlignment="Bottom" HorizontalAlignment="Center" Text="使用OAuth进行登录" FontSize="18"/>
<ui:Button Grid.Row="2" Margin="20,10" Content="登录" Height="30" VerticalAlignment="Top" HorizontalAlignment="Stretch" Name="_Login" Click="Login_Click"/>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -205,12 +197,11 @@
</Border>
</Grid>
<TextBlock Name="Tips" Text="你瞅啥" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="Gray" FontSize="9">

</TextBlock>
</Grid>
</Grid>


</Grid>

</Grid>

</ui:UiWindow>
Loading

0 comments on commit 7713610

Please sign in to comment.