1
0
mirror of synced 2024-11-28 09:30:51 +01:00

impr: Make providers close instantly

This commit is contained in:
WerWolv 2024-06-05 23:02:38 +02:00
parent 4797512207
commit 789d469477

View File

@ -185,24 +185,24 @@ namespace hex {
impl::s_hoveringFunctions->erase(id);
}
static u32 tooltipId = 0;
static u32 s_tooltipId = 0;
u32 addTooltip(Region region, std::string value, color_t color) {
tooltipId++;
impl::s_tooltips->insert({ tooltipId, { region, std::move(value), color } });
s_tooltipId++;
impl::s_tooltips->insert({ s_tooltipId, { region, std::move(value), color } });
return tooltipId;
return s_tooltipId;
}
void removeTooltip(u32 id) {
impl::s_tooltips->erase(id);
}
static u32 tooltipFunctionId;
static u32 s_tooltipFunctionId;
u32 addTooltipProvider(TooltipFunction function) {
tooltipFunctionId++;
impl::s_tooltipFunctions->insert({ tooltipFunctionId, std::move(function) });
s_tooltipFunctionId++;
impl::s_tooltipFunctions->insert({ s_tooltipFunctionId, std::move(function) });
return tooltipFunctionId;
return s_tooltipFunctionId;
}
void removeTooltipProvider(u32 id) {
@ -269,6 +269,7 @@ namespace hex {
static i64 s_currentProvider = -1;
static AutoReset<std::vector<std::unique_ptr<prv::Provider>>> s_providers;
static AutoReset<std::list<std::unique_ptr<prv::Provider>>> s_providersToRemove;
namespace impl {
@ -425,20 +426,37 @@ namespace hex {
}
}
provider->close();
EventProviderClosed::post(provider);
static std::mutex eraseMutex;
// Move provider over to a list of providers to delete
eraseMutex.lock();
auto removeIt = s_providersToRemove->emplace(s_providersToRemove->end(), std::move(*it));
eraseMutex.unlock();
// Remove left over references from the main provider list
s_providers->erase(it);
impl::s_closingProviders.erase(provider);
if (s_currentProvider >= i64(s_providers->size()))
setCurrentProvider(0);
if (s_providers->empty())
EventProviderChanged::post(provider, nullptr);
EventProviderClosed::post(removeIt->get());
RequestUpdateWindowTitle::post();
TaskManager::runWhenTasksFinished([it, provider] {
EventProviderDeleted::post(provider);
impl::s_closingProviders.erase(provider);
// Do the destruction of the provider in the background once all tasks have finished
TaskManager::runWhenTasksFinished([removeIt] {
EventProviderDeleted::post(removeIt->get());
TaskManager::createBackgroundTask("Closing Provider", [removeIt](Task &) {
eraseMutex.lock();
auto provider = std::move(*removeIt);
s_providersToRemove->erase(removeIt);
eraseMutex.unlock();
s_providers->erase(it);
if (s_currentProvider >= i64(s_providers->size()))
setCurrentProvider(0);
if (s_providers->empty())
EventProviderChanged::post(provider, nullptr);
provider->close();
});
});
}
@ -615,7 +633,7 @@ namespace hex {
}
void* getLibImHexModuleHandle() {
return hex::getContainingModule((void*)&getLibImHexModuleHandle);
return hex::getContainingModule(reinterpret_cast<void*>(&getLibImHexModuleHandle));
}
@ -745,22 +763,22 @@ namespace hex {
}
std::optional<LinuxDistro> getLinuxDistro() {
std::ifstream file("/etc/os-release");
wolv::io::File file("/etc/os-release", wolv::io::File::Mode::Read);
std::string name;
std::string version;
std::string line;
while (std::getline(file, line)) {
auto fileContent = file.readString();
for (const auto &line : wolv::util::splitString(fileContent, "\n")) {
if (line.find("PRETTY_NAME=") != std::string::npos) {
name = line.substr(line.find("=") + 1);
name.erase(std::remove(name.begin(), name.end(), '\"'), name.end());
std::erase(name, '\"');
} else if (line.find("VERSION_ID=") != std::string::npos) {
version = line.substr(line.find("=") + 1);
version.erase(std::remove(version.begin(), version.end(), '\"'), version.end());
std::erase(version, '\"');
}
}
return {{name, version}};
return { { name, version } };
}
std::string getImHexVersion(bool withBuildType) {