Skip to content

Commit

Permalink
Fix Setting Scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Mar 12, 2021
1 parent 671ae49 commit 93d274a
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 98 deletions.
26 changes: 8 additions & 18 deletions src/HandyWinget/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
using HandyControl.Controls;
using HandyControl.Themes;
using HandyControl.Themes;
using HandyControl.Tools;
using HandyWinget.Assets;
using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using nucs.JsonSettings;
using nucs.JsonSettings.Autosave;
using System.IO;
using System.Runtime;
using System.Windows;
using System.Windows.Media;

using static HandyWinget.Assets.Helper;
namespace HandyWinget
{
public partial class App : Application
{
ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();

public App()
{
if (!Directory.Exists(Consts.CachePath))
{
Directory.CreateDirectory(Consts.CachePath);
}

ProfileOptimization.SetProfileRoot(Consts.CachePath);
ProfileOptimization.StartProfile("Profile");
ApplicationHelper.StartProfileOptimization();
}

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

if (!Settings.Version.Equals(RegistryHelper.GetKey<int>(Consts.VersionKey, Consts.AppName, HKEYType.CurrentUser)))
if (!Settings.Version.Equals(RegistryHelper.GetValue<int>(Consts.VersionKey, Consts.AppName)))
{
if (File.Exists(Consts.ConfigPath))
{
File.Delete(Consts.ConfigPath);
}
RegistryHelper.AddOrUpdateKey(Consts.VersionKey, Consts.AppName, Settings.Version, HKEYType.CurrentUser);
RegistryHelper.AddOrUpdateKey(Consts.VersionKey, Consts.AppName, Settings.Version);
}

UpdateTheme(Settings.Theme);
Expand All @@ -59,7 +49,7 @@ internal void UpdateAccent(Brush accent)
if (ThemeManager.Current.AccentColor != accent)
{
ThemeManager.Current.AccentColor = accent;
ModernWpf.ThemeManager.Current.AccentColor = accent == null ? null : (Color?)Helper.GetColorFromBrush(accent);
ModernWpf.ThemeManager.Current.AccentColor = accent == null ? null : ApplicationHelper.GetColorFromBrush(accent);
}
}
}
Expand Down
30 changes: 0 additions & 30 deletions src/HandyWinget/Assets/DispatcherHelper.cs

This file was deleted.

25 changes: 5 additions & 20 deletions src/HandyWinget/Assets/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
using HandyControl.Controls;
using HandyControl.Tools;
using Microsoft.VisualBasic;
using Microsoft.Win32;
using nucs.JsonSettings;
using nucs.JsonSettings.Autosave;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Media;

