Skip to content

Commit 93d274a

Browse files
committed
Fix Setting Scope
1 parent 671ae49 commit 93d274a

File tree

8 files changed

+32
-98
lines changed

8 files changed

+32
-98
lines changed

src/HandyWinget/App.xaml.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,33 @@
1-
using HandyControl.Controls;
2-
using HandyControl.Themes;
1+
using HandyControl.Themes;
2+
using HandyControl.Tools;
33
using HandyWinget.Assets;
44
using Microsoft.AppCenter;
55
using Microsoft.AppCenter.Analytics;
66
using Microsoft.AppCenter.Crashes;
7-
using nucs.JsonSettings;
8-
using nucs.JsonSettings.Autosave;
97
using System.IO;
10-
using System.Runtime;
118
using System.Windows;
129
using System.Windows.Media;
13-
10+
using static HandyWinget.Assets.Helper;
1411
namespace HandyWinget
1512
{
1613
public partial class App : Application
1714
{
18-
ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();
19-
2015
public App()
2116
{
22-
if (!Directory.Exists(Consts.CachePath))
23-
{
24-
Directory.CreateDirectory(Consts.CachePath);
25-
}
26-
27-
ProfileOptimization.SetProfileRoot(Consts.CachePath);
28-
ProfileOptimization.StartProfile("Profile");
17+
ApplicationHelper.StartProfileOptimization();
2918
}
19+
3020
protected override void OnStartup(StartupEventArgs e)
3121
{
3222
base.OnStartup(e);
3323

34-
if (!Settings.Version.Equals(RegistryHelper.GetKey<int>(Consts.VersionKey, Consts.AppName, HKEYType.CurrentUser)))
24+
if (!Settings.Version.Equals(RegistryHelper.GetValue<int>(Consts.VersionKey, Consts.AppName)))
3525
{
3626
if (File.Exists(Consts.ConfigPath))
3727
{
3828
File.Delete(Consts.ConfigPath);
3929
}
40-
RegistryHelper.AddOrUpdateKey(Consts.VersionKey, Consts.AppName, Settings.Version, HKEYType.CurrentUser);
30+
RegistryHelper.AddOrUpdateKey(Consts.VersionKey, Consts.AppName, Settings.Version);
4131
}
4232

4333
UpdateTheme(Settings.Theme);
@@ -59,7 +49,7 @@ internal void UpdateAccent(Brush accent)
5949
if (ThemeManager.Current.AccentColor != accent)
6050
{
6151
ThemeManager.Current.AccentColor = accent;
62-
ModernWpf.ThemeManager.Current.AccentColor = accent == null ? null : (Color?)Helper.GetColorFromBrush(accent);
52+
ModernWpf.ThemeManager.Current.AccentColor = accent == null ? null : ApplicationHelper.GetColorFromBrush(accent);
6353
}
6454
}
6555
}

src/HandyWinget/Assets/DispatcherHelper.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/HandyWinget/Assets/Helper.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,26 @@
11
using HandyControl.Controls;
2+
using HandyControl.Tools;
23
using Microsoft.VisualBasic;
34
using Microsoft.Win32;
5+
using nucs.JsonSettings;
6+
using nucs.JsonSettings.Autosave;
47
using System;
58
using System.Collections.Generic;
69
using System.ComponentModel;
710
using System.Diagnostics;
811
using System.IO;
912
using System.Linq;
10-
using System.Runtime.InteropServices;
11-
using System.Windows.Media;
1213

1314
namespace HandyWinget.Assets
1415
{
1516
public abstract class Helper
1617
{
17-
[DllImport("wininet.dll")]
18-
private static extern bool InternetGetConnectedState(out int Description, int ReservedValue);
19-
public static bool IsConnectedToInternet()
20-
{
21-
return InternetGetConnectedState(out int Desc, 0);
22-
}
18+
public static ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();
19+
2320
public static string ConvertBytesToMegabytes(long bytes)
2421
{
2522
return ((bytes / 1024f) / 1024f).ToString("0.00");
2623
}
27-
public static Color GetColorFromBrush(Brush brush)
28-
{
29-
if (brush.GetType() == typeof(LinearGradientBrush))
30-
{
31-
var linearBrush = (LinearGradientBrush)brush;
32-
return new SolidColorBrush(linearBrush.GradientStops[1].Color).Color;
33-
}
34-
else
35-
{
36-
return ((SolidColorBrush)brush).Color;
37-
}
38-
}
3924

4025
public static bool IsWingetInstalled()
4126
{

src/HandyWinget/HandyWinget.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<UseWPF>true</UseWPF>
66
<AssemblyName>HandyWinget</AssemblyName>
77
<RootNamespace>HandyWinget</RootNamespace>
8-
<Version>3.0.1.0</Version>
8+
<Version>3.0.2.0</Version>
99
<Configurations>Debug;Release</Configurations>
1010
<Copyright>Copyright © Mahdi 2018-2021</Copyright>
11-
<FileVersion>3.0.1.0</FileVersion>
12-
<AssemblyVersion>3.0.1.0</AssemblyVersion>
11+
<FileVersion>3.0.2.0</FileVersion>
12+
<AssemblyVersion>3.0.2.0</AssemblyVersion>
1313
<LangVersion>latest</LangVersion>
1414
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
1515
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
@@ -26,8 +26,8 @@
2626
<None Remove="Resources\icon.ico" />
2727
</ItemGroup>
2828
<ItemGroup>
29-
<PackageReference Include="HandyControls" Version="3.1.1" />
30-
<PackageReference Include="Downloader" Version="2.2.2" />
29+
<PackageReference Include="HandyControls" Version="3.2.0" />
30+
<PackageReference Include="Downloader" Version="2.2.3" />
3131
<PackageReference Include="ModernWpfUis" Version="1.2.0" />
3232
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.1.0" />
3333
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.1.0" />

src/HandyWinget/MainWindow.xaml.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
using HandyControl.Controls;
22
using HandyControl.Themes;
33
using HandyControl.Tools;
4-
using HandyWinget.Assets;
54
using HandyWinget.Views;
65
using ModernWpf.Controls;
76
using ModernWpf.Controls.Primitives;
8-
using nucs.JsonSettings;
9-
using nucs.JsonSettings.Autosave;
10-
using System.Diagnostics;
117
using System.Windows;
12-
using System.Windows.Controls;
138
using System.Windows.Input;
149
using System.Windows.Media;
10+
using static HandyWinget.Assets.Helper;
1511
namespace HandyWinget
1612
{
1713
public partial class MainWindow
1814
{
19-
ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();
2015
internal static MainWindow Instance;
2116

2217
public MainWindow()
@@ -46,9 +41,9 @@ public void CommandButtonsVisibility(Visibility visibility)
4641
appBarIsInstalled.Visibility = visibility;
4742
appBarSeperator.Visibility = visibility;
4843
}
49-
private void NavigationView_SelectionChanged(ModernWpf.Controls.NavigationView sender, ModernWpf.Controls.NavigationViewSelectionChangedEventArgs args)
44+
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
5045
{
51-
var selectedItem = (ModernWpf.Controls.NavigationViewItem)args.SelectedItem;
46+
var selectedItem = (NavigationViewItem)args.SelectedItem;
5247
if (selectedItem != null)
5348
{
5449
switch (selectedItem.Tag)
@@ -94,7 +89,7 @@ private void ApplicationTheme_Click(object sender, RoutedEventArgs e)
9489

9590
if (Settings.Accent !=null)
9691
{
97-
picker.SelectedBrush = new SolidColorBrush(Helper.GetColorFromBrush(Settings.Accent));
92+
picker.SelectedBrush = new SolidColorBrush(ApplicationHelper.GetColorFromBrush(Settings.Accent));
9893
}
9994

10095
picker.SelectedColorChanged += delegate
@@ -108,7 +103,7 @@ private void ApplicationTheme_Click(object sender, RoutedEventArgs e)
108103
}
109104
}
110105

111-
private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
106+
private void Window_KeyDown(object sender, KeyEventArgs e)
112107
{
113108
if (Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.LeftShift) && e.Key == Key.P)
114109
{
@@ -165,9 +160,8 @@ private void appBarIsInstalled_Checked(object sender, RoutedEventArgs e)
165160

166161
private void OpenFlyout(string resourceKey, FrameworkElement element)
167162
{
168-
ISettings _setting = JsonSettings.Load<ISettings>();
169163
var cmdBarFlyout = (CommandBarFlyout)Resources[resourceKey];
170-
var paneMode = _setting.PaneDisplayMode;
164+
var paneMode = Settings.PaneDisplayMode;
171165
switch (paneMode)
172166
{
173167
case NavigationViewPaneDisplayMode.Auto:

src/HandyWinget/Views/CreatePackage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private async void btnGetHashWeb_Click(object sender, RoutedEventArgs e)
163163
var downloader = new DownloadService();
164164
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
165165
downloader.DownloadFileCompleted += OnDownloadFileCompleted;
166-
await downloader.DownloadFileAsync(txtUrl.Text, new DirectoryInfo(Consts.TempSetupPath));
166+
await downloader.DownloadFileTaskAsync(txtUrl.Text, new DirectoryInfo(Consts.TempSetupPath));
167167
}
168168
catch (Exception ex)
169169
{

src/HandyWinget/Views/General.xaml.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
using HandyControl.Controls;
2+
using HandyControl.Tools;
23
using HandyWinget.Assets;
34
using ModernWpf.Controls;
4-
using nucs.JsonSettings;
5-
using nucs.JsonSettings.Autosave;
65
using System;
76
using System.Reflection;
87
using System.Windows;
98
using System.Windows.Controls;
10-
9+
using static HandyWinget.Assets.Helper;
1110
namespace HandyWinget.Views
1211
{
1312
/// <summary>
1413
/// Interaction logic for General
1514
/// </summary>
1615
public partial class General : UserControl
1716
{
18-
ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();
19-
2017
string Version = string.Empty;
2118
public General()
2219
{

src/HandyWinget/Views/Packages.xaml.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using Downloader;
22
using HandyControl.Controls;
3+
using HandyControl.Tools;
34
using HandyControl.Tools.Extension;
45
using HandyWinget.Assets;
56
using Microsoft.VisualBasic;
67
using Microsoft.Win32;
78
using ModernWpf.Controls;
89
using Newtonsoft.Json;
9-
using nucs.JsonSettings;
10-
using nucs.JsonSettings.Autosave;
1110
using System;
1211
using System.Collections.Generic;
1312
using System.Collections.ObjectModel;
@@ -23,12 +22,11 @@
2322
using System.Windows.Data;
2423
using System.Windows.Input;
2524
using YamlDotNet.Serialization;
26-
25+
using static HandyWinget.Assets.Helper;
2726
namespace HandyWinget.Views
2827
{
2928
public partial class Packages : UserControl
3029
{
31-
ISettings Settings = JsonSettings.Load<ISettings>().EnableAutosave();
3230

3331
internal static Packages Instance;
3432

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

8280
MainWindow.Instance.CommandButtonsVisibility(Visibility.Collapsed);
83-
bool _isConnected = Helper.IsConnectedToInternet();
81+
bool _isConnected = ApplicationHelper.IsConnectedToInternet();
8482
if ((_isConnected && !Directory.Exists(Consts.ManifestPath)) || (_isConnected && IsRefresh is true))
8583
{
8684
if (IsRefresh)
@@ -539,7 +537,7 @@ public void InstallPackage()
539537
prgStatus.ShowError = false;
540538
prgStatus.IsIndeterminate = true;
541539
prgStatus.Value = 0;
542-
if (Helper.IsConnectedToInternet())
540+
if (ApplicationHelper.IsConnectedToInternet())
543541
{
544542
switch (Settings.InstallMode)
545543
{
@@ -693,7 +691,7 @@ public async void InstallInternalMode()
693691
downloaderService = new DownloadService();
694692
downloaderService.DownloadProgressChanged += DownloaderService_DownloadProgressChanged;
695693
downloaderService.DownloadFileCompleted += DownloaderService_DownloadFileCompleted;
696-
await downloaderService.DownloadFileAsync(url, _TempSetupPath);
694+
await downloaderService.DownloadFileTaskAsync(url, _TempSetupPath);
697695
}
698696
else
699697
{

0 commit comments

Comments
 (0)