-
Notifications
You must be signed in to change notification settings - Fork 166
Auto Theme Switcher #1919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto Theme Switcher #1919
Conversation
|
For your info, I embedded ThemeTool.exe in the mod which is an old executable from Windows 7 (Blog with download link: https://rsn.home.blog/2018/10/26/change-themes-on-the-command-line). |
|
Embedding an executable that way isn't acceptable for mods in the repository. One core principle of Windhawk mods is that they're open source. You have the following options:
Also, the executable requires .NET Framework 3.5 which isn't installed by default. I look at the way that ThemeTool is implemented. It uses the |
|
Ok, I will look into implementing it. |
|
Here, I ported it: // ==WindhawkMod==
// @id apply-theme
// @name ApplyTheme
// @description Demo: Run mspaint.exe to ApplyTheme
// @version 0.1
// @author m417z
// @github https://github.com/m417z
// @twitter https://twitter.com/m417z
// @homepage https://m417z.com/
// @include mspaint.exe
// @compilerOptions -lole32 -loleaut32
// ==/WindhawkMod==
#include <comdef.h>
#include <winrt/base.h>
// Based on:
// https://github.com/qwerty12/AutoHotkeyScripts/blob/a9423f59c945a3a031cb38b25cf461a34de9a6d3/SetThemeFromdotThemeFile.ahk
bool ApplyTheme(PCWSTR themePath) {
// {C04B329E-5823-4415-9C93-BA44688947B0}
constexpr winrt::guid CLSID_IThemeManager{
0xC04B329E,
0x5823,
0x4415,
{0x9C, 0x93, 0xBA, 0x44, 0x68, 0x89, 0x47, 0xB0}};
// {0646EBBE-C1B7-4045-8FD0-FFD65D3FC792}
constexpr winrt::guid IID_IThemeManager{
0x0646EBBE,
0xC1B7,
0x4045,
{0x8F, 0xD0, 0xFF, 0xD6, 0x5D, 0x3F, 0xC7, 0x92}};
winrt::com_ptr<IUnknown> pThemeManager;
HRESULT hr =
CoCreateInstance(CLSID_IThemeManager, nullptr, CLSCTX_INPROC_SERVER,
IID_IThemeManager, pThemeManager.put_void());
if (FAILED(hr) || !pThemeManager) {
return false;
}
_bstr_t bstrTheme(themePath);
void** vtable = *(void***)pThemeManager.get();
using ApplyThemeFunc = HRESULT(WINAPI*)(IUnknown*, BSTR);
ApplyThemeFunc ApplyThemeMethod = (ApplyThemeFunc)vtable[4];
hr = ApplyThemeMethod(pThemeManager.get(), bstrTheme);
if (FAILED(hr)) {
return false;
}
return true;
}
BOOL Wh_ModInit() {
CoInitialize(nullptr);
ApplyTheme(L"C:\\Windows\\Resources\\Themes\\aero.theme");
CoUninitialize();
return TRUE;
} |
|
I've been thinking about the "mods as tools" situation (#1916 (comment)). For the reasons I stated in that comment, I think it's best to have each such mod to run in a separate process. Windhawk doesn't have a built-in functionality for something like that, but for now, I implemented some code to handle that. Here's your mod with that code added at the bottom, and with the (now unnecessary) mutex removed: Please try it and let me know if it behaves as expected in all cases. If it is, let's adapt it. In the future, such functionality might become part of Windhawk. |
|
Yes it behaves as expected. So would this implementation only be relevant for mods that inject into explorer in order to prevent shell instability? |
The only thing that is a bit annoying is that when the mod is loading you get the mouse loading indicator for 3-5 seconds |
I don't see it, it loads instantly for me. Can you enable logs and post the logs that you get when the mod is enabled? Also, are there any crash events in the event viewer? Here's a guide for finding crash reports: |
|
Actually I do see the hourglass cursor now. Here's the fix: |
… Wh_FreeStringSetting
…pearance, Return out of loop if exiting
|
Now the only thing that's missing is a readme. Please add it with a description of the mod, what it does, and how to use it. |
|
Congratulations on your first mod! 🎉 |
Automatically changes between light and dark mode based on a set schedule.