Skip to content

Commit

Permalink
Trying to implement CefGlue instead of CefNet
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDotH committed May 2, 2023
1 parent ffd3c7c commit 2881a90
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 202 deletions.
Binary file removed Libraries/CefNet.Avalonia.dll
Binary file not shown.
Binary file removed Libraries/CefNet.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Avalonia.Threading;
using DevBase.Api.Apis.OpenLyricsClient.Structure.Json;
using DevBase.Async.Task;
using DevBase.Generics;
Expand Down Expand Up @@ -188,17 +189,20 @@ public async Task StartAuthorization()

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
CefAuthWindow cefAuthWindow = new CefAuthWindow("https://openlyricsclient.com/api/auth/spotify/begin", "/welcome");
Dispatcher.UIThread.InvokeAsync(async() =>
{
CefAuthWindow cefAuthWindow = new CefAuthWindow("https://openlyricsclient.com/api/auth/spotify/begin", "/welcome");
cefAuthWindow.Width = 1100;
cefAuthWindow.Height = 850;
cefAuthWindow.Title = "Connect to spotify";
cefAuthWindow.Width = 1100;
cefAuthWindow.Height = 850;
cefAuthWindow.Title = "Connect to spotify";
cefAuthWindow.ShowDialog<string>(MainWindow.Instance);
await cefAuthWindow.ShowDialog(MainWindow.Instance);
token = await cefAuthWindow.GetAuthCode();
token = await cefAuthWindow.GetAuthCode();
cefAuthWindow.Close();
cefAuthWindow.Close();
});
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Expand Down
64 changes: 0 additions & 64 deletions OpenLyricsClient/External/CefNet/CefNetImplementation.cs

This file was deleted.

91 changes: 0 additions & 91 deletions OpenLyricsClient/External/CefNet/Utils/CefSetup.cs

This file was deleted.

10 changes: 1 addition & 9 deletions OpenLyricsClient/External/CefNet/View/CefAuthWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:avalonia="clr-namespace:CefNet.Avalonia;assembly=CefNet.Avalonia"
Background="White"
mc:Ignorable="d"
d:DesignWidth="800" d:DesignHeight="450"
WindowStartupLocation="CenterScreen"
x:Class="OpenLyricsClient.External.CefNet.View.CefAuthWindow"

Title="CefAuthWindow">

<Grid >
<avalonia:WebView Name="AuthWebView"
BrowserCreated="WebView_OnBrowserCreated"
AddressChange="AuthWebView_OnAddressChange"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"/>
</Grid>
<Decorator Name="WebViewContainer"/>
</Window>
27 changes: 20 additions & 7 deletions OpenLyricsClient/External/CefNet/View/CefAuthWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using CefNet;
using CefNet.Avalonia;
using OpenLyricsClient.Backend;
using OpenLyricsClient.External.CefNet.Structure;
using Xilium.CefGlue.Avalonia;

namespace OpenLyricsClient.External.CefNet.View;

Expand All @@ -22,7 +21,7 @@ public partial class CefAuthWindow : Window
private string _accessToken;
private string _refreshToken;

private WebView _authWebView;
private AvaloniaCefBrowser _authWebView;

public CefAuthWindow()
{
Expand All @@ -34,11 +33,26 @@ public CefAuthWindow()
this._refreshToken = string.Empty;

InitializeComponent();

Decorator webViewContainer = this.Get<Decorator>(nameof(WebViewContainer));

AvaloniaCefBrowser browser = new AvaloniaCefBrowser();
browser.Address = "https://google.de";
/*browser.AddressChanged += BrowserOnAddressChanged;*/

webViewContainer.Child = browser;

this._authWebView = browser;

#if DEBUG
this.AttachDevTools();
#endif
}


private void BrowserOnAddressChanged(object sender, string address)
{
}

public CefAuthWindow(string authUrl, string authCompleteIDentifier) : this()
{
this._authURL = authUrl;
Expand All @@ -48,15 +62,14 @@ public CefAuthWindow(string authUrl, string authCompleteIDentifier) : this()
this._accessToken = string.Empty;
this._refreshToken = string.Empty;

this._authWebView = this.Get<WebView>(nameof(AuthWebView));
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}

private void WebView_OnBrowserCreated(object? sender, EventArgs e)
/*private void WebView_OnBrowserCreated(object? sender, EventArgs e)
{
this._authWebView.Navigate(this._authURL);
}
Expand All @@ -78,7 +91,7 @@ private void AuthWebView_OnAddressChange(object? sender, AddressChangeEventArgs
}
}
}
}
}*/

public async Task<Token> GetAuthCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Avalonia.Platform;
using Avalonia.Rendering.SceneGraph;
using Avalonia.Skia;
using CefNet;
using OpenLyricsClient.Backend.Utils;
using SkiaSharp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SettingsSpotifyViewModel()
Core.INSTANCE.SettingsHandler.SettingsChanged += SettingManagerOnSettingsChanged;

DisconnectFromSpotify = ReactiveCommand.CreateFromTask(DisconnectSpotify);
ConnectToSpotify = ReactiveCommand.CreateFromTask(StartSpotifyAuthFlow);
ConnectToSpotify = ReactiveCommand.Create(StartSpotifyAuthFlow);
}

private async Task DisconnectSpotify()
Expand All @@ -42,7 +42,7 @@ private async Task DisconnectSpotify()
await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "IsSpotifyConnected");
}

private async Task StartSpotifyAuthFlow()
private void StartSpotifyAuthFlow()
{
/*if (Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected == false &&
Core.INSTANCE.SettingManager.Settings.SpotifyAccess?.Statistics != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
Expand All @@ -18,8 +19,10 @@
using OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify;
using OpenLyricsClient.Backend.Settings.Sections.Lyrics;
using OpenLyricsClient.Backend.Structure.Other;
using OpenLyricsClient.External.CefNet.View;
using OpenLyricsClient.Frontend.Models.Elements;
using OpenLyricsClient.Frontend.Structure;
using OpenLyricsClient.Frontend.View.Windows;
using SpotifyAPI.Web;
using Image = Avalonia.Controls.Image;
using ResponseData = DevBase.Web.ResponseData.ResponseData;
Expand Down
1 change: 0 additions & 1 deletion OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:pages="clr-namespace:OpenLyricsClient.Frontend.View.Pages"
xmlns:assists="clr-namespace:Material.Styles.Assists;assembly=Material.Styles"
xmlns:windows="clr-namespace:OpenLyricsClient.Frontend.Models.Windows"
xmlns:avalonia="clr-namespace:CefNet.Avalonia;assembly=CefNet.Avalonia"
mc:Ignorable="d"
Width="1500"
Height="800"
Expand Down
2 changes: 0 additions & 2 deletions OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using CefNet.Avalonia;
using CefNet.WinApi;
using ScalableWindow = OpenLyricsClient.Frontend.Scaling.ScalableWindow;

namespace OpenLyricsClient.Frontend.View.Windows
Expand Down
Loading

0 comments on commit 2881a90

Please sign in to comment.