Skip to content

Commit db8f651

Browse files
committed
chore: recognize catalyst as a platform (like visionOS)
1 parent 26860f8 commit db8f651

5 files changed

Lines changed: 63 additions & 10 deletions

File tree

lib/common/mobile/mac/mac-catalyst-application-manager.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ChildProcess } from "child_process";
22
import * as path from "path";
33
import { ApplicationManagerBase } from "../application-manager-base";
4-
import { hook } from "../../helpers";
4+
import { hook, sleep } from "../../helpers";
55
import { cache } from "../../decorators";
66
import { IOS_LOG_PREDICATE } from "../../constants";
77
import {
@@ -64,12 +64,26 @@ export class MacCatalystApplicationManager extends ApplicationManagerBase {
6464

6565
public async stopApplication(
6666
appData: Mobile.IApplicationData,
67+
): Promise<void> {
68+
const executablePath = this.getExecutablePath();
69+
await this.signalApplication(executablePath, "TERM", appData);
70+
if (await this.waitForApplicationExit(executablePath)) {
71+
return;
72+
}
73+
await this.signalApplication(executablePath, "KILL", appData);
74+
await this.waitForApplicationExit(executablePath);
75+
}
76+
77+
private async signalApplication(
78+
executablePath: string,
79+
signal: string,
80+
appData: Mobile.IApplicationData,
6781
): Promise<void> {
6882
try {
6983
// Anchored so it never matches our own log stream process.
7084
await this.$childProcess.spawnFromEvent(
7185
"pkill",
72-
["-f", `^${this.getExecutablePath()}$`],
86+
[`-${signal}`, "-f", `^${executablePath}$`],
7387
"close",
7488
);
7589
} catch (err) {
@@ -80,6 +94,32 @@ export class MacCatalystApplicationManager extends ApplicationManagerBase {
8094
}
8195
}
8296

97+
// Returning before the old instance dies makes open -n spawn a duplicate.
98+
private async waitForApplicationExit(
99+
executablePath: string,
100+
): Promise<boolean> {
101+
for (let attempt = 0; attempt < 40; attempt++) {
102+
if (!(await this.isApplicationRunning(executablePath))) {
103+
return true;
104+
}
105+
await sleep(50);
106+
}
107+
return false;
108+
}
109+
110+
private async isApplicationRunning(executablePath: string): Promise<boolean> {
111+
try {
112+
await this.$childProcess.spawnFromEvent(
113+
"pgrep",
114+
["-f", `^${executablePath}$`],
115+
"close",
116+
);
117+
return true;
118+
} catch (err) {
119+
return false;
120+
}
121+
}
122+
83123
public async getDebuggableApps(): Promise<
84124
Mobile.IDeviceApplicationInformation[]
85125
> {

lib/services/bundler/bundler-compiler-service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
PackageManagers,
1212
CONFIG_FILE_NAME_DISPLAY,
1313
VITE_DIST_FOLDER_NAME,
14+
PlatformTypes,
1415
} from "../../constants";
1516
import {
1617
IPackageManager,
@@ -788,6 +789,11 @@ export class BundlerCompilerService
788789
const platformKey = platform.toLowerCase();
789790
const envData = Object.assign({}, env, { [platformKey]: true });
790791

792+
// Bundlers only know the base platforms, so Catalyst also flags ios.
793+
if (this.$mobileHelper.isCatalystPlatform(platformKey)) {
794+
envData[PlatformTypes.ios] = true;
795+
}
796+
791797
const appId = projectData.projectIdentifiers[platform];
792798
const appPath = projectData.getAppDirectoryRelativePath();
793799
const appResourcesPath = projectData.getAppResourcesRelativeDirectoryPath();

lib/services/ios-project-service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,24 @@ export class IOSProjectService
166166
const requestedPlatform = this.$mobileHelper.normalizePlatformName(
167167
this.$options.platformOverride ?? this.$devicePlatformsConstants.iOS,
168168
);
169-
// Mac Catalyst keeps every iOS convention; only the platform root differs.
170-
const platform = this.$mobileHelper.isCatalystPlatform(requestedPlatform)
169+
// Mac Catalyst ships no runtime of its own, it reuses the iOS one.
170+
const runtimePlatform = this.$mobileHelper.isCatalystPlatform(
171+
requestedPlatform,
172+
)
171173
? this.$devicePlatformsConstants.iOS
172174
: requestedPlatform;
173175
const projectRoot = this.$options.hostProjectPath
174176
? this.$options.hostProjectPath
175177
: path.join(projectData.platformsDir, requestedPlatform.toLowerCase());
176178
const runtimePackage = this.$projectDataService.getRuntimePackage(
177179
projectData.projectDir,
178-
platform.toLowerCase() as constants.SupportedPlatform,
180+
runtimePlatform.toLowerCase() as constants.SupportedPlatform,
179181
);
180182

181183
this._platformData = {
182184
frameworkPackageName: runtimePackage.name,
183-
normalizedPlatformName: platform,
184-
platformNameLowerCase: platform.toLowerCase(),
185+
normalizedPlatformName: requestedPlatform,
186+
platformNameLowerCase: requestedPlatform.toLowerCase(),
185187
appDestinationDirectoryPath: path.join(
186188
projectRoot,
187189
projectData.projectName,

lib/services/plugins-service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,10 @@ This framework comes from ${dependencyName} plugin, which is installed multiple
640640
);
641641
pluginData.isPlugin = !!cacheData.nativescript;
642642
pluginData.pluginPlatformsFolderPath = (platform: string) => {
643-
if (this.$mobileHelper.isvisionOSPlatform(platform)) {
643+
if (
644+
this.$mobileHelper.isvisionOSPlatform(platform) ||
645+
this.$mobileHelper.isCatalystPlatform(platform)
646+
) {
644647
platform = constants.PlatformTypes.ios;
645648
}
646649
return path.join(

lib/services/project-changes-service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ export class ProjectChangesService implements IProjectChangesService {
9292

9393
if (
9494
!this.$fs.exists(platformResourcesDir) &&
95-
platformData.platformNameLowerCase ===
96-
this.$devicePlatformsConstants.visionOS.toLowerCase()
95+
(platformData.platformNameLowerCase ===
96+
this.$devicePlatformsConstants.visionOS.toLowerCase() ||
97+
platformData.platformNameLowerCase ===
98+
this.$devicePlatformsConstants.Catalyst.toLowerCase())
9799
) {
98100
platformResourcesDir = path.join(
99101
projectData.appResourcesDirectoryPath,

0 commit comments

Comments
 (0)