Spaces:
Running
Running
File size: 32,478 Bytes
11f18c1 b33cdea 0751b83 b33cdea 11f18c1 b33cdea 11f18c1 b33cdea 0751b83 b33cdea 11f18c1 b33cdea 0751b83 b33cdea 11f18c1 b33cdea 0751b83 b33cdea 11f18c1 b33cdea 11f18c1 b33cdea 0751b83 11f18c1 0751b83 11f18c1 0751b83 11f18c1 0751b83 11f18c1 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 b33cdea 0751b83 2b4106d a63efb1 2b4106d a63efb1 2b4106d a63efb1 0751b83 | 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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 |
// NEXUS Operating System Core
class NexusOS {
constructor() {
this.windows = [];
this.processes = [];
this.system = {
cpuUsage: 0,
memoryUsage: 0,
diskUsage: 0,
networkSpeed: { up: 0, down: 0 },
batteryLevel: 100
};
this.applications = {
'terminal': {
title: 'NEXUS Terminal',
icon: 'fas fa-terminal',
content: '<div class="terminal" id="terminal"></div>',
width: 600,
height: 400,
onOpen: this.initTerminal.bind(this),
permissions: ['system_access']
},
'quantum-explorer': {
title: 'Quantum Explorer',
icon: 'fas fa-project-diagram',
content: '<div id="file-explorer"><div class="sidebar"></div><div class="content"></div></div>',
width: 800,
height: 500,
onOpen: this.initFileExplorer.bind(this),
permissions: ['filesystem_read']
},
'kernel-control': {
title: 'Kernel Control',
icon: 'fas fa-sliders-h',
content: '<div id="settings-grid"></div>',
width: 700,
height: 600,
onOpen: this.initSettings.bind(this),
permissions: ['system_admin']
},
'quantum-browser': {
title: 'Quantum Browser',
icon: 'fas fa-network-wired',
content: '<div class="browser-container"><div class="toolbar"></div><div class="url-bar"></div><iframe src="about:blank" class="w-full h-full border-0"></iframe></div>',
width: 1024,
height: 768,
onOpen: this.initBrowser.bind(this),
permissions: ['network_access']
},
'quantum-processor': {
title: 'Quantum Processor',
icon: 'fas fa-atom',
content: '<div id="process-manager"><table class="process-table"><thead><tr><th>PID</th><th>Name</th><th>CPU</th><th>Memory</th><th>Actions</th></tr></thead><tbody></tbody></table></div>',
width: 800,
height: 500,
onOpen: this.initProcessManager.bind(this),
permissions: ['system_admin']
},
'quantum-ide': {
title: 'Quantum IDE',
icon: 'fas fa-code',
content: '<div id="code-editor"><div class="toolbar"></div><div class="editor"></div><div class="status-bar"></div></div>',
width: 900,
height: 600,
onOpen: this.initCodeEditor.bind(this),
permissions: ['filesystem_write']
},
'holographic-player': {
title: 'Holographic Player',
icon: 'fas fa-vr-cardboard',
content: '<div id="media-player"><video controls></video><div class="playlist"></div></div>',
width: 800,
height: 500,
onOpen: this.initMediaPlayer.bind(this),
permissions: ['filesystem_read']
}
};
this.init();
}
init() {
// Initialize system monitoring
this.updateSystemStats();
setInterval(this.updateSystemStats.bind(this), 2000);
// Initialize clock
this.updateClock();
setInterval(this.updateClock.bind(this), 1000);
// Initialize network monitoring
this.initNetworkMonitor();
// Initialize battery monitoring
this.initBatteryMonitor();
// Initialize desktop context menu
this.initDesktopContextMenu();
// Initialize start menu
this.initStartMenu();
// Initialize file system
this.initVirtualFileSystem();
// Initialize system processes
this.spawnSystemProcess('system-monitor');
this.spawnSystemProcess('network-service');
this.spawnSystemProcess('notification-service');
// Initialize sample apps
setTimeout(() => {
this.createNotification('System', 'QuantumOS Hypervisor initialized successfully', 'info');
// Start background services
this.startBackgroundServices();
}, 1000);
}
updateClock() {
const now = new Date();
const timeStr = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
const dateStr = now.toLocaleDateString([], { month: 'short', day: 'numeric' });
document.getElementById('clock').textContent = `${timeStr} | ${dateStr}`;
}
initDesktopContextMenu() {
document.getElementById('desktop').addEventListener('contextmenu', (e) => {
e.preventDefault();
this.showContextMenu(e.clientX, e.clientY, [
{ text: 'New Terminal', icon: 'fas fa-terminal', action: () => this.openApp('terminal') },
{ text: 'New Window', icon: 'fas fa-window-maximize', action: () => this.createWindow('Untitled', '', 400, 300) },
{ separator: true },
{ text: 'Refresh', icon: 'fas fa-sync-alt', action: () => location.reload() },
{ text: 'Settings', icon: 'fas fa-cog', action: () => this.openApp('settings') }
]);
});
}
initStartMenu() {
const startButton = document.getElementById('start-button');
const startMenu = document.getElementById('start-menu-content');
startButton.addEventListener('click', (e) => {
e.stopPropagation();
startMenu.classList.toggle('hidden');
});
// Populate start menu
startMenu.innerHTML = Object.entries(this.applications).map(([id, app]) => `
<div class="start-menu-item flex items-center space-x-3 p-2 rounded hover:bg-gray-700 cursor-pointer" onclick="os.openApp('${id}')">
<i class="${app.icon}"></i>
<span>${app.title}</span>
</div>
`).join('');
// Close menu when clicking elsewhere
document.addEventListener('click', () => startMenu.classList.add('hidden'));
}
openApp(appId) {
const app = this.applications[appId];
if (!app) return;
const window = this.createWindow(
app.title,
app.content,
app.width,
app.height,
app.icon
);
if (app.onOpen) app.onOpen(window);
}
createWindow(title, content, width, height, icon) {
const windowId = 'window-' + Math.random().toString(36).substr(2, 9);
const windowElement = document.createElement('div');
windowElement.className = 'window hidden';
windowElement.style.width = width + 'px';
windowElement.style.height = height + 'px';
windowElement.id = windowId;
windowElement.innerHTML = `
<div class="window-titlebar">
${icon ? `<i class="${icon} mr-2"></i>` : ''}
<span class="window-title">${title}</span>
<div class="window-controls">
<div class="window-control window-minimize">_</div>
<div class="window-control window-maximize">□</div>
<div class="window-control window-close">×</div>
</div>
</div>
<div class="window-content">${content}</div>
`;
document.getElementById('window-manager').appendChild(windowElement);
// Position window initially at center with slight random offset
const left = Math.max(100, (window.innerWidth - width) / 2 + (Math.random() * 100 - 50));
const top = Math.max(50, (window.innerHeight - height) / 2 + (Math.random() * 100 - 50));
windowElement.style.left = left + 'px';
windowElement.style.top = top + 'px';
// Make window draggable
this.makeDraggable(windowElement);
// Add window controls
const closeBtn = windowElement.querySelector('.window-close');
const minimizeBtn = windowElement.querySelector('.window-minimize');
const maximizeBtn = windowElement.querySelector('.window-maximize');
closeBtn.addEventListener('click', () => {
windowElement.style.transform = 'scale(0.8)';
windowElement.style.opacity = '0';
setTimeout(() => windowElement.remove(), 300);
});
minimizeBtn.addEventListener('click', () => {
windowElement.classList.add('minimized');
});
maximizeBtn.addEventListener('click', () => {
windowElement.classList.toggle('maximized');
if (windowElement.classList.contains('maximized')) {
windowElement.style.width = 'calc(100% - 20px)';
windowElement.style.height = 'calc(100% - 80px)';
windowElement.style.top = '10px';
windowElement.style.left = '10px';
} else {
windowElement.style.width = width + 'px';
windowElement.style.height = height + 'px';
windowElement.style.top = top + 'px';
windowElement.style.left = left + 'px';
}
});
// Show window with animation
setTimeout(() => {
windowElement.classList.remove('hidden');
}, 10);
// Add to windows list
this.windows.push({
id: windowId,
element: windowElement,
title: title
});
return windowElement;
}
makeDraggable(element) {
const titlebar = element.querySelector('.window-titlebar');
let isDragging = false;
let offsetX, offsetY;
titlebar.addEventListener('mousedown', (e) => {
if (e.target.classList.contains('window-control')) return;
isDragging = true;
offsetX = e.clientX - element.getBoundingClientRect().left;
offsetY = e.clientY - element.getBoundingClientRect().top;
element.style.zIndex = 999;
});
document.addEventListener('mousemove', (e) => {
if (!isDragging) return;
let left = e.clientX - offsetX;
let top = e.clientY - offsetY;
// Boundary checking
left = Math.max(0, Math.min(left, window.innerWidth - element.offsetWidth));
top = Math.max(0, Math.min(top, window.innerHeight - element.offsetHeight));
element.style.left = left + 'px';
element.style.top = top + 'px';
});
document.addEventListener('mouseup', () => {
isDragging = false;
});
}
showContextMenu(x, y, items) {
// Remove existing context menu
const existingMenu = document.querySelector('.context-menu');
if (existingMenu) existingMenu.remove();
// Create new context menu
const menu = document.createElement('div');
menu.className = 'context-menu';
menu.style.left = x + 'px';
menu.style.top = y + 'px';
// Add items to menu
items.forEach(item => {
if (item.separator) {
const separator = document.createElement('div');
separator.className = 'border-t border-gray-600 my-1';
menu.appendChild(separator);
} else {
const menuItem = document.createElement('div');
menuItem.className = 'context-menu-item flex items-center space-x-2';
menuItem.innerHTML = `
<i class="${item.icon} text-sm"></i>
<span>${item.text}</span>
`;
menuItem.addEventListener('click', item.action);
menu.appendChild(menuItem);
}
});
document.body.appendChild(menu);
// Close menu when clicking elsewhere
const closeMenu = () => {
menu.remove();
document.removeEventListener('click', closeMenu);
};
setTimeout(() => {
document.addEventListener('click', closeMenu);
}, 100);
}
createNotification(title, message, type = 'info') {
const notification = document.createElement('div');
notification.className = 'notification';
notification.innerHTML = `
<div class="flex items-start justify-between">
<div class="flex-1">
<h4 class="font-bold mb-1">${title}</h4>
<p class="text-sm opacity-80">${message}</p>
</div>
<button class="close-btn ml-2 text-gray-400 hover:text-white">
<i class="fas fa-times"></i>
</button>
</div>
`;
const notificationCenter = document.getElementById('notification-center');
notificationCenter.classList.remove('hidden');
notificationCenter.insertBefore(notification, notificationCenter.firstChild);
// Auto-remove after 5 seconds
setTimeout(() => {
notification.style.animation = 'fadeOut 0.3s forwards';
setTimeout(() => notification.remove(), 300);
}, 5000);
// Close button
notification.querySelector('.close-btn').addEventListener('click', () => {
notification.style.animation = 'fadeOut 0.3s forwards';
setTimeout(() => notification.remove(), 300);
});
}
initTerminal(windowElement) {
const terminal = windowElement.querySelector('.terminal');
const commandHistory = [];
let historyIndex = -1;
// Register as system process
const pid = this.spawnProcess('terminal', windowElement);
// Initial prompt
this.addTerminalLine(terminal, 'Quantum Terminal v1.1.0');
this.addTerminalLine(terminal, 'Connected to QuantumOS Kernel');
this.addTerminalLine(terminal, 'System resources: ' +
`CPU: ${this.system.cpuUsage}% | ` +
`RAM: ${this.system.memoryUsage}% | ` +
`DISK: ${this.system.diskUsage}%`);
this.addTerminalLine(terminal, 'Type "help" for available commands');
this.addTerminalLine(terminal, 'Type "man <command>" for detailed help');
this.addPrompt(terminal);
terminal.addEventListener('click', () => {
const input = terminal.querySelector('.terminal-input:last-child');
if (input) input.focus();
});
terminal.addEventListener('keydown', (e) => {
const input = terminal.querySelector('.terminal-input:last-child');
if (!input) return;
// Handle up/down for command history
if (e.key === 'ArrowUp' && commandHistory.length > 0) {
e.preventDefault();
historyIndex = Math.min(historyIndex + 1, commandHistory.length - 1);
input.textContent = commandHistory[historyIndex];
placeCaretAtEnd(input);
} else if (e.key === 'ArrowDown' && commandHistory.length > 0) {
e.preventDefault();
historyIndex = Math.max(historyIndex - 1, -1);
input.textContent = historyIndex >= 0 ? commandHistory[historyIndex] : '';
placeCaretAtEnd(input);
} else if (e.key === 'Enter') {
e.preventDefault();
const command = input.textContent.trim();
if (command) {
commandHistory.unshift(command);
historyIndex = -1;
this.processCommand(terminal, command);
}
this.addPrompt(terminal);
}
});
function placeCaretAtEnd(el) {
el.focus();
const range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
}
addTerminalLine(terminal, text) {
const line = document.createElement('div');
line.className = 'terminal-line';
line.textContent = text;
terminal.appendChild(line);
terminal.scrollTop = terminal.scrollHeight;
}
addPrompt(terminal) {
const prompt = document.createElement('div');
prompt.className = 'terminal-input';
prompt.innerHTML = `
<span class="terminal-prompt">$</span>
<span class="terminal-cursor"></span>
`;
prompt.setAttribute('contenteditable', 'true');
terminal.appendChild(prompt);
prompt.focus();
terminal.scrollTop = terminal.scrollHeight;
}
processCommand(terminal, command) {
this.addTerminalLine(terminal, `$ ${command}`);
const parts = command.split(' ').filter(p => p);
const cmd = parts[0].toLowerCase();
const args = parts.slice(1);
try {
switch (cmd) {
case 'help':
case '?':
this.addTerminalLine(terminal, 'Available commands:');
this.addTerminalLine(terminal, ' help/? - Show this help');
this.addTerminalLine(terminal, ' man <cmd> - Command manual');
this.addTerminalLine(terminal, ' clear/cls - Clear terminal');
this.addTerminalLine(terminal, ' echo <text> - Print text');
this.addTerminalLine(terminal, ' time/date - Show current time/date');
this.addTerminalLine(terminal, ' apps - List available applications');
this.addTerminalLine(terminal, ' ps - List running processes');
this.addTerminalLine(terminal, ' kill <pid> - Terminate process');
this.addTerminalLine(terminal, ' sysinfo - Show system information');
this.addTerminalLine(terminal, ' mkdir <name> - Create directory');
this.addTerminalLine(terminal, ' ls <path> - List files');
this.addTerminalLine(terminal, ' cd <path> - Change directory');
this.addTerminalLine(terminal, ' cat <file> - Show file contents');
break;
case 'man':
if (args.length === 0) {
this.addTerminalLine(terminal, 'Usage: man <command>');
break;
}
const manCmd = args[0].toLowerCase();
this.showManualPage(terminal, manCmd);
break;
case 'clear':
case 'cls':
terminal.innerHTML = '';
break;
case 'echo':
this.addTerminalLine(terminal, args.join(' '));
break;
case 'time':
case 'date':
this.addTerminalLine(terminal, new Date().toLocaleString());
break;
case 'apps':
this.addTerminalLine(terminal, 'Available applications:');
Object.entries(this.applications).forEach(([id, app]) => {
this.addTerminalLine(terminal, ` ${id} - ${app.title} [${app.permissions.join(', ')}]`);
});
break;
case 'ps':
this.addTerminalLine(terminal, 'Running processes:');
this.addTerminalLine(terminal, 'PID\tName\t\tCPU\tMemory');
this.processes.forEach(proc => {
this.addTerminalLine(terminal,
`${proc.pid}\t${proc.name}\t${proc.cpuUsage || 0}%\t${proc.memoryUsage || 0}MB`);
});
break;
case 'kill':
if (args.length === 0) {
this.addTerminalLine(terminal, 'Usage: kill <pid>');
break;
}
const pid = parseInt(args[0]);
this.terminateProcess(pid, terminal);
break;
case 'sysinfo':
this.addTerminalLine(terminal, 'System Information:');
this.addTerminalLine(terminal, `QuantumOS v1.1.0`);
this.addTerminalLine(terminal, `CPU: ${this.system.cpuUsage}% usage`);
this.addTerminalLine(terminal, `Memory: ${this.system.memoryUsage}% of ${this.totalMemory}MB used`);
this.addTerminalLine(terminal, `Disk: ${this.system.diskUsage}% used`);
this.addTerminalLine(terminal, `Network: ↑${this.system.networkSpeed.up}KB/s ↓${this.system.networkSpeed.down}KB/s`);
this.addTerminalLine(terminal, `Battery: ${this.system.batteryLevel}%`);
this.addTerminalLine(terminal, `Processes: ${this.processes.length} running`);
break;
case 'mkdir':
if (args.length === 0) {
this.addTerminalLine(terminal, 'Usage: mkdir <directory-name>');
break;
}
this.createDirectory(args[0], terminal);
break;
case 'ls':
this.listFiles(args[0] || '.', terminal);
break;
case 'cd':
if (args.length === 0) {
this.addTerminalLine(terminal, 'Usage: cd <directory>');
break;
}
this.changeDirectory(args[0], terminal);
break;
case 'cat':
if (args.length === 0) {
this.addTerminalLine(terminal, 'Usage: cat <file>');
break;
}
this.showFileContents(args[0], terminal);
break;
default:
this.addTerminalLine(terminal, `Command not found: ${cmd}`);
}
} catch (err) {
this.addTerminalLine(terminal, `Error: ${err.message}`);
}
}
}
// System process management
spawnProcess(name, windowElement = null) {
const pid = Math.floor(Math.random() * 10000) + 1000;
this.processes.push({
pid,
name,
window: windowElement,
cpuUsage: 0,
memoryUsage: Math.floor(Math.random() * 50) + 10,
startTime: new Date()
});
return pid;
}
spawnSystemProcess(name) {
return this.spawnProcess(name);
}
terminateProcess(pid, terminal = null) {
const index = this.processes.findIndex(p => p.pid === pid);
if (index === -1) {
if (terminal) this.addTerminalLine(terminal, `Process ${pid} not found`);
return false;
}
const process = this.processes[index];
if (process.window) {
process.window.remove();
}
this.processes.splice(index, 1);
if (terminal) this.addTerminalLine(terminal, `Terminated process ${pid} (${process.name})`);
return true;
}
// Virtual file system
initVirtualFileSystem() {
this.fileSystem = {
'/': {
type: 'directory',
children: {
'home': {
type: 'directory',
children: {
'user': {
type: 'directory',
children: {
'documents': { type: 'directory', children: {} },
'downloads': { type: 'directory', children: {} },
'desktop': { type: 'directory', children: {} }
}
}
}
},
'system': {
type: 'directory',
children: {
'logs': { type: 'directory', children: {} },
'config': {
type: 'directory',
children: {
'system.cfg': {
type: 'file',
content: 'system.version=1.1.0\nsystem.name=QuantumOS'
}
}
}
}
}
}
}
};
this.currentDirectory = '/home/user';
}
createDirectory(name, terminal) {
const path = this.resolvePath(name);
if (path.type === 'directory') {
this.addTerminalLine(terminal, `Directory already exists: ${name}`);
return;
}
const parent = this.getParentDirectory(name);
if (!parent) {
this.addTerminalLine(terminal, `Invalid path: ${name}`);
return;
}
const dirName = this.getLastPathComponent(name);
parent.children[dirName] = { type: 'directory', children: {} };
this.addTerminalLine(terminal, `Created directory: ${name}`);
}
listFiles(path, terminal) {
const targetPath = path ? this.resolvePath(path) : this.resolvePath(this.currentDirectory);
if (!targetPath || targetPath.type !== 'directory') {
this.addTerminalLine(terminal, `No such directory: ${path}`);
return;
}
this.addTerminalLine(terminal, `Contents of ${path || '.'}:`);
Object.keys(targetPath.children).forEach(name => {
const item = targetPath.children[name];
this.addTerminalLine(terminal, ` ${name}${item.type === 'directory' ? '/' : ''}`);
});
}
// System monitoring
updateSystemStats() {
// Simulate system resource usage
this.system = {
cpuUsage: Math.min(100, Math.max(5, Math.floor(Math.random() * 40) + 5)),
memoryUsage: Math.min(100, Math.max(10, Math.floor(Math.random() * 60) + 10)),
diskUsage: Math.min(100, Math.max(5, Math.floor(Math.random() * 30) + 5)),
networkSpeed: {
up: Math.floor(Math.random() * 1000),
down: Math.floor(Math.random() * 5000)
},
batteryLevel: this.system.batteryLevel > 0 ?
Math.max(0, this.system.batteryLevel - (Math.random() * 2)) :
0
};
// Update process stats
this.processes.forEach(proc => {
proc.cpuUsage = Math.floor(Math.random() * 10);
});
}
initNetworkMonitor() {
setInterval(() => {
// Simulate network status changes
if (Math.random() > 0.95) {
this.createNotification('Network', 'Network connection lost', 'warning');
} else if (Math.random() > 0.9) {
this.createNotification('Network', 'Network connection restored', 'success');
}
}, 30000);
}
initBatteryMonitor() {
setInterval(() => {
if (this.system.batteryLevel < 20) {
this.createNotification('Battery', `Low battery: ${this.system.batteryLevel}% remaining`, 'warning');
} else if (this.system.batteryLevel < 5) {
this.createNotification('Battery', `Critical battery: ${this.system.batteryLevel}% remaining`, 'error');
}
}, 60000);
}
// Quantum Boot Sequence Components
class QuantumBootLoader {
constructor() {
this.steps = [
{ name: "Quantum Coherence Check", duration: 1500 },
{ name: "Temporal Synchronization", duration: 2000 },
{ name: "Neural Network Initialization", duration: 2500 },
{ name: "Biosynth Interface Activation", duration: 1800 },
{ name: "Consensus Protocol Handshake", duration: 3000 }
];
this.currentStep = 0;
}
async start() {
const bootScreen = document.createElement('div');
bootScreen.id = 'quantum-boot';
bootScreen.innerHTML = `
<div class="boot-overlay">
<div class="boot-logo">
<div class="quantum-sphere"></div>
<h1>NEXUS QUANTUM OS</h1>
<div class="version">v3.1.4</div>
</div>
<div class="boot-progress">
<div class="progress-bar"></div>
<div class="step-info"></div>
</div>
<div class="boot-hint">Press Q + Enter to initialize hypervisor</div>
</div>
`;
document.body.appendChild(bootScreen);
// Wait for Q+Enter
return new Promise((resolve) => {
const handler = (e) => {
if (e.key.toLowerCase() === 'q' && e.keyCode === 13) {
e.preventDefault();
document.removeEventListener('keydown', handler);
this.runBootSequence().then(resolve);
}
};
document.addEventListener('keydown', handler);
});
}
async runBootSequence() {
const progressBar = document.querySelector('.boot-progress .progress-bar');
const stepInfo = document.querySelector('.boot-progress .step-info');
for (const [index, step] of this.steps.entries()) {
this.currentStep = index;
const progress = (index / this.steps.length) * 100;
progressBar.style.width = `${progress}%`;
stepInfo.textContent = `[${index+1}/${this.steps.length}] ${step.name}...`;
// Simulate quantum fluctuations
await this.quantumFluctuation(step.duration);
}
// Complete boot
progressBar.style.width = '100%';
stepInfo.textContent = 'Quantum state stabilized - Ready';
await new Promise(r => setTimeout(r, 1000));
document.getElementById('quantum-boot').remove();
}
quantumFluctuation(duration) {
return new Promise(resolve => {
const interval = setInterval(() => {
// Add quantum randomness
const currentProgress = document.querySelector('.progress-bar').style.width;
const currentWidth = parseFloat(currentProgress) || 0;
const fluctuation = (Math.random() * 5) - 2.5;
document.querySelector('.progress-bar').style.width = `${Math.min(100, Math.max(0, currentWidth + fluctuation))}%`;
}, 300);
setTimeout(() => {
clearInterval(interval);
resolve();
}, duration);
});
}
}
// Initialize OS with quantum boot sequence
document.addEventListener('DOMContentLoaded', async () => {
const bootLoader = new QuantumBootLoader();
await bootLoader.start();
window.os = new QuantumOS();
os.createNotification('System', 'QuantumOS Hypervisor online', 'success');
});
// Register global error handler
window.addEventListener('error', (e) => {
window.os.createNotification('System Error', e.message, 'error');
console.error(e);
});
});
|