Skip to content

Commit ba4e27e

Browse files
committed
fixup! Add macOS split tunneling
1 parent d3d15dd commit ba4e27e

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

gui/src/main/macos-split-tunneling.ts

+19-21
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ export class MacOsSplitTunnelingAppListRetriever implements ISplitTunnelingAppLi
3838
fromCache = false;
3939

4040
const applicationBundlePaths = await this.findApplicationBundlePaths();
41-
for (const applicationBundlePath of applicationBundlePaths) {
42-
// `getApplication updates the cache so no need to use the result.`
43-
await this.getApplication(applicationBundlePath, false);
44-
}
45-
4641
const executablePaths = this.additionalApplications.values();
47-
for (const executablePath of executablePaths) {
48-
await this.getApplication(executablePath, true);
49-
}
42+
await Promise.all([
43+
// `getApplication updates the cache so no need to use the result.`
44+
...applicationBundlePaths.map((applicationBundlePath) =>
45+
this.getApplication(applicationBundlePath, false),
46+
),
47+
...executablePaths.map((executablePath) => this.getApplication(executablePath, true)),
48+
]);
5049
}
5150

5251
// Return applications from cache.
@@ -56,20 +55,19 @@ export class MacOsSplitTunnelingAppListRetriever implements ISplitTunnelingAppLi
5655
public async getMetadataForApplications(
5756
applicationPaths: string[],
5857
): Promise<{ fromCache: boolean; applications: ISplitTunnelingApplication[] }> {
59-
for (const applicationPath of applicationPaths) {
60-
if (!this.applicationCache.includes(applicationPath)) {
61-
await this.addApplicationPathToCache(applicationPath);
62-
}
63-
}
58+
await Promise.all(
59+
applicationPaths
60+
.filter((applicationPath) => !this.applicationCache.includes(applicationPath))
61+
.map((applicationPath) => this.addApplicationPathToCache(applicationPath)),
62+
);
6463

6564
const applications = await this.getApplications();
6665

67-
applications.applications = applications.applications.filter(
68-
(application) =>
69-
applicationPaths.find(
70-
(applicationPath) =>
71-
applicationPath.toLowerCase() === application.absolutepath.toLowerCase(),
72-
) !== undefined,
66+
applications.applications = applications.applications.filter((application) =>
67+
applicationPaths.some(
68+
(applicationPath) =>
69+
applicationPath.toLowerCase() === application.absolutepath.toLowerCase(),
70+
),
7371
);
7472

7573
return applications;
@@ -82,7 +80,7 @@ export class MacOsSplitTunnelingAppListRetriever implements ISplitTunnelingAppLi
8280

8381
public async addApplicationPathToCache(applicationPath: string): Promise<void> {
8482
const application = await this.getApplication(applicationPath, true);
85-
if (application !== undefined && application.deletable) {
83+
if (application?.deletable) {
8684
this.additionalApplications.add(application);
8785
}
8886
}
@@ -113,7 +111,7 @@ export class MacOsSplitTunnelingAppListRetriever implements ISplitTunnelingAppLi
113111
}
114112

115113
private async findApplicationBundlePaths() {
116-
const readdirPromises = this.getAppDirectories().map(async (directory) =>
114+
const readdirPromises = this.getAppDirectories().map((directory) =>
117115
this.readDirectory(directory),
118116
);
119117
const applicationBundlePaths = (await Promise.all(readdirPromises)).flat();

0 commit comments

Comments
 (0)