Skip to content

Portable Tool for an Ideal Windows Setup

add refresh desktop & ref

Greedeks83d471b74554
diff --git a/.Source/GTweak/Utilities/Managers/ExplorerManager.cs b/.Source/GTweak/Utilities/Managers/ExplorerManager.cs
index fd59dcd9..ab4dbd27 100644
--- a/.Source/GTweak/Utilities/Managers/ExplorerManager.cs
+++ b/.Source/GTweak/Utilities/Managers/ExplorerManager.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Linq;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
using GTweak.Utilities.Controls;
@@ -9,25 +9,48 @@ namespace GTweak.Utilities.Managers
{
internal class ExplorerManager
{
- internal static readonly Dictionary<string, bool> IntfMapping = new[]
+ [DllImport("shell32.dll")]
+ static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
+ const uint SHCNE_ASSOCCHANGED = 0x08000000;
+ const uint SHCNF_FLUSH = 0x1000;
+
+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
+ static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
+ const uint HWND_BROADCAST = 0xffff;
+ const uint WM_SETTINGCHANGE = 0x001A;
+ const uint SMTO_ABORTIFHUNG = 0x0002;
+
+ internal enum ExplorerAction { None, Refresh, Restart }
+
+ internal static readonly Dictionary<string, ExplorerAction> IntfActions = new Dictionary<string, ExplorerAction>()
{
- new { Button = "TglButton5", NeedRestart = true },
- new { Button = "TglButton6", NeedRestart = true },
- new { Button = "TglButton11", NeedRestart = true },
- new { Button = "TglButton12", NeedRestart = true },
- new { Button = "TglButton13", NeedRestart = true },
- new { Button = "TglButton17", NeedRestart = true },
- new { Button = "TglButton19", NeedRestart = true },
- new { Button = "TglButton23", NeedRestart = true },
- new { Button = "TglButton24", NeedRestart = true },
- new { Button = "TglButton27", NeedRestart = true }
- }.ToDictionary(x => x.Button, x => x.NeedRestart);
-
- internal static readonly Dictionary<string, bool> PackageMapping = new[]
+ ["Checkbox4"] = ExplorerAction.Restart,
+ ["Checkbox5"] = ExplorerAction.Restart,
+ ["Checkbox6"] = ExplorerAction.Restart,
+ ["Checkbox7"] = ExplorerAction.Restart,
+ ["Checkbox8"] = ExplorerAction.Refresh,
+ ["Checkbox9"] = ExplorerAction.Refresh,
+ ["Checkbox10"] = ExplorerAction.Refresh,
+ ["Checkbox11"] = ExplorerAction.Refresh,
+ ["Checkbox12"] = ExplorerAction.Refresh,
+ ["Checkbox13"] = ExplorerAction.Refresh,
+ ["TglButton5"] = ExplorerAction.Restart,
+ ["TglButton6"] = ExplorerAction.Restart,
+ ["TglButton11"] = ExplorerAction.Restart,
+ ["TglButton12"] = ExplorerAction.Restart,
+ ["TglButton13"] = ExplorerAction.Restart,
+ ["TglButton17"] = ExplorerAction.Restart,
+ ["TglButton19"] = ExplorerAction.Restart,
+ ["TglButton23"] = ExplorerAction.Restart,
+ ["TglButton24"] = ExplorerAction.Restart,
+ ["TglButton27"] = ExplorerAction.Restart
+ };
+
+ internal static readonly Dictionary<string, ExplorerAction> PackageActions = new Dictionary<string, ExplorerAction>()
{
- new { Package = "Widgets", NeedRestart = true },
- new { Package = "Edge", NeedRestart = true }
- }.ToDictionary(x => x.Package, x => x.NeedRestart);
+ ["Widgets"] = ExplorerAction.Restart,
+ ["Edge"] = ExplorerAction.Restart
+ };
internal static void Restart(Action action = null)
{
@@ -56,5 +79,18 @@ namespace GTweak.Utilities.Managers
}
});
}
+
+ internal static void RefreshDesktop()
+ {
+ Task.Run(delegate
+ {
+ try
+ {
+ SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);
+ SendMessageTimeout(new IntPtr((int)HWND_BROADCAST), WM_SETTINGCHANGE, UIntPtr.Zero, "TraySettings", SMTO_ABORTIFHUNG, 100, out UIntPtr result);
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ });
+ }
}
}
diff --git a/.Source/GTweak/View/InterfaceView.xaml b/.Source/GTweak/View/InterfaceView.xaml
index f2b317ca..a151b64a 100644
--- a/.Source/GTweak/View/InterfaceView.xaml
+++ b/.Source/GTweak/View/InterfaceView.xaml
@@ -65,7 +65,7 @@
<StackPanel Orientation="Horizontal" Height="45" MouseEnter="Tweak_MouseEnter" MouseLeave="Tweak_MouseLeave" ToolTip="{DynamicResource exblock3_desc_intf}" ToolTipService.IsEnabled="False" Background="Transparent">
<TextBlock Style="{StaticResource TextDefault}" VerticalAlignment="Center" Text="{DynamicResource exblock3_intf}"/>
- <uc:ExpandableBox Text="{DynamicResource btn_change}" Margin="7,5,5,0" Height="32" VerticalAlignment="Center">
+ <uc:ExpandableBox Text="{DynamicResource btn_change}" Margin="7,5,5,0" Height="32" VerticalAlignment="Center" Closed="ExpandableBox_Closed">
<CheckBox x:Uid="Checkbox8" Content="{DynamicResource chk_pc_intf}" IsChecked="{Binding [Checkbox8].State}" Click="CheckBox_Click" />
<CheckBox x:Uid="Checkbox9" Content="{DynamicResource chk_net_intf}" IsChecked="{Binding [Checkbox9].State}" Margin="0,4,0,0" Click="CheckBox_Click"/>
<CheckBox x:Uid="Checkbox10" Content="{DynamicResource chk_trash_intf}" IsChecked="{Binding [Checkbox10].State}" Margin="0,4,0,0" Click="CheckBox_Click"/>
diff --git a/.Source/GTweak/View/InterfaceView.xaml.cs b/.Source/GTweak/View/InterfaceView.xaml.cs
index 0152c39e..9287c0bc 100644
--- a/.Source/GTweak/View/InterfaceView.xaml.cs
+++ b/.Source/GTweak/View/InterfaceView.xaml.cs
@@ -15,7 +15,7 @@ namespace GTweak.View
public partial class InterfaceView : UserControl
{
private readonly InterfaceTweaks _intfTweaks = new InterfaceTweaks();
- private bool _isExpRestartNeed = false;
+ private ExplorerManager.ExplorerAction _explorerAction = ExplorerManager.ExplorerAction.None;
public InterfaceView()
{
@@ -61,16 +61,28 @@ namespace GTweak.View
{
CheckBox checkBox = (CheckBox)sender;
_intfTweaks.ApplyTweaksCheckBox(checkBox.Uid, checkBox.IsChecked == false);
- _isExpRestartNeed = true;
+
+ if (ExplorerManager.IntfActions.TryGetValue(checkBox.Uid, out ExplorerManager.ExplorerAction explorerAction))
+ {
+ _explorerAction = explorerAction;
+ }
}
private void ExpandableBox_Closed(object sender, EventArgs e)
{
- if (_isExpRestartNeed)
+ switch (_explorerAction)
{
- ExplorerManager.Restart();
- _isExpRestartNeed = false;
+ case ExplorerManager.ExplorerAction.Restart:
+ ExplorerManager.Restart();
+ break;
+ case ExplorerManager.ExplorerAction.Refresh:
+ ExplorerManager.RefreshDesktop();
+ break;
+ default:
+ break;
}
+
+ _explorerAction = ExplorerManager.ExplorerAction.None;
}
private void TglButton_ChangedState(object sender, RoutedEventArgs e)
@@ -79,14 +91,14 @@ namespace GTweak.View
_intfTweaks.ApplyTweaks(toggleButton.Name, toggleButton.State);
- if (ExplorerManager.IntfMapping.TryGetValue(toggleButton.Name, out bool needRestart))
+ if (ExplorerManager.IntfActions.TryGetValue(toggleButton.Name, out ExplorerManager.ExplorerAction explorerAction) && explorerAction == ExplorerManager.ExplorerAction.Restart)
{
ExplorerManager.Restart();
}
- if (NotificationManager.IntfActions.TryGetValue(toggleButton.Name, out NotificationManager.NoticeAction action))
+ if (NotificationManager.IntfActions.TryGetValue(toggleButton.Name, out NotificationManager.NoticeAction noticeAction))
{
- NotificationManager.Show().WithDelay(300).Perform(action);
+ NotificationManager.Show().WithDelay(300).Perform(noticeAction);
}
}
}
diff --git a/.Source/GTweak/View/PackagesView.xaml.cs b/.Source/GTweak/View/PackagesView.xaml.cs
index 2ddb65c6..74f16028 100644
--- a/.Source/GTweak/View/PackagesView.xaml.cs
+++ b/.Source/GTweak/View/PackagesView.xaml.cs
@@ -104,7 +104,7 @@ namespace GTweak.View
await Dispatcher.BeginInvoke(new Action(() =>
{
- if (ExplorerManager.PackageMapping.TryGetValue(packageName, out bool needRestart))
+ if (ExplorerManager.PackageActions.TryGetValue(packageName, out ExplorerManager.ExplorerAction explorerAction))
{
ExplorerManager.Restart();
}
diff --git a/.Source/GTweak/Windows/ImportWindow.xaml.cs b/.Source/GTweak/Windows/ImportWindow.xaml.cs
index ea77e22d..365c3876 100644
--- a/.Source/GTweak/Windows/ImportWindow.xaml.cs
+++ b/.Source/GTweak/Windows/ImportWindow.xaml.cs
@@ -19,8 +19,9 @@ namespace GTweak.Windows
private readonly ServicesTweaks _svcTweaks = new ServicesTweaks();
private readonly SystemTweaks _sysTweaks = new SystemTweaks();
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
- private readonly HashSet<NotificationManager.NoticeAction> _requiredActions = new HashSet<NotificationManager.NoticeAction>();
- private bool _isExpRestartNeed = false, _isWDNotyNeed = false;
+ private readonly HashSet<NotificationManager.NoticeAction> _notyActions = new HashSet<NotificationManager.NoticeAction>();
+ private ExplorerManager.ExplorerAction _expAction = ExplorerManager.ExplorerAction.None;
+ private bool _isWDNotyNeed = false;
public ImportWindow(in string importedFile)
{
@@ -52,14 +53,21 @@ namespace GTweak.Windows
}
else
{
- if (_isExpRestartNeed)
+ switch (_expAction)
{
- ExplorerManager.Restart();
+ case ExplorerManager.ExplorerAction.Restart:
+ ExplorerManager.Restart();
+ break;
+ case ExplorerManager.ExplorerAction.Refresh:
+ ExplorerManager.RefreshDesktop();
+ break;
+ default:
+ break;
}
- if (_requiredActions.Count != 0)
+ if (_notyActions.Count != 0)
{
- NotificationManager.Show().Perform(_requiredActions.Max());
+ NotificationManager.Show().Perform(_notyActions.Max());
}
}
@@ -72,10 +80,10 @@ namespace GTweak.Windows
{
INIManager iniManager = new INIManager(PathLocator.Files.Config);
- var allSections = new (string Section, Action<string, bool> TweakAction, IEnumerable<KeyValuePair<string, NotificationManager.NoticeAction>> NoticeActions, IEnumerable<KeyValuePair<string, bool>> ExplorerMapping)[]
+ var allSections = new (string Section, Action<string, bool> TweakAction, IEnumerable<KeyValuePair<string, NotificationManager.NoticeAction>> NoticeActions, IEnumerable<KeyValuePair<string, ExplorerManager.ExplorerAction>> ExplorerMapping)[]
{
(INIManager.SectionConf, _confTweaks.ApplyTweaks, NotificationManager.ConfActions, null),
- (INIManager.SectionIntf, _intfTweaks.ApplyTweaks, NotificationManager.IntfActions, ExplorerManager.IntfMapping),
+ (INIManager.SectionIntf, _intfTweaks.ApplyTweaks, NotificationManager.IntfActions, ExplorerManager.IntfActions),
(INIManager.SectionSvc, _svcTweaks.ApplyTweaks, null, null),
(INIManager.SectionSys, null, NotificationManager.SysActions, null)
};
@@ -117,7 +125,7 @@ namespace GTweak.Windows
foreach (var act in NotificationManager.SysActions.Where(a => a.Key == tweak))
{
- _requiredActions.Add(act.Value);
+ _notyActions.Add(act.Value);
}
}
else if (tweak == "TglButton3")
@@ -152,22 +160,28 @@ namespace GTweak.Windows
TweakAction?.Invoke(tweak, Convert.ToBoolean(value));
}
- if (NoticeActions != null)
+ if (NoticeActions is Dictionary<string, NotificationManager.NoticeAction> dict)
{
- foreach (var act in NoticeActions.Where(a => a.Key == tweak))
+ if (dict.TryGetValue(tweak, out NotificationManager.NoticeAction action))
{
- _requiredActions.Add(act.Value);
+ _notyActions.Add(action);
}
}
- if (ExplorerMapping != null && ExplorerMapping.Any(a => a.Key == tweak && a.Value))
+ if (ExplorerMapping is IDictionary<string, ExplorerManager.ExplorerAction> expDict)
{
- _isExpRestartNeed = true;
+ if (expDict.TryGetValue(tweak, out ExplorerManager.ExplorerAction action))
+ {
+ if (action > _expAction)
+ {
+ _expAction = action;
+ }
+ }
}
if (section == INIManager.SectionSvc)
{
- _requiredActions.Add(NotificationManager.NoticeAction.Restart);
+ _notyActions.Add(NotificationManager.NoticeAction.Restart);
}
}
}