namespace HandyWinget.Assets
{
public abstract class Helper
{
[DllImport("wininet.dll")]
private static extern bool InternetGetConnectedState(out int Description, int ReservedValue);
public static bool IsConnectedToInternet()
{
return InternetGetConnectedState(out int Desc, 0);
}
public static ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();

public static string ConvertBytesToMegabytes(long bytes)
{
return ((bytes / 1024f) / 1024f).ToString("0.00");
}
public static Color GetColorFromBrush(Brush brush)
{
if (brush.GetType() == typeof(LinearGradientBrush))
{
var linearBrush = (LinearGradientBrush)brush;
return new SolidColorBrush(linearBrush.GradientStops[1].Color).Color;
}
else
{
return ((SolidColorBrush)brush).Color;
}
}

public static bool IsWingetInstalled()
{
Expand Down
10 changes: 5 additions & 5 deletions src/HandyWinget/HandyWinget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<UseWPF>true</UseWPF>
<AssemblyName>HandyWinget</AssemblyName>
<RootNamespace>HandyWinget</RootNamespace>
<Version>3.0.1.0</Version>
<Version>3.0.2.0</Version>
<Configurations>Debug;Release</Configurations>
<Copyright>Copyright © Mahdi 2018-2021</Copyright>
<FileVersion>3.0.1.0</FileVersion>
<AssemblyVersion>3.0.1.0</AssemblyVersion>
<FileVersion>3.0.2.0</FileVersion>
<AssemblyVersion>3.0.2.0</AssemblyVersion>
<LangVersion>latest</LangVersion>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
Expand All @@ -26,8 +26,8 @@
<None Remove="Resources\icon.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="HandyControls" Version="3.1.1" />
<PackageReference Include="Downloader" Version="2.2.2" />
<PackageReference Include="HandyControls" Version="3.2.0" />
<PackageReference Include="Downloader" Version="2.2.3" />
<PackageReference Include="ModernWpfUis" Version="1.2.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.1.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.1.0" />
Expand Down
18 changes: 6 additions & 12 deletions src/HandyWinget/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
using HandyControl.Controls;
using HandyControl.Themes;
using HandyControl.Tools;
using HandyWinget.Assets;
using HandyWinget.Views;
using ModernWpf.Controls;
using ModernWpf.Controls.Primitives;
using nucs.JsonSettings;
using nucs.JsonSettings.Autosave;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using static HandyWinget.Assets.Helper;
namespace HandyWinget
{
public partial class MainWindow
{
ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();
internal static MainWindow Instance;

public MainWindow()
Expand Down Expand Up @@ -46,9 +41,9 @@ public void CommandButtonsVisibility(Visibility visibility)
appBarIsInstalled.Visibility = visibility;
appBarSeperator.Visibility = visibility;
}
private void NavigationView_SelectionChanged(ModernWpf.Controls.NavigationView sender, ModernWpf.Controls.NavigationViewSelectionChangedEventArgs args)
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
var selectedItem = (ModernWpf.Controls.NavigationViewItem)args.SelectedItem;
var selectedItem = (NavigationViewItem)args.SelectedItem;
if (selectedItem != null)
{
switch (selectedItem.Tag)
Expand Down Expand Up @@ -94,7 +89,7 @@ private void ApplicationTheme_Click(object sender, RoutedEventArgs e)

if (Settings.Accent !=null)
{
picker.SelectedBrush = new SolidColorBrush(Helper.GetColorFromBrush(Settings.Accent));
picker.SelectedBrush = new SolidColorBrush(ApplicationHelper.GetColorFromBrush(Settings.Accent));
}

picker.SelectedColorChanged += delegate
Expand All @@ -108,7 +103,7 @@ private void ApplicationTheme_Click(object sender, RoutedEventArgs e)
}
}

private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.LeftShift) && e.Key == Key.P)
{
Expand Down Expand Up @@ -165,9 +160,8 @@ private void appBarIsInstalled_Checked(object sender, RoutedEventArgs e)

private void OpenFlyout(string resourceKey, FrameworkElement element)
{
ISettings _setting = JsonSettings.Load<ISettings>();
var cmdBarFlyout = (CommandBarFlyout)Resources[resourceKey];
var paneMode = _setting.PaneDisplayMode;
var paneMode = Settings.PaneDisplayMode;
switch (paneMode)
{
case NavigationViewPaneDisplayMode.Auto:
Expand Down
2 changes: 1 addition & 1 deletion src/HandyWinget/Views/CreatePackage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private async void btnGetHashWeb_Click(object sender, RoutedEventArgs e)
var downloader = new DownloadService();
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
downloader.DownloadFileCompleted += OnDownloadFileCompleted;
await downloader.DownloadFileAsync(txtUrl.Text, new DirectoryInfo(Consts.TempSetupPath));
await downloader.DownloadFileTaskAsync(txtUrl.Text, new DirectoryInfo(Consts.TempSetupPath));
}
catch (Exception ex)
{
Expand Down
7 changes: 2 additions & 5 deletions src/HandyWinget/Views/General.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using HandyControl.Controls;
using HandyControl.Tools;
using HandyWinget.Assets;
using ModernWpf.Controls;
using nucs.JsonSettings;
using nucs.JsonSettings.Autosave;
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;

using static HandyWinget.Assets.Helper;
namespace HandyWinget.Views
{
/// <summary>
/// Interaction logic for General
/// </summary>
public partial class General : UserControl
{
ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();

string Version = string.Empty;
public General()
{
Expand Down
12 changes: 5 additions & 7 deletions src/HandyWinget/Views/Packages.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Downloader;
using HandyControl.Controls;
using HandyControl.Tools;
using HandyControl.Tools.Extension;
using HandyWinget.Assets;
using Microsoft.VisualBasic;
using Microsoft.Win32;
using ModernWpf.Controls;
using Newtonsoft.Json;
using nucs.JsonSettings;
using nucs.JsonSettings.Autosave;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -23,12 +22,11 @@
using System.Windows.Data;
using System.Windows.Input;
using YamlDotNet.Serialization;

using static HandyWinget.Assets.Helper;
namespace HandyWinget.Views
{
public partial class Packages : UserControl
{
ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();

internal static Packages Instance;

Expand Down Expand Up @@ -80,7 +78,7 @@ public async void DownloadManifests(bool IsRefresh = false)
tgCancelDownload.Visibility = Visibility.Collapsed;

MainWindow.Instance.CommandButtonsVisibility(Visibility.Collapsed);
bool _isConnected = Helper.IsConnectedToInternet();
bool _isConnected = ApplicationHelper.IsConnectedToInternet();
if ((_isConnected && !Directory.Exists(Consts.ManifestPath)) || (_isConnected && IsRefresh is true))
{
if (IsRefresh)
Expand Down Expand Up @@ -539,7 +537,7 @@ public void InstallPackage()
prgStatus.ShowError = false;
prgStatus.IsIndeterminate = true;
prgStatus.Value = 0;
if (Helper.IsConnectedToInternet())
if (ApplicationHelper.IsConnectedToInternet())
{
switch (Settings.InstallMode)
{
Expand Down Expand Up @@ -693,7 +691,7 @@ public async void InstallInternalMode()
downloaderService = new DownloadService();
downloaderService.DownloadProgressChanged += DownloaderService_DownloadProgressChanged;
downloaderService.DownloadFileCompleted += DownloaderService_DownloadFileCompleted;
await downloaderService.DownloadFileAsync(url, _TempSetupPath);
await downloaderService.DownloadFileTaskAsync(url, _TempSetupPath);
}
else
{
Expand Down

0 comments on commit 93d274a

Please sign in to comment.