Skip to content

Commit

Permalink
show recently updated content when startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed May 25, 2024
1 parent e1448e5 commit 75e2d27
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 29 deletions.
18 changes: 18 additions & 0 deletions src/Starward.Language/Lang.Designer.cs

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

6 changes: 6 additions & 0 deletions src/Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1404,4 +1404,10 @@ Do you accept the risk and continue to use it?</value>
<data name="GachaLogPage_ViaCloudGame" xml:space="preserve">
<value>via Cloud Game</value>
</data>
<data name="UpdateContentWindow_ClickToRefresh" xml:space="preserve">
<value>Click to Refresh</value>
</data>
<data name="UpdateContentWindow_RecentlyUpdatedContent" xml:space="preserve">
<value>Recently Updated Content</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/Starward.Language/Lang.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1404,4 +1404,10 @@
<data name="CloudGameGachaWindow_OpenTheGachaRecordsPageInGameAndThenClickTheButtonOnTheRight" xml:space="preserve">
<value>在游戏中打开抽卡记录页面,然后点击右边的按键。</value>
</data>
<data name="UpdateContentWindow_ClickToRefresh" xml:space="preserve">
<value>点击刷新</value>
</data>
<data name="UpdateContentWindow_RecentlyUpdatedContent" xml:space="preserve">
<value>最近更新内容</value>
</data>
</root>
7 changes: 7 additions & 0 deletions src/Starward/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ public static DateTimeOffset HyperionDeviceFpLastUpdateTime



public static string? LastAppVersion
{
get => GetValue<string>();
set => SetValue(value);
}



#endregion

Expand Down
114 changes: 114 additions & 0 deletions src/Starward/Helpers/TransparentBackdrop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using System;
using System.Runtime.InteropServices;
using Vanara.PInvoke;

namespace Starward.Helpers;

public partial class TransparentBackdrop : SystemBackdrop
{

private readonly WindowsSystemDispatcherQueueHelper dispatcherQueueHelper = new();

private readonly nuint _subclassId = (nuint)Random.Shared.Next(100000, 999999);

ComCtl32.SUBCLASSPROC _wndProcHandler;

private nint _hwnd;


protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop connectedTarget, XamlRoot xamlRoot)
{
base.OnTargetConnected(connectedTarget, xamlRoot);

dispatcherQueueHelper.EnsureWindowsSystemDispatcherQueueController();
var com = new Windows.UI.Composition.Compositor();
connectedTarget.SystemBackdrop = com.CreateColorBrush(Windows.UI.Color.FromArgb(0, 255, 255, 255));

_hwnd = (nint)xamlRoot.ContentIslandEnvironment.AppWindowId.Value;
_wndProcHandler = new ComCtl32.SUBCLASSPROC(WndProc);
ComCtl32.SetWindowSubclass(_hwnd, _wndProcHandler, _subclassId, IntPtr.Zero);

using var rgn = Gdi32.CreateRectRgn(-2, -2, -1, -1);
DwmApi.DwmEnableBlurBehindWindow(_hwnd, new DwmApi.DWM_BLURBEHIND()
{
dwFlags = DwmApi.DWM_BLURBEHIND_Mask.DWM_BB_ENABLE | DwmApi.DWM_BLURBEHIND_Mask.DWM_BB_BLURREGION,
fEnable = true,
hRgnBlur = rgn,
});
}


protected override void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
{

}


protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget)
{
base.OnTargetDisconnected(disconnectedTarget);
disconnectedTarget.SystemBackdrop = null;
ComCtl32.RemoveWindowSubclass(_hwnd, _wndProcHandler, _subclassId);
DwmApi.DwmEnableBlurBehindWindow(_hwnd, new DwmApi.DWM_BLURBEHIND()
{
dwFlags = DwmApi.DWM_BLURBEHIND_Mask.DWM_BB_ENABLE | DwmApi.DWM_BLURBEHIND_Mask.DWM_BB_BLURREGION,
fEnable = false,
});
}


private unsafe IntPtr WndProc(HWND hWnd, uint uMsg, IntPtr wParam, IntPtr lParam, nuint uIdSubclass, IntPtr dwRefData)
{
if (uMsg == (uint)User32.WindowMessage.WM_PAINT)
{
var hdc = User32.BeginPaint(hWnd, out var ps);
if (hdc.IsNull) return new IntPtr(0);

var brush = Gdi32.GetStockObject(Gdi32.StockObjectType.BLACK_BRUSH);
User32.FillRect(hdc, ps.rcPaint, brush);
return new IntPtr(1);
}

return ComCtl32.DefSubclassProc(hWnd, uMsg, wParam, lParam);
}


public partial class WindowsSystemDispatcherQueueHelper
{
[StructLayout(LayoutKind.Sequential)]
struct DispatcherQueueOptions
{
internal int dwSize;
internal int threadType;
internal int apartmentType;
}

[LibraryImport("CoreMessaging.dll")]
private static partial int CreateDispatcherQueueController(in DispatcherQueueOptions options, out nint dispatcherQueueController);

nint m_dispatcherQueueController;
public void EnsureWindowsSystemDispatcherQueueController()
{
if (Windows.System.DispatcherQueue.GetForCurrentThread() != null)
{
// one already exists, so we'll just use it.
return;
}

if (m_dispatcherQueueController == 0)
{
DispatcherQueueOptions options;
options.dwSize = Marshal.SizeOf(typeof(DispatcherQueueOptions));
options.threadType = 2; // DQTYPE_THREAD_CURRENT
options.apartmentType = 2; // DQTAT_COM_STA

_ = CreateDispatcherQueueController(options, out m_dispatcherQueueController);
}
}
}


}
7 changes: 0 additions & 7 deletions src/Starward/MyWindows/CloudGameGachaWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Starward.Core;
using Starward.Messages;
using System;
using System.Runtime.InteropServices;
using System.Text.Json.Nodes;
using System.Web;

Expand Down Expand Up @@ -130,10 +129,4 @@ private async void Button_Click(object sender, RoutedEventArgs e)




[return: MarshalAs(UnmanagedType.Bool)]
[LibraryImport("uxtheme.dll", EntryPoint = "#138", SetLastError = true)]
private static partial bool ShouldSystemUseDarkMode();


}
7 changes: 0 additions & 7 deletions src/Starward/MyWindows/SystemTrayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Starward.Helpers;
using System;
using System.IO;
using System.Runtime.InteropServices;
using Vanara.PInvoke;

// To learn more about WinUI, the WinUI project structure,
Expand Down Expand Up @@ -116,12 +115,6 @@ public override void Hide()



[return: MarshalAs(UnmanagedType.Bool)]
[LibraryImport("uxtheme.dll", EntryPoint = "#138", SetLastError = true)]
private static partial bool ShouldSystemUseDarkMode();



[RelayCommand]
public void ShowMainWindow()
{
Expand Down
7 changes: 0 additions & 7 deletions src/Starward/MyWindows/TestUrlProtocolWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using Vanara.PInvoke;

// To learn more about WinUI, the WinUI project structure,
Expand Down Expand Up @@ -68,10 +67,4 @@ public override nint WindowSubclassProc(HWND hWnd, uint uMsg, nint wParam, nint
}



[return: MarshalAs(UnmanagedType.Bool)]
[LibraryImport("uxtheme.dll", EntryPoint = "#138", SetLastError = true)]
private static partial bool ShouldSystemUseDarkMode();


}
62 changes: 62 additions & 0 deletions src/Starward/MyWindows/UpdateContentWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8" ?>
<local:WindowEx x:Class="Starward.MyWindows.UpdateContentWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="using:Starward.Language"
xmlns:local="using:Starward.MyWindows"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid x:Name="RootGrid" Loaded="RootGrid_Loaded">

<StackPanel x:Name="StackPanel_Loading"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="24">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="16"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind lang:Lang.UpdateContentWindow_RecentlyUpdatedContent}" />
<ProgressRing Width="32"
Height="32"
IsActive="True" />
</StackPanel>


<StackPanel x:Name="StackPanel_Error"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="16"
Visibility="Collapsed">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="16"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind lang:Lang.DownloadGamePage_SomethingError}" />
<Button x:Name="Button_Retry"
Width="40"
Height="40"
Padding="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Click="Button_Retry_Click"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<FontIcon Foreground="{ThemeResource TextFillColorSecondaryBrush}" Glyph="&#xE72C;" />
</Button>
</StackPanel>


<WebView2 x:Name="webview"
Margin="0,32,0,0"
DefaultBackgroundColor="Transparent"
Visibility="Collapsed">
<WebView2.Resources>
<SolidColorBrush x:Key="BrushForThemeBackgroundColor" Color="Transparent" />
</WebView2.Resources>
</WebView2>

</Grid>

</local:WindowEx>
Loading

0 comments on commit 75e2d27

Please sign in to comment.