diff --git a/extensions/devtools.cpp b/extensions/devtools.cpp index 6e99f65..d6ff2e6 100644 --- a/extensions/devtools.cpp +++ b/extensions/devtools.cpp @@ -1,4 +1,5 @@ #include "devtools.h" +#include "module.h" #include #include #include @@ -89,12 +90,17 @@ namespace DevTools void Initialize() { QString chromePath = settings.value(CHROME_LOCATION).toString(); - wchar_t programFiles[MAX_PATH + 100] = {}; - if (chromePath.isEmpty()) for (auto folder : { CSIDL_PROGRAM_FILESX86, CSIDL_PROGRAM_FILES, CSIDL_LOCAL_APPDATA }) + if (chromePath.isEmpty()) { - SHGetFolderPathW(NULL, folder, NULL, SHGFP_TYPE_CURRENT, programFiles); - wcscat_s(programFiles, L"/Google/Chrome/Application/chrome.exe"); - if (std::filesystem::exists(programFiles)) chromePath = S(programFiles); + for (auto [_, process] : GetAllProcesses()) + if (process && process->find(L"\\chrome.exe") != std::string::npos) chromePath = S(process.value()); + wchar_t programFiles[MAX_PATH + 100] = {}; + for (auto folder : { CSIDL_PROGRAM_FILESX86, CSIDL_PROGRAM_FILES, CSIDL_LOCAL_APPDATA }) + { + SHGetFolderPathW(NULL, folder, NULL, SHGFP_TYPE_CURRENT, programFiles); + wcscat_s(programFiles, L"/Google/Chrome/Application/chrome.exe"); + if (std::filesystem::exists(programFiles)) chromePath = S(programFiles); + } } auto chromePathEdit = new QLineEdit(chromePath); static struct : QObject diff --git a/extensions/translatewrapper.cpp b/extensions/translatewrapper.cpp index 17bb208..77f9271 100644 --- a/extensions/translatewrapper.cpp +++ b/extensions/translatewrapper.cpp @@ -192,7 +192,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) if (useCache) { auto translationCache = ::translationCache.Acquire(); - if (auto it = translationCache->find(sentence); it != translationCache->end()) translation = it->second + L"\x200b"; // dumb hack to not try to translate if stored empty translation + if (auto it = translationCache->find(sentence); it != translationCache->end()) translation = it->second; } if (translation.empty() && (!translateSelectedOnly || sentenceInfo["current select"])) if (rateLimiter.Request() || !useRateLimiter || (!rateLimitSelected && sentenceInfo["current select"])) std::tie(cache, translation) = Translate(sentence, tlp.Copy());