Repository navigation
Add a restart option to the exit prompt #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b29758a
ac2dded
e93739b
f4e8324
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| #include "settings_overlay.h" | ||
| #include "steam_input_layout.h" | ||
| #include "runtime_config.h" | ||
| #include "platform/host_platform.h" | ||
| #include "gx_worker.h" | ||
| #include "perf_stats.h" | ||
|
|
||
|
|
@@ -62,17 +63,32 @@ inline void Flush(bool force = false) { | |
| // fiber re-enters runtime teardown and can fault while the fiber machinery is | ||
| // still active. A window close is an intentional successful exit, so end the | ||
| // process directly and do not run the crash/atexit paths. | ||
| [[noreturn]] inline void ExitForAuroraWindowClose() noexcept { | ||
| settings_overlay::ReleaseControllers(); | ||
| SteamInputLayout::Release(); | ||
| WindowPlacementPersistence::Flush(true); | ||
| [[noreturn]] inline void ExitAuroraProcess() noexcept { | ||
| #if defined(_WIN32) | ||
| ::ExitProcess(0); | ||
| #else | ||
| std::_Exit(EXIT_SUCCESS); | ||
| #endif | ||
| } | ||
|
|
||
| [[noreturn]] inline void ExitForAuroraWindowClose() noexcept { | ||
| settings_overlay::ReleaseControllers(); | ||
| SteamInputLayout::Release(); | ||
| WindowPlacementPersistence::Flush(true); | ||
| ExitAuroraProcess(); | ||
| } | ||
|
|
||
| // Returns only if the new instance could not be started; the LED is left for the new instance to set. | ||
| inline void RestartForAuroraWindowClose() noexcept { | ||
| WindowPlacementPersistence::Flush(true); | ||
| settings_overlay::ReleaseControllers(false); | ||
| // The Steam Input layout is only restored once the new instance exists, so a failed restart keeps it. | ||
| if (RuntimePlatform::RelaunchSelf()) { | ||
| SteamInputLayout::Release(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Serialize the restart handoff so the replacement's layout is not overwritten.
Require the parent to deliver its restore before the replacement sends its apply, or require the replacement to confirm its override after the parent restore. Either change removes the race. Choose the mechanism that matches the platform's handoff contract.
|
||
| ExitAuroraProcess(); | ||
| } | ||
| } | ||
|
|
||
| // Update cached Aurora window/framebuffer dimensions based on pending events. | ||
| inline void ProcessAuroraEvents(const AuroraEvent* events) { | ||
| if (!events) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,18 @@ | |
| #include <windows.h> | ||
| #include <shlobj.h> | ||
| #else | ||
| #include <climits> | ||
| #include <fcntl.h> | ||
| #include <spawn.h> | ||
| #include <unistd.h> | ||
| #endif | ||
|
|
||
| #if !defined(_WIN32) && !defined(__APPLE__) | ||
| #include <dirent.h> | ||
| #endif | ||
|
|
||
| #if defined(__APPLE__) | ||
| #include <crt_externs.h> | ||
| #include <mach-o/dyld.h> | ||
| #include <pwd.h> | ||
| #endif | ||
|
|
@@ -95,4 +103,62 @@ uint64_t CurrentProcessId() noexcept { | |
| #endif | ||
| } | ||
|
|
||
| bool RelaunchSelf() noexcept { | ||
| #if defined(_WIN32) | ||
| std::wstring path(32768, L'\0'); | ||
| const DWORD length = GetModuleFileNameW(nullptr, path.data(), static_cast<DWORD>(path.size())); | ||
| if (length == 0 || length >= path.size()) { | ||
| return false; | ||
| } | ||
| path.resize(length); | ||
| std::wstring commandLine = GetCommandLineW(); | ||
| STARTUPINFOW startup{}; | ||
| startup.cb = sizeof(startup); | ||
| PROCESS_INFORMATION process{}; | ||
| if (!CreateProcessW(path.c_str(), commandLine.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, | ||
| &startup, &process)) { | ||
| return false; | ||
| } | ||
| CloseHandle(process.hThread); | ||
| CloseHandle(process.hProcess); | ||
| return true; | ||
| #else | ||
| std::string path; | ||
| // Mark inherited descriptors close-on-exec, or the new instance keeps this one's sockets and devices open. | ||
| #if defined(__APPLE__) | ||
| uint32_t size = 0; | ||
| if (_NSGetExecutablePath(nullptr, &size) != -1 || size == 0) { | ||
| return false; | ||
| } | ||
| path.resize(size); | ||
| if (_NSGetExecutablePath(path.data(), &size) != 0) { | ||
| return false; | ||
| } | ||
| char** const env = *_NSGetEnviron(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| for (int fd = 3, max = getdtablesize(); fd < max; ++fd) { | ||
| fcntl(fd, F_SETFD, FD_CLOEXEC); | ||
| } | ||
| #else | ||
| path.resize(PATH_MAX); | ||
| const ssize_t length = readlink("/proc/self/exe", path.data(), path.size() - 1); | ||
| if (length <= 0) { | ||
| return false; | ||
| } | ||
| path.resize(static_cast<size_t>(length)); | ||
| char** const env = environ; | ||
| if (DIR* dir = opendir("/proc/self/fd")) { | ||
| while (const dirent* entry = readdir(dir)) { | ||
| if (const int fd = std::atoi(entry->d_name); fd > 2 && fd != dirfd(dir)) { | ||
| fcntl(fd, F_SETFD, FD_CLOEXEC); | ||
| } | ||
| } | ||
| closedir(dir); | ||
| } | ||
| #endif | ||
| char* const argv[] = {path.data(), nullptr}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve the original POSIX arguments. A graphical
|
||
| pid_t pid = 0; | ||
| return posix_spawn(&pid, path.c_str(), nullptr, nullptr, argv, env) == 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the restart from writing transcript mirrors into the parent's pipe. On POSIX, The replacement must not write to the parent's transcript pipe after the parent exits. The required behavior is either of these:
Choosing between these depends on the desired console behavior, which this review does not establish. Either option must keep the replacement's own transcript intact.
|
||
| #endif | ||
| } | ||
|
|
||
| } // namespace RuntimePlatform | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore Wii Remote input when the relaunch fails.
RestartForAuroraWindowClose()releases the controllers before it callsRuntimePlatform::RelaunchSelf(). The release callsWiimote::Shutdown(), which powers off the remotes and stops the scanner. IfRelaunchSelf()returns false, the function returns and the game keeps running. Nothing on that path starts the remote manager again. Wii Remote input stays unavailable until the process restarts.On the failure path, restart Wii Remote scanning. Call
Wiimote::Initialize()after theRelaunchSelf()check fails.