in src/gemini_95/index.ts [221:283]
function closeApp(appName: string): void {
const appData = openApps.get(appName);
if (!appData) return;
const { windowEl, taskbarButton } = appData;
windowEl.style.display = 'none'; // Hide the window
windowEl.classList.remove('active');
taskbarButton.remove(); // Remove taskbar button
openApps.delete(appName); // Remove from open apps map
// Clean up DOS instance if applicable
if (dosInstances[appName]) {
console.log(`Cleaning up ${appName} instance (iframe approach)`);
const container = document.getElementById(`${appName}-content`);
if (container) container.innerHTML = ''; // Clear iframe
delete dosInstances[appName];
}
// Stop Paint Critique if Paint is closed
if (appName === 'paint') {
if (paintCritiqueIntervalId) {
clearInterval(paintCritiqueIntervalId);
paintCritiqueIntervalId = null;
if (paintAssistant) paintAssistant.classList.remove('visible');
console.log("Stopped paint critique interval.");
}
// Disconnect ResizeObserver for Paint
const paintContent = appData.windowEl.querySelector('.window-content') as HTMLDivElement | null;
if (paintContent && paintResizeObserverMap.has(paintContent)) {
paintResizeObserverMap.get(paintContent)?.disconnect();
paintResizeObserverMap.delete(paintContent);
console.log("Disconnected paint ResizeObserver.");
}
}
// Stop Minesweeper Timer if Minesweeper is closed
if (appName === 'minesweeper') {
if (minesweeperTimerInterval) {
clearInterval(minesweeperTimerInterval);
minesweeperTimerInterval = null;
console.log("Stopped Minesweeper timer.");
}
}
// Activate the next highest window if the closed one was active
if (activeWindow === windowEl) {
activeWindow = null; // Clear current active window
let nextAppToActivate: HTMLDivElement | null = null;
let maxZ = -1; // Use -1 to ensure any window is higher
openApps.forEach((data) => {
// No need to check display style, bringToFront will handle visibility
const z = parseInt(data.windowEl.style.zIndex || '0', 10);
if (z > maxZ) {
maxZ = z;
nextAppToActivate = data.windowEl;
}
});
if (nextAppToActivate) {
bringToFront(nextAppToActivate);
}
}
}