Skip to content

Commit

Permalink
Deduplicate flatpak socket connecting code
Browse files Browse the repository at this point in the history
  • Loading branch information
0e4ef622 committed Jan 28, 2022
1 parent 93ef8d5 commit dd64928
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,33 +233,24 @@ int _tmain(VOID)

const char *const temp_path = get_temp_path();

char connected = 0;
for (int pipeNum = 0; pipeNum < 10; ++pipeNum) {

snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/discord-ipc-%d", temp_path, pipeNum);
printf("Attempting to connect to %s\n", addr.sun_path);
char *paths[] = {"%s/discord-ipc-%d", "%s/app/com.discordapp.Discord/discord-ipc-%d"};

if (l_connect(sock_fd, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
printf("Failed to connect\n");
} else {
connected = 1;
break;
}
}
if (!connected) {
char connected = 0;
for (int p = 0; p < sizeof(paths) / sizeof(paths[0]); p++) {
for (int pipeNum = 0; pipeNum < 10; ++pipeNum) {

snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/app/com.discordapp.Discord/discord-ipc-%d", temp_path, pipeNum);
snprintf(addr.sun_path, sizeof(addr.sun_path), paths[p], temp_path, pipeNum);
printf("Attempting to connect to %s\n", addr.sun_path);

if (l_connect(sock_fd, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
printf("Failed to connect\n");
} else {
connected = 1;
break;
goto breakout;
}
}
}
breakout:;

if (!connected) {
printf("Could not connect to discord client\n");
Expand Down

0 comments on commit dd64928

Please sign in to comment.