CatPortal / modules /CatOS-Core.js
NikaMimi's picture
Upload 17 files
06163ac verified
/**
* CatOS Core System Module
* Main system initialization and state management
*/
class CatOSCore {
constructor() {
// System state
this.windows = new Map();
this.apps = new Map();
this.nextWindowId = 1;
this.focusedWindow = null;
this.startMenuOpen = false;
this.wallpapers = [
'static/wallpapers/wallpaper1.png',
'static/wallpapers/wallpaper2.png',
'static/wallpapers/wallpaper3.png',
'static/wallpapers/wallpaper4.png',
'static/wallpapers/wallpaper5.png',
'static/wallpapers/wallpaper6.png'
];
}
// Initialize CatOS
init() {
this.showLoadingScreen();
this.updateClock();
this.setRandomWallpaper();
// Boot sequence
setTimeout(() => {
this.hideLoadingScreen();
this.playStartupSound();
this.showWelcomeMessage();
}, 3000);
}
// Loading screen management
showLoadingScreen() {
const loadingScreen = document.getElementById('loading-screen');
if (loadingScreen) {
loadingScreen.classList.remove('hidden');
} else {
console.warn('Loading screen element not found');
}
}
hideLoadingScreen() {
const loadingScreen = document.getElementById('loading-screen');
if (loadingScreen) {
loadingScreen.classList.add('hidden');
setTimeout(() => {
loadingScreen.style.display = 'none';
}, 500);
} else {
console.warn('Loading screen element not found');
}
}
// Clock functionality
updateClock() {
const updateTime = () => {
const now = new Date();
const timeString = now.toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit'
});
const clockElement = document.querySelector('.time');
if (clockElement) {
clockElement.textContent = timeString;
}
};
updateTime(); // Update immediately
setInterval(updateTime, 1000); // Update every second
}
// Wallpaper management
setRandomWallpaper() {
const desktop = document.getElementById('desktop');
if (!desktop) return;
const randomWallpaper = this.wallpapers[Math.floor(Math.random() * this.wallpapers.length)];
// Create a temporary image to preload
const img = new Image();
img.onload = () => {
desktop.style.backgroundImage = `url('${randomWallpaper}')`;
desktop.style.backgroundSize = 'cover';
desktop.style.backgroundPosition = 'center';
desktop.style.backgroundRepeat = 'no-repeat';
};
img.src = randomWallpaper;
}
// System sounds and notifications
playStartupSound() {
// Cat-themed startup notification
this.showNotification('πŸ±β€πŸ’» CatOS Ready!', 'Welcome to your purr-fessional workspace!');
}
showWelcomeMessage() {
// Optional: Show welcome message for new users
if (!localStorage.getItem('catos-visited')) {
this.showNotification(
'πŸŽ‰ First time visitor detected!',
'Try opening the terminal and typing "help" for cat commands!'
);
localStorage.setItem('catos-visited', 'true');
}
}
showNotification(title, message) {
// Simple notification system
const notification = document.createElement('div');
notification.className = 'system-notification';
notification.innerHTML = `
<div class="notification-header">${title}</div>
<div class="notification-body">${message}</div>
`;
// Add notification styles if not already present
if (!document.querySelector('#notification-styles')) {
const style = document.createElement('style');
style.id = 'notification-styles';
style.textContent = `
.system-notification {
position: fixed;
top: 80px;
right: 20px;
background: var(--window-bg);
border: 1px solid var(--window-border);
border-radius: var(--radius-lg);
padding: var(--spacing-md);
box-shadow: var(--window-shadow);
min-width: 300px;
z-index: 10000;
animation: slideInRight 0.3s ease;
}
.notification-header {
font-weight: 600;
color: var(--text-primary);
margin-bottom: var(--spacing-sm);
}
.notification-body {
color: var(--text-secondary);
font-size: 0.875rem;
}
@keyframes slideInRight {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
`;
document.head.appendChild(style);
}
document.body.appendChild(notification);
// Auto remove after 5 seconds
setTimeout(() => {
notification.style.animation = 'slideInRight 0.3s ease reverse';
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
}, 5000);
}
// App registration
registerApps() {
// This will be called after modules are registered
if (this.appManager) {
this.appManager.registerAllApps(this);
}
}
// Event listener setup
setupEventListeners() {
// This will be called after modules are registered
if (this.eventHandler) {
this.eventHandler.setup(this);
}
}
// Method to be called by other modules to register themselves
registerModule(name, moduleInstance) {
this[name] = moduleInstance;
moduleInstance.core = this;
}
}
// Make available globally
window.CatOSCore = CatOSCore;