2021-05-29 19:52:18 +00:00
|
|
|
#include <hex/plugin.hpp>
|
|
|
|
|
2022-02-01 17:09:40 +00:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2022-12-29 18:26:00 +00:00
|
|
|
#include <hex/api/theme_manager.hpp>
|
2022-12-05 08:31:16 +00:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2022-02-01 17:09:40 +00:00
|
|
|
|
2022-12-02 11:00:04 +00:00
|
|
|
#include <romfs/romfs.hpp>
|
2022-02-15 21:50:04 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2021-05-29 19:52:18 +00:00
|
|
|
#include "views/view_tty_console.hpp"
|
|
|
|
|
2022-02-15 21:50:04 +00:00
|
|
|
using namespace hex;
|
|
|
|
|
2021-06-06 16:19:17 +00:00
|
|
|
namespace hex::plugin::windows {
|
|
|
|
|
2021-06-06 17:17:51 +00:00
|
|
|
void addFooterItems();
|
2022-02-01 23:36:09 +00:00
|
|
|
void addTitleBarButtons();
|
2021-10-31 15:28:10 +00:00
|
|
|
void registerSettings();
|
2023-01-01 01:29:38 +00:00
|
|
|
void registerProviders();
|
2021-06-06 16:19:17 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 21:50:04 +00:00
|
|
|
static void detectSystemTheme() {
|
|
|
|
// Setup system theme change detector
|
2022-08-08 09:22:59 +00:00
|
|
|
EventManager::subscribe<EventOSThemeChanged>([] {
|
2023-02-02 20:13:56 +00:00
|
|
|
bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color").get<std::string>() == api::ThemeManager::NativeTheme;
|
2022-08-08 09:22:59 +00:00
|
|
|
if (!themeFollowSystem)
|
|
|
|
return;
|
2022-02-15 21:50:04 +00:00
|
|
|
|
|
|
|
HKEY hkey;
|
|
|
|
if (RegOpenKey(HKEY_CURRENT_USER, R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", &hkey) == ERROR_SUCCESS) {
|
|
|
|
DWORD value = 0;
|
|
|
|
DWORD size = sizeof(DWORD);
|
|
|
|
|
|
|
|
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
|
|
|
|
if (error == ERROR_SUCCESS) {
|
2022-12-29 18:26:00 +00:00
|
|
|
EventManager::post<RequestChangeTheme>(value == 0 ? "Dark" : "Light");
|
2022-06-30 13:09:57 +00:00
|
|
|
} else {
|
2022-08-09 14:29:52 +00:00
|
|
|
ImHexApi::System::impl::setBorderlessWindowMode(false);
|
2022-02-15 21:50:04 +00:00
|
|
|
}
|
2022-08-09 14:29:52 +00:00
|
|
|
} else {
|
|
|
|
ImHexApi::System::impl::setBorderlessWindowMode(false);
|
2022-02-15 21:50:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
EventManager::subscribe<EventWindowInitialized>([=] {
|
2023-02-02 20:13:56 +00:00
|
|
|
bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color").get<std::string>() == api::ThemeManager::NativeTheme;
|
2022-08-08 09:22:59 +00:00
|
|
|
|
2022-02-15 21:50:04 +00:00
|
|
|
if (themeFollowSystem)
|
|
|
|
EventManager::post<EventOSThemeChanged>();
|
|
|
|
});
|
|
|
|
}
|
2021-06-06 16:19:17 +00:00
|
|
|
|
2022-02-15 22:07:48 +00:00
|
|
|
static void checkBorderlessWindowOverride() {
|
|
|
|
bool borderlessWindowForced = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.force_borderless_window_mode", 0) != 0;
|
|
|
|
|
|
|
|
if (borderlessWindowForced)
|
|
|
|
ImHexApi::System::impl::setBorderlessWindowMode(true);
|
|
|
|
}
|
|
|
|
|
2021-05-29 19:52:18 +00:00
|
|
|
IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") {
|
2021-06-06 16:19:17 +00:00
|
|
|
using namespace hex::plugin::windows;
|
|
|
|
|
2022-12-05 08:31:16 +00:00
|
|
|
hex::log::debug("Using romfs: '{}'", romfs::name());
|
2022-12-02 11:00:04 +00:00
|
|
|
for (auto &path : romfs::list("lang"))
|
|
|
|
hex::ContentRegistry::Language::addLocalization(nlohmann::json::parse(romfs::get(path).string()));
|
|
|
|
|
2022-02-16 20:32:33 +00:00
|
|
|
hex::ContentRegistry::Views::add<ViewTTYConsole>();
|
|
|
|
|
2021-06-06 17:17:51 +00:00
|
|
|
addFooterItems();
|
2022-02-01 23:36:09 +00:00
|
|
|
addTitleBarButtons();
|
2021-10-31 15:28:10 +00:00
|
|
|
registerSettings();
|
2023-01-01 01:29:38 +00:00
|
|
|
registerProviders();
|
2022-02-15 21:50:04 +00:00
|
|
|
|
|
|
|
detectSystemTheme();
|
2022-02-15 22:07:48 +00:00
|
|
|
checkBorderlessWindowOverride();
|
2021-05-29 19:52:18 +00:00
|
|
|
}
|