diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp index 649007004351..932b68c0df42 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp @@ -572,7 +572,7 @@ StackPanel SetupOpenURIControls(StackPanel& parent, StackPanel& row, Shortcut& s } Shortcut tempShortcut; tempShortcut.operationType = Shortcut::OperationType::OpenURI; - tempShortcut.uriToOpen = (uriTextBox.Text().c_str()); + tempShortcut.uriToOpen = ShortcutControl::RemoveExtraQuotes(uriTextBox.Text().c_str()); ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; //ShortcutControl::RunProgramTextOnChange(rowIndex, shortcutRemapBuffer, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput); diff --git a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp index 773693b72e60..aa05c68888af 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp @@ -325,7 +325,7 @@ namespace KeyboardEventHandlers { toast(L"Error", L"the URI is bad"); } - + Logger::trace(L"CKBH:returning.."); return 1; } @@ -1154,7 +1154,7 @@ namespace KeyboardEventHandlers if (targetPid != 0) { Logger::trace(L"CKBH:{}, already running, pid:{}", fileNamePart, targetPid); - if (!ShowProgram(targetPid, fileNamePart, false, true)) + if (!ShowProgram(targetPid, fileNamePart, false, true, 0)) { /*auto future = std::async(std::launch::async, [=] { std::this_thread::sleep_for(std::chrono::milliseconds(30)); @@ -1215,14 +1215,14 @@ namespace KeyboardEventHandlers processId = GetProcessId(newProcessHandle); } - ShowProgram(processId, fileNamePart, true, false); + ShowProgram(processId, fileNamePart, true, false, 0); } return; } - bool ShowProgram(DWORD pid, std::wstring programName, bool isNewProcess, bool hideIfVisible) + bool ShowProgram(DWORD pid, std::wstring programName, bool isNewProcess, bool hideIfVisible, int retryCount) { - Logger::trace(L"CKBH:ShowProgram starting with {},{},{}", pid, programName, isNewProcess); + Logger::trace(L"CKBH:ShowProgram starting with {},{},{}, retryCount:{}", pid, programName, isNewProcess, retryCount); // a good place to look for this... // https://github.com/ritchielawrence/cmdow @@ -1245,7 +1245,7 @@ namespace KeyboardEventHandlers } else { - Logger::trace(L"CKBH:{}, no GetForegroundWindow, doing SW_RESTORE", programName); + Logger::trace(L"CKBH:{}, not ForegroundWindow, doing SW_RESTORE", programName); // Check if the window is minimized if (IsIconic(hwnd)) @@ -1275,7 +1275,16 @@ namespace KeyboardEventHandlers } else { - Logger::trace(L"CKBH:{}, No hwnd from FindMainWindow", programName); + if (retryCount < 20) + { + Logger::trace(L"CKBH:hwnd not found will retry for pid:{}", pid); + + auto future = std::async(std::launch::async, [=] { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + ShowProgram(pid, programName, isNewProcess, hideIfVisible, retryCount + 1); + return false; + }); + } } if (isNewProcess) diff --git a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.h b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.h index cefdd21b16be..5ad7c547e527 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.h +++ b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.h @@ -59,7 +59,7 @@ namespace KeyboardEventHandlers std::wstring GetFileNameFromPath(const std::wstring& fullPath); // Function to a find and show a running program - bool ShowProgram(DWORD pid, std::wstring programName, bool isNewProcess, bool hideIfVisible); + bool ShowProgram(DWORD pid, std::wstring programName, bool isNewProcess, bool hideIfVisible, int retryCount); // Function to a handle an os-level shortcut remap intptr_t HandleOSLevelShortcutRemapEvent(KeyboardManagerInput::InputInterface& ii, LowlevelKeyboardEvent* data, State& state) noexcept;