Merge pull request #7859 from Robyt3/Windows-ShellExecute-Fixes

Ensure client window is maximized and active after restarting, refactoring
This commit is contained in:
Jupeyy 2024-01-27 11:27:40 +00:00 committed by GitHub
commit 349eb38ebf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 27 deletions

View file

@ -4106,7 +4106,7 @@ void cmdline_free(int argc, const char **argv)
#endif
}
PROCESS shell_execute(const char *file)
PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state)
{
#if defined(CONF_FAMILY_WINDOWS)
const std::wstring wide_file = windows_utf8_to_wide(file);
@ -4116,7 +4116,18 @@ PROCESS shell_execute(const char *file)
info.cbSize = sizeof(SHELLEXECUTEINFOW);
info.lpVerb = L"open";
info.lpFile = wide_file.c_str();
info.nShow = SW_SHOWMINNOACTIVE;
switch(window_state)
{
case EShellExecuteWindowState::FOREGROUND:
info.nShow = SW_SHOW;
break;
case EShellExecuteWindowState::BACKGROUND:
info.nShow = SW_SHOWMINNOACTIVE;
break;
default:
dbg_assert(false, "window_state invalid");
dbg_break();
}
info.fMask = SEE_MASK_NOCLOSEPROCESS;
// Save and restore the FPU control word because ShellExecute might change it
fenv_t floating_point_environment;

View file

@ -2517,26 +2517,29 @@ typedef pid_t PROCESS;
constexpr PROCESS INVALID_PROCESS = 0;
#endif
/*
Function: shell_execute
Executes a given file.
enum class EShellExecuteWindowState
{
FOREGROUND,
BACKGROUND,
};
Returns:
handle/pid of the new process
*/
PROCESS shell_execute(const char *file);
/**
* Executes a given file.
*
* @param file The file to execute.
* @param window_state The window state how the process window should be shown.
*
* @return Handle of the new process, or `INVALID_PROCESS` on error.
*/
PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state);
/*
Function: kill_process
Sends kill signal to a process.
Parameters:
process - handle/pid of the process
Returns:
0 - Error
1 - Success
*/
/**
* Sends kill signal to a process.
*
* @param process Handle of the process to kill.
*
* @return 1 on success, 0 on error.
*/
int kill_process(PROCESS process);
/**

View file

@ -4508,7 +4508,7 @@ int main(int argc, const char **argv)
if(Restarting)
{
shell_execute(aRestartBinaryPath);
shell_execute(aRestartBinaryPath, EShellExecuteWindowState::FOREGROUND);
}
PerformFinalCleanup();

View file

@ -146,13 +146,9 @@ void CMenus::RenderStartMenu(CUIRect MainView)
char aBuf[IO_MAX_PATH_LENGTH];
Storage()->GetBinaryPath(PLAT_SERVER_EXEC, aBuf, sizeof(aBuf));
// No / in binary path means to search in $PATH, so it is expected that the file can't be opened. Just try executing anyway.
if(str_find(aBuf, "/") == 0)
if(str_find(aBuf, "/") == 0 || fs_is_file(aBuf))
{
m_ServerProcess.m_Process = shell_execute(aBuf);
}
else if(fs_is_file(aBuf))
{
m_ServerProcess.m_Process = shell_execute(aBuf);
m_ServerProcess.m_Process = shell_execute(aBuf, EShellExecuteWindowState::BACKGROUND);
}
else
{