Skip to content

Commit

Permalink
删除 HasStatusBar
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Aug 12, 2024
1 parent e9938fc commit ce531d8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
73 changes: 47 additions & 26 deletions WinGetStore/WinGetStore/Common/SettingsPaneRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,49 @@ public static class SettingsPaneRegister

public static void Register(Window window)
{
if (IsSearchPaneSupported)
try
{
SearchPane searchPane = SearchPane.GetForCurrentView();
searchPane.QuerySubmitted -= SearchPane_QuerySubmitted;
searchPane.QuerySubmitted += SearchPane_QuerySubmitted;
}
if (IsSearchPaneSupported)
{
SearchPane searchPane = SearchPane.GetForCurrentView();
searchPane.QuerySubmitted -= SearchPane_QuerySubmitted;
searchPane.QuerySubmitted += SearchPane_QuerySubmitted;
}

if (IsSettingsPaneSupported)
if (IsSettingsPaneSupported)
{
SettingsPane searchPane = SettingsPane.GetForCurrentView();
searchPane.CommandsRequested -= OnCommandsRequested;
searchPane.CommandsRequested += OnCommandsRequested;
window.Dispatcher.AcceleratorKeyActivated -= Dispatcher_AcceleratorKeyActivated;
window.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
}
}
catch (Exception ex)
{
SettingsPane searchPane = SettingsPane.GetForCurrentView();
searchPane.CommandsRequested -= OnCommandsRequested;
searchPane.CommandsRequested += OnCommandsRequested;
window.Dispatcher.AcceleratorKeyActivated -= Dispatcher_AcceleratorKeyActivated;
window.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
SettingsHelper.LogManager.GetLogger(nameof(SettingsPaneRegister)).Error(ex.ExceptionToMessage(), ex);
}
}

public static void Unregister(Window window)
{
if (IsSearchPaneSupported)
try
{
SearchPane searchPane = SearchPane.GetForCurrentView();
searchPane.QuerySubmitted -= SearchPane_QuerySubmitted;
}
if (IsSearchPaneSupported)
{
SearchPane searchPane = SearchPane.GetForCurrentView();
searchPane.QuerySubmitted -= SearchPane_QuerySubmitted;
}

if (IsSettingsPaneSupported)
if (IsSettingsPaneSupported)
{
SettingsPane.GetForCurrentView().CommandsRequested -= OnCommandsRequested;
window.Dispatcher.AcceleratorKeyActivated -= Dispatcher_AcceleratorKeyActivated;
}
}
catch (Exception ex)
{
SettingsPane.GetForCurrentView().CommandsRequested -= OnCommandsRequested;
window.Dispatcher.AcceleratorKeyActivated -= Dispatcher_AcceleratorKeyActivated;
SettingsHelper.LogManager.GetLogger(nameof(SettingsPaneRegister)).Error(ex.ExceptionToMessage(), ex);
}
}

Expand Down Expand Up @@ -126,20 +140,27 @@ private static void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, Ac

private static bool CheckSearchExtension()
{
XDocument doc = XDocument.Load(Path.Combine(Package.Current.InstalledLocation.Path, "AppxManifest.xml"));
XNamespace ns = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/uap/windows10");
IEnumerable<XElement> extensions = doc.Root.Descendants(ns + "Extension");
if (extensions != null)
try
{
foreach (XElement extension in extensions)
XDocument doc = XDocument.Load(Path.Combine(Package.Current.InstalledLocation.Path, "AppxManifest.xml"));
XNamespace ns = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/uap/windows10");
IEnumerable<XElement> extensions = doc.Root.Descendants(ns + "Extension");
if (extensions != null)
{
XAttribute category = extension.Attribute("Category");
if (category != null && category.Value == "windows.search")
foreach (XElement extension in extensions)
{
return true;
XAttribute category = extension.Attribute("Category");
if (category != null && category.Value == "windows.search")
{
return true;
}
}
}
}
catch (Exception ex)
{
SettingsHelper.LogManager.GetLogger(nameof(SettingsPaneRegister)).Error(ex.ExceptionToMessage(), ex);
}
return false;
}
}
Expand Down
7 changes: 5 additions & 2 deletions WinGetStore/WinGetStore/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Metadata;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
Expand All @@ -18,6 +19,8 @@ public static class ThemeHelper
{
private static Window CurrentApplicationWindow;

public static bool IsStatusBarSupported { get; } = ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar");

// Keep reference so it does not get optimized/garbage collected
public static UISettings UISettings { get; } = new UISettings();
public static AccessibilitySettings AccessibilitySettings { get; } = new AccessibilitySettings();
Expand Down Expand Up @@ -245,7 +248,7 @@ public static async void UpdateSystemCaptionButtonColors()
WindowHelper.ActiveWindows.Values.ForEach(async (window) =>
{
await window.Dispatcher.ResumeForegroundAsync();
if (UIHelper.HasStatusBar)
if (IsStatusBarSupported)
{
StatusBar StatusBar = StatusBar.GetForCurrentView();
StatusBar.ForegroundColor = ForegroundColor;
Expand Down Expand Up @@ -273,7 +276,7 @@ public static async void UpdateSystemCaptionButtonColors(Window window)
Color ForegroundColor = IsDark || IsHighContrast ? Colors.White : Colors.Black;
Color BackgroundColor = IsHighContrast ? Color.FromArgb(255, 0, 0, 0) : IsDark ? Color.FromArgb(255, 32, 32, 32) : Color.FromArgb(255, 243, 243, 243);

if (UIHelper.HasStatusBar)
if (IsStatusBarSupported)
{
StatusBar StatusBar = StatusBar.GetForCurrentView();
StatusBar.ForegroundColor = ForegroundColor;
Expand Down
3 changes: 1 addition & 2 deletions WinGetStore/WinGetStore/Helpers/TilesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Security.Principal;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;
using Windows.ApplicationModel.Resources.Core;
using Windows.Data.Xml.Dom;
using Windows.Storage;
using Windows.UI.Notifications;
Expand Down Expand Up @@ -246,7 +245,7 @@ static AdaptiveContainer CreateCard(CatalogPackage catalogPackage)
},
new AdaptiveColumn
{
Items =
Items =
{
new AdaptiveTextBlock(catalogPackage.Name)
{
Expand Down
5 changes: 0 additions & 5 deletions WinGetStore/WinGetStore/Helpers/UIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Metadata;
using Windows.UI.Xaml;
using WinGetStore.Common;

namespace WinGetStore.Helpers
{
public static class UIHelper
{
public static bool HasTitleBar => !CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar;
public static bool HasStatusBar => ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar");

public static string ExceptionToMessage(this Exception ex)
{
StringBuilder builder = new StringBuilder().AppendLine();
Expand Down

0 comments on commit ce531d8

Please sign in to comment.