Skip to content

Commit

Permalink
feat: simple guardian for WeaselServer.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed May 22, 2024
1 parent 957a8e3 commit a439ac7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions WeaselTSF/LanguageBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ void CLangBarItemButton::SetLangbarStatus(DWORD dwStatus, BOOL fSet) {
return;
}

std::wstring WeaselTSF::_GetRootDir() {
std::wstring dir{};
RegGetStringValue(HKEY_LOCAL_MACHINE, GetWeaselRegName(), L"WeaselRoot", dir);
return dir;
}

void WeaselTSF::_HandleLangBarMenuSelect(UINT wID) {
std::wstring dir{};
switch (wID) {
Expand Down
16 changes: 16 additions & 0 deletions WeaselTSF/WeaselTSF.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "stdafx.h"

#include <WeaselIPCData.h>
#include <thread>
#include <shellapi.h>
#include "WeaselTSF.h"
#include "CandidateList.h"
#include "LanguageBar.h"
Expand Down Expand Up @@ -217,6 +219,8 @@ STDMETHODIMP WeaselTSF::OnActivated(REFCLSID clsid,
return S_OK;
}

static unsigned int retry = 0;

void WeaselTSF::_EnsureServerConnected() {
if (!m_client.Echo()) {
m_client.Disconnect();
Expand All @@ -227,5 +231,17 @@ void WeaselTSF::_EnsureServerConnected() {
if (ok) {
_UpdateLanguageBar(_status);
}
retry++;
if (retry >= 6) {
if (!m_client.Echo()) {
std::wstring dir = _GetRootDir();
std::thread th([dir]() {
ShellExecuteW(NULL, L"open", (dir + L"\\start_service.bat").c_str(),
NULL, dir.c_str(), SW_HIDE);
});
th.detach();
}
retry = 0;
}
}
}
2 changes: 2 additions & 0 deletions WeaselTSF/WeaselTSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class WeaselTSF : public ITfTextInputProcessorEx,
void _UninitCompartment();
HRESULT _HandleCompartment(REFGUID guidCompartment);

std::wstring _GetRootDir();

bool isImmersive() const {
return (_activateFlags & TF_TMF_IMMERSIVEMODE) != 0;
}
Expand Down

0 comments on commit a439ac7

Please sign in to comment.