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