-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeb-OS.html
More file actions
1814 lines (1575 loc) · 77 KB
/
Copy pathWeb-OS.html
File metadata and controls
1814 lines (1575 loc) · 77 KB
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
999
1000
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ubuntu Web OS (VFS Prototype)</title>
<!-- Tailwind CSS & Lucide Icons (Web-safe fallbacks included) -->
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/lucide-static@0.341.0/font/lucide.min.css" rel="stylesheet">
<style>
/* Ubuntu Font & UI tweaks */
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap');
body {
font-family: 'Ubuntu', sans-serif;
user-select: none;
overflow: hidden;
}
.window-active {
z-index: 50;
}
.window-inactive {
z-index: 30;
}
/* Custom scrollbar for Ubuntu look */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-thumb {
background: #4a4a4a;
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: #77216F;
}
/* Terminal styling */
.terminal-body {
font-family: 'Courier New', Courier, monospace;
}
/* ドラッグ時のiframeイベント吸収防止 */
.dragging-window iframe {
pointer-events: none !important;
}
</style>
</head>
<body class="w-screen h-screen bg-[#2c001e] text-white overflow-hidden relative" id="desktop-root">
<!-- ==================== 1. BOOT / DISK MANAGER OVERLAY ==================== -->
<div id="boot-screen" class="absolute inset-0 bg-[#2c001e] flex flex-col items-center justify-center z-[100] transition-opacity duration-500">
<div class="text-center max-w-md w-full px-6">
<!-- Ubuntu Logo style SVG -->
<div class="flex justify-center mb-8">
<svg class="w-24 h-24 text-[#e95420]" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm0 4c1.105 0 2 .895 2 2s-.895 2-2 2-2-.895-2-2 .895-2 2-2zm-6.5 5.5c.828 0 1.5.672 1.5 1.5s-.672 1.5-1.5 1.5-1.5-.672-1.5-1.5.672-1.5 1.5-1.5zm13 0c.828 0 1.5.672 1.5 1.5s-.672 1.5-1.5 1.5-1.5-.672-1.5-1.5.672-1.5 1.5-1.5zM12 14c-1.105 0-2 .895-2 2s.895 2 2 2 2-.895 2-2-.895-2-2-2z"/>
</svg>
</div>
<h1 class="text-3xl font-bold mb-2">Ubuntu Web OS</h1>
<p class="text-gray-400 mb-8 text-sm">仮想ファイルシステム (8MiB VFS) へようこそ</p>
<!-- Step 1: Choose Boot Option -->
<div id="boot-options" class="space-y-4">
<button onclick="showCreateDisk()" class="w-full py-3 px-4 bg-[#e95420] hover:bg-[#cf4a1b] font-semibold rounded text-white transition duration-200">
新規仮想ディスクを作成して起動
</button>
<button onclick="showLoadDisk()" class="w-full py-3 px-4 bg-[#5e2750] hover:bg-[#4a1e3f] font-semibold rounded text-white border border-[#aea79f] transition duration-200">
既存の仮想ディスクを読み込む
</button>
</div>
<!-- Step 2A: Create Disk Form -->
<div id="create-disk-form" class="hidden text-left bg-[#3d0c2f] p-6 rounded shadow-lg border border-[#5e2750] space-y-4">
<h2 class="text-lg font-bold text-[#e95420] border-b border-[#5e2750] pb-2">仮想ドライブ新規作成</h2>
<div>
<label class="block text-xs text-gray-300 mb-1">ユーザー名 (User Name)</label>
<input type="text" id="new-username" value="ubuntu" class="w-full bg-[#2c001e] border border-[#aea79f] p-2 rounded text-white text-sm outline-none focus:border-[#e95420]">
</div>
<div>
<label class="block text-xs text-gray-300 mb-1">パスワード (Password)</label>
<input type="password" id="new-password" value="ubuntu" class="w-full bg-[#2c001e] border border-[#aea79f] p-2 rounded text-white text-sm outline-none focus:border-[#e95420]">
</div>
<div class="text-xs text-gray-400 bg-[#2c001e] p-2 rounded leading-relaxed">
※作成時、システム確保領域およびデフォルト構造を含む仮想ディスクファイル(約8MiB分のデータを含むZIP想定のJSONファイル)が生成・自動ダウンロードされます。
</div>
<div class="flex space-x-2 pt-2">
<button onclick="cancelBootStep()" class="flex-1 py-2 bg-gray-600 hover:bg-gray-700 rounded text-sm font-semibold">戻る</button>
<button onclick="handleCreateDisk()" class="flex-1 py-2 bg-[#e95420] hover:bg-[#cf4a1b] rounded text-sm font-semibold">作成して起動</button>
</div>
</div>
<!-- Step 2B: Load Disk Form -->
<div id="load-disk-form" class="hidden text-left bg-[#3d0c2f] p-6 rounded shadow-lg border border-[#5e2750] space-y-4">
<h2 class="text-lg font-bold text-[#e95420] border-b border-[#5e2750] pb-2">仮想ドライブ読み込み</h2>
<!-- Drag & Drop Area -->
<div id="drop-zone" class="border-2 border-dashed border-[#aea79f] hover:border-[#e95420] rounded p-6 text-center cursor-pointer transition"
onclick="document.getElementById('disk-file-input').click()">
<p class="text-xs text-gray-300">ここに仮想ディスクファイル (.json) をドラッグ&ドロップ、またはクリックして選択</p>
<input type="file" id="disk-file-input" class="hidden" accept=".json" onchange="handleFileSelect(event)">
<div id="selected-file-name" class="mt-2 text-xs text-[#e95420] font-semibold"></div>
</div>
<div>
<label class="block text-xs text-gray-300 mb-1">ユーザー名</label>
<input type="text" id="load-username" class="w-full bg-[#2c001e] border border-[#aea79f] p-2 rounded text-white text-sm outline-none" placeholder="ubuntu">
</div>
<div>
<label class="block text-xs text-gray-300 mb-1">パスワード</label>
<input type="password" id="load-password" class="w-full bg-[#2c001e] border border-[#aea79f] p-2 rounded text-white text-sm outline-none" placeholder="••••••••">
</div>
<div id="load-error-msg" class="text-xs text-red-400 hidden"></div>
<div class="flex space-x-2 pt-2">
<button onclick="cancelBootStep()" class="flex-1 py-2 bg-gray-600 hover:bg-gray-700 rounded text-sm font-semibold">戻る</button>
<button onclick="handleLoadDisk()" class="flex-1 py-2 bg-[#e95420] hover:bg-[#cf4a1b] rounded text-sm font-semibold">マウントして起動</button>
</div>
</div>
<!-- Booting Progress Indicator -->
<div id="boot-loading" class="hidden mt-8 space-y-2">
<div class="w-full bg-gray-700 h-1.5 rounded overflow-hidden">
<div class="bg-[#e95420] h-full w-0 animate-[pulse_1.5s_infinite]" style="width: 100%"></div>
</div>
<p class="text-xs text-gray-400" id="boot-status-text">仮想システムを構築中...</p>
</div>
</div>
</div>
<!-- ==================== 2. MAIN DESKTOP ENVIRONMENT ==================== -->
<div id="desktop-env" class="hidden w-full h-full flex flex-col relative overflow-hidden">
<!-- Top Bar -->
<header class="h-7 bg-[#111111] text-xs px-4 flex items-center justify-between select-none z-40 text-[#dfdbd2]">
<div class="flex items-center space-x-4">
<span class="font-bold hover:text-white cursor-pointer" onclick="toggleActivities()">アクティビティ</span>
<span class="hover:text-white cursor-pointer" id="current-focused-app">デスクトップ</span>
</div>
<!-- Center Clock -->
<div class="absolute left-1/2 -translate-x-1/2 font-semibold" id="top-bar-clock">
6月 20日 16:54
</div>
<!-- Right Status Area -->
<div class="flex items-center space-x-3">
<i class="lucide-wifi w-3.5 h-3.5"></i>
<i class="lucide-volume-2 w-3.5 h-3.5"></i>
<i class="lucide-battery w-3.5 h-3.5"></i>
<span class="hover:text-white cursor-pointer" onclick="openSystemSettings()" id="top-user-indicator">ubuntu</span>
</div>
</header>
<!-- Desktop Body Area -->
<div class="flex-1 flex relative overflow-hidden">
<!-- Ubuntu Left Dock (Launcher) -->
<aside class="w-16 bg-[#111111]/85 backdrop-blur-sm flex flex-col items-center py-4 space-y-4 z-40 border-r border-[#2d2d2d]">
<!-- Terminal Launcher -->
<button onclick="openApp('terminal')" class="group relative p-2.5 rounded-lg hover:bg-white/10 transition" title="端末 (Terminal)">
<div class="w-10 h-10 bg-[#300a24] border border-[#dfdbd2]/20 rounded-md flex items-center justify-center text-green-400 font-mono text-lg font-bold shadow-md">
>_
</div>
<span class="absolute left-16 top-1/2 -translate-y-1/2 bg-neutral-900 text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition whitespace-nowrap pointer-events-none">端末 (Terminal)</span>
</button>
<!-- File Manager Launcher -->
<button onclick="openApp('files')" class="group relative p-2.5 rounded-lg hover:bg-white/10 transition" title="ファイルマネージャ">
<div class="w-10 h-10 bg-gradient-to-br from-amber-400 to-amber-600 rounded-md flex items-center justify-center text-white shadow-md">
<i class="lucide-folder-open w-6 h-6"></i>
</div>
<span class="absolute left-16 top-1/2 -translate-y-1/2 bg-neutral-900 text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition whitespace-nowrap pointer-events-none">ファイル</span>
</button>
<!-- File Uploader Launcher -->
<button onclick="openApp('uploader')" class="group relative p-2.5 rounded-lg hover:bg-white/10 transition" title="ファイルアップローダー">
<div class="w-10 h-10 bg-gradient-to-br from-blue-400 to-blue-600 rounded-md flex items-center justify-center text-white shadow-md">
<i class="lucide-upload-cloud w-6 h-6"></i>
</div>
<span class="absolute left-16 top-1/2 -translate-y-1/2 bg-neutral-900 text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition whitespace-nowrap pointer-events-none">アップローダー</span>
</button>
<!-- System Settings Launcher -->
<button onclick="openApp('settings')" class="group relative p-2.5 rounded-lg hover:bg-white/10 transition" title="システム設定">
<div class="w-10 h-10 bg-neutral-700 rounded-md flex items-center justify-center text-white shadow-md">
<i class="lucide-settings w-6 h-6"></i>
</div>
<span class="absolute left-16 top-1/2 -translate-y-1/2 bg-neutral-900 text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition whitespace-nowrap pointer-events-none">設定</span>
</button>
<div class="flex-grow"></div>
<!-- Shutdown Indicator -->
<button onclick="systemShutdown()" class="group relative p-2.5 rounded-lg hover:bg-red-900/40 transition text-red-500 hover:text-red-400" title="OSシャットダウン (セーブ)">
<i class="lucide-power w-6 h-6"></i>
<span class="absolute left-16 top-1/2 -translate-y-1/2 bg-neutral-900 text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition whitespace-nowrap pointer-events-none">シャットダウン</span>
</button>
</aside>
<!-- Interactive Desktop Area -->
<main id="desktop-grid" class="flex-1 relative overflow-hidden p-6" ondragover="event.preventDefault()" ondrop="handleDesktopFileDrop(event)">
<!-- Grid for desktop icons (Dynamically Populated) -->
<div id="desktop-icons" class="grid grid-flow-row auto-rows-[90px] grid-cols-[repeat(auto-fill,minmax(80px,1fr))] gap-4 justify-items-center select-none">
<!-- Dynamic Desktop Icons Rendered Here -->
</div>
<!-- Windows Container -->
<div id="windows-container" class="absolute inset-0 pointer-events-none z-10">
<!-- Windows will be injected here via javascript -->
</div>
</main>
</div>
</div>
<!-- ==================== 3. MODAL / DIALOGS ==================== -->
<!-- 以前ここに配置されていた固定モーダル(HTMLランナー、エディタ)は、利便性向上のため通常のウィンドウとして組み込みました -->
<!-- ==================== 4. SCRIPT SECTION 1: STORAGE & INTEGRITY ==================== -->
<script>
/**
* SCRIPT 1: Storage Config, State Persistence & Virtual Disk Package Maker (8MiB)
* * このセクションは、仮想ファイルシステム(VFS)全体のステート管理と、
* ディスクのエクスポート、データの整合性、ユーザー設定などの維持を担当します。
* 2回目以降は、このファイルから生成された「仮想ディスク.json」を起動画面でマウントするだけで動作可能です。
*/
// 仮想アプリID
const appId = typeof __app_id !== 'undefined' ? __app_id : 'ubuntu-webfs-v1';
// 仮想ファイルシステムの基本構造
// 8MiBの仮想ディスク制限を満たすための設計、及び初期化メソッド
let VFS = {
user: {
username: "ubuntu",
password: "ubuntu" // 簡単な認証用
},
settings: {
themeColor: "#2c001e", // Ubuntu Plum
bgImage: "", // VFS内の画像パス。空ならthemeColorが優先
cursor: "default"
},
// 仮想階層構造
// 各キーは絶対パス。値は { type: 'file'|'dir', content: String, size: Number, mime: String }
files: {}
};
/**
* 8MiB相当のダミーアロケーションデータを含んだ初期構造ファイルを作成する
* ダウンロードさせることで、実質的な仮想ストレージのベースをローカルに確保させる
*/
function generateNewVfs(username, password) {
const vfs = {
user: { username, password },
settings: {
themeColor: "#2c001e",
bgImage: "",
cursor: "default"
},
files: {
"/home": { type: "dir", size: 0 },
[`/home/${username}`]: { type: "dir", size: 0 },
[`/home/${username}/Desktop`]: { type: "dir", size: 0 },
[`/home/${username}/Downloads`]: { type: "dir", size: 0 },
[`/home/${username}/Documents`]: { type: "dir", size: 0 },
[`/home/${username}/Desktop/README.txt`]: {
type: "file",
content: "Ubuntu Web VFS 仮想環境へようこそ!\n\n・デスクトップ上のアイコンをダブルクリックすると開くことができます。\n・端末(Terminal)から Linux 風の各種ファイル操作が可能です。\n・sudo shutdown コマンドを実行、または左ドック下部の電源ボタンからディスクを保存して終了できます。\n・デスクトップの壁紙は『設定』からカスタマイズ可能です。",
size: 280,
mime: "text/plain"
},
[`/home/${username}/Desktop/お絵かきサンプル.html`]: {
type: "file",
content: `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Canvas Paint Sample</title>
<style>
body { margin: 0; background: #fafafa; font-family: sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; overflow: hidden;}
canvas { border: 2px solid #333; background: #fff; cursor: crosshair; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
h3 { margin: 5px; color: #333; }
p { margin: 2px; font-size: 12px; color: #666; }
</style>
</head>
<body>
<h3>ブラウザ内仮想ペイント</h3>
<p>マウスをドラッグしてお絵かきができます</p>
<canvas id="paintCanvas" width="400" height="300"></canvas>
<button onclick="ctx.clearRect(0,0,400,300)" style="margin-top: 10px; padding: 6px 12px; background: #e95420; color: white; border: none; border-radius: 4px; cursor: pointer;">クリア</button>
<script>
const canvas = document.getElementById('paintCanvas');
const ctx = canvas.getContext('2d');
let painting = false;
ctx.strokeStyle = '#e95420';
ctx.lineWidth = 4;
ctx.lineCap = 'round';
canvas.addEventListener('mousedown', () => painting = true);
canvas.addEventListener('mouseup', () => { painting = false; ctx.beginPath(); });
canvas.addEventListener('mousemove', draw);
function draw(e) {
if(!painting) return;
const rect = canvas.getBoundingClientRect();
ctx.lineTo(e.clientX - rect.left, e.clientY - rect.top);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(e.clientX - rect.left, e.clientY - rect.top);
}
<\/script>
</body>
</html>`,
size: 1540,
mime: "text/html"
},
// 8MiB 相当のシステムダミーファイルを埋め込む (8MiB = 8,388,608 bytes)
// 仮想ディスクイメージの整合性と「ドライブをフォーマットして確保した」感覚を再現するため、
// 約8,000,000文字の空隙スペース(またはシステムゼロファイル)をアロケーション領域として格納します。
"/sys/allocation.dat": {
type: "file",
content: "0".repeat(8000000), // 8000000文字のダミーデータ (約8MB分)
size: 8000000,
mime: "application/octet-stream"
}
}
};
return vfs;
}
/**
* VFSを文字列シリアライズしてクライアントにファイルとしてダウンロードさせる (保存)
*/
function exportVfsToDiskFile() {
const serialized = JSON.stringify(VFS);
const blob = new Blob([serialized], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `ubuntu_virtual_disk_${VFS.user.username}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
/**
* 読み込まれたVFSファイルの構造チェックとユーザー認証
*/
function validateAndMountVfs(vfsObject, username, password) {
if (!vfsObject || !vfsObject.user || !vfsObject.files) {
throw new Error("無効なディスク構造です。");
}
if (vfsObject.user.username !== username || vfsObject.user.password !== password) {
throw new Error("ユーザー名、またはパスワードが一致しません。");
}
// VFSのマウント
VFS = vfsObject;
return true;
}
</script>
<!-- ==================== 5. SCRIPT SECTION 2: RUNTIME CORE ENGINE ==================== -->
<script>
/**
* SCRIPT 2: OS Core Runtime (Ubuntu UI Controller, Terminal commands, VFS Access, App Handlers)
* * システムが正常にブート(仮想ディスクが選択・マウント)された後に動作する
* 必須のOS挙動制御スクリプトです。
*/
let currentUser = "ubuntu";
let currentPath = `/home/ubuntu`; // ターミナルのカレントディレクトリ
let openWindows = {}; // 起動しているウィンドウの参照
let windowZIndexCounter = 30; // ウィンドウ重ね合わせ制御用
// UIパーツ切替制御用
function showCreateDisk() {
document.getElementById("boot-options").classList.add("hidden");
document.getElementById("create-disk-form").classList.remove("hidden");
}
function showLoadDisk() {
document.getElementById("boot-options").classList.add("hidden");
document.getElementById("load-disk-form").classList.remove("hidden");
}
function cancelBootStep() {
document.getElementById("create-disk-form").classList.add("hidden");
document.getElementById("load-disk-form").classList.add("hidden");
document.getElementById("boot-options").classList.remove("hidden");
document.getElementById("load-error-msg").classList.add("hidden");
}
// 新規仮想ディスクの生成ハンドラ
function handleCreateDisk() {
const user = document.getElementById("new-username").value.trim();
const pass = document.getElementById("new-password").value.trim();
if (!user || !pass) {
customAlert("ユーザー名とパスワードを入力してください。");
return;
}
// ローディング開始
document.getElementById("create-disk-form").classList.add("hidden");
document.getElementById("boot-loading").classList.remove("hidden");
setTimeout(() => {
// VFSの生成・アサイン
VFS = generateNewVfs(user, pass);
currentUser = user;
currentPath = `/home/${user}`;
// 生成した初期ディスクをダウンロード(8MiB分のデータを含む)
exportVfsToDiskFile();
document.getElementById("boot-status-text").innerText = "仮想OS起動完了...";
setTimeout(() => {
bootSystem();
}, 1000);
}, 1500);
}
// ドラッグアンドドロップによる仮想ディスクのロード
let loadedDiskContent = null;
const dropZone = document.getElementById("drop-zone");
// ドラッグ&ドロップイベントリスナー
dropZone.addEventListener("dragover", (e) => {
e.preventDefault();
dropZone.classList.add("border-[#e95420]", "bg-[#4a1e3f]");
});
dropZone.addEventListener("dragleave", (e) => {
e.preventDefault();
dropZone.classList.remove("border-[#e95420]", "bg-[#4a1e3f]");
});
dropZone.addEventListener("drop", (e) => {
e.preventDefault();
dropZone.classList.remove("border-[#e95420]", "bg-[#4a1e3f]");
if (e.dataTransfer.files.length > 0) {
processSelectedDiskFile(e.dataTransfer.files[0]);
}
});
function handleFileSelect(e) {
if (e.target.files.length > 0) {
processSelectedDiskFile(e.target.files[0]);
}
}
function processSelectedDiskFile(file) {
const reader = new FileReader();
reader.onload = function(evt) {
try {
loadedDiskContent = JSON.parse(evt.target.result);
document.getElementById("selected-file-name").innerText = `${file.name} (読み込み完了)`;
} catch(e) {
customAlert("ディスクファイルの解析に失敗しました。有効なJSON構造ではありません。");
loadedDiskContent = null;
}
};
reader.readAsText(file);
}
// 既存仮想ディスクのマウントと起動
function handleLoadDisk() {
const user = document.getElementById("load-username").value.trim();
const pass = document.getElementById("load-password").value.trim();
const errorDiv = document.getElementById("load-error-msg");
if (!loadedDiskContent) {
errorDiv.innerText = "仮想ディスクファイルを選択またはドロップしてください。";
errorDiv.classList.remove("hidden");
return;
}
if (!user || !pass) {
errorDiv.innerText = "認証用のユーザー名とパスワードを入力してください。";
errorDiv.classList.remove("hidden");
return;
}
try {
validateAndMountVfs(loadedDiskContent, user, pass);
currentUser = user;
currentPath = `/home/${user}`;
errorDiv.classList.add("hidden");
document.getElementById("load-disk-form").classList.add("hidden");
document.getElementById("boot-loading").classList.remove("hidden");
setTimeout(() => {
bootSystem();
}, 1500);
} catch(err) {
errorDiv.innerText = err.message;
errorDiv.classList.remove("hidden");
}
}
// システム全体のロード完了処理
function bootSystem() {
document.getElementById("boot-screen").classList.add("opacity-0", "pointer-events-none");
document.getElementById("desktop-env").classList.remove("hidden");
// カスタム設定の適用
applySystemSettings();
// UI表示アップデート
document.getElementById("top-user-indicator").innerText = currentUser;
// 時計の更新開始
startClock();
// デスクトップ上に存在するファイル群をレンダリング
renderDesktopIcons();
// 初回起動時、ターミナルとファイルマネージャーを立ち上げておく
openApp("terminal");
openApp("files");
}
// 時計処理
function startClock() {
const clockEl = document.getElementById("top-bar-clock");
function update() {
const now = new Date();
const m = now.getMonth() + 1;
const d = now.getDate();
const h = String(now.getHours()).padStart(2, '0');
const min = String(now.getMinutes()).padStart(2, '0');
clockEl.innerText = `${m}月 ${d}日 ${h}:${min}`;
}
setInterval(update, 1000);
update();
}
// システム設定の適用 (テーマ背景、カーソル等)
function applySystemSettings() {
const root = document.getElementById("desktop-root");
// 背景画像が指定されており、それが仮想ファイルシステム内にあるか
if (VFS.settings.bgImage && VFS.files[VFS.settings.bgImage] && VFS.files[VFS.settings.bgImage].type === 'file') {
// インラインデータスキームへの解決(簡易再現としてbase64想定。またはテキストデータそのものをインラインで入れる)
const fileObj = VFS.files[VFS.settings.bgImage];
if (fileObj.content.startsWith("data:image")) {
root.style.backgroundImage = `url('${fileObj.content}')`;
root.style.backgroundSize = "cover";
root.style.backgroundPosition = "center";
} else {
// テキスト色での塗りつぶし
root.style.background = VFS.settings.themeColor;
}
} else {
root.style.background = VFS.settings.themeColor;
root.style.backgroundImage = "none";
}
// カーソル設定
root.style.cursor = VFS.settings.cursor || "default";
}
/* ==================== 6. WINDOWS MANAGEMENT SYSTEM ==================== */
// アプリ定義
const appTemplates = {
terminal: {
title: "端末 (Terminal)",
icon: "lucide-terminal",
width: 600,
height: 400,
content: `
<div class="flex-grow flex flex-col bg-black/95 text-green-400 p-2 terminal-body font-mono text-sm overflow-y-auto leading-relaxed h-full" id="term-body-[id]" onclick="focusTerminal('[id]')">
<div id="term-output-[id]">
<div>Welcome to Ubuntu Web OS Virtual Terminal v1.0</div>
<div>Type <span class="text-white font-bold">help</span> to see available commands.</div>
<br>
</div>
<div class="flex items-center">
<span class="text-green-500 font-semibold shrink-0" id="term-prompt-[id]">ubuntu@webfs:~$</span>
<input type="text" id="term-input-[id]" class="bg-transparent text-green-300 border-none outline-none flex-grow ml-2 font-mono" onkeydown="handleTerminalCommand(event, '[id]')">
</div>
</div>
`
},
files: {
title: "ファイルマネージャ",
icon: "lucide-folder",
width: 700,
height: 450,
content: `
<div class="flex-grow flex flex-col bg-[#2a2a2a] text-white h-full overflow-hidden" id="files-body-[id]">
<!-- File Manager Top bar -->
<div class="bg-[#1e1e1e] p-2 flex items-center justify-between border-b border-neutral-700">
<div class="flex items-center space-x-2">
<button onclick="goUpDirectory('[id]')" class="p-1 hover:bg-neutral-700 rounded transition" title="親フォルダへ">
<i class="lucide-arrow-up w-4 h-4"></i>
</button>
<div class="text-xs text-neutral-400 bg-neutral-900 px-3 py-1.5 rounded flex items-center border border-neutral-800" style="min-width: 250px;">
<i class="lucide-hard-drive w-3.5 h-3.5 mr-1.5 text-amber-500"></i>
<span id="files-path-display-[id]">/home/ubuntu</span>
</div>
</div>
<!-- Action Controls -->
<div class="flex space-x-1">
<button onclick="showCreateNewDialog('[id]', 'file')" class="px-2 py-1 bg-[#e95420] text-xs font-semibold rounded hover:bg-[#cf4a1b]" title="新しいファイルを作成">
+ ファイル
</button>
<button onclick="showCreateNewDialog('[id]', 'dir')" class="px-2 py-1 bg-amber-600 text-xs font-semibold rounded hover:bg-amber-700" title="新しいディレクトリを作成">
+ フォルダ
</button>
</div>
</div>
<!-- Main Layout: Folder list -->
<div class="flex-1 flex overflow-hidden">
<!-- Left Sidebar Shortcuts -->
<div class="w-1/4 bg-[#1e1e1e] border-r border-neutral-800 p-2 text-xs space-y-1">
<div class="text-neutral-500 px-2 py-1 font-semibold">場所</div>
<button onclick="navigateToPath('[id]', '/home/' + currentUser)" class="w-full text-left px-2 py-1.5 hover:bg-[#4a1e3f] rounded flex items-center">
<i class="lucide-home w-4 h-4 mr-2 text-purple-400"></i> ホーム
</button>
<button onclick="navigateToPath('[id]', '/home/' + currentUser + '/Desktop')" class="w-full text-left px-2 py-1.5 hover:bg-[#4a1e3f] rounded flex items-center">
<i class="lucide-monitor w-4 h-4 mr-2 text-blue-400"></i> デスクトップ
</button>
<button onclick="navigateToPath('[id]', '/home/' + currentUser + '/Downloads')" class="w-full text-left px-2 py-1.5 hover:bg-[#4a1e3f] rounded flex items-center">
<i class="lucide-download w-4 h-4 mr-2 text-green-400"></i> ダウンロード
</button>
<button onclick="navigateToPath('[id]', '/home/' + currentUser + '/Documents')" class="w-full text-left px-2 py-1.5 hover:bg-[#4a1e3f] rounded flex items-center">
<i class="lucide-file-text w-4 h-4 mr-2 text-yellow-400"></i> ドキュメント
</button>
</div>
<!-- Right: Grid View of files -->
<div class="w-3/4 p-4 overflow-y-auto" id="files-grid-[id]" ondragover="event.preventDefault()" ondrop="handleFileManagerDrop(event, '[id]')">
<!-- Directory items will be injected here -->
</div>
</div>
</div>
`
},
uploader: {
title: "ファイルアップローダー",
icon: "lucide-upload",
width: 500,
height: 380,
content: `
<div class="flex-grow flex flex-col bg-[#2e2e2e] p-6 text-center select-none h-full justify-between">
<h3 class="text-lg font-bold text-white">実機から仮想OSへファイルのアップロード</h3>
<p class="text-xs text-gray-400">アップロードしたファイルは <strong>~/Downloads</strong> ディレクトリに即座に配置されます。</p>
<!-- Drop area -->
<div id="uploader-drop-[id]" class="border-2 border-dashed border-gray-500 hover:border-[#e95420] bg-[#1e1e1e] rounded-lg p-8 flex flex-col items-center justify-center cursor-pointer transition my-4"
onclick="document.getElementById('uploader-input-[id]').click()">
<i class="lucide-upload-cloud w-12 h-12 text-[#e95420] mb-2"></i>
<span class="text-sm text-gray-300">ファイルをドロップまたはクリック</span>
<span class="text-[10px] text-gray-500 mt-1">実機のファイルシステムから仮想環境に取り込みます</span>
<input type="file" id="uploader-input-[id]" class="hidden" multiple onchange="uploadRealFiles(event, '[id]')">
</div>
<!-- Upload list summary -->
<div class="text-left bg-neutral-900 p-2 rounded max-h-24 overflow-y-auto text-xs text-gray-400 font-mono" id="uploader-log-[id]">
ログ: 待機中...
</div>
</div>
`
},
settings: {
title: "システム設定",
icon: "lucide-settings",
width: 500,
height: 400,
content: `
<div class="flex-grow flex flex-col bg-[#2a2a2a] p-4 text-white space-y-4 overflow-y-auto h-full text-sm">
<h2 class="text-base font-bold border-b border-neutral-700 pb-2 text-[#e95420]">外観と壁紙のカスタマイズ</h2>
<!-- Quick Color -->
<div class="space-y-2">
<label class="block text-xs text-gray-400 font-semibold">デスクトップテーマ背景色</label>
<div class="flex space-x-2">
<button onclick="setThemeBgColor('#2c001e')" class="w-8 h-8 rounded-full border-2 border-white bg-[#2c001e]" title="Ubuntu Plum"></button>
<button onclick="setThemeBgColor('#002b36')" class="w-8 h-8 rounded-full border-2 border-neutral-600 bg-[#002b36]" title="Solarized Dark"></button>
<button onclick="setThemeBgColor('#111111')" class="w-8 h-8 rounded-full border-2 border-neutral-600 bg-neutral-900" title="Midnight Black"></button>
<button onclick="setThemeBgColor('#4a5568')" class="w-8 h-8 rounded-full border-2 border-neutral-600 bg-slate-600" title="Classic Slate"></button>
</div>
</div>
<!-- Custom BG Path -->
<div class="space-y-2">
<label class="block text-xs text-gray-400 font-semibold">仮想ディスク内の画像から壁紙設定</label>
<p class="text-[10px] text-gray-400 leading-relaxed">
※仮想OS内の画像パス (例: /home/ubuntu/Downloads/wallpaper.png など) を入力します。Base64や画像データを読み込んだテキストファイルを指定可能です。
</p>
<div class="flex space-x-2">
<input type="text" id="settings-bg-input" class="bg-neutral-900 border border-neutral-700 rounded p-1.5 text-xs flex-grow outline-none text-green-400" placeholder="/home/ubuntu/Downloads/bg.txt">
<button onclick="saveBgPath()" class="px-3 py-1 bg-[#e95420] text-xs font-semibold rounded hover:bg-[#cf4a1b]">適用</button>
</div>
</div>
<!-- Cursor Option -->
<div class="space-y-2">
<label class="block text-xs text-gray-400 font-semibold">カーソルの種類</label>
<select id="settings-cursor" onchange="setSystemCursor(this.value)" class="bg-neutral-900 border border-neutral-700 rounded p-1.5 text-xs w-full text-white outline-none">
<option value="default">デフォルト (標準)</option>
<option value="crosshair">十字架 (クロスヘア)</option>
<option value="text">テキスト入力</option>
<option value="pointer">ポインター (手形)</option>
</select>
</div>
<!-- Disk info info -->
<div class="bg-neutral-900/60 p-3 rounded text-xs space-y-1 text-gray-400 border border-neutral-800">
<div class="font-semibold text-white">仮想ディスク情報</div>
<div id="settings-disk-usage">使用済み容量: 計算中...</div>
<div>最大論理容量制限: 8MiB</div>
</div>
</div>
`
},
htmlRunner: {
title: "仮想HTMLランナー",
icon: "lucide-play-circle",
width: 800,
height: 550,
content: `
<div class="flex-grow flex flex-col h-full bg-white relative">
<div class="bg-[#252526] px-4 py-1.5 text-xs text-gray-400 flex items-center justify-between border-b border-neutral-700 select-none">
<span class="flex items-center">
<i class="lucide-globe w-3 h-3 mr-1"></i>
<span id="runner-virtual-path-[id]"></span>
</span>
<span class="text-yellow-500 font-semibold text-[10px] bg-yellow-950 px-2 py-0.5 rounded">隔離サンドボックス</span>
</div>
<iframe id="html-runner-iframe-[id]" class="flex-grow w-full h-full border-none pointer-events-auto bg-white text-black"></iframe>
</div>
`
},
textEditor: {
title: "テキストエディタ",
icon: "lucide-edit-3",
width: 650,
height: 480,
content: `
<div class="flex-grow flex flex-col h-full bg-[#1e1e1e]">
<div class="bg-[#2d2d2d] px-3 py-1.5 flex items-center justify-between text-xs border-b border-neutral-700 select-none">
<span class="text-gray-300 truncate" id="editor-filename-[id]"></span>
<button onclick="saveEditorContent('[id]')" class="px-3 py-1 bg-green-700 hover:bg-green-600 rounded text-white font-semibold flex items-center transition">
<i class="lucide-save w-3 h-3 mr-1"></i> 保存
</button>
</div>
<div class="flex-grow relative">
<textarea id="editor-textarea-[id]" class="absolute inset-0 w-full h-full bg-[#1e1e1e] text-green-300 font-mono p-4 outline-none resize-none text-sm leading-relaxed pointer-events-auto" spellcheck="false"></textarea>
</div>
</div>
`
}
};
/**
* 新しく仮想ウィンドウを開く
*/
function openApp(appKey, customTitle = null) {
const template = appTemplates[appKey];
if (!template) return null;
const id = `${appKey}_${Date.now()}`;
const displayTitle = customTitle ? `${template.title} - ${customTitle}` : template.title;
// ウィンドウ初期座標のばらつきを付与
const offsetCount = Object.keys(openWindows).length;
const leftX = 120 + (offsetCount * 25) % 300;
const topY = 60 + (offsetCount * 25) % 200;
const windowHtml = `
<div id="${id}" class="absolute bg-[#1e1e1e] text-white rounded-lg shadow-2xl border border-[#3c3c3c] flex flex-col pointer-events-auto select-none overflow-hidden window-active"
style="width: ${template.width}px; height: ${template.height}px; left: ${leftX}px; top: ${topY}px; z-index: ${windowZIndexCounter++}"
onclick="bringToFront('${id}')">
<!-- Window Header (Ubuntu Style title bar) -->
<div class="bg-[#2d2d2d] h-9 px-3 flex items-center justify-between cursor-move shrink-0 border-b border-neutral-800"
onmousedown="dragStart(event, '${id}')">
<!-- App Name & Icon -->
<div class="flex items-center space-x-2 truncate pr-2">
<span class="text-xs font-bold text-[#dfdbd2] flex items-center truncate">
<i class="${template.icon} w-3.5 h-3.5 mr-1 text-[#e95420] shrink-0"></i>
<span class="truncate" id="window-title-${id}">${displayTitle}</span>
</span>
</div>
<!-- Header Controls (Ubuntu alignment right) -->
<div class="flex items-center space-x-2 shrink-0 ml-2">
<button onclick="minimizeWindow('${id}')" class="w-4 h-4 rounded-full bg-neutral-600 hover:bg-neutral-500 flex items-center justify-center text-[10px] text-white">─</button>
<button onclick="toggleMaximizeWindow('${id}')" class="w-4 h-4 rounded-full bg-neutral-600 hover:bg-neutral-500 flex items-center justify-center text-[8px] text-white">⬜</button>
<button onclick="closeWindow('${id}')" class="w-4 h-4 rounded-full bg-red-600 hover:bg-red-500 flex items-center justify-center text-[9px] text-white">✕</button>
</div>
</div>
<!-- Window Inner Content -->
<div class="flex-grow overflow-hidden flex flex-col relative">
${template.content.replace(/\[id\]/g, id)}
</div>
</div>
`;
// コンテナに追加
const container = document.getElementById("windows-container");
container.insertAdjacentHTML("beforeend", windowHtml);
// ウィンドウ管理オブジェクトに記憶
openWindows[id] = {
id: id,
appKey: appKey,
title: displayTitle,
isMaximized: false,
prevLeft: `${leftX}px`,
prevTop: `${topY}px`,
prevWidth: `${template.width}px`,
prevHeight: `${template.height}px`
};
// 特異的なアプリ起動処理
if (appKey === 'terminal') {
initTerminal(id);
} else if (appKey === 'files') {
initFileManager(id);
} else if (appKey === 'settings') {
initSettingsPanel();
}
// フォーカス対象をヘッダーへ通知
document.getElementById("current-focused-app").innerText = displayTitle;
bringToFront(id);
return id;
}
// 重ね合わせの一番上にする
function bringToFront(id) {
const el = document.getElementById(id);
if (!el) return;
// 他のすべてをinactiveにする
Object.keys(openWindows).forEach(winId => {
const otherEl = document.getElementById(winId);
if (otherEl) {
otherEl.classList.remove("window-active");
otherEl.classList.add("window-inactive");
}
});
el.classList.add("window-active");
el.classList.remove("window-inactive");
el.style.zIndex = windowZIndexCounter++;
const wState = openWindows[id];
if (wState) {
document.getElementById("current-focused-app").innerText = wState.title;
}
if (wState && wState.appKey === 'terminal') {
const input = document.getElementById(`term-input-${id}`);
if (input) input.focus();
}
}
// ウィンドウ削除
function closeWindow(id) {
const el = document.getElementById(id);
if (el) el.remove();
delete openWindows[id];
document.getElementById("current-focused-app").innerText = "デスクトップ";
}
// 最小化(Ubuntu風の簡易挙動としてフェードアウトクローズとみなす)
function minimizeWindow(id) {
const el = document.getElementById(id);
if (el) {
el.style.transform = "scale(0.8)";
el.style.opacity = "0";
el.style.pointerEvents = "none";
setTimeout(() => {
el.style.transform = "none";
el.style.opacity = "1";
el.style.pointerEvents = "auto";
}, 3000); // 3秒後に戻るデモ挙動
}
}
// 最大化・トグル
function toggleMaximizeWindow(id) {
const el = document.getElementById(id);
const wState = openWindows[id];
if (!el || !wState) return;
if (!wState.isMaximized) {
// 現在の値を退避
wState.prevLeft = el.style.left;
wState.prevTop = el.style.top;
wState.prevWidth = el.style.width;
wState.prevHeight = el.style.height;
// 最大化スタイル
el.style.left = "0px";
el.style.top = "0px";
el.style.width = "100%";
el.style.height = "100%";
wState.isMaximized = true;
} else {
// 元に戻す
el.style.left = wState.prevLeft;
el.style.top = wState.prevTop;
el.style.width = wState.prevWidth;
el.style.height = wState.prevHeight;
wState.isMaximized = false;
}
}
// ドラッグ&ドロップ移動
let dragObj = null;
let dragStartX = 0, dragStartY = 0;
let dragStartLeft = 0, dragStartTop = 0;
function dragStart(e, id) {
dragObj = document.getElementById(id);
if (!dragObj) return;
bringToFront(id);
dragStartX = e.clientX;
dragStartY = e.clientY;
dragStartLeft = parseInt(dragObj.style.left) || 0;
dragStartTop = parseInt(dragObj.style.top) || 0;
document.body.classList.add('dragging-window');
document.addEventListener("mousemove", dragMove);
document.addEventListener("mouseup", dragEnd);
}
function dragMove(e) {
if (!dragObj) return;
const dx = e.clientX - dragStartX;
const dy = e.clientY - dragStartY;
// デスクトップの高さ・幅の中で自由に移動可能
dragObj.style.left = `${dragStartLeft + dx}px`;
dragObj.style.top = `${dragStartTop + dy}px`;
}
function dragEnd() {
dragObj = null;
document.body.classList.remove('dragging-window');
document.removeEventListener("mousemove", dragMove);
document.removeEventListener("mouseup", dragEnd);
}
/* ==================== 7. TERMINAL LOGIC ==================== */
// コマンド履歴保持用
let commandHistory = [];
let historyIndex = -1;
function initTerminal(id) {
const prompt = document.getElementById(`term-prompt-${id}`);
if (prompt) {
prompt.innerText = `${currentUser}@ubuntu:${getPrettyPath(currentPath)}$ `;
}
focusTerminal(id);
}
function focusTerminal(id) {
const input = document.getElementById(`term-input-${id}`);
if (input) input.focus();
}
function handleTerminalCommand(e, id) {
if (e.key === "Enter") {
const input = document.getElementById(`term-input-${id}`);
const commandLine = input.value.trim();
if (commandLine) {
executeCommand(commandLine, id);
commandHistory.push(commandLine);
historyIndex = commandHistory.length;
}
input.value = "";
} else if (e.key === "ArrowUp") {
// 履歴を遡る
if (historyIndex > 0) {
historyIndex--;
e.target.value = commandHistory[historyIndex];
}
} else if (e.key === "ArrowDown") {
if (historyIndex < commandHistory.length - 1) {
historyIndex++;
e.target.value = commandHistory[historyIndex];
} else {