Skip to content
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

ウィンドウスレッド以外からTVTestのAPIを呼び出さないようにする、など #115

Merged
merged 4 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TVTComment/Model/IPC/IPCMessage/ChatIPCMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Decode(IEnumerable<string> content)
public IEnumerable<string> Encode()
{
string[] ret = new string[5];
ret[0] = Chat.Text;
ret[0] = Chat.Text.Replace('\u001E', '〓').Replace('\u001F', '〓');
switch (Chat.Position)
{
case Chat.PositionType.Normal:
Expand Down
7 changes: 3 additions & 4 deletions Viewer/TVTComment/IPC/RawIPCMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ namespace TVTComment
{
std::string RawIPCMessage::ToString() const
{
std::string ret;
std::string ret = this->MessageName;
for (const std::string &content : this->Contents)
ret += content+" ";
ret.pop_back();
return this->MessageName + ret;
ret += " " + content;
return ret;
}
}
17 changes: 12 additions & 5 deletions Viewer/TVTComment/TVTComment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace TVTComment
if (CreateProcessW(NULL, &(this->collectExePath + L" " + receivePipeName.substr(9) + L" " + sendPipeName.substr(9))[0], NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) == 0)
throw std::system_error(std::system_error(GetLastError(), std::system_category()));
pid = pi.dwProcessId;
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

this->ipcTunnel->Connect();
}
Expand Down Expand Up @@ -135,7 +137,11 @@ namespace TVTComment
}
else if (auto message = dynamic_cast<const ChannelSelectIPCMessage *>(&msg))
{
this->tvtest->SetChannel(message->SpaceIndex, message->ChannelIndex,message->ServiceId);
//タイムアウトつきでウィンドウスレッドにチャンネル変更を指示する
this->channelSelectSpaceIndex = message->SpaceIndex;
this->channelSelectChannelIndex = message->ChannelIndex;
this->channelSelectServiceId = message->ServiceId;
SendMessageTimeout(this->dialog, WM_CHANNELSELECT, 0, 0, SMTO_NORMAL, CHANNELSELECT_TIMEOUT, nullptr);
}
else if (auto message = dynamic_cast<const CloseIPCMessage *>(&msg))
{
Expand All @@ -146,7 +152,6 @@ namespace TVTComment
else if (auto message = dynamic_cast<const SetChatOpacityIPCMessage *>(&msg))
{
lastOpacity = (WPARAM)message->Opacity;
this->tvtest->SetPluginCommandState(static_cast<int>(Command::HideComment), 0);
PostMessage(this->dialog, WM_SETCHATOPACITY, (WPARAM)message->Opacity, 0);
}
#pragma warning(pop)
Expand Down Expand Up @@ -276,6 +281,10 @@ namespace TVTComment
case WM_ONCHANNELSELECTIONCHANGE:
this->OnChannelSelectionChange();
break;

case WM_CHANNELSELECT:
this->tvtest->SetChannel(this->channelSelectSpaceIndex, this->channelSelectChannelIndex, this->channelSelectServiceId);
break;
}

return FALSE;
Expand Down Expand Up @@ -400,12 +409,10 @@ namespace TVTComment
case Command::HideComment:
if (this->commentWindow->GetOpacity() != 0) {
lastOpacity = this->commentWindow->GetOpacity();
PostMessage(this->dialog, WM_SETCHATOPACITY, 0, 0);
this->tvtest->SetPluginCommandState(static_cast<int>(Command::HideComment), TVTest::COMMAND_ICON_STATE_CHECKED);
PostMessage(this->dialog, WM_SETCHATOPACITY, 0, 1);
}
else {
PostMessage(this->dialog, WM_SETCHATOPACITY, lastOpacity, 0);
this->tvtest->SetPluginCommandState(static_cast<int>(Command::HideComment), 0);
}
break;
}
Expand Down
8 changes: 7 additions & 1 deletion Viewer/TVTComment/TVTComment.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ namespace TVTComment

std::wstring collectExePath;//起動するEXEのパス

int channelSelectSpaceIndex;//WM_CHANNELSELECTをタイムアウトつきで呼び出すときの引数
int channelSelectChannelIndex;
uint16_t channelSelectServiceId;
static constexpr int CHANNELSELECT_TIMEOUT = 5000;//WM_CHANNELSELECTの完了を待つタイムアウト(ミリ秒)

static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf8_utf16_conv;

private:
Expand All @@ -69,7 +74,8 @@ namespace TVTComment
static constexpr int WM_DISABLEPLUGIN = WM_APP + 1002;//プラグインを無効化する(別スレッドから無効化するときに使う)
static constexpr int WM_ONCHANNELLISTCHANGE = WM_APP + 1003;//メンバ関数OnChannelListChangeを呼ぶ(別スレッドから送るときに使う)
static constexpr int WM_ONCHANNELSELECTIONCHANGE = WM_APP + 1004;//メンバ関数OnChannelSelectionChangeを呼ぶ(別スレッドから送るときに使う)
static constexpr int WM_SETCHATOPACITY = WM_APP + 1005;//コメント透過度を設定する wParamに透過度を渡す(0~255)
static constexpr int WM_SETCHATOPACITY = WM_APP + 1005;//コメント透過度を設定する wParamに透過度(0~255)、lParamに表示状態(非0で非表示)を渡す
static constexpr int WM_CHANNELSELECT = WM_APP + 1006;//チャンネル変更する

enum class UserInteractionRequestType{ConnectSucceed,ConnectFail,InvalidMessage,ReceiveError,SendError, FetalErrorInTask};

Expand Down
2 changes: 2 additions & 0 deletions Viewer/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ LRESULT CViewer::ForceWindowProcMain(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
commentWindow_.Destroy();
}
commentWindow_.SetOpacity(newOpacity);
bool hideState = lParam != 0;
m_pApp->SetPluginCommandState(static_cast<int>(TVTComment::Command::HideComment), hideState ? TVTest::COMMAND_ICON_STATE_CHECKED : 0);
break;
}
#pragma endregion
Expand Down