Skip to content

Commit

Permalink
explorer fix 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ad2017gd committed Aug 18, 2023
1 parent edb1b5b commit 44f0cca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
39 changes: 25 additions & 14 deletions RainbowTaskbar/ExplorerTAP/ExplorerTAP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,23 @@ class ExplorerTAP
public static int tries = 0;

public static bool IsInjected { get; set; } = false;
public static bool IsInjecting { get; set; } = false;

public static bool NeedsTAP() {
var taskbarHWND = TaskbarHelper.FindWindow("Shell_TrayWnd", null);
return
taskbarHWND != IntPtr.Zero &&
TaskbarHelper.FindWindowEx(taskbarHWND, IntPtr.Zero, "Windows.UI.Composition.DesktopWindowContentBridge", null) != IntPtr.Zero &&
TaskbarHelper.FindWindowEx(taskbarHWND, IntPtr.Zero, "WorkerW", null) == IntPtr.Zero;

}

public static void TryInject() {

var taskbarHWND = TaskbarHelper.FindWindow("Shell_TrayWnd", null);

if (
taskbarHWND != IntPtr.Zero &&
TaskbarHelper.FindWindowEx(taskbarHWND, IntPtr.Zero, "Windows.UI.Composition.DesktopWindowContentBridge", null) != IntPtr.Zero &&
TaskbarHelper.FindWindowEx(taskbarHWND, IntPtr.Zero, "WorkerW", null) == IntPtr.Zero
) {
if (NeedsTAP()) {
IsInjecting = true;
// We re on win11 with new taskbar

string dllPath = Environment.GetEnvironmentVariable("temp") + "\\RainbowTaskbarDLL.dll";
Expand Down Expand Up @@ -103,9 +110,8 @@ public static void TryInject() {
// too lazy to make an event, this shall work
Task.Delay(1250).Wait();


IsInjecting = false;
IsInjected = true;
tries = 0;
}

}
Expand All @@ -117,16 +123,21 @@ public static void Reset() {
}

public static void SetAppearanceType(TransparencyInstruction.TransparencyInstructionStyle type) {
var taskbarHWND = TaskbarHelper.FindWindow("Shell_TrayWnd", null);
if (!IsInjected || taskbarHWND == IntPtr.Zero) return;
int hres = SetAppearanceTypeDLL((uint) type);
if (unchecked((uint)hres) != 0 && tries++ < 5) { // MK_E_UNAVAILABLE or other errors?
TryInject();
if (tries >= 5) {
if (!NeedsTAP() || IsInjecting) return;
uint hres = unchecked((uint) SetAppearanceTypeDLL((uint) type));
if (hres == 0) tries = 0;
if (hres != 0 && tries < 5) { // MK_E_UNAVAILABLE or other errors?
while(hres != 0 && tries++ < 5) {
TryInject();
hres = unchecked((uint) SetAppearanceTypeDLL((uint) type));
}
if (hres != 0 && tries >= 5) {
MessageBox.Show(
$"0x{hres.ToString("X8")} : {Marshal.GetExceptionForHR(hres)?.Message}\n\nThere seems to be an issue with the RainbowTaskbar DLL injected into explorer.exe. This process is very experimental, so please open up an issue on GitHub (Right-click RainbowTaskbar on system tray -> Submit an issue or request) to try and debug the problem. Make sure to also include any other errors you might have encountered.", "RainbowTaskbar Error", MessageBoxButton.OK, MessageBoxImage.Warning
$"0x{hres.ToString("X8")} : {Marshal.GetExceptionForHR(unchecked((int)hres))?.Message}\n\nThere seems to be an issue with the RainbowTaskbar DLL injected into explorer.exe. This process is very experimental, so please open up an issue on GitHub (Right-click RainbowTaskbar on system tray -> Submit an issue or request) to try and debug the problem. Make sure to also include any other errors you might have encountered.", "RainbowTaskbar Error", MessageBoxButton.OK, MessageBoxImage.Warning
);
}


}
}
}
Expand Down
6 changes: 3 additions & 3 deletions RainbowTaskbar/RainbowTaskbar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Version>2.3.1</Version>
<Version>2.3.1.1</Version>
<PackageProjectUrl>https://ad2017.dev/rnb</PackageProjectUrl>
<Description>RainbowTaskbar is a Windows utility to customize the shell taskbar.</Description>
<Authors>Ad2017, zCri</Authors>
Expand All @@ -18,8 +18,8 @@
<AnalysisLevel>latest</AnalysisLevel>
<Nullable>disable</Nullable>
<ErrorReport>prompt</ErrorReport>
<AssemblyVersion>2.3.1</AssemblyVersion>
<FileVersion>2.3.1</FileVersion>
<AssemblyVersion>2.3.1.1</AssemblyVersion>
<FileVersion>2.3.1.1</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down

0 comments on commit 44f0cca

Please sign in to comment.