mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
fix(EnsureAvailableMemory/macOS): warn based on memory pressure rather than available RAM
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
ae331cfc9a
commit
0b578fa767
4 changed files with 83 additions and 10 deletions
|
|
@ -25,6 +25,47 @@ EnsureAvailableMemory::EnsureAvailableMemory(LaunchTask* parent, MinecraftInstan
|
|||
|
||||
void EnsureAvailableMemory::executeTask()
|
||||
{
|
||||
#ifdef Q_OS_MACOS
|
||||
QString text;
|
||||
switch (MacOSHardwareInfo::memoryPressureLevel()) {
|
||||
case MacOSHardwareInfo::MemoryPressureLevel::Normal:
|
||||
emitSucceeded();
|
||||
return;
|
||||
case MacOSHardwareInfo::MemoryPressureLevel::Warning:
|
||||
text =
|
||||
tr("The system is under increased memory pressure. This may cause lag or slowdowns.\n"
|
||||
"If possible, close other applications before continuing.\n\n"
|
||||
"Launch anyway?");
|
||||
break;
|
||||
case MacOSHardwareInfo::MemoryPressureLevel::Critical:
|
||||
text =
|
||||
tr("Your system is under critical memory pressure. This may lead to severe slowdowns or crashes.\n"
|
||||
"It is highly recommended to close other applications or restart your system.\n\n"
|
||||
"Launch anyway?");
|
||||
break;
|
||||
}
|
||||
|
||||
bool shouldAbort = false;
|
||||
|
||||
if (m_instance->settings()->get("LowMemWarning").toBool()) {
|
||||
auto* dialog = CustomMessageBox::selectable(nullptr, tr("High memory pressure"), text, QMessageBox::Icon::Warning,
|
||||
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No,
|
||||
QMessageBox::StandardButton::No);
|
||||
|
||||
shouldAbort = dialog->exec() == QMessageBox::No;
|
||||
dialog->deleteLater();
|
||||
}
|
||||
|
||||
const auto message = tr("The system is under high memory pressure");
|
||||
if (shouldAbort) {
|
||||
emit logLine(message, MessageLevel::Fatal);
|
||||
emitFailed(message);
|
||||
return;
|
||||
}
|
||||
|
||||
emit logLine(message, MessageLevel::Warning);
|
||||
emitSucceeded();
|
||||
#else
|
||||
const uint64_t available = HardwareInfo::availableRamMiB();
|
||||
if (available == 0) {
|
||||
// could not read
|
||||
|
|
@ -66,4 +107,5 @@ void EnsureAvailableMemory::executeTask()
|
|||
}
|
||||
|
||||
emitSucceeded();
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,12 @@ void PrintInstanceInfo::executeTask()
|
|||
::runPciconf(log);
|
||||
#else
|
||||
log << "CPU: " + HardwareInfo::cpuInfo();
|
||||
#ifdef Q_OS_MACOS
|
||||
log << "Memory pressure level: " + MacOSHardwareInfo::memoryPressureLevelName();
|
||||
#else
|
||||
log << QString("RAM: %1 MiB (available: %2 MiB)").arg(HardwareInfo::totalRamMiB()).arg(HardwareInfo::availableRamMiB());
|
||||
#endif
|
||||
|
||||
#endif
|
||||
log.append(HardwareInfo::gpuInfo());
|
||||
log << "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue