Skip to content

Commit

Permalink
添加WebView2支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Poker-sang committed Aug 28, 2023
1 parent 77e2d0e commit 31f1471
Show file tree
Hide file tree
Showing 27 changed files with 975 additions and 284 deletions.
3 changes: 2 additions & 1 deletion DanmakuPlayer.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bangumi/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Danmaku/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Danmaku/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Flyout/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 2 additions & 0 deletions DanmakuPlayer/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using DanmakuPlayer.Services;
using Microsoft.UI.Xaml;
using WinUI3Utilities;
Expand All @@ -8,6 +9,7 @@ public partial class App : Application
{
public App()
{
Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--remote-debugging-port=9222");
InitializeComponent();
CurrentContext.Title = nameof(DanmakuPlayer);
AppContext.Initialize();
Expand Down
24 changes: 20 additions & 4 deletions DanmakuPlayer/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public partial record AppConfig
/// <summary>
/// 前景色
/// </summary>
/// <remarks>default: 0xFFA9A9A9</remarks>
public uint Foreground { get; set; } = 0xFFA9A9A9;
/// <remarks>default: 0xFFFFFFFF</remarks>
public uint Foreground { get; set; } = 0xFFFFFFFF;

#endregion

Expand All @@ -39,7 +39,7 @@ public partial record AppConfig
/// 倍速(times)
/// </summary>
/// <remarks>default: 1 ∈ [0.5, 2]</remarks>
public double PlaySpeed { get; set; } = 1;
public double PlaybackRate { get; set; } = 1;

/// <summary>
/// 帧率(second)
Expand Down Expand Up @@ -70,7 +70,7 @@ public partial record AppConfig
/// <inheritdoc cref="DanmakuDuration"/>
/// 方便计算使用float
[AttributeIgnore(typeof(SettingsViewModelAttribute<>), typeof(GenerateConstructorAttribute), typeof(AppContextAttribute<>))]
public float DanmakuActualDuration => (float)(DanmakuDuration * PlaySpeed);
public float DanmakuActualDuration => (float)(DanmakuDuration * PlaybackRate);

/// <summary>
/// 弹幕透明度
Expand Down Expand Up @@ -212,6 +212,22 @@ public partial record AppConfig

#endregion

#region 网页设置

/// <summary>
/// 使用WebView2
/// </summary>
/// <remarks>default: <see langword="true"/></remarks>
public bool EnableWebView2 { get; set; } = true;

/// <summary>
/// 使用WebView2
/// </summary>
/// <remarks>default: <see langword="true"/></remarks>
public bool LockWebView2 { get; set; } = true;

#endregion

public AppConfig()
{

Expand Down
4 changes: 1 addition & 3 deletions DanmakuPlayer/AppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public static void Initialize()
? new() : appConfigurations;
}

public static void SetDefaultAppConfig() => AppConfig = new();

public static AppConfig AppConfig { get; private set; } = null!;
public static AppConfig AppConfig { get; set; } = null!;

public static BackgroundPanel BackgroundPanel { get; set; } = null!;

Expand Down
8 changes: 8 additions & 0 deletions DanmakuPlayer/DanmakuPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

<ItemGroup>
<None Remove="Views\Controls\BackgroundPanel.xaml" />
<None Remove="Views\Controls\CollapsibleArea.xaml" />
<None Remove="Views\Controls\ColorPickerButton.xaml" />
<None Remove="Views\Controls\InputDialog.xaml" />
<None Remove="Views\Controls\SettingsDialog.xaml" />
<None Remove="Views\Controls\WebView2ForVideo.xaml" />
<Page Update="Views\Controls\InputDialog.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand All @@ -48,6 +50,7 @@
<PackageReference Include="CommunityToolkit.Labs.WinUI.SettingsControls" Version="0.0.18" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.5.1" />
<PackageReference Include="Microsoft.Playwright" Version="1.37.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230724000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
Expand Down Expand Up @@ -102,6 +105,11 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
<Page Update="Views\Controls\WebView2ForVideo.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Expand Down
4 changes: 2 additions & 2 deletions DanmakuPlayer/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<Identity
Name="70a1252b-77b7-4c9b-884e-3ee5eb046424"
Publisher="CN=Poker"
Version="3.4.0.0" />
Publisher="CN=poker"
Version="3.5.0.0" />

<Properties>
<DisplayName>Danmaku Player</DisplayName>
Expand Down
21 changes: 18 additions & 3 deletions DanmakuPlayer/Resources/zh-Hans/SettingsDialog.resw
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@
<data name="PlayHeader.Text" xml:space="preserve">
<value>播放设置</value>
</data>
<data name="PlaySpeedCard.Description" xml:space="preserve">
<data name="PlaybackRateCard.Description" xml:space="preserve">
<value>是否按倍速播放</value>
</data>
<data name="PlaySpeedCard.Header" xml:space="preserve">
<data name="PlaybackRateCard.Header" xml:space="preserve">
<value>播放倍速</value>
</data>
<data name="RadioButtonDarkTheme.Content" xml:space="preserve">
Expand Down Expand Up @@ -320,4 +320,19 @@
<data name="TopMostCard.Header" xml:space="preserve">
<value>固定最前</value>
</data>
</root>
<data name="EnableWebView2Card.Description" xml:space="preserve">
<value>在应用内使用网页,并连接网页中的播放器</value>
</data>
<data name="EnableWebView2Card.Header" xml:space="preserve">
<value>使用WebView2</value>
</data>
<data name="LockWebView2Card.Description" xml:space="preserve">
<value>鼠标、键盘等操作不会输入到WebView2</value>
</data>
<data name="LockWebView2Card.Header" xml:space="preserve">
<value>锁定WebView2</value>
</data>
<data name="WebView2Header.Text" xml:space="preserve">
<value>WebView2设置</value>
</data>
</root>
2 changes: 1 addition & 1 deletion DanmakuPlayer/Services/DanmakuServices/DanmakuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static async Task WaitForRender(CanvasControl canvas, CancellationToken

public static Danmaku[] DisplayingDanmaku(float time, AppConfig appConfig)
{
var actualDuration = Math.Max(10, appConfig.DanmakuDuration) * appConfig.PlaySpeed;
var actualDuration = Math.Max(10, appConfig.DanmakuDuration) * appConfig.PlaybackRate;

var firstIndex = Array.FindIndex(Pool, t => t.Time > time - actualDuration);
if (firstIndex is -1)
Expand Down
8 changes: 8 additions & 0 deletions DanmakuPlayer/Themes/Generic.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DanmakuPlayer">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Views/Controls/CollapsibleArea.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Loading

0 comments on commit 31f1471

Please sign in to comment.