Skip to content

Commit 7a54c25

Browse files
committed
fix(windows): devtools auto-start
1 parent 1dbb30b commit 7a54c25

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

lib/common/definitions/mobile.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ declare global {
366366

367367
interface IStartApplicationData extends IApplicationData {
368368
waitForDebugger?: boolean;
369+
/**
370+
* True when launching as part of a debug session (`ns debug`), regardless of --debug-brk.
371+
* Windows uses this to signal the host to start the inspector (via a sentinel file);
372+
* a plain `ns run` leaves it unset so the inspector/devtools server is never created.
373+
*/
374+
debugMode?: boolean;
369375
}
370376

371377
interface IInstallAppData extends IApplicationData {

lib/common/mobile/windows/windows-application-manager.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,12 @@ export class WindowsApplicationManager extends ApplicationManagerBase {
224224
} else {
225225
// PFN already cached from the pre-resolve above; no extra round-trip.
226226
const pfn = this._packageFamilyNames.get(appData.appId) ?? appData.appId;
227+
// Any debug session starts the inspector; --debug-brk additionally signals break-on-start.
228+
if (appData.debugMode) {
229+
this._writeMarker(pfn, "ns-inspector");
230+
}
227231
if (appData.waitForDebugger) {
228-
this._writeDebugBreakMarker(pfn);
232+
this._writeMarker(pfn, "ns-debugbreak");
229233
}
230234
// UWP apps are launched via shell:AppsFolder\<PFN>!<ApplicationId>.
231235
// The ApplicationId comes from the <Application Id="..."> attribute in the manifest.
@@ -320,22 +324,19 @@ export class WindowsApplicationManager extends ApplicationManagerBase {
320324
return this._packageFamilyNames.get(appId) ?? appId;
321325
}
322326

323-
private _writeDebugBreakMarker(pfn: string): void {
327+
// Writes a sentinel file into the packaged app's LocalState that the C# host consumes on launch
328+
// (RuntimeHost.ConsumeMarker). Used to signal the inspector ("ns-inspector") and break-on-start
329+
// ("ns-debugbreak") out-of-band, since a UWP app launched via shell:AppsFolder inherits no env.
330+
private _writeMarker(pfn: string, name: string): void {
324331
const localAppData = process.env.LOCALAPPDATA;
325332
if (!localAppData) return;
326-
const markerPath = path.join(
327-
localAppData,
328-
"Packages",
329-
pfn,
330-
"LocalState",
331-
"ns-debugbreak",
332-
);
333+
const markerPath = path.join(localAppData, "Packages", pfn, "LocalState", name);
333334
try {
334335
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
335336
fs.writeFileSync(markerPath, "", "utf8");
336-
this.$logger.info(`[Windows] Debug break marker: ${markerPath}`);
337+
this.$logger.info(`[Windows] Wrote ${name} marker: ${markerPath}`);
337338
} catch (e) {
338-
this.$logger.warn(`[Windows] Could not write debug break marker: ${e}`);
339+
this.$logger.warn(`[Windows] Could not write ${name} marker: ${e}`);
339340
}
340341
}
341342
}

lib/controllers/run-controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ export class RunController extends EventEmitter implements IRunController {
275275
const debugOptions = deviceDescriptor.debugOptions || {};
276276

277277
liveSyncResultInfo.waitForDebugger = !!debugOptions.debugBrk;
278+
// Any debug session (attach or --debug-brk) should bring up the inspector. Windows keys the
279+
// inspector start off this (a plain `ns run` never sets it, so the inspector stays off).
280+
liveSyncResultInfo.debugMode = true;
278281
liveSyncResultInfo.forceRefreshWithSocket = true;
279282

280283
const refreshInfo = await this.refreshApplicationWithoutDebug(

lib/definitions/livesync.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ declare global {
252252
modifiedFilesData: Mobile.ILocalToDevicePathData[];
253253
isFullSync: boolean;
254254
waitForDebugger?: boolean;
255+
/** True for any `ns debug` session (attach or --debug-brk); drives the Windows inspector start. */
256+
debugMode?: boolean;
255257
deviceAppData: Mobile.IDeviceAppData;
256258
didRecover?: boolean;
257259
forceRefreshWithSocket?: boolean;

lib/services/livesync/windows-device-livesync-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class WindowsDeviceLiveSyncService
3131
projectName: projectData.projectName,
3232
projectDir: projectData.projectDir,
3333
waitForDebugger: _liveSyncInfo?.waitForDebugger,
34+
debugMode: _liveSyncInfo?.debugMode,
3435
} as Mobile.IStartApplicationData);
3536
}
3637

0 commit comments

Comments
 (0)