//#region src/browser/install-lock.ts
const locked = {
	playwright: false,
	cloakbrowser: false
};
const activeController = {
	playwright: null,
	cloakbrowser: null
};
function acquireBrowserInstallLock(kind) {
	if (locked[kind]) return null;
	locked[kind] = true;
	const controller = new AbortController();
	activeController[kind] = controller;
	let released = false;
	return {
		signal: controller.signal,
		release: () => {
			if (released) return;
			released = true;
			locked[kind] = false;
			if (activeController[kind] === controller) activeController[kind] = null;
		}
	};
}
/** User-initiated cancel — aborts the in-flight install for this kind. */
function cancelBrowserInstall(kind) {
	const controller = activeController[kind];
	if (!controller) return false;
	controller.abort();
	return true;
}
function isBrowserInstallRunning(kind) {
	return locked[kind];
}
/** Test helper — reset lock state between unit tests. */
function resetBrowserInstallLockForTests() {
	for (const kind of ["playwright", "cloakbrowser"]) {
		activeController[kind]?.abort();
		activeController[kind] = null;
		locked[kind] = false;
	}
}
//#endregion
export { acquireBrowserInstallLock, cancelBrowserInstall, isBrowserInstallRunning, resetBrowserInstallLockForTests };

//# sourceMappingURL=install-lock.js.map