Skip to content

Commit fb16dd8

Browse files
committed
Fix shutdown/restart commands on Windows.
1 parent 01923f3 commit fb16dd8

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

es-app/src/guis/GuiMenu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
180180
row.makeAcceptInputHandler([window] {
181181
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
182182
[] {
183-
if(system("sudo shutdown -r now") != 0)
183+
if(runRestartCommand() != 0)
184184
LOG(LogWarning) << "Restart terminated with non-zero result!";
185185
}, "NO", nullptr));
186186
});
@@ -191,7 +191,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
191191
row.makeAcceptInputHandler([window] {
192192
window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES",
193193
[] {
194-
if(system("sudo shutdown -h now") != 0)
194+
if(runShutdownCommand() != 0)
195195
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
196196
}, "NO", nullptr));
197197
});

es-core/src/platform.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,21 @@ std::string getHomePath()
3434
boost::filesystem::path genericPath(homePath);
3535
return genericPath.generic_string();
3636
}
37+
38+
int runShutdownCommand()
39+
{
40+
#ifdef WIN32 // windows
41+
return system("shutdown -s -t 0");
42+
#else // osx / linux
43+
return system("sudo shutdown -h now");
44+
#endif
45+
}
46+
47+
int runRestartCommand()
48+
{
49+
#ifdef WIN32 // windows
50+
return system("shutdown -r -t 0");
51+
#else // osx / linux
52+
return system("sudo shutdown -r now");
53+
#endif
54+
}

es-core/src/platform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
#include <string>
1919

2020
std::string getHomePath();
21-
void setHomePathOverride(const std::string& path);
21+
22+
int runShutdownCommand(); // shut down the system (returns 0 if successful)
23+
int runRestartCommand(); // restart the system (returns 0 if successful)

0 commit comments

Comments
 (0)