File size: 6,490 Bytes
06163ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
/**
* 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; |