(macOS) Disabled reboot and power off menu entries as these require root privileges.

This commit is contained in:
Leon Styhre 2020-08-23 19:17:06 +02:00
parent b8c6366349
commit b7678007fa
4 changed files with 26 additions and 8 deletions

View file

@ -721,11 +721,11 @@ Using this option, you can locate game images in the ROM directory tree. The ima
Displays the framerate and VRAM statistics as an overlay. You normally never need to use this. **Note:** As of version 1.0.0 the VRAM usage statistics is not accurate; this issue will be addressed in future ES versions. Displays the framerate and VRAM statistics as an overlay. You normally never need to use this. **Note:** As of version 1.0.0 the VRAM usage statistics is not accurate; this issue will be addressed in future ES versions.
**Show "reboot system" menu entry** **Show "reboot system" menu entry - Unix and Windows only**
Gives the ability to hide the "Reboot system" entry on the quit menu. Anyone who has accidentally rebooted a system from such a menu will appreciate this. Gives the ability to hide the "Reboot system" entry on the quit menu. Anyone who has accidentally rebooted a system from such a menu will appreciate this.
**Show "power off system" menu entry** **Show "power off system" menu entry - Unix and Windows only**
Gives the ability to hide the "Power off system" entry on the quit menu. Anyone who has accidentally powered off a system from such a menu will appreciate this. Gives the ability to hide the "Power off system" entry on the quit menu. Anyone who has accidentally powered off a system from such a menu will appreciate this.
@ -743,11 +743,11 @@ The menu where you quit ES, or reboot or power off your system.
If the option _"When to save metadata"_ has been set to _"On exit"_, the gamelist.xml files will be updated at this point. If the option _"When to save metadata"_ has been set to _"On exit"_, the gamelist.xml files will be updated at this point.
**Reboot system** **Reboot system - Unix and Windows only**
Can be disabled, meaning the entry will not show up at all. Can be disabled, meaning the entry will not show up at all.
**Power off system** **Power off system - Unix and Windows only**
Can be disabled, meaning the entry will not show up at all. Can be disabled, meaning the entry will not show up at all.

View file

@ -682,6 +682,9 @@ void GuiMenu::openOtherSettings()
s->addSaveFunc([gpu_statistics] { Settings::getInstance()->setBool("DisplayGPUStatistics", s->addSaveFunc([gpu_statistics] { Settings::getInstance()->setBool("DisplayGPUStatistics",
gpu_statistics->getState()); }); gpu_statistics->getState()); });
// macOS requires root privileges to reboot and power off so it doesn't make much
// sense to enable these settings and menu entries for this operating system.
#if !defined(__APPLE__)
// Hide Reboot System option in the quit menu. // Hide Reboot System option in the quit menu.
auto show_rebootsystem = std::make_shared<SwitchComponent>(mWindow); auto show_rebootsystem = std::make_shared<SwitchComponent>(mWindow);
show_rebootsystem->setState(Settings::getInstance()->getBool("ShowRebootSystem")); show_rebootsystem->setState(Settings::getInstance()->getBool("ShowRebootSystem"));
@ -695,6 +698,7 @@ void GuiMenu::openOtherSettings()
s->addWithLabel("SHOW \"POWER OFF SYSTEM\" MENU ENTRY", show_poweroffsystem); s->addWithLabel("SHOW \"POWER OFF SYSTEM\" MENU ENTRY", show_poweroffsystem);
s->addSaveFunc([show_poweroffsystem] { Settings::getInstance()->setBool("ShowPoweroffSystem", s->addSaveFunc([show_poweroffsystem] { Settings::getInstance()->setBool("ShowPoweroffSystem",
show_poweroffsystem->getState()); }); show_poweroffsystem->getState()); });
#endif
mWindow->pushGui(s); mWindow->pushGui(s);
} }
@ -732,6 +736,9 @@ void GuiMenu::openQuitMenu()
} }
} }
// macOS requires root privileges to reboot and power off so it doesn't make much
// sense to enable these settings and menu entries for this operating system.
#if !defined(__APPLE__)
if (Settings::getInstance()->getBool("ShowRebootSystem")) { if (Settings::getInstance()->getBool("ShowRebootSystem")) {
row.elements.clear(); row.elements.clear();
row.makeAcceptInputHandler([window, this] { row.makeAcceptInputHandler([window, this] {
@ -765,6 +772,7 @@ void GuiMenu::openQuitMenu()
Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
s->addRow(row); s->addRow(row);
} }
#endif
mWindow->pushGui(s); mWindow->pushGui(s);
} }

View file

@ -30,18 +30,24 @@
int runRebootCommand() int runRebootCommand()
{ {
#if defined(_WIN64) // Windows. #if defined(_WIN64)
return system("shutdown -r -t 0"); return system("shutdown -r -t 0");
#else // macOS and Linux. #elif defined(__APPLE__)
// This will probably never be used as macOS requires root privileges to reboot.
return system("shutdown -r now");
#else
return system("shutdown --reboot now"); return system("shutdown --reboot now");
#endif #endif
} }
int runPoweroffCommand() int runPoweroffCommand()
{ {
#if defined(_WIN64) // Windows. #if defined(_WIN64)
return system("shutdown -s -t 0"); return system("shutdown -s -t 0");
#else // macOS and Linux. #elif defined(__APPLE__)
// This will probably never be used as macOS requires root privileges to power off.
return system("shutdown now");
#else
return system("shutdown --poweroff now"); return system("shutdown --poweroff now");
#endif #endif
} }

View file

@ -205,8 +205,12 @@ void Settings::setDefaults()
mBoolMap["ShowHiddenFiles"] = true; mBoolMap["ShowHiddenFiles"] = true;
mBoolMap["ShowHiddenGames"] = true; mBoolMap["ShowHiddenGames"] = true;
mBoolMap["DisplayGPUStatistics"] = false; mBoolMap["DisplayGPUStatistics"] = false;
// macOS requires root privileges to reboot and power off so it doesn't make much
// sense to enable these settings and menu entries for this operating system.
#if !defined(__APPLE__)
mBoolMap["ShowRebootSystem"] = true; mBoolMap["ShowRebootSystem"] = true;
mBoolMap["ShowPoweroffSystem"] = true; mBoolMap["ShowPoweroffSystem"] = true;
#endif
// //
// Settings configured via command-line arguments. // Settings configured via command-line arguments.