Skip to content

Commit 97f6955

Browse files
committed
(feat) add explicit disconnect on gui close
1 parent cb2148a commit 97f6955

6 files changed

Lines changed: 41 additions & 5 deletions

File tree

pipetap-dll/inject/control_server.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ namespace pipetap::inject {
623623
}
624624
break;
625625

626+
case PT_CMD_CLIENT_DISCONNECT:
627+
NamedPipeClient::instance().close_all(/*reason=*/0u, /*win32err=*/0u);
628+
break;
629+
626630
default:
627631
// Ignore unknown control messages
628632
break;

pipetap-gui/app/app.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ namespace pipetap {
2525
using pipetap::win::IntegrityRidToCStr;
2626
using pipetap::win::RelaunchAsAdministrator;
2727

28+
namespace {
29+
ui::replay::Manager& ReplayManager() { static ui::replay::Manager replay; return replay; }
30+
ui::proxy::Manager& ProxyManager() { static ui::proxy::Manager proxy; return proxy; }
31+
injection::VM& InjectorVm() { static injection::VM inj; return inj; }
32+
ui::pipelist::VM& PipesVm() { static ui::pipelist::VM pipelist; return pipelist; }
33+
}
34+
2835
static void MenuBarRightText(const char* txt, const ImVec4* color = nullptr) {
2936
float w = ImGui::CalcTextSize(txt).x;
3037
float full = ImGui::GetWindowContentRegionMax().x;
@@ -44,10 +51,10 @@ namespace pipetap {
4451
}
4552

4653
void UI() {
47-
static ui::replay::Manager replay;
48-
static ui::proxy::Manager proxy;
49-
static injection::VM inj;
50-
static ui::pipelist::VM pipelist;
54+
auto& replay = ReplayManager();
55+
auto& proxy = ProxyManager();
56+
auto& inj = InjectorVm();
57+
auto& pipelist = PipesVm();
5158

5259
// visibility for each panel
5360
static bool show_replay = true;
@@ -222,4 +229,13 @@ namespace pipetap {
222229
ImGui::End();
223230
ImGui::PopStyleVar();
224231
}
232+
233+
void UIShutdown() {
234+
auto& proxy = ProxyManager();
235+
for (auto& tab : proxy.tabs) {
236+
if (tab && tab->client) {
237+
tab->client->Stop();
238+
}
239+
}
240+
}
225241
} // namespace pipetap

pipetap-gui/app/ctrlclient.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ namespace pipetap::ctrlclient {
3838
// prevent late UI calls
3939
{ std::lock_guard<std::mutex> lk(cb_mx_); cb_ = nullptr; }
4040

41+
if (connected.load(std::memory_order_acquire)) {
42+
PT_ClientDisconnect bye{};
43+
bye.reason = 0;
44+
(void)SendControlMessage(PT_CMD_CLIENT_DISCONNECT, &bye, sizeof(bye), nullptr, 0);
45+
}
46+
4147
DisconnectHandles(true);
4248

4349
if (reader_.joinable()) {

pipetap-gui/include/app.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
namespace pipetap
44
{
55
void UI();
6-
}
6+
void UIShutdown();
7+
}

pipetap-gui/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE, _In_ LPWSTR,
194194
g_SwapChainOccluded = (hr == DXGI_STATUS_OCCLUDED);
195195
}
196196

197+
// Gracefully drop any control connections before tearing down ImGui/DirectX
198+
pipetap::UIShutdown();
199+
197200
// Cleanup
198201
ImGui_ImplDX11_Shutdown();
199202
ImGui_ImplWin32_Shutdown();

pipetap-shared/include/pipetap/controlpipe.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ enum : uint16_t {
7171
PT_CMD_PROXY_OPEN = 0x1201, // VALUE: PT_ProxyOpen + name bytes
7272
PT_CMD_PROXY_SEND = 0x1202, // VALUE: PT_ProxySend + data bytes
7373
PT_CMD_PROXY_CLOSE = 0x1203, // VALUE: PT_ProxyClose
74+
PT_CMD_CLIENT_DISCONNECT = 0x12F0, // VALUE: PT_ClientDisconnect (GUI closing)
7475
};
7576

7677
// PT_HELLO
@@ -162,6 +163,11 @@ struct PT_ProxyClose {
162163
uint64_t session_id;
163164
};
164165

166+
// GUI notifying DLL that the control client is intentionally dropping
167+
struct PT_ClientDisconnect {
168+
uint32_t reason; // 0 = GUI exit
169+
};
170+
165171
// Closed event (DLL -> GUI)
166172
struct PT_ProxyClosed {
167173
uint64_t session_id;

0 commit comments

Comments
 (0)