feat: add Flutter USB mirroring and single-instance desktop clients
This commit is contained in:
1 parent
3a7bb071f0
commit
a339465392
30 files changed
+1688
-104
No files matched your search
@@ -0,0 +1,40 @@
|
||||
#ifndef RUNNER_DESKTOP_INSTANCE_H_
|
||||
#define RUNNER_DESKTOP_INSTANCE_H_
|
||||
#include <windows.h>
|
||||
|
||||
// Shared with the Avalonia entry point, across installed/portable copies in
|
||||
// the same interactive Windows session.
|
||||
class DesktopInstance {
|
||||
public:
|
||||
DesktopInstance() {
|
||||
event_ = CreateEventW(nullptr, FALSE, FALSE, L"Local\\TTSTD.ADS.Desktop.Activate");
|
||||
mutex_ = CreateMutexW(nullptr, TRUE, L"Local\\TTSTD.ADS.Desktop.Instance");
|
||||
primary_ = mutex_ && GetLastError() != ERROR_ALREADY_EXISTS;
|
||||
}
|
||||
~DesktopInstance() {
|
||||
if (wait_) UnregisterWaitEx(wait_, INVALID_HANDLE_VALUE);
|
||||
if (primary_) ReleaseMutex(mutex_);
|
||||
if (mutex_) CloseHandle(mutex_);
|
||||
if (event_) CloseHandle(event_);
|
||||
}
|
||||
bool valid() const { return event_ && mutex_; }
|
||||
bool primary() const { return primary_; }
|
||||
void Activate() {
|
||||
AllowSetForegroundWindow(ASFW_ANY);
|
||||
SetEvent(event_);
|
||||
}
|
||||
bool Listen(HWND window) {
|
||||
return RegisterWaitForSingleObject(&wait_, event_, Wake,
|
||||
reinterpret_cast<void*>(window), INFINITE, WT_EXECUTEDEFAULT) != FALSE;
|
||||
}
|
||||
static UINT ActivationMessage() {
|
||||
return RegisterWindowMessageW(L"TTSTD.ADS.Desktop.Activate");
|
||||
}
|
||||
private:
|
||||
static void CALLBACK Wake(void* context, BOOLEAN) {
|
||||
PostMessageW(reinterpret_cast<HWND>(context), ActivationMessage(), 0, 0);
|
||||
}
|
||||
HANDLE event_ = nullptr, mutex_ = nullptr, wait_ = nullptr;
|
||||
bool primary_ = false;
|
||||
};
|
||||
#endif
|
||||
Reference in new issue
Block a user