Skip to content

Commit 632b395

Browse files
Adds proper callback/monitoring of OBS for deeplinking launching OBS, opening owned products window, etc..
1 parent c3f2732 commit 632b395

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

loader/main.cpp

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,66 @@ int send_auth_to_obs(std::string payload) {
144144
return 0;
145145
}
146146

147+
int open_obs_mp_window()
148+
{
149+
int pipe_number = 0;
150+
std::string pipe_name = "elgato_cloud";
151+
std::string base_name = "\\\\.\\pipe\\" + pipe_name;
152+
std::string attempt_name;
153+
HANDLE pipe = INVALID_HANDLE_VALUE;
154+
SECURITY_ATTRIBUTES sa;
155+
SECURITY_DESCRIPTOR sd;
156+
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
157+
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
158+
sa.nLength = sizeof(sa);
159+
sa.lpSecurityDescriptor = &sd;
160+
sa.bInheritHandle = FALSE;
161+
162+
int connect_attempts_remaining = 60;
163+
164+
printf("Waiting for OBS to launch...");
165+
166+
while (connect_attempts_remaining-- > 0 &&
167+
pipe == INVALID_HANDLE_VALUE) {
168+
pipe_number = 0;
169+
attempt_name = base_name + std::to_string(pipe_number);
170+
printf("Attempting %s\n", attempt_name.c_str());
171+
pipe = CreateFileA(attempt_name.c_str(), GENERIC_WRITE,
172+
0, &sa, OPEN_EXISTING, 0, NULL);
173+
if (pipe != INVALID_HANDLE_VALUE) {
174+
printf("Success\n");
175+
break;
176+
}
177+
if (pipe == INVALID_HANDLE_VALUE) {
178+
Sleep(1000);
179+
}
180+
}
181+
if (pipe == INVALID_HANDLE_VALUE) {
182+
printf("Could not connect to OBS!");
183+
return 1;
184+
}
185+
DWORD mode = PIPE_READMODE_MESSAGE;
186+
auto success = SetNamedPipeHandleState(pipe, &mode, NULL, NULL);
187+
if (!success) {
188+
CloseHandle(pipe);
189+
printf("Could not configure named pipe!");
190+
return 1;
191+
}
192+
193+
DWORD written = 0;
194+
std::string payload = "elgatolink://open";
195+
success = WriteFile(pipe, payload.c_str(), static_cast<DWORD>(payload.size()), &written,
196+
NULL);
197+
if (!success || written < payload.size()) {
198+
printf("Failed to write to named pipe!");
199+
CloseHandle(pipe);
200+
return 1;
201+
}
202+
203+
CloseHandle(pipe);
204+
return 0;
205+
}
206+
147207
int launch_obs()
148208
{
149209
DWORD buffer_size = BUFFER_SIZE;
@@ -216,8 +276,10 @@ int main(int argc, char *argv[]) {
216276
// Send auth to OBS which requested it.
217277
return send_auth_to_obs(payload);
218278
} else {
219-
return launch_obs();
279+
int resp = launch_obs();
280+
open_obs_mp_window();
281+
//return open_obs_mp_window();
220282
}
221283
printf("No obs found to launch.");
222-
return 1;
284+
//return 1;
223285
}

src/elgato-cloud-data.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ void ElgatoCloud::_Listen()
169169
{
170170
_listenThread = std::thread([this]() {
171171
listen_on_pipe("elgato_cloud", [this](std::string d) {
172+
obs_log(LOG_INFO, "Pipe received: %s", d.c_str());
172173
if (d.find("elgatolink://auth") == 0) {
173174
if (mainWindowOpen && window) {
174175
QMetaObject::invokeMethod(
@@ -242,6 +243,29 @@ void ElgatoCloud::_Listen()
242243
authorizing = false;
243244
return;
244245
}
246+
else if (d.find("elgatolink://open") == 0)
247+
{
248+
obs_log(LOG_INFO, "OPEN COMMAND RECEIEVED!");
249+
if (mainWindowOpen && window) {
250+
QMetaObject::invokeMethod(
251+
QCoreApplication::instance()
252+
->thread(),
253+
[this]() {
254+
//window->setLoading();
255+
window->show();
256+
window->raise();
257+
window->activateWindow();
258+
LoadPurchasedProducts();
259+
});
260+
} else {
261+
QMetaObject::invokeMethod(
262+
QCoreApplication::instance()
263+
->thread(),
264+
[this]() {
265+
OpenElgatoCloudWindow();
266+
});
267+
}
268+
}
245269
});
246270
});
247271

0 commit comments

Comments
 (0)