Skip to content

Commit

Permalink
Ver 2.4.0-Alpha.1 Hotfix 1
Browse files Browse the repository at this point in the history
Deprecate CefSharp.
Use Webview2 Instead.
  • Loading branch information
Shiroiame-Kusu committed Dec 26, 2024
1 parent adb7938 commit 0a7832d
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 96 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build

on:
push:
Expand Down Expand Up @@ -34,10 +34,7 @@ jobs:
- name: Build the project(Release)
run: dotnet build -p:Configuration=Release "Kairo/Kairo.csproj"

- name: Build the project(Debug)
run: dotnet build "Kairo/Kairo.csproj"

- name: Upload Kairo(Release,dotnet6-windows)
- name: Upload Kairo(Release,dotnet9-windows)
uses: actions/upload-artifact@v4
with:
name: Kairo_dotnet9
Expand All @@ -64,7 +61,7 @@ jobs:
- name: Upload Kairo(Publish,Single File)
uses: actions/upload-artifact@v4
with:
name: Kairo_dotnet6_publish_SingleFile
name: Kairo_dotnet9_publish_SingleFile
path: ${{ github.workspace }}\Kairo\bin\Release\net9.0-windows\win-x64\publish
if-no-files-found: ignore

Expand Down
13 changes: 2 additions & 11 deletions Kairo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Security;
using CefSharp.Wpf;
using System.Runtime.ConstrainedExecution;
using CefSharp;
using System.Diagnostics;
using System.Security.Policy;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -58,19 +56,12 @@ protected override void OnStartup(StartupEventArgs e)
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)
{
Cef.Shutdown();
//Cef.Shutdown();
base.OnExit(e);
}
private static void CurrentDomain_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
Expand Down
3 changes: 2 additions & 1 deletion Kairo/Components/OAuth/OAuthCallbackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public OAuthCallbackHandler() {
public static void Init()
{
Task.Run(() => {
WebApplicationBuilder builder = WebApplication.CreateBuilder(["--urls=http://localhost:16092"]);
string[] a = { "--urls=http://localhost:16092" };
WebApplicationBuilder builder = WebApplication.CreateBuilder(a);
builder.Services.AddControllers();
WebApplication app = builder.Build();
app.UseRouting();
Expand Down
7 changes: 2 additions & 5 deletions Kairo/Dashboard/Home.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Kairo.Dashboard"
xmlns:cefSharpCore="clr-namespace:CefSharp;assembly=CefSharp.Core"
xmlns:cefSharpWpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Home">
Expand Down Expand Up @@ -44,9 +43,7 @@
CornerRadius="8"
Background="{DynamicResource ControlFillColorDefaultBrush}"
>
<cefSharpWpf:ChromiumWebBrowser x:Name="Browser">

</cefSharpWpf:ChromiumWebBrowser>
<wv2:WebView2 x:Name="webView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DefaultBackgroundColor="transparent"/>
</Border>
</Grid>
<Grid Grid.Row="1">
Expand Down
58 changes: 17 additions & 41 deletions Kairo/Dashboard/Home.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
using System.Security.Cryptography;
using Markdig;
using System.Windows.Controls;
using CefSharp;
using CefSharp.Wpf;
using System.Text;
using HtmlAgilityPack;
using System.Linq;
Expand Down Expand Up @@ -74,16 +72,14 @@ private async void CheckIsSignedTodayOrNot()

private void InitializeCustomComponents()
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CEF"));

InitializeComponent();

DataContext = this;
title_username.Text += Global.Config.Username;
Resources["BorderColor"] = Global.isDarkThemeEnabled ? Colors.White : Colors.LightGray;
Traffic.Text += $"{(MainWindow.Traffic / 1024)}GB";
BandWidth.Text += $"{MainWindow.Inbound * 8 / 1024}/{MainWindow.Outbound * 8 / 1024}Mbps";
}

private async void FetchAnnouncement()
{
try
Expand All @@ -98,59 +94,39 @@ private async void FetchAnnouncement()
if (Global.isDarkThemeEnabled)
{
htmlDoc.LoadHtml(html);
var cssContent = "* { color: white; } a { color: aqua}";
var cssContent = "* { color: white; } a { color: aqua} html {background: none !important;}";
var styleNode = HtmlNode.CreateNode($"<style>{cssContent}</style>");
//var scriptNode = HtmlNode.CreateNode("<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/smooth-scrollbar.js'></script>");
var newHeadNode = htmlDoc.CreateElement("head");
newHeadNode.AppendChild(styleNode);
//newHeadNode.AppendChild(scriptNode);
htmlDoc.DocumentNode.PrependChild(newHeadNode);
InitializeWebView(htmlDoc.DocumentNode.OuterHtml);
}
else
{
InitializeWebView(html);
}
Browser.LoadHtml(Global.isDarkThemeEnabled ? htmlDoc.DocumentNode.OuterHtml: html, "http://localhost",Encoding.UTF8);
Browser.LoadingStateChanged += OnLoadingStateChanged;


}

}
}
catch (Exception _) {

CrashInterception.ShowException(_);
}
}
private void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
private async void InitializeWebView(string a)
{
if (!e.IsLoading)
//if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WebView2"))) Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WebView2"));
//await WebViewInstaller.CheckAndInstallAsync(false, false, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WebView2"));
Dispatcher.BeginInvoke(async () =>
{
string css = @"
html {
scroll-behavior: smooth;
}
::-webkit-scrollbar {
width: 8px;
opacity: 0;
transition: opacity 0.5s;
}
::-webkit-scrollbar-track {
background: #555;
border-radius: 10px; /* Rounded corners for the track */
}
::-webkit-scrollbar-thumb {
background: #f1f1f1;
border-radius: 10px; /* Rounded corners for the track */
}
::-webkit-scrollbar-thumb:hover {
background: #888;
}
.show-scrollbar ::-webkit-scrollbar {
opacity: 1;";
string script = $"var style = document.createElement('style'); style.innerHTML = `{css}`; document.head.appendChild(style);";
string script2 = "let timeout; document.addEventListener('scroll', function() { document.documentElement.classList.add('show-scrollbar'); clearTimeout(timeout); timeout = setTimeout(() => { document.documentElement.classList.remove('show-scrollbar'); }, 1000); });";
Browser.ExecuteScriptAsync(script);
Browser.ExecuteScriptAsync(script2);

}
await webView.EnsureCoreWebView2Async();
webView.CoreWebView2.NavigateToString(a);
});

}
private async void RefreshAvatar()
{
Expand Down
13 changes: 0 additions & 13 deletions Kairo/Dashboard/ProxyList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,21 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using Wpf.Ui.Controls;
using Kairo.Utils;
using Kairo.Dashboard;
using System.Windows.Threading;
using System.Text.RegularExpressions;
using System.IO;
using static Kairo.Utils.PNAP;
using MenuItem = Wpf.Ui.Controls.MenuItem;
using ContextMenu = System.Windows.Controls.ContextMenu;
using System.Windows.Media.Animation;
using System.Drawing;
using System.Windows.Shapes;
using Brushes = System.Windows.Media.Brushes;
using Color = System.Windows.Media.Color;
using Kairo.Utils.Components;
using Kairo.Extensions;
using Microsoft.Win32.SafeHandles;
using Newtonsoft.Json.Serialization;
using Kairo.Components;
using System.Security.Policy;
using System.Windows.Forms;
using CefSharp.Wpf;
using Application = System.Windows.Application;
using HorizontalAlignment = System.Windows.HorizontalAlignment;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
Expand Down
13 changes: 0 additions & 13 deletions Kairo/Dashboard/Settings.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
using Kairo.Utils;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;
using TextBox = System.Windows.Controls.TextBox;

namespace Kairo.Dashboard
{
Expand Down
12 changes: 6 additions & 6 deletions Kairo/Kairo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
<Resource Include="resource\favicon2.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CefSharp.Wpf.NETCore" Version="126.2.180" />
<PackageReference Include="Downloader" Version="3.0.6" />
<PackageReference Include="HandyControl" Version="3.4.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.61" />
<PackageReference Include="Markdig" Version="0.37.0" />
<PackageReference Include="Downloader" Version="3.3.1" />
<PackageReference Include="HandyControl" Version="3.5.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
<PackageReference Include="Markdig" Version="0.39.1" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2903.40" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<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="9.0.0" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand Down
1 change: 1 addition & 0 deletions Kairo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private async void Login_Click(object sender, RoutedEventArgs e)
}
public async Task<bool> Login(string RefreshToken)
{
if (islogin) return false;
Global.Config.RefreshToken = RefreshToken;
VisibilityChange(true);
if (!string.IsNullOrEmpty(RefreshToken))
Expand Down
Loading

0 comments on commit 0a7832d

Please sign in to comment.