File size: 47,150 Bytes
4704761 7e7139d 4704761 7e7139d 4704761 7e7139d 4704761 7e7139d 4704761 7e7139d 4704761 7e7139d 4704761 7e7139d 4704761 0075b97 4704761 e75a42b 4704761 e75a42b 4704761 0075b97 4704761 e75a42b 4704761 e75a42b 4704761 e75a42b 4704761 0075b97 cf5bb85 0075b97 cf5bb85 0075b97 cf5bb85 4704761 0075b97 4704761 7e7139d b42f07d 7e7139d b42f07d 7e7139d b42f07d 7e7139d b42f07d 7e7139d b42f07d 7e7139d b42f07d 7e7139d b42f07d 7e7139d b42f07d 7e7139d b42f07d 7e7139d 4704761 0075b97 4704761 0075b97 4704761 0075b97 4704761 7e7139d 4704761 f1768f2 4704761 f1768f2 4704761 f1768f2 4704761 f1768f2 4704761 e75a42b 4704761 e75a42b 4704761 e75a42b 4704761 7e7139d e75a42b 0075b97 4704761 0e29305 | 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 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WinDeskOS - Virtual Desktop</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Segoe+UI:wght@300;400;500;600&display=swap');
* {
font-family: 'Segoe UI', sans-serif;
}
.window {
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
}
.desktop-icon {
transition: all 0.2s ease;
position: absolute;
}
.desktop-icon:hover {
background-color: rgba(255, 255, 255, 0.1);
transform: scale(1.05);
}
.desktop-icon.dragging {
opacity: 0.8;
z-index: 9999;
}
.taskbar-item {
transition: all 0.2s ease;
}
.taskbar-item:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.start-menu {
transition: all 0.3s ease;
transform-origin: bottom left;
}
.context-menu {
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}
.desktop-bg {
background: linear-gradient(135deg, #0078d4 0%, #106ebe 100%);
}
</style>
</head>
<body class="bg-gray-900 text-white overflow-hidden h-screen flex flex-col">
<!-- Desktop Area -->
<div class="desktop-bg flex-1 relative p-4" id="desktop">
<!-- Desktop Icons -->
<div id="desktop-icon-1" class="desktop-icon cursor-pointer p-2 rounded text-center" style="top: 16px; left: 16px;" data-app="recycle-bin">
<i data-feather="trash-2" class="w-8 h-8 mx-auto text-blue-300"></i>
<p class="text-xs mt-1 text-white">Recycle Bin</p>
</div>
<div id="desktop-icon-2" class="desktop-icon cursor-pointer p-2 rounded text-center" style="top: 16px; left: 96px;" data-app="documents">
<i data-feather="folder" class="w-8 h-8 mx-auto text-yellow-300"></i>
<p class="text-xs mt-1 text-white">Documents</p>
</div>
<div id="desktop-icon-3" class="desktop-icon cursor-pointer p-2 rounded text-center" style="top: 80px; left: 16px;" data-app="pictures">
<i data-feather="image" class="w-8 h-8 mx-auto text-green-300"></i>
<p class="text-xs mt-1 text-white">Pictures</p>
</div>
<div id="desktop-icon-4" class="desktop-icon cursor-pointer p-2 rounded text-center" style="top: 80px; left: 96px;" data-app="browser">
<i data-feather="globe" class="w-8 h-8 mx-auto text-purple-300"></i>
<p class="text-xs mt-1 text-white">Browser</p>
</div>
<!-- Windows -->
<div id="windows-container" class="absolute inset-0 pointer-events-none">
<!-- Windows will be dynamically added here -->
</div>
</div>
<!-- Taskbar -->
<div class="bg-gray-800 bg-opacity-90 border-t border-gray-700 h-10 flex items-center px-2">
<!-- Start Button -->
<button id="start-button" class="taskbar-item h-8 w-8 bg-blue-600 hover:bg-blue-500 rounded flex items-center justify-center mr-2">
<i data-feather="grid" class="w-4 h-4"></i>
</button>
<!-- User Profile Button -->
<div class="taskbar-item h-8 px-3 bg-gray-700 hover:bg-gray-600 rounded flex items-center justify-center cursor-pointer mr-2" onclick="showUserMenu()">
<i data-feather="user" class="w-4 h-4 mr-2"></i>
<span id="username-display" class="text-xs">User</span>
</div>
<!-- Taskbar Apps -->
<div class="flex space-x-1">
<div class="taskbar-item h-8 w-8 bg-gray-700 hover:bg-gray-600 rounded flex items-center justify-center cursor-pointer" onclick="openWindow('browser')">
<i data-feather="globe" class="w-4 h-4"></i>
</div>
<div class="taskbar-item h-8 w-8 bg-gray-700 hover:bg-gray-600 rounded flex items-center justify-center cursor-pointer" onclick="openWindow('explorer')">
<i data-feather="folder" class="w-4 h-4"></i>
</div>
<div class="taskbar-item h-8 w-8 bg-gray-700 hover:bg-gray-600 rounded flex items-center justify-center cursor-pointer" onclick="openWindow('settings')">
<i data-feather="settings" class="w-4 h-4"></i>
</div>
</div>
<!-- System Tray -->
<div class="ml-auto flex items-center space-x-3">
<div class="text-xs cursor-pointer hover:text-blue-300" onclick="toggleVolume()">
<i data-feather="volume-2" id="volume-icon" class="w-4 h-4"></i>
</div>
<div class="text-xs cursor-pointer hover:text-blue-300" onclick="toggleWiFiMenu()">
<i data-feather="wifi" id="wifi-icon" class="w-4 h-4"></i>
</div>
<div class="text-xs cursor-pointer hover:text-blue-300" onclick="toggleBatteryInfo()">
<i data-feather="battery" id="battery-icon" class="w-4 h-4"></i>
</div>
<div class="text-xs">
<span id="time">15:30</span>
</div>
<div class="w-4 h-4 bg-green-500 rounded-full cursor-pointer" onclick="showNotificationCenter()"></div>
</div>
</div>
<!-- User Menu -->
<div id="user-menu" class="fixed bottom-12 left-14 w-48 bg-gray-800 bg-opacity-95 rounded-lg window hidden transform scale-95 opacity-0 pointer-events-none z-50">
<div class="p-3 border-b border-gray-700">
<div class="text-sm font-semibold" id="user-menu-name">User</div>
<div class="text-xs text-gray-400" id="user-menu-email">user@example.com</div>
</div>
<div class="p-1">
<div class="px-3 py-2 hover:bg-gray-700 cursor-pointer rounded text-sm flex items-center space-x-2" onclick="showUserSettings()">
<i data-feather="settings" class="w-4 h-4"></i>
<span>Account Settings</span>
</div>
<div class="px-3 py-2 hover:bg-gray-700 cursor-pointer rounded text-sm flex items-center space-x-2" onclick="lockSession()">
<i data-feather="lock" class="w-4 h-4"></i>
<span>Lock Session</span>
</div>
<div class="border-t border-gray-700 my-1"></div>
<div class="px-3 py-2 hover:bg-gray-700 cursor-pointer rounded text-sm flex items-center space-x-2" onclick="logout()">
<i data-feather="log-out" class="w-4 h-4"></i>
<span>Sign Out</span>
</div>
</div>
</div>
<!-- Start Menu -->
<div id="start-menu" class="start-menu fixed bottom-10 left-2 w-80 h-96 bg-gray-800 bg-opacity-95 rounded-lg window hidden transform scale-95 opacity-0 pointer-events-none">
<div class="p-4">
<div class="text-xl font-semibold mb-4">Applications</div>
<div class="grid grid-cols-2 gap-2">
<div class="p-3 rounded hover:bg-gray-700 cursor-pointer flex items-center space-x-2" onclick="openWindow('browser')">
<i data-feather="globe" class="w-6 h-6 text-blue-400"></i>
<span>Browser</span>
</div>
<div class="p-3 rounded hover:bg-gray-700 cursor-pointer flex items-center space-x-2" onclick="openWindow('explorer')">
<i data-feather="folder" class="w-6 h-6 text-yellow-400"></i>
<span>File Explorer</span>
</div>
<div class="p-3 rounded hover:bg-gray-700 cursor-pointer flex items-center space-x-2" onclick="openWindow('settings')">
<i data-feather="settings" class="w-6 h-6 text-gray-400"></i>
<span>Settings</span>
</div>
<div class="p-3 rounded hover:bg-gray-700 cursor-pointer flex items-center space-x-2" onclick="openWindow('notepad')">
<i data-feather="edit" class="w-6 h-6 text-green-400"></i>
<span>Notepad</span>
</div>
<div class="p-3 rounded hover:bg-gray-700 cursor-pointer flex items-center space-x-2" onclick="openWindow('calculator')">
<i data-feather="calculator" class="w-6 h-6 text-purple-400"></i>
<span>Calculator</span>
</div>
<div class="p-3 rounded hover:bg-gray-700 cursor-pointer flex items-center space-x-2" onclick="openWindow('weather')">
<i data-feather="cloud" class="w-6 h-6 text-blue-400"></i>
<span>Weather</span>
</div>
<div class="p-3 rounded hover:bg-gray-700 cursor-pointer flex items-center space-x-2" onclick="openWindow('calendar')">
<i data-feather="calendar" class="w-6 h-6 text-red-400"></i>
<span>Calendar</span>
</div>
</div>
</div>
</div>
<!-- Context Menu -->
<div id="context-menu" class="context-menu fixed bg-gray-800 bg-opacity-95 rounded-lg py-2 hidden z-50">
<div class="px-4 py-2 hover:bg-gray-700 cursor-pointer flex items-center space-x-2">
<i data-feather="folder-plus" class="w-4 h-4"></i>
<span>New Folder</span>
</div>
<div class="px-4 py-2 hover:bg-gray-700 cursor-pointer flex items-center space-x-2">
<i data-feather="file-text" class="w-4 h-4"></i>
<span>New Text Document</span>
</div>
<div class="border-t border-gray-700 my-1"></div>
<div class="px-4 py-2 hover:bg-gray-700 cursor-pointer flex items-center space-x-2">
<i data-feather="settings" class="w-4 h-4"></i>
<span>Personalize</span>
</div>
<div class="px-4 py-2 hover:bg-gray-700 cursor-pointer flex items-center space-x-2">
<i data-feather="info" class="w-4 h-4"></i>
<span>Properties</span>
</div>
<div class="border-t border-gray-700 my-1"></div>
<div class="px-4 py-2 hover:bg-gray-700 cursor-pointer flex items-center space-x-2">
<i data-feather="refresh-cw" class="w-4 h-4"></i>
<span>Refresh</span>
</div>
</div>
<!-- Notification Center -->
<div id="notification-center" class="fixed right-2 bottom-12 w-80 h-96 bg-gray-800 bg-opacity-95 rounded-lg window hidden transform scale-95 opacity-0 pointer-events-none z-50">
<div class="p-4">
<div class="flex items-center justify-between mb-4">
<div class="text-lg font-semibold">Notifications</div>
<button onclick="hideNotificationCenter()" class="w-6 h-6 rounded hover:bg-gray-700 flex items-center justify-center">
<i data-feather="x" class="w-4 h-4"></i>
</button>
</div>
<div class="space-y-2 max-h-64 overflow-y-auto">
<div class="p-3 bg-gray-700 rounded">
<div class="text-sm font-medium">System</div>
<div class="text-xs text-gray-300">Welcome to WinDeskOS!</div>
<div class="text-xs text-gray-400 mt-1">Just now</div>
</div>
</div>
<div class="border-t border-gray-700 mt-4 pt-4">
<div class="text-sm font-semibold mb-2">Quick Settings</div>
<div class="grid grid-cols-3 gap-2">
<div class="p-2 bg-gray-700 rounded text-center cursor-pointer hover:bg-gray-600" onclick="toggleDarkMode()">
<i data-feather="moon" class="w-5 h-5 mx-auto"></i>
<div class="text-xs mt-1">Dark Mode</div>
</div>
<div class="p-2 bg-gray-700 rounded text-center cursor-pointer hover:bg-gray-600" onclick="toggleVolume()">
<i data-feather="volume-2" class="w-5 h-5 mx-auto"></i>
<div class="text-xs mt-1">Volume</div>
</div>
<div class="p-2 bg-gray-700 rounded text-center cursor-pointer hover:bg-gray-600" onclick="toggleWiFi()">
<i data-feather="wifi" class="w-5 h-5 mx-auto"></i>
<div class="text-xs mt-1">Wi-Fi</div>
</div>
</div>
</div>
</div>
</div>
<!-- Calculator App Content -->
<script id="calculator-template" type="text/template">
</script>
<!-- Weather App Content -->
<script id="weather-template" type="text/template">
</script>
<script>
let windows = [];
let zIndexCounter = 1000;
let currentUser = null;
// Check authentication on page load
function checkAuthentication() {
const userData = localStorage.getItem('currentUser');
// Allow admin user to bypass login for demo purposes
if (!userData) {
// Create demo admin user if none exists
const demoUser = {
username: 'admin',
rememberMe: true,
loginTime: new Date().toISOString()
};
localStorage.setItem('currentUser', JSON.stringify(demoUser));
currentUser = demoUser;
} else {
currentUser = JSON.parse(userData);
}
document.getElementById('username-display').textContent = currentUser.username;
document.getElementById('user-menu-name').textContent = currentUser.username;
document.getElementById('user-menu-email').textContent = `${currentUser.username}@windeskos.com`;
// Load user-specific data
loadUserData();
}
// Update time
function updateTime() {
const now = new Date();
document.getElementById('time').textContent = now.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
}
setInterval(updateTime, 1000);
updateTime();
// User menu functions
function showUserMenu() {
const menu = document.getElementById('user-menu');
const isVisible = !menu.classList.contains('hidden');
if (isVisible) {
menu.classList.add('hidden');
menu.classList.remove('scale-100', 'opacity-100');
menu.classList.add('scale-95', 'opacity-0');
menu.style.pointerEvents = 'none';
} else {
menu.classList.remove('hidden');
setTimeout(() => {
menu.classList.remove('scale-95', 'opacity-0');
menu.classList.add('scale-100', 'opacity-100');
menu.style.pointerEvents = 'auto';
}, 10);
}
}
function logout() {
// Save user data before logout
saveUserData();
// Clear current session
localStorage.removeItem('currentUser');
// Redirect to login
window.location.href = 'login.html';
}
function lockSession() {
saveUserData();
window.location.href = 'login.html?locked=true';
}
function showUserSettings() {
alert('User settings would open here');
}
// User data management
function saveUserData() {
if (!currentUser) return;
const userData = {
desktopIconPositions: JSON.parse(localStorage.getItem('desktopIconPositions') || '{}'),
openWindows: windows.map(windowId => {
const window = document.getElementById(windowId);
if (window) {
return {
type: window.getAttribute('data-window-type'),
position: {
left: window.style.left,
top: window.style.top,
width: window.style.width,
height: window.style.height
}
};
}
return null;
}).filter(Boolean),
calculatorState: {
currentInput: currentInput,
previousInput: previousInput,
operation: operation,
shouldResetInput: shouldResetInput
},
lastSaved: new Date().toISOString()
};
localStorage.setItem(`userData_${currentUser.username}`, JSON.stringify(userData));
}
function loadUserData() {
if (!currentUser) return;
const userData = localStorage.getItem(`userData_${currentUser.username}`);
if (userData) {
const data = JSON.parse(userData);
// Load desktop icon positions
if (data.desktopIconPositions) {
Object.keys(data.desktopIconPositions).forEach(iconId => {
const icon = document.getElementById(iconId);
if (icon && data.desktopIconPositions[iconId]) {
icon.style.left = data.desktopIconPositions[iconId].left;
icon.style.top = data.desktopIconPositions[iconId].top;
}
});
}
// Load calculator state
if (data.calculatorState) {
currentInput = data.calculatorState.currentInput || '0';
previousInput = data.calculatorState.previousInput || '0';
operation = data.calculatorState.operation || null;
shouldResetInput = data.calculatorState.shouldResetInput || false;
}
// Open saved windows
if (data.openWindows && data.openWindows.length > 0) {
setTimeout(() => {
data.openWindows.forEach(windowData => {
const windowElement = createWindow(windowData.type);
if (windowElement && windowData.position) {
windowElement.style.left = windowData.position.left;
windowElement.style.top = windowData.position.top;
windowElement.style.width = windowData.position.width;
windowElement.style.height = windowData.position.height;
}
});
}, 500);
}
}
}
// Auto-save user data periodically
setInterval(saveUserData, 30000); // Save every 30 seconds
// Save data before page unload
window.addEventListener('beforeunload', saveUserData);
// Start menu toggle
document.getElementById('start-button').addEventListener('click', function(e) {
e.stopPropagation();
const menu = document.getElementById('start-menu');
const isVisible = !menu.classList.contains('hidden');
if (isVisible) {
menu.classList.add('hidden');
menu.classList.remove('scale-100', 'opacity-100');
menu.classList.add('scale-95', 'opacity-0');
menu.style.pointerEvents = 'none';
} else {
menu.classList.remove('hidden');
setTimeout(() => {
menu.classList.remove('scale-95', 'opacity-0');
menu.classList.add('scale-100', 'opacity-100');
menu.style.pointerEvents = 'auto';
}, 10);
}
});
// Close start menu when clicking elsewhere
document.addEventListener('click', function(e) {
if (!e.target.closest('#start-menu') && !e.target.closest('#start-button')) {
const menu = document.getElementById('start-menu');
menu.classList.add('hidden');
menu.classList.remove('scale-100', 'opacity-100');
menu.classList.add('scale-95', 'opacity-0');
menu.style.pointerEvents = 'none';
}
});
// Context menu
document.getElementById('desktop').addEventListener('contextmenu', function(e) {
e.preventDefault();
const menu = document.getElementById('context-menu');
menu.style.left = e.pageX + 'px';
menu.style.top = e.pageY + 'px';
menu.classList.remove('hidden');
});
document.addEventListener('click', function() {
document.getElementById('context-menu').classList.add('hidden');
});
// Desktop icon dragging functionality
function setupIconDragging() {
const desktopIcons = document.querySelectorAll('.desktop-icon');
let dragTimeout = null;
let lastClickTime = 0;
desktopIcons.forEach(icon => {
let isDragging = false;
let startX, startY, startLeft, startTop;
let clickCount = 0;
icon.addEventListener('mousedown', function(e) {
if (e.button !== 0) return; // Only left click
// Start drag after short delay to distinguish from click
dragTimeout = setTimeout(() => {
isDragging = true;
startX = e.clientX;
startY = e.clientY;
const computedStyle = window.getComputedStyle(icon);
startLeft = parseInt(computedStyle.left) || 0;
startTop = parseInt(computedStyle.top) || 0;
icon.classList.add('dragging');
icon.style.zIndex = '9999';
e.preventDefault();
}, 150); // Reduced delay for faster response
});
document.addEventListener('mousemove', function(e) {
if (!isDragging) return;
clearTimeout(dragTimeout);
const dx = e.clientX - startX;
const dy = e.clientY - startY;
icon.style.left = (startLeft + dx) + 'px';
icon.style.top = (startTop + dy) + 'px';
});
document.addEventListener('mouseup', function() {
clearTimeout(dragTimeout);
if (isDragging) {
isDragging = false;
icon.classList.remove('dragging');
icon.style.zIndex = '';
// Save position to localStorage
const positions = JSON.parse(localStorage.getItem('desktopIconPositions') || '{}');
positions[icon.id] = {
left: icon.style.left,
top: icon.style.top
};
localStorage.setItem('desktopIconPositions', JSON.stringify(positions));
}
});
// Double click to open app
icon.addEventListener('click', function(e) {
clearTimeout(dragTimeout);
if (isDragging) return;
const currentTime = new Date().getTime();
const timeDiff = currentTime - lastClickTime;
if (timeDiff < 300 && timeDiff > 0) { // Double click within 300ms
const appType = icon.getAttribute('data-app');
openWindow(appType);
lastClickTime = 0;
} else {
lastClickTime = currentTime;
}
});
});
}
// Load saved icon positions
function loadIconPositions() {
const positions = JSON.parse(localStorage.getItem('desktopIconPositions') || '{}');
Object.keys(positions).forEach(iconId => {
const icon = document.getElementById(iconId);
if (icon && positions[iconId]) {
icon.style.left = positions[iconId].left;
icon.style.top = positions[iconId].top;
}
});
}
// Window management
function openWindow(type) {
const windowElement = createWindow(type);
}
function createWindow(type) {
const windowId = 'window-' + Date.now();
const windowContent = getWindowContent(type);
const windowElement = document.createElement('div');
windowElement.id = windowId;
windowElement.setAttribute('data-window-type', type);
windowElement.className = 'window bg-gray-800 bg-opacity-95 rounded-lg absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-96 h-64 pointer-events-auto';
windowElement.style.zIndex = zIndexCounter++;
windowElement.innerHTML = `
<div class="flex items-center justify-between p-3 bg-gray-900 rounded-t-lg cursor-move border-b border-gray-700">
<div class="flex items-center space-x-2">
<i data-feather="${windowContent.icon}" class="w-4 h-4 ${windowContent.iconColor}"></i>
<span>${windowContent.title}</span>
</div>
<div class="flex space-x-1">
<button class="w-6 h-6 rounded hover:bg-gray-700 flex items-center justify-center">–</button>
<button class="w-6 h-6 rounded hover:bg-gray-700 flex items-center justify-center">□</button>
<button class="w-6 h-6 rounded hover:bg-red-600 flex items-center justify-center" onclick="closeWindow('${windowId}')">×</button>
</div>
</div>
<div class="p-4 h-[calc(100%-3rem)]">
${windowContent.content}
</div>
`;
document.getElementById('windows-container').appendChild(windowElement);
feather.replace();
// Make window draggable
makeDraggable(windowElement);
windows.push(windowId);
return windowElement;
}
function closeWindow(id) {
const window = document.getElementById(id);
if (window) {
window.remove();
windows = windows.filter(winId => winId !== id);
}
}
function makeDraggable(element) {
const header = element.querySelector('.bg-gray-900');
let isDragging = false;
let isResizing = false;
let resizeDirection = '';
let startX, startY, startLeft, startTop, startWidth, startHeight;
// Add resize handles
const resizeHandles = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'];
resizeHandles.forEach(dir => {
const handle = document.createElement('div');
handle.className = `resize-handle resize-${dir}`;
handle.style.cssText = `
position: absolute;
background: transparent;
z-index: 10;
`;
// Position and size based on direction
switch(dir) {
case 'n': handle.style.top = '0'; handle.style.left = '10px'; handle.style.right = '10px'; handle.style.height = '4px'; handle.style.cursor = 'ns-resize'; break;
case 'ne': handle.style.top = '0'; handle.style.right = '0'; handle.style.width = '6px'; handle.style.height = '6px'; handle.style.cursor = 'nesw-resize'; break;
case 'e': handle.style.top = '10px'; handle.style.right = '0'; handle.style.width = '4px'; handle.style.bottom = '10px'; handle.style.cursor = 'ew-resize'; break;
case 'se': handle.style.bottom = '0'; handle.style.right = '0'; handle.style.width = '6px'; handle.style.height = '6px'; handle.style.cursor = 'nwse-resize'; break;
case 's': handle.style.bottom = '0'; handle.style.left = '10px'; handle.style.right = '10px'; handle.style.height = '4px'; handle.style.cursor = 'ns-resize'; break;
case 'sw': handle.style.bottom = '0'; handle.style.left = '0'; handle.style.width = '6px'; handle.style.height = '6px'; handle.style.cursor = 'nesw-resize'; break;
case 'w': handle.style.top = '10px'; handle.style.left = '0'; handle.style.width = '4px'; handle.style.bottom = '10px'; handle.style.cursor = 'ew-resize'; break;
case 'nw': handle.style.top = '0'; handle.style.left = '0'; handle.style.width = '6px'; handle.style.height = '6px'; handle.style.cursor = 'nwse-resize'; break;
}
handle.addEventListener('mousedown', function(e) {
e.stopPropagation();
isResizing = true;
resizeDirection = dir;
startX = e.clientX;
startY = e.clientY;
startWidth = element.offsetWidth;
startHeight = element.offsetHeight;
startLeft = parseInt(element.style.left) || (window.innerWidth/2 - startWidth/2);
startTop = parseInt(element.style.top) || (window.innerHeight/2 - startHeight/2);
// Bring to front
element.style.zIndex = zIndexCounter++;
});
element.appendChild(handle);
});
header.addEventListener('mousedown', function(e) {
isDragging = true;
startX = e.clientX;
startY = e.clientY;
// Get current position from computed style
const computedStyle = window.getComputedStyle(element);
startLeft = parseInt(computedStyle.left) || (window.innerWidth/2 - element.offsetWidth/2);
startTop = parseInt(computedStyle.top) || (window.innerHeight/2 - element.offsetHeight/2);
// Bring to front
element.style.zIndex = zIndexCounter++;
element.style.left = startLeft + 'px';
element.style.top = startTop + 'px';
});
document.addEventListener('mousemove', function(e) {
if (isDragging) {
const dx = e.clientX - startX;
const dy = e.clientY - startY;
element.style.left = (startLeft + dx) + 'px';
element.style.top = (startTop + dy) + 'px';
}
if (isResizing) {
const dx = e.clientX - startX;
const dy = e.clientY - startY;
let newWidth = startWidth;
let newHeight = startHeight;
let newLeft = startLeft;
let newTop = startTop;
switch(resizeDirection) {
case 'e':
newWidth = Math.max(200, startWidth + dx);
break;
case 'w':
newWidth = Math.max(200, startWidth - dx);
newLeft = startLeft + dx;
break;
case 's':
newHeight = Math.max(150, startHeight + dy);
break;
case 'n':
newHeight = Math.max(150, startHeight - dy);
newTop = startTop + dy;
break;
case 'se':
newWidth = Math.max(200, startWidth + dx);
newHeight = Math.max(150, startHeight + dy);
break;
case 'sw':
newWidth = Math.max(200, startWidth - dx);
newHeight = Math.max(150, startHeight + dy);
newLeft = startLeft + dx;
break;
case 'ne':
newWidth = Math.max(200, startWidth + dx);
newHeight = Math.max(150, startHeight - dy);
newTop = startTop + dy;
break;
case 'nw':
newWidth = Math.max(200, startWidth - dx);
newHeight = Math.max(150, startHeight - dy);
newLeft = startLeft + dx;
newTop = startTop + dy;
break;
}
element.style.width = newWidth + 'px';
element.style.height = newHeight + 'px';
element.style.left = newLeft + 'px';
element.style.top = newTop + 'px';
}
});
document.addEventListener('mouseup', function() {
isDragging = false;
isResizing = false;
});
}
function getWindowContent(type) {
const contents = {
'browser': {
icon: 'globe',
iconColor: 'text-blue-400',
title: 'Browser',
content: '<div class="h-full flex items-center justify-center"><p class="text-gray-400">Browser content would go here</p></div>'
},
'explorer': {
icon: 'folder',
iconColor: 'text-yellow-400',
title: 'File Explorer',
content: '<div class="h-full flex items-center justify-center"><p class="text-gray-400">File Explorer content would go here</p></div>'
},
'settings': {
icon: 'settings',
iconColor: 'text-gray-400',
title: 'Settings',
content: '<div class="h-full flex items-center justify-center"><p class="text-gray-400">Settings content would go here</p></div>'
},
'notepad': {
icon: 'edit',
iconColor: 'text-green-400',
title: 'Notepad',
content: '<textarea class="w-full h-full bg-gray-700 text-white p-2 rounded resize-none" placeholder="Start typing..."></textarea>'
},
'calculator': {
icon: 'calculator',
iconColor: 'text-purple-400',
title: 'Calculator',
content: document.getElementById('calculator-template').innerHTML
},
'weather': {
icon: 'cloud',
iconColor: 'text-blue-400',
title: 'Weather',
content: document.getElementById('weather-template').innerHTML
},
'calendar': {
icon: 'calendar',
iconColor: 'text-red-400',
title: 'Calendar',
content: '<div class="h-full flex items-center justify-center"><p class="text-gray-400">Calendar content would go here</p></div>'
},
'documents': {
icon: 'folder',
iconColor: 'text-yellow-400',
title: 'Documents',
content: '<div class="h-full flex items-center justify-center"><p class="text-gray-400">Documents folder content</p></div>'
},
'pictures': {
icon: 'image',
iconColor: 'text-green-400',
title: 'Pictures',
content: '<div class="h-full flex items-center justify-center"><p class="text-gray-400">Pictures folder content</p></div>'
},
'recycle-bin': {
icon: 'trash-2',
iconColor: 'text-blue-400',
title: 'Recycle Bin',
content: '<div class="h-full flex items-center justify-center"><p class="text-gray-400">Recycle Bin is empty</p></div>'
}
};
return contents[type] || contents['browser'];
}
// Calculator functionality
let currentInput = '0';
let previousInput = '0';
let operation = null;
let shouldResetInput = false;
function calcInput(value) {
if (currentInput === '0' || shouldResetInput) {
currentInput = value;
shouldResetInput = false;
} else {
currentInput += value;
}
updateCalcDisplay();
}
function calcOperation(op) {
if (operation !== null) calcCalculate();
previousInput = currentInput;
operation = op;
shouldResetInput = true;
}
function calcCalculate() {
let result;
const prev = parseFloat(previousInput);
const current = parseFloat(currentInput);
if (isNaN(prev) || isNaN(current)) return;
switch(operation) {
case '+': result = prev + current; break;
case '-': result = prev - current; break;
case '*': result = prev * current; break;
case '/': result = prev / current; break;
case '%': result = prev % current; break;
default: return;
}
currentInput = result.toString();
operation = null;
shouldResetInput = true;
updateCalcDisplay();
}
function calcClear() {
currentInput = '0';
previousInput = '0';
operation = null;
shouldResetInput = false;
updateCalcDisplay();
}
function calcBackspace() {
currentInput = currentInput.slice(0, -1);
if (currentInput === '') currentInput = '0';
updateCalcDisplay();
}
function updateCalcDisplay() {
const display = document.getElementById('calc-display');
if (display) display.textContent = currentInput;
}
// Weather functionality
async function fetchWeather() {
try {
const response = await fetch('https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=temperature_2m,weather_code');
const data = await response.json();
const tempElement = document.getElementById('weather-temp');
const descElement = document.getElementById('weather-desc');
const locationElement = document.getElementById('weather-location');
if (tempElement) tempElement.textContent = `${data.current.temperature_2m}°C`;
if (descElement) descElement.textContent = getWeatherDescription(data.current.weather_code);
if (locationElement) locationElement.textContent = 'Berlin, Germany';
} catch (error) {
console.error('Error fetching weather:', error);
}
}
function getWeatherDescription(code) {
const weatherCodes = {
0: 'Clear sky',
1: 'Mainly clear',
2: 'Partly cloudy',
3: 'Overcast',
45: 'Fog',
48: 'Depositing rime fog',
51: 'Light drizzle',
53: 'Moderate drizzle',
55: 'Dense drizzle',
61: 'Slight rain',
63: 'Moderate rain',
65: 'Heavy rain',
80: 'Slight rain showers',
81: 'Moderate rain showers',
82: 'Violent rain showers'
};
return weatherCodes[code] || 'Unknown weather';
}
// System tray functionality
function toggleVolume() {
alert('Volume control would open here');
}
function toggleWiFiMenu() {
alert('Wi-Fi settings would open here');
}
function toggleBatteryInfo() {
alert('Battery information would show here');
}
function showNotificationCenter() {
const center = document.getElementById('notification-center');
center.classList.remove('hidden');
setTimeout(() => {
center.classList.remove('scale-95', 'opacity-0');
center.classList.add('scale-100', 'opacity-100');
center.style.pointerEvents = 'auto';
}, 10);
}
function hideNotificationCenter() {
const center = document.getElementById('notification-center');
center.classList.add('hidden');
center.classList.remove('scale-100', 'opacity-100');
center.classList.add('scale-95', 'opacity-0');
center.style.pointerEvents = 'none';
}
function toggleDarkMode() {
document.body.classList.toggle('bg-gray-900');
document.body.classList.toggle('bg-gray-100');
document.body.classList.toggle('text-white');
document.body.classList.toggle('text-gray-900');
}
function toggleWiFi() {
const wifiIcon = document.getElementById('wifi-icon');
const isConnected = wifiIcon.getAttribute('data-feather') === 'wifi';
feather.replace({
'wifi-icon': isConnected ? 'wifi-off' : 'wifi'
});
}
// Initialize feather icons and handle drag prevention
feather.replace();
// Prevent drag on icons
document.querySelectorAll('.desktop-icon i, .taskbar-item i').forEach(icon => {
icon.addEventListener('mousedown', function(e) {
e.stopPropagation();
});
});
// Setup icon dragging and load positions
setupIconDragging();
loadIconPositions();
// Initial weather fetch
setTimeout(fetchWeather, 1000);
// Initialize authentication check
checkAuthentication();
</script>
</body>
</html>
|