index.html 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254
  1. <!DOCTYPE html>
  2. <html lang="zh-Hans-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>PageOS 用户桌面</title>
  7. <style>
  8. /* 全局 */
  9. * {
  10. color: var(--secondary-font-color);
  11. font-family: "Maple Mono CN", "Courier New", Courier, monospace;
  12. box-sizing: border-box;
  13. transition: all 0.2s ease;
  14. }
  15. ::selection {
  16. background: var(--accent-bg-color);
  17. color: var(--accent-font-color);
  18. }
  19. :root,
  20. body {
  21. height: 100%;
  22. margin: 0;
  23. overflow: hidden;
  24. --accent-color: #64ffda; /* 强调色:边框 */
  25. --secondary-color: #00695c; /* 次要色:未激活边框 */
  26. --danger-color: #ff6d00; /* 着重色:边框 */
  27. --accent-bg-color: #009688;
  28. --secondary-bg-color: #616161;
  29. --content-bg-color: #424242;
  30. --accent-font-color: #f5f5f5;
  31. --secondary-font-color: #eeeeee;
  32. --margin-padding: 0.5rem;
  33. --border-thickness: 0.2rem;
  34. --border-radius: 0.5rem;
  35. --title-bar-height: 2rem;
  36. --title-bar-justify-content: left;
  37. --task-bar-height: 3rem;
  38. --shadow: 0.6rem 0.6rem 0.1rem 0.1rem rgba(0, 0, 0, 0.2);
  39. --focused-bg-color: rgba(255, 255, 255, 0.1);
  40. --favicon: url("data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8IS0tIOWkluahhuefqeW9oiAtLT4KICA8cmVjdCB4PSIyIiB5PSIyIiB3aWR0aD0iMjgiIGhlaWdodD0iMjgiIHJ4PSIxMCIgcnk9IjEwIgogICAgZmlsbD0iIzQyNDI0MiIKICAgIHN0cm9rZT0iIzAwNjk1YyIKICAgIHN0cm9rZS13aWR0aD0iNCIvPgoKICA8IS0tIOW3puecvO+8muWwj+WchueCuSAtLT4KICA8Y2lyY2xlIGN4PSIxMiIgY3k9IjE0IiByPSIxLjUiIGZpbGw9IiNmNWY1ZjUiIC8+CgogIDwhLS0g5Y+z55y877ya5bCP5ZyG54K5IC0tPgogIDxjaXJjbGUgY3g9IjIwIiBjeT0iMTQiIHI9IjEuNSIgZmlsbD0iI2Y1ZjVmNSIgLz4KCiAgPCEtLSDpvLvlrZDvvJrnq5bnur8gLS0+CiAgPGxpbmUgeDE9IjE2IiB5MT0iMTYiIHgyPSIxNiIgeTI9IjE4IiBzdHJva2U9IiNmNWY1ZjUiIHN0cm9rZS13aWR0aD0iMS41IiAvPgoKICA8IS0tIOW+rueskeeahOWYtO+8muS4iuaJrOeahOW8p+e6vyAtLT4KICA8cGF0aCBkPSJNIDE0IDIwIFEgMTYgMjIgMTggMjAiIAogICAgICAgIGZpbGw9Im5vbmUiIAogICAgICAgIHN0cm9rZT0iI2Y1ZjVmNSIgCiAgICAgICAgc3Ryb2tlLXdpZHRoPSIxLjUiIAogICAgICAgIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgLz4KPC9zdmc+");
  41. }
  42. button {
  43. background-color: var(--secondary-bg-color);
  44. background-position: center;
  45. background-repeat: no-repeat;
  46. border: none;
  47. display: flex;
  48. align-self: center;
  49. justify-content: center;
  50. &:hover,
  51. &:focus {
  52. background-color: var(--focused-bg-color);
  53. }
  54. }
  55. .warning,
  56. .error {
  57. color: var(--danger-color);
  58. }
  59. </style>
  60. <style>
  61. /* 窗口样式 */
  62. #windows-container {
  63. position: fixed;
  64. top: 0;
  65. left: 0;
  66. right: 0;
  67. bottom: 0;
  68. pointer-events: none;
  69. z-index: 1000;
  70. }
  71. .window {
  72. color: var(--secondary-font-color);
  73. position: absolute;
  74. display: flex;
  75. flex-direction: column;
  76. background: var(--content-bg-color);
  77. box-sizing: border-box;
  78. border: var(--border-thickness) solid var(--secondary-color);
  79. border-radius: var(--border-radius);
  80. overflow: hidden;
  81. pointer-events: auto;
  82. &.dragging {
  83. transition: left 0s, right 0s;
  84. }
  85. &.resizing {
  86. transition: width 0s, height 0s;
  87. }
  88. &.focused {
  89. --secondary-font-color: var(--accent-font-color);
  90. --secondary-color: var(--accent-color);
  91. box-shadow: var(--shadow);
  92. }
  93. &.dragging,
  94. &.resizing {
  95. --secondary-color: var(--danger-color);
  96. iframe {
  97. display: none;
  98. }
  99. }
  100. &.borderless {
  101. border: none;
  102. .window-title-bar {
  103. height: 0;
  104. display: none;
  105. }
  106. }
  107. &.minimized {
  108. /* max-height: var(--title-bar-height); */
  109. opacity: 0;
  110. transform: scale(0.8);
  111. pointer-events: none;
  112. }
  113. &.fullscreen {
  114. top: 0 !important;
  115. left: 0 !important;
  116. width: 100% !important;
  117. height: 100% !important;
  118. border: none !important;
  119. border-radius: 0;
  120. box-shadow: none !important;
  121. }
  122. &.borderless,
  123. &.fullscreen {
  124. .resize-handle {
  125. display: none;
  126. }
  127. }
  128. .resize-handle {
  129. border-radius: calc(0.5 * var(--border-radius)) 0 0 0;
  130. position: absolute;
  131. bottom: 0;
  132. right: 0;
  133. width: calc(2 * var(--border-thickness));
  134. height: calc(2 * var(--border-thickness));
  135. background: var(--secondary-color);
  136. cursor: nwse-resize;
  137. }
  138. }
  139. .window-title-bar {
  140. height: var(--title-bar-height);
  141. background: var(--accent-bg-color);
  142. display: flex;
  143. align-items: center;
  144. justify-content: flex-start;
  145. cursor: move;
  146. user-select: none;
  147. white-space: nowrap;
  148. & > *:first-child {
  149. margin: 0 var(--margin-padding);
  150. min-width: calc(var(--title-bar-height) - var(--margin-padding));
  151. }
  152. }
  153. .window-title {
  154. flex: 1;
  155. justify-content: var(--title-bar-justify-content);
  156. font-weight: bold;
  157. overflow: hidden;
  158. text-overflow: ellipsis;
  159. }
  160. .window-icon {
  161. display: flex;
  162. align-items: center;
  163. justify-content: center;
  164. & > * {
  165. pointer-events: none;
  166. }
  167. }
  168. .window-controls {
  169. display: flex;
  170. flex-shrink: 0;
  171. }
  172. .window-controls button {
  173. color: var(--secondary-font-color);
  174. background: none;
  175. border: none;
  176. width: var(--title-bar-height);
  177. height: var(--title-bar-height);
  178. cursor: pointer;
  179. font-size: 16px;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. & > * {
  184. pointer-events: none;
  185. }
  186. &:hover,
  187. &:focus {
  188. background: var(--focused-bg-color);
  189. }
  190. &.close:hover,
  191. &.close:focus {
  192. background-color: var(--danger-color);
  193. }
  194. }
  195. .window-tab-bar {
  196. display: flex;
  197. background: var(--content-bg-color);
  198. }
  199. .tab {
  200. font-size: small;
  201. padding: var(--margin-padding);
  202. cursor: pointer;
  203. border-bottom: var(--border-thickness) solid transparent;
  204. user-select: none;
  205. &:hover {
  206. background: var(--focused-bg-color);
  207. }
  208. &.active {
  209. background: var(--secondary-bg-color);
  210. border-bottom: var(--border-thickness) solid var(--secondary-color);
  211. }
  212. }
  213. .window-content {
  214. flex: 1;
  215. overflow: auto;
  216. display: flex;
  217. .tab-content {
  218. flex: 1;
  219. display: none;
  220. padding: var(--margin-padding);
  221. &.active {
  222. display: flex;
  223. flex-direction: column;
  224. gap: var(--margin-padding);
  225. }
  226. }
  227. }
  228. </style>
  229. <style>
  230. /* 背景 */
  231. bg {
  232. position: fixed;
  233. top: 0;
  234. left: 0;
  235. right: 0;
  236. bottom: 0;
  237. pointer-events: none;
  238. overflow: hidden;
  239. z-index: -1;
  240. background: url("assets/pageos_文字壁纸.svg");
  241. background-size: cover;
  242. background-position: center;
  243. background-attachment: fixed;
  244. }
  245. </style>
  246. <style>
  247. /* 任务栏 */
  248. taskbar-container {
  249. position: fixed;
  250. bottom: 0;
  251. left: 0;
  252. right: 0;
  253. height: var(--margin-padding); /* 底部触发区域高度 */
  254. z-index: 3100; /* 确保任务栏始终在最顶层 */
  255. pointer-events: auto;
  256. &:hover {
  257. height: var(--task-bar-height);
  258. }
  259. &:hover task-bar {
  260. bottom: var(--margin-padding);
  261. opacity: 1;
  262. pointer-events: auto;
  263. }
  264. }
  265. task-bar {
  266. position: absolute;
  267. background-color: var(--content-bg-color);
  268. border-radius: var(--border-radius);
  269. border: var(--border-thickness) solid var(--secondary-color);
  270. bottom: var(--margin-padding);
  271. height: var(--task-bar-height);
  272. left: 50%;
  273. transform: translateX(-50%);
  274. display: flex;
  275. justify-content: space-between;
  276. align-items: center;
  277. width: 90%;
  278. max-width: 1024px;
  279. overflow: hidden;
  280. &.hide {
  281. bottom: calc(var(--task-bar-height) * -1);
  282. opacity: 0;
  283. pointer-events: none;
  284. }
  285. &:hover {
  286. box-shadow: var(--shadow);
  287. --secondary-color: var(--accent-color);
  288. --secondary-font-color: var(--accent-font-color);
  289. }
  290. & > *:first-child {
  291. border-left: none;
  292. }
  293. & > * {
  294. height: 100%;
  295. border-left: var(--border-thickness) solid var(--secondary-color);
  296. min-width: var(--task-bar-height);
  297. display: flex;
  298. overflow: hidden;
  299. overflow-x: scroll;
  300. & > * {
  301. cursor: pointer;
  302. padding: var(--margin-padding);
  303. height: 100%;
  304. min-width: var(--task-bar-height);
  305. display: flex;
  306. align-items: center;
  307. justify-content: center;
  308. border-radius: calc(var(--border-radius) - var(--margin-padding));
  309. background-color: var(--content-bg-color);
  310. }
  311. }
  312. }
  313. window-buttons {
  314. flex: 1;
  315. & > * {
  316. border-top: var(--border-thickness) solid transparent;
  317. border-bottom: var(--border-thickness) solid transparent;
  318. font-size: large;
  319. & > * {
  320. pointer-events: none;
  321. }
  322. }
  323. & > *.focused {
  324. border-bottom: var(--border-thickness) solid var(--accent-color);
  325. }
  326. }
  327. bar-space > * {
  328. font-size: larger;
  329. }
  330. .app-launcher {
  331. background-image: var(--favicon);
  332. }
  333. .power {
  334. display: none;
  335. }
  336. #translate {
  337. position: relative;
  338. .translateSelectLanguage {
  339. background-color: var(--content-bg-color);
  340. color: inherit;
  341. opacity: 0;
  342. cursor: pointer;
  343. position: absolute;
  344. top: 0;
  345. right: 0;
  346. bottom: 0;
  347. left: 0;
  348. & > * {
  349. border: var(--border-thickness) solid var(--secondary-color);
  350. border-radius: var(--border-radius);
  351. background-color: var(--content-bg-color);
  352. color: inherit;
  353. }
  354. }
  355. }
  356. </style>
  357. <link
  358. rel="icon"
  359. type="image/svg+xml"
  360. href="data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8IS0tIOWkluahhuefqeW9oiAtLT4KICA8cmVjdCB4PSIyIiB5PSIyIiB3aWR0aD0iMjgiIGhlaWdodD0iMjgiIHJ4PSIxMCIgcnk9IjEwIgogICAgZmlsbD0iIzQyNDI0MiIKICAgIHN0cm9rZT0iIzAwNjk1YyIKICAgIHN0cm9rZS13aWR0aD0iNCIvPgoKICA8IS0tIOW3puecvO+8muWwj+WchueCuSAtLT4KICA8Y2lyY2xlIGN4PSIxMiIgY3k9IjE0IiByPSIxLjUiIGZpbGw9IiNmNWY1ZjUiIC8+CgogIDwhLS0g5Y+z55y877ya5bCP5ZyG54K5IC0tPgogIDxjaXJjbGUgY3g9IjIwIiBjeT0iMTQiIHI9IjEuNSIgZmlsbD0iI2Y1ZjVmNSIgLz4KCiAgPCEtLSDpvLvlrZDvvJrnq5bnur8gLS0+CiAgPGxpbmUgeDE9IjE2IiB5MT0iMTYiIHgyPSIxNiIgeTI9IjE4IiBzdHJva2U9IiNmNWY1ZjUiIHN0cm9rZS13aWR0aD0iMS41IiAvPgoKICA8IS0tIOW+rueskeeahOWYtO+8muS4iuaJrOeahOW8p+e6vyAtLT4KICA8cGF0aCBkPSJNIDE0IDIwIFEgMTYgMjIgMTggMjAiIAogICAgICAgIGZpbGw9Im5vbmUiIAogICAgICAgIHN0cm9rZT0iI2Y1ZjVmNSIgCiAgICAgICAgc3Ryb2tlLXdpZHRoPSIxLjUiIAogICAgICAgIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgLz4KPC9zdmc+"
  361. />
  362. <script
  363. src="https://lib.baomitu.com/translate.js/3.17.0/translate.js"
  364. type="text/javascript"
  365. ></script>
  366. </head>
  367. <body>
  368. <bg></bg>
  369. <div id="windows-container"></div>
  370. <taskbar-container>
  371. <task-bar>
  372. <bar-space>
  373. <button class="app-launcher" title="应用程序启动器"></button>
  374. <button class="search" title="全局搜索">
  375. <!-- Copyright (c) 2018-2025 Tabler -->
  376. <svg
  377. xmlns="http://www.w3.org/2000/svg"
  378. width="24"
  379. height="24"
  380. viewBox="0 0 24 24"
  381. fill="none"
  382. stroke="currentColor"
  383. stroke-width="2"
  384. stroke-linecap="round"
  385. stroke-linejoin="round"
  386. class="icon icon-tabler icons-tabler-outline icon-tabler-search"
  387. >
  388. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  389. <path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" />
  390. <path d="M21 21l-6 -6" /></svg
  391. ></button>
  392. </bar-space>
  393. <window-buttons></window-buttons>
  394. <status-space>
  395. <button id="translate" class="language-tools" title="语言工具">
  396. <!-- Copyright (c) 2018-2025 Tabler -->
  397. <svg
  398. xmlns="http://www.w3.org/2000/svg"
  399. width="24"
  400. height="24"
  401. viewBox="0 0 24 24"
  402. fill="none"
  403. stroke="currentColor"
  404. stroke-width="2"
  405. stroke-linecap="round"
  406. stroke-linejoin="round"
  407. class="icon icon-tabler icons-tabler-outline icon-tabler-world"
  408. >
  409. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  410. <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
  411. <path d="M3.6 9h16.8" />
  412. <path d="M3.6 15h16.8" />
  413. <path d="M11.5 3a17 17 0 0 0 0 18" />
  414. <path d="M12.5 3a17 17 0 0 1 0 18" />
  415. </svg>
  416. </button>
  417. <button class="power" title="电源状态">
  418. <!-- Copyright (c) 2018-2025 Tabler -->
  419. <svg
  420. xmlns="http://www.w3.org/2000/svg"
  421. width="24"
  422. height="24"
  423. viewBox="0 0 24 24"
  424. fill="none"
  425. stroke="currentColor"
  426. stroke-width="2"
  427. stroke-linecap="round"
  428. stroke-linejoin="round"
  429. class="icon icon-tabler icons-tabler-outline icon-tabler-battery-vertical-eco"
  430. >
  431. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  432. <path
  433. d="M7 18v-11c0 -1.105 .895 -2 2 -2h.5c.276 0 .5 -.224 .5 -.5s.224 -.5 .5 -.5h3c.276 0 .5 .224 .5 .5s.224 .5 .5 .5h.5c1.105 0 2 .895 2 2v1m-8 12c-1.105 0 -2 -.895 -2 -2"
  434. />
  435. <path
  436. d="M13 17.143c0 -2.84 2.09 -5.143 4.667 -5.143h2.333v.857c0 2.84 -2.09 5.143 -4.667 5.143h-2.333z"
  437. />
  438. <path d="M13 21v-3" />
  439. </svg>
  440. </button>
  441. <button class="date-time" title="日期时间">0/0/0 0:0</button>
  442. </status-space>
  443. <bar-space>
  444. <button class="exit" title="退出">
  445. <!-- Copyright (c) 2018-2025 Tabler -->
  446. <svg
  447. xmlns="http://www.w3.org/2000/svg"
  448. width="24"
  449. height="24"
  450. viewBox="0 0 24 24"
  451. fill="none"
  452. stroke="currentColor"
  453. stroke-width="2"
  454. stroke-linecap="round"
  455. stroke-linejoin="round"
  456. class="icon icon-tabler icons-tabler-outline icon-tabler-logout"
  457. >
  458. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  459. <path
  460. d="M14 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2"
  461. />
  462. <path d="M9 12h12l-3 -3" />
  463. <path d="M18 15l3 -3" />
  464. </svg>
  465. </button>
  466. </bar-space>
  467. </task-bar>
  468. </taskbar-container>
  469. <script type="text/js-worker" id="processWorker">
  470. // 进程 Worker 脚本
  471. class WorkerProcess {
  472. constructor(id, parentId) {
  473. this.id = id;
  474. this.parentId = parentId;
  475. this.command = "";
  476. this.settings = {};
  477. this.active = false;
  478. }
  479. // 添加设置项
  480. addSetting(key, defaultValue) {
  481. this.settings[key] = defaultValue;
  482. }
  483. // 更新设置项
  484. updateSetting(key, value) {
  485. if (this.settings.hasOwnProperty(key)) {
  486. this.settings[key] = value;
  487. }
  488. }
  489. // 安全命令执行(白名单机制)
  490. safeExecute(commandName) {
  491. const commandMap = {
  492. log: (msg) => console.log(msg),
  493. calculate: (expr) => eval(expr), // 仅允许计算表达式
  494. };
  495. if (commandMap[commandName]) {
  496. return commandMap[commandName](...arguments);
  497. } else {
  498. console.error(`未知命令: ${commandName}`);
  499. }
  500. }
  501. // 发送消息到主线程
  502. sendMessage(targetId, messageType, data) {
  503. self.postMessage({
  504. type: "process-message",
  505. from: this.id,
  506. targetId,
  507. messageType,
  508. data,
  509. });
  510. }
  511. // 处理主线程消息
  512. handleMessage(event) {
  513. const { type, data } = event.data;
  514. if (type === "execute") {
  515. const [cmd, ...args] = data.command.split(" ");
  516. return this.safeExecute(cmd, ...args);
  517. } else if (type === "update-setting") {
  518. this.updateSetting(data.key, data.value);
  519. } else if (type === "message") {
  520. // 处理其他进程消息
  521. console.log(`进程 ${this.id} 收到消息:`, data);
  522. }
  523. }
  524. }
  525. // Worker 入口
  526. self.addEventListener("message", (event) => {
  527. if (event.data.type === "init") {
  528. const { id, parentId } = event.data;
  529. const process = new WorkerProcess(id, parentId);
  530. // 处理后续消息
  531. self.addEventListener("message", (e) => {
  532. process.handleMessage(e);
  533. });
  534. self.postMessage({ type: "ready", id });
  535. }
  536. });
  537. </script>
  538. <script>
  539. (function () {
  540. // 加载 CSS
  541. function loadCSS(url) {
  542. return new Promise((resolve, reject) => {
  543. //// 检查是否已加载
  544. const existingLinks = document.querySelectorAll(
  545. `link[href="${url}"]`
  546. );
  547. if (existingLinks.length > 0) {
  548. return resolve(url);
  549. }
  550. //// 创建新的 link 元素
  551. const link = document.createElement("link");
  552. link.rel = "stylesheet";
  553. link.type = "text/css";
  554. link.href = url;
  555. //// 成功加载处理
  556. link.onload = () => {
  557. link.onload = null;
  558. link.onerror = null;
  559. resolve(url);
  560. };
  561. //// 加载失败处理
  562. link.onerror = () => {
  563. link.onerror = null;
  564. link.onload = null;
  565. document.head.removeChild(link);
  566. reject(new Error(`无法加载 CSS 文件: ${url}`));
  567. };
  568. //// 添加到文档头部
  569. document.head.appendChild(link);
  570. });
  571. }
  572. // translate-js 翻译系统
  573. //// 初始化翻译系统
  574. function initTranslate() {
  575. try {
  576. translate.service.use("client.edge");
  577. translate.request.listener.start();
  578. translate.setAutoDiscriminateLocalLanguage();
  579. translate.language.setUrlParamControl();
  580. translate.ignore.class.push("notTranslate");
  581. translate.execute();
  582. } catch (e) {
  583. console.error("翻译系统出错:" + e);
  584. }
  585. }
  586. //// 刷新翻译
  587. function refreshTranslate() {
  588. try {
  589. translate.selectLanguageTag.refreshRender();
  590. } catch (e) {
  591. console.error("刷新翻译出错:" + e);
  592. }
  593. }
  594. // 初始化
  595. function initialize() {
  596. initTranslate(); //// 翻译系统
  597. loadCSS(
  598. "https://chinese-fonts-cdn.deno.dev/packages/maple-mono-cn/dist/MapleMono-CN-Regular/result.css"
  599. ); //// 加载字体 CSS
  600. }
  601. // 触发器
  602. //// 网页加载完毕后触发初始化
  603. window.addEventListener("DOMContentLoaded", () => initialize());
  604. // 统一焦点管理器(合并输入管理和焦点管理)
  605. class FocusManager {
  606. constructor() {
  607. // 原FocusManager属性
  608. this.focusedWindowId = null;
  609. this.focusedElement = null;
  610. // 原InputManager属性
  611. this.windowStack = []; // 窗口堆叠顺序(最近使用在前)
  612. this.captureInputProcess = null; // 捕获输入的进程ID
  613. }
  614. // 任务栏窗口按钮样式更新
  615. updateWindowButtons(windowId) {
  616. const winBtns = document.querySelectorAll(
  617. "task-bar window-buttons button"
  618. );
  619. winBtns.forEach((winBtn) => {
  620. winBtn.classList.toggle(
  621. "focused",
  622. winBtn.dataset.windowId === windowId
  623. );
  624. });
  625. }
  626. // 设置焦点窗口
  627. focusWindow(windowId) {
  628. if (this.focusedWindowId === windowId) return;
  629. // 移除旧窗口的焦点
  630. if (this.focusedWindowId) {
  631. const prevWindow = wManager.windows.get(this.focusedWindowId);
  632. if (prevWindow) prevWindow.blur();
  633. }
  634. // 更新窗口堆叠顺序(原 InputManager 逻辑)
  635. this.windowStack = this.windowStack.filter((id) => id !== windowId);
  636. this.windowStack.unshift(windowId);
  637. // 设置新焦点窗口
  638. this.focusedWindowId = windowId;
  639. this.releaseInput(); // 窗口聚焦时释放输入捕获
  640. const window = wManager.windows.get(windowId);
  641. if (window) {
  642. window.focus();
  643. this.updateWindowButtons(windowId);
  644. }
  645. }
  646. // 设置捕获输入的进程(原 InputManager 方法)
  647. captureInput(processId) {
  648. this.captureInputProcess = processId;
  649. }
  650. // 释放输入捕获(原 InputManager 方法)
  651. releaseInput() {
  652. this.captureInputProcess = null;
  653. }
  654. // 移除已关闭窗口的状态(合并原 InputManager 和 FocusManager 逻辑)
  655. removeWindow(windowId) {
  656. // 原 InputManager 窗口移除逻辑
  657. this.windowStack = this.windowStack.filter((id) => id !== windowId);
  658. if (this.focusedWindowId === windowId) {
  659. this.focusedWindowId = null;
  660. if (this.windowStack.length > 0) {
  661. this.focusWindow(this.windowStack[0]);
  662. }
  663. }
  664. // 原 FocusManager 窗口移除逻辑
  665. if (this.focusedWindowId === windowId) {
  666. this.focusedWindowId = null;
  667. }
  668. if (
  669. this.focusedElement &&
  670. this.focusedElement.closest(`[data-window-id="${windowId}"]`)
  671. ) {
  672. this.focusedElement = null;
  673. }
  674. }
  675. // 切换到下一个窗口 (Alt+Tab)(原 InputManager 方法)
  676. nextWindow() {
  677. if (this.windowStack.length < 2) return;
  678. // 将当前窗口移到末尾
  679. const current = this.windowStack.shift();
  680. this.windowStack.push(current);
  681. // 聚焦新窗口
  682. this.focusedWindowId = this.windowStack[0];
  683. return this.focusedWindowId;
  684. }
  685. // 设置焦点元素(原 FocusManager 方法)
  686. focusElement(element, windowId) {
  687. if (this.focusedElement) {
  688. this.focusedElement.blur();
  689. }
  690. this.focusedElement = element;
  691. this.focusWindow(windowId);
  692. element.focus();
  693. }
  694. // 清除焦点(原 FocusManager 方法)
  695. clearFocus() {
  696. // 清除当前焦点元素
  697. if (this.focusedElement) {
  698. this.focusedElement.blur();
  699. this.focusedElement = null;
  700. }
  701. // 清除当前焦点窗口的样式
  702. if (this.focusedWindowId) {
  703. const prevWindow = wManager.windows.get(this.focusedWindowId);
  704. if (prevWindow) prevWindow.blur();
  705. this.focusedWindowId = null;
  706. }
  707. this.updateWindowButtons(this.focusedWindowId);
  708. }
  709. }
  710. // 层级管理器
  711. class LayerManager {
  712. static LAYERS = {
  713. BACKGROUND: { zIndex: 100, maxWindows: 10 }, // 背景层
  714. WINDOW: { zIndex: 1000, maxWindows: 100 }, // 窗口层
  715. TOP: { zIndex: 3000, maxWindows: 10 }, // 顶层(弹窗、菜单等)
  716. };
  717. constructor() {
  718. this.windowLayers = new Map(); // windowId -> layerType
  719. this.layerStacks = {
  720. BACKGROUND: [],
  721. WINDOW: [],
  722. TOP: [],
  723. };
  724. }
  725. // 添加窗口到指定层
  726. addToLayer(windowId, layerType = "WINDOW") {
  727. if (!LayerManager.LAYERS[layerType]) {
  728. console.error(`无效的层级类型: ${layerType}`);
  729. return;
  730. }
  731. // 从原有层移除
  732. this.removeWindow(windowId);
  733. // 添加到新层
  734. this.windowLayers.set(windowId, layerType);
  735. this.layerStacks[layerType].push(windowId);
  736. // 确保不超过最大窗口数
  737. const maxWindows = LayerManager.LAYERS[layerType].maxWindows;
  738. if (this.layerStacks[layerType].length > maxWindows) {
  739. const removedId = this.layerStacks[layerType].shift();
  740. this.windowLayers.delete(removedId);
  741. }
  742. // 层级变更时更新所有窗口
  743. this.updateAllWindows();
  744. }
  745. // 获取窗口所在层
  746. getWindowLayer(windowId) {
  747. return this.windowLayers.get(windowId) || "WINDOW";
  748. }
  749. // 提升窗口到层内最前
  750. bringToFront(windowId) {
  751. const layerType = this.getWindowLayer(windowId);
  752. const stack = this.layerStacks[layerType];
  753. // 从原位置移除
  754. const index = stack.indexOf(windowId);
  755. if (index > -1) {
  756. stack.splice(index, 1);
  757. }
  758. // 添加到栈顶
  759. stack.push(windowId);
  760. // 层级变更时更新所有窗口
  761. this.updateAllWindows();
  762. }
  763. // 移除窗口
  764. removeWindow(windowId) {
  765. const layerType = this.getWindowLayer(windowId);
  766. if (layerType) {
  767. const stack = this.layerStacks[layerType];
  768. const index = stack.indexOf(windowId);
  769. if (index > -1) {
  770. stack.splice(index, 1);
  771. }
  772. }
  773. this.windowLayers.delete(windowId);
  774. // 层级变更时更新所有窗口
  775. this.updateAllWindows();
  776. }
  777. // 遍历更新所有窗口层级(新增方法)
  778. updateAllWindows() {
  779. // 遍历所有层
  780. for (const [layerType, stack] of Object.entries(this.layerStacks)) {
  781. const baseZIndex = LayerManager.LAYERS[layerType].zIndex;
  782. // 遍历层内所有窗口
  783. stack.forEach((windowId, index) => {
  784. const window = wManager.windows.get(windowId);
  785. if (window) {
  786. // 计算z-index: 基础值 + 在层内的位置
  787. window.element.style.zIndex = baseZIndex + index;
  788. }
  789. });
  790. }
  791. }
  792. }
  793. // 全局焦点管理器实例
  794. const fManager = new FocusManager();
  795. // 窗口管理类
  796. class WindowManager {
  797. constructor() {
  798. this.windows = new Map();
  799. this.layerManager = new LayerManager();
  800. this.windowIdCounter = 0;
  801. this.windowsContainer =
  802. document.getElementById("windows-container");
  803. // 全屏窗口计数
  804. this.fullscreenCount = 0;
  805. this.taskBar = document.querySelector("task-bar");
  806. }
  807. // 创建新窗口
  808. createWindow(processId, config = {}) {
  809. const windowId = `window-${this.windowIdCounter++}`; // 使用递增ID
  810. const win = new PageWin(windowId, processId, config);
  811. translate.execute([win.element]);
  812. this.windows.set(windowId, win);
  813. this.windowsContainer.appendChild(win.element);
  814. // 如果窗口初始为全屏,则增加计数
  815. if (config.fullscreen) {
  816. this.updateFullscreenCount(1);
  817. }
  818. // 任务栏窗口按钮
  819. const taskbar = document.querySelector("task-bar window-buttons");
  820. const windowBtn = document.createElement("button");
  821. windowBtn.innerHTML = win.config.icon
  822. ? win.config.icon
  823. : win.config.title.charAt(0).toUpperCase();
  824. windowBtn.title = win.config.title;
  825. windowBtn.dataset.windowId = windowId;
  826. windowBtn.addEventListener("click", () => {
  827. fManager.focusWindow(windowId);
  828. this.focusWindow(windowId);
  829. });
  830. // 设置右键菜单选项
  831. const menuOptions = [
  832. { label: "移动窗口", action: "move" },
  833. { label: "最小化", action: "minimize" },
  834. { label: "最大化", action: "maximize" },
  835. { label: "关闭", action: "close" },
  836. ];
  837. windowBtn.dataset.menuOptions = JSON.stringify(menuOptions);
  838. translate.execute([windowBtn]);
  839. taskbar.appendChild(windowBtn);
  840. return windowId;
  841. }
  842. // TODO: 是否删除:聚焦窗口
  843. focusWindow(windowId) {
  844. const win = this.windows.get(windowId);
  845. if (win) {
  846. // 使用层级管理器设置z-index
  847. const zIndex = this.layerManager.bringToFront(windowId);
  848. win.element.style.zIndex = zIndex;
  849. win.focus(); // 通知窗口获得焦点
  850. }
  851. }
  852. // 关闭窗口的统一入口
  853. closeWindow(windowId) {
  854. const win = this.windows.get(windowId);
  855. if (win) {
  856. // 如果窗口是全屏状态,则减少计数
  857. if (win.config.fullscreen) {
  858. this.updateFullscreenCount(-1);
  859. }
  860. win.cleanup();
  861. this.windows.delete(windowId);
  862. win.element.remove();
  863. // 删除任务栏窗口按钮
  864. const taskbar = document.querySelector("task-bar window-buttons");
  865. taskbar.querySelector(`[data-window-id="${windowId}"]`).remove();
  866. // 更新焦点管理器和层级管理器
  867. fManager.removeWindow(windowId);
  868. this.layerManager.removeWindow(windowId);
  869. }
  870. }
  871. moveWindow(windowId) {
  872. const win = this.windows.get(windowId);
  873. if (win) {
  874. // 激活窗口
  875. this.focusWindow(windowId);
  876. fManager.focusWindow(windowId);
  877. win.element.classList.add("dragging");
  878. win.isDragging = true;
  879. }
  880. }
  881. minimizeWindow(windowId) {
  882. const win = this.windows.get(windowId);
  883. if (win) {
  884. win.toggleMinimize();
  885. }
  886. }
  887. maximizeWindow(windowId) {
  888. const win = this.windows.get(windowId);
  889. if (win) {
  890. win.toggleMaximize();
  891. }
  892. }
  893. // 通过进程 ID 获取窗口
  894. getWindowsByProcess(processId) {
  895. return Array.from(this.windows.values()).filter(
  896. (w) => w.processId === processId
  897. );
  898. }
  899. // 更新全屏窗口计数
  900. updateFullscreenCount(change) {
  901. this.fullscreenCount += change;
  902. if (this.fullscreenCount < 0) {
  903. this.fullscreenCount = 0;
  904. }
  905. if (this.fullscreenCount > 0) {
  906. this.taskBar.classList.add("hide");
  907. } else {
  908. this.taskBar.classList.remove("hide");
  909. }
  910. }
  911. }
  912. // 窗口类
  913. class PageWin {
  914. constructor(id, processId, config) {
  915. var i = document.createElement("i");
  916. i.textContent = "空内容";
  917. this.id = id;
  918. this.processId = processId;
  919. this.config = {
  920. css: {},
  921. borderless: false,
  922. fullscreen: false,
  923. minimized: false,
  924. icon: '<!-- Copyright (c) 2018-2025 Tabler --><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-app-window"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 5m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z" /><path d="M6 8h.01" /><path d="M9 8h.01" /></svg>',
  925. title: "窗口",
  926. width: window.innerWidth * 0.5,
  927. height: window.innerHeight * 0.5,
  928. x: window.innerWidth * 0.25,
  929. y: window.innerHeight * 0.25,
  930. tabs: [
  931. {
  932. title: "标签页",
  933. css: {},
  934. content: i,
  935. },
  936. ], // { title: string, css: string }[]
  937. ...config,
  938. };
  939. this.activeTabIndex = 0;
  940. this.isDragging = false;
  941. this.dragOffset = { x: 0, y: 0 };
  942. this.isResizing = false;
  943. this.resizeDirection = null;
  944. this.originalSize = null;
  945. this.originalPosition = null;
  946. this.preMaximizeState = null;
  947. this.createDOM();
  948. this.setupEventListeners();
  949. }
  950. // 创建窗口DOM结构
  951. createDOM() {
  952. this.element = document.createElement("div");
  953. this.element.dataset.windowId = this.id;
  954. for (var property in this.config.css) {
  955. this.element.style[property] = this.config.css[property];
  956. }
  957. this.element.style.width = `${this.config.width}px`;
  958. this.element.style.height = `${this.config.height}px`;
  959. this.element.style.left = `${this.config.x}px`;
  960. this.element.style.top = `${this.config.y}px`;
  961. this.element.tabIndex = -1; // 使窗口可聚焦
  962. this.element.classList.add("window");
  963. if (this.config.borderless) {
  964. this.element.classList.add("borderless");
  965. }
  966. if (this.config.fullscreen) {
  967. this.element.classList.add("fullscreen");
  968. }
  969. if (this.config.minimized) {
  970. this.element.classList.add("minimized");
  971. }
  972. // 标题栏
  973. const titleBar = document.createElement("div");
  974. titleBar.className = "window-title-bar";
  975. titleBar.innerHTML = `<div class="window-icon">${
  976. this.config.icon
  977. ? this.config.icon
  978. : this.config.title.charAt(0).toUpperCase()
  979. }</div>
  980. <div class="window-title">${this.config.title}</div>
  981. <div class="window-controls">
  982. <button class="minimize">
  983. <!-- Copyright (c) 2018-2025 Tabler -->
  984. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-chevron-compact-down"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 11l8 3l8 -3" /></svg>
  985. </button>
  986. <button class="maximize">
  987. <!-- Copyright (c) 2018-2025 Tabler -->
  988. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-maximize"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 8v-2a2 2 0 0 1 2 -2h2" /><path d="M4 16v2a2 2 0 0 0 2 2h2" /><path d="M16 4h2a2 2 0 0 1 2 2v2" /><path d="M16 20h2a2 2 0 0 0 2 -2v-2" /></svg>
  989. </button>
  990. <button class="close">
  991. <!-- Copyright (c) 2018-2025 Tabler -->
  992. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-square-x"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14z" /><path d="M9 9l6 6m0 -6l-6 6" /></svg>
  993. </button>
  994. </div>`;
  995. // 标签页栏
  996. const tabBar = document.createElement("div");
  997. tabBar.className = "window-tab-bar";
  998. this.config.tabs.forEach((tab, index) => {
  999. const tabEl = document.createElement("div");
  1000. tabEl.className = `tab ${
  1001. index === this.activeTabIndex ? "active" : ""
  1002. }`;
  1003. tabEl.textContent = tab.title;
  1004. tabEl.dataset.tabIndex = index;
  1005. tabBar.appendChild(tabEl);
  1006. });
  1007. // 内容区
  1008. const content = document.createElement("div");
  1009. content.className = "window-content";
  1010. this.config.tabs.forEach((tab, index) => {
  1011. const tabConEl = document.createElement("div");
  1012. tabConEl.className = `tab-content ${
  1013. index === this.activeTabIndex ? "active" : ""
  1014. }`;
  1015. if (tab.content) {
  1016. try {
  1017. tabConEl.appendChild(tab.content);
  1018. } catch (e) {
  1019. var p = document.createElement("p");
  1020. p.style.color = "var(--danger-color)";
  1021. p.textContent = e;
  1022. tabConEl.appendChild(p);
  1023. }
  1024. } else {
  1025. var i = document.createElement("i");
  1026. i.textContent = "空内容";
  1027. tabConEl.appendChild(i);
  1028. }
  1029. tabConEl.dataset.tabContentIndex = index;
  1030. for (var property in tab.css) {
  1031. tabConEl.style[property] = tab.css[property];
  1032. }
  1033. content.appendChild(tabConEl);
  1034. });
  1035. this.element.appendChild(titleBar);
  1036. if (this.config.tabs.length > 1) {
  1037. this.element.appendChild(tabBar);
  1038. }
  1039. this.element.appendChild(content);
  1040. // 调整大小手柄
  1041. const resizeHandle = document.createElement("div");
  1042. resizeHandle.className = "resize-handle";
  1043. this.element.appendChild(resizeHandle);
  1044. this.switchTab(0);
  1045. }
  1046. // 设置事件监听
  1047. setupEventListeners() {
  1048. const titleBar = this.element.querySelector(".window-title-bar");
  1049. const minimizeBtn = this.element.querySelector(".minimize");
  1050. const maximizeBtn = this.element.querySelector(".maximize");
  1051. const closeBtn = this.element.querySelector(".close");
  1052. const tabs = this.element.querySelectorAll(".tab");
  1053. const resizeHandle = this.element.querySelector(".resize-handle");
  1054. this.element.addEventListener("mousedown", (e) => {
  1055. wManager.focusWindow(this.id);
  1056. fManager.focusWindow(this.id);
  1057. });
  1058. // 拖动窗口
  1059. titleBar.addEventListener("mousedown", (e) => {
  1060. if (
  1061. e.target === minimizeBtn ||
  1062. e.target === maximizeBtn ||
  1063. e.target === closeBtn
  1064. ) {
  1065. return;
  1066. }
  1067. this.isDragging = true;
  1068. this.element.classList.add("dragging");
  1069. if (this.config.fullscreen) {
  1070. this.dragOffset = {
  1071. x: (this.config.width / window.innerWidth) * e.clientX,
  1072. y: e.clientY,
  1073. };
  1074. this.element.style.left = `${e.clientX - this.dragOffset.x}px`;
  1075. this.element.style.top = `${e.clientY - this.dragOffset.y}px`;
  1076. this.toggleMaximize();
  1077. } else {
  1078. this.dragOffset = {
  1079. x: e.clientX - this.element.offsetLeft,
  1080. y: e.clientY - this.element.offsetTop,
  1081. };
  1082. }
  1083. });
  1084. this.handleDocumentMouseMove = (e) => {
  1085. if (this.isDragging) {
  1086. // 计算边界,确保窗口不会移出屏幕
  1087. let newX = e.clientX - this.dragOffset.x;
  1088. let newY = e.clientY - this.dragOffset.y;
  1089. // newX = Math.max(
  1090. // 0,
  1091. // Math.min(newX, window.innerWidth - this.element.offsetWidth)
  1092. // );
  1093. // newY = Math.max(
  1094. // 0,
  1095. // Math.min(newY, window.innerHeight - this.element.offsetHeight)
  1096. // );
  1097. // 设置新的位置
  1098. this.element.style.left = newX + "px";
  1099. this.element.style.top = newY + "px";
  1100. }
  1101. };
  1102. this.handleDocumentMouseUp = () => {
  1103. this.isDragging = false;
  1104. this.element.classList.remove("dragging");
  1105. };
  1106. // 添加触摸事件支持
  1107. titleBar.addEventListener("touchstart", (e) => {
  1108. if (
  1109. e.target === minimizeBtn ||
  1110. e.target === maximizeBtn ||
  1111. e.target === closeBtn
  1112. ) {
  1113. return;
  1114. }
  1115. this.isDragging = true;
  1116. this.element.classList.add("dragging");
  1117. if (this.config.fullscreen) {
  1118. this.dragOffset = {
  1119. x:
  1120. (this.config.width / window.innerWidth) *
  1121. e.touches[0].clientX,
  1122. y: e.touches[0].clientY,
  1123. };
  1124. this.element.style.left = `${
  1125. e.touches[0].clientX - this.dragOffset.x
  1126. }px`;
  1127. this.element.style.top = `${
  1128. e.touches[0].clientY - this.dragOffset.y
  1129. }px`;
  1130. this.toggleMaximize();
  1131. } else {
  1132. this.dragOffset = {
  1133. x: e.touches[0].clientX - this.element.offsetLeft,
  1134. y: e.touches[0].clientY - this.element.offsetTop,
  1135. };
  1136. }
  1137. e.preventDefault(); // 防止触摸滚动
  1138. });
  1139. this.handleDocumentTouchMove = (e) => {
  1140. if (this.isDragging) {
  1141. // 计算边界,确保窗口不会移出屏幕
  1142. let newX = e.touches[0].clientX - this.dragOffset.x;
  1143. let newY = e.touches[0].clientY - this.dragOffset.y;
  1144. // newX = Math.max(
  1145. // 0,
  1146. // Math.min(newX, window.innerWidth - this.element.offsetWidth)
  1147. // );
  1148. // newY = Math.max(
  1149. // 0,
  1150. // Math.min(newY, window.innerHeight - this.element.offsetHeight)
  1151. // );
  1152. // 设置新的位置
  1153. this.element.style.left = newX + "px";
  1154. this.element.style.top = newY + "px";
  1155. e.preventDefault(); // 防止触摸滚动
  1156. }
  1157. };
  1158. this.handleDocumentTouchEnd = () => {
  1159. this.isDragging = false;
  1160. this.element.classList.remove("dragging");
  1161. };
  1162. document.addEventListener(
  1163. "touchmove",
  1164. this.handleDocumentTouchMove,
  1165. { passive: false }
  1166. );
  1167. document.addEventListener("touchend", this.handleDocumentTouchEnd);
  1168. document.addEventListener(
  1169. "mousemove",
  1170. this.handleDocumentMouseMove
  1171. );
  1172. document.addEventListener("mouseup", this.handleDocumentMouseUp);
  1173. // 窗口控制按钮
  1174. minimizeBtn.addEventListener("click", () => this.toggleMinimize());
  1175. maximizeBtn.addEventListener("click", () => this.toggleMaximize());
  1176. closeBtn.addEventListener("click", () =>
  1177. wManager.closeWindow(this.id)
  1178. );
  1179. // 标签页切换
  1180. tabs.forEach((tab) => {
  1181. tab.addEventListener("click", (e) => {
  1182. const tabIndex = parseInt(e.target.dataset.tabIndex);
  1183. this.switchTab(tabIndex);
  1184. fManager.focusWindow(this.id);
  1185. });
  1186. });
  1187. // 调整大小事件
  1188. resizeHandle.addEventListener("mousedown", this.handleResizeStart);
  1189. }
  1190. // 窗口获得焦点
  1191. focus() {
  1192. if (this.config.minimized) {
  1193. this.config.minimized = !this.config.minimized;
  1194. this.element.classList.remove("minimized");
  1195. }
  1196. this.element.classList.add("focused");
  1197. }
  1198. // 窗口失去焦点
  1199. blur() {
  1200. this.element.classList.remove("focused");
  1201. }
  1202. // 切换标签页
  1203. switchTab(index) {
  1204. this.activeTabIndex = index;
  1205. const tabs = this.element.querySelectorAll(".tab");
  1206. const contents = this.element.querySelectorAll(".tab-content");
  1207. tabs.forEach((tab, i) => {
  1208. tab.classList.toggle("active", i === index);
  1209. });
  1210. contents.forEach((content, i) => {
  1211. content.classList.toggle("active", i === index);
  1212. });
  1213. }
  1214. // 最小化/恢复窗口
  1215. toggleMinimize() {
  1216. if (this.config.fullscreen) {
  1217. this.config.fullscreen = !this.config.fullscreen;
  1218. this.element.classList.remove("fullscreen");
  1219. wManager.updateFullscreenCount(-1);
  1220. }
  1221. fManager.clearFocus();
  1222. this.config.minimized = !this.config.minimized;
  1223. this.element.classList.toggle("minimized", this.config.minimized);
  1224. }
  1225. // 最大化/恢复窗口
  1226. toggleMaximize() {
  1227. if (this.config.minimized) {
  1228. this.config.minimized = !this.config.minimized;
  1229. this.element.classList.remove("minimized");
  1230. }
  1231. const wasFullscreen = this.config.fullscreen;
  1232. this.config.fullscreen = !this.config.fullscreen;
  1233. const isNowFullscreen = this.config.fullscreen;
  1234. this.element.classList.toggle("fullscreen", this.config.fullscreen);
  1235. // 更新全屏计数
  1236. if (wasFullscreen && !isNowFullscreen) {
  1237. wManager.updateFullscreenCount(-1);
  1238. } else if (!wasFullscreen && isNowFullscreen) {
  1239. wManager.updateFullscreenCount(1);
  1240. }
  1241. }
  1242. // 关闭窗口
  1243. cleanup() {
  1244. // 移除所有事件监听器
  1245. document.removeEventListener(
  1246. "mousemove",
  1247. this.handleDocumentMouseMove
  1248. );
  1249. document.removeEventListener("mouseup", this.handleDocumentMouseUp);
  1250. document.removeEventListener("mousemove", this.handleResize);
  1251. document.removeEventListener("mouseup", this.handleResizeEnd);
  1252. // 从窗口元素移除 win-close 监听器
  1253. if (this.closeHandler) {
  1254. this.element.removeEventListener("win-close", this.closeHandler);
  1255. }
  1256. // 通知管理器移除窗口状态(统一管理)
  1257. fManager.removeWindow(this.id);
  1258. }
  1259. // 设置关闭处理器
  1260. setCloseHandler(handler) {
  1261. this.closeHandler = handler;
  1262. this.element.addEventListener("win-close", handler);
  1263. }
  1264. close() {
  1265. // 触发关闭事件
  1266. this.element.dispatchEvent(
  1267. new CustomEvent("win-close", { bubbles: true })
  1268. );
  1269. // 清理窗口
  1270. this.cleanup();
  1271. // 从DOM和管理器中移除
  1272. this.element.remove();
  1273. wManager.windows.delete(this.id);
  1274. }
  1275. // 调整大小功能
  1276. handleResizeStart = (e) => {
  1277. e.stopPropagation();
  1278. this.isResizing = true;
  1279. this.element.classList.add("resizing");
  1280. this.resizeStartX = e.clientX;
  1281. this.resizeStartY = e.clientY;
  1282. this.originalWidth = this.element.offsetWidth;
  1283. this.originalHeight = this.element.offsetHeight;
  1284. document.addEventListener("mousemove", this.handleResize);
  1285. document.addEventListener("mouseup", this.handleResizeEnd);
  1286. wManager.focusWindow(this.id);
  1287. fManager.focusWindow(this.id);
  1288. };
  1289. handleResize = (e) => {
  1290. if (!this.isResizing) return;
  1291. const dx = e.clientX - this.resizeStartX;
  1292. const dy = e.clientY - this.resizeStartY;
  1293. const minWidth = 200;
  1294. const minHeight = 150;
  1295. const newWidth = Math.max(minWidth, this.originalWidth + dx);
  1296. const newHeight = Math.max(minHeight, this.originalHeight + dy);
  1297. this.element.style.width = `${newWidth}px`;
  1298. this.element.style.height = `${newHeight}px`;
  1299. };
  1300. handleResizeEnd = () => {
  1301. this.isResizing = false;
  1302. this.element.classList.remove("resizing");
  1303. document.removeEventListener("mousemove", this.handleResize);
  1304. document.removeEventListener("mouseup", this.handleResizeEnd);
  1305. };
  1306. }
  1307. // 全局窗口管理器实例
  1308. const wManager = new WindowManager();
  1309. // 拦截全局输入事件
  1310. document.addEventListener("keydown", (e) => {
  1311. // 只有焦点窗口能接收键盘事件
  1312. if (!fManager.focusedWindowId) return;
  1313. // 阻止事件冒泡到非焦点窗口
  1314. const targetWindow = e.target.closest(".window");
  1315. if (
  1316. !targetWindow ||
  1317. targetWindow.dataset.windowId !== fManager.focusedWindowId
  1318. ) {
  1319. e.stopPropagation();
  1320. }
  1321. });
  1322. document.addEventListener("mousedown", (e) => {
  1323. const windowElement = e.target.closest(".window");
  1324. if (windowElement) {
  1325. // 点击窗口时设置焦点
  1326. fManager.focusWindow(windowElement.dataset.windowId);
  1327. } else {
  1328. // 点击窗口外区域清除焦点
  1329. fManager.clearFocus();
  1330. }
  1331. });
  1332. class ProcessManager {
  1333. constructor() {
  1334. this.workers = new Map();
  1335. this.registry = new Map(); // 权限注册表 {进程 ID: 允许通信的目标 ID 集合}
  1336. }
  1337. // 创建新进程
  1338. async createProcess(id, parentId = null) {
  1339. const workerScript =
  1340. document.querySelector("#processWorker").textContent;
  1341. const blob = new Blob([workerScript], {
  1342. type: "application/javascript",
  1343. });
  1344. const worker = new Worker(URL.createObjectURL(blob));
  1345. this.workers.set(id, worker);
  1346. // 初始化权限
  1347. this.registry.set(id, new Set());
  1348. if (parentId) {
  1349. this.allowCommunication(parentId, id);
  1350. }
  1351. // 处理 Worker 消息
  1352. worker.onmessage = (event) => {
  1353. if (event.data.type === "process-message") {
  1354. const { targetId, messageType, data, from } = event.data;
  1355. this.sendMessage(from, targetId, messageType, data);
  1356. }
  1357. };
  1358. // 初始化 Worker
  1359. worker.postMessage({
  1360. type: "init",
  1361. id,
  1362. parentId,
  1363. });
  1364. return new Promise((resolve) => {
  1365. worker.addEventListener(
  1366. "message",
  1367. function ready(e) {
  1368. if (e.data.type === "ready") {
  1369. resolve();
  1370. }
  1371. },
  1372. { once: true }
  1373. );
  1374. });
  1375. }
  1376. // 允许进程通信
  1377. allowCommunication(sourceId, targetId) {
  1378. if (this.registry.has(sourceId)) {
  1379. this.registry.get(sourceId).add(targetId);
  1380. }
  1381. }
  1382. // 发送进程消息
  1383. sendMessage(sourceId, targetId, messageType, data) {
  1384. if (!this.registry.get(sourceId)?.has(targetId)) {
  1385. console.error(`进程 ${sourceId} 无权向 ${targetId} 发送消息`);
  1386. return;
  1387. }
  1388. const worker = this.workers.get(targetId);
  1389. if (worker) {
  1390. worker.postMessage({
  1391. type: "message",
  1392. data: {
  1393. type: messageType,
  1394. data,
  1395. from: sourceId,
  1396. },
  1397. });
  1398. }
  1399. }
  1400. // 执行进程命令
  1401. executeCommand(processId, command) {
  1402. const worker = this.workers.get(processId);
  1403. if (worker) {
  1404. worker.postMessage({
  1405. type: "execute",
  1406. data: { command },
  1407. });
  1408. }
  1409. }
  1410. // 更新进程设置
  1411. updateSetting(processId, key, value) {
  1412. const worker = this.workers.get(processId);
  1413. if (worker) {
  1414. worker.postMessage({
  1415. type: "update-setting",
  1416. data: { key, value },
  1417. });
  1418. }
  1419. }
  1420. // 终止进程
  1421. terminateProcess(processId) {
  1422. const worker = this.workers.get(processId);
  1423. if (worker) {
  1424. worker.terminate();
  1425. this.workers.delete(processId);
  1426. this.registry.delete(processId);
  1427. }
  1428. }
  1429. }
  1430. // 初始化进程管理器
  1431. const pManager = new ProcessManager();
  1432. // 应用程序:创建一个进程,该进程可创建多个窗口,当所有该进程的窗口都关闭时,进程自动退出
  1433. async function application(appProcessId, windowConfigs) {
  1434. await pManager.createProcess(appProcessId);
  1435. var count = 0;
  1436. // 跟踪窗口关闭状态
  1437. let windows = [];
  1438. windowConfigs.forEach((windowConfig) => {
  1439. // 创建窗口
  1440. const windowId = wManager.createWindow(appProcessId, windowConfig);
  1441. // 焦点
  1442. fManager.focusWindow(windowId);
  1443. wManager.focusWindow(windowId);
  1444. // 通过事件监听来监控窗口关闭
  1445. const windowObj = { windowId: windowId, closed: false };
  1446. windows[count] = windowObj;
  1447. // 监听窗口关闭事件
  1448. const closeHandler = () => {
  1449. windowObj.closed = true;
  1450. // 检查是否所有窗口都已关闭
  1451. const allClosed = windows.every((w) => w.closed);
  1452. if (allClosed) {
  1453. // 所有窗口都已关闭,终止进程
  1454. pManager.terminateProcess(appProcessId);
  1455. }
  1456. };
  1457. // 设置关闭处理器
  1458. const windowInstance = wManager.windows.get(windowId);
  1459. if (windowInstance) {
  1460. windowInstance.setCloseHandler(closeHandler);
  1461. } else {
  1462. console.warn(`未找到窗口实例: ${windowId}`);
  1463. }
  1464. count++;
  1465. });
  1466. }
  1467. // 自定义右键菜单功能
  1468. function initOptionMenu(doc) {
  1469. // 隐藏菜单后,将菜单移动到屏幕内
  1470. function inScreen(contextMenu) {
  1471. contextMenu.style.left = "2px";
  1472. contextMenu.style.top = "2px";
  1473. }
  1474. // 初始化样式
  1475. var style = doc.createElement("style");
  1476. style.type = "text/css";
  1477. style.innerHTML = `
  1478. #custom-context-menu {
  1479. --accent-color: #64ffda; /* 强调色:边框 */
  1480. --secondary-color: #00695c; /* 次要色:未激活边框 */
  1481. --danger-color: #ff6d00; /* 着重色:边框 */
  1482. --accent-bg-color: #009688;
  1483. --secondary-bg-color: #616161;
  1484. --content-bg-color: #424242;
  1485. --accent-font-color: #f5f5f5;
  1486. --secondary-font-color: #eeeeee;
  1487. --margin-padding: 0.5rem;
  1488. --border-thickness: 0.2rem;
  1489. --border-radius: 0.5rem;
  1490. --title-bar-height: 2rem;
  1491. --title-bar-justify-content: left;
  1492. --task-bar-height: 3rem;
  1493. --shadow: 0.6rem 0.6rem 0.1rem 0.1rem rgba(0, 0, 0, 0.2);
  1494. --focused-bg-color: rgba(255, 255, 255, 0.1);
  1495. font-size: small;
  1496. user-select: none;
  1497. position: absolute;
  1498. background-color: var(--content-bg-color);
  1499. border: var(--border-thickness) solid var(--secondary-color);
  1500. border-radius: var(--border-radius);
  1501. padding: 0;
  1502. opacity: 0;
  1503. transform: scale(0.8);
  1504. pointer-events: none;
  1505. z-index: 4000; /* 确保在顶层 */
  1506. min-width: 150px;
  1507. &.show {
  1508. display: block;
  1509. opacity: 1;
  1510. transform: scale(1);
  1511. pointer-events: auto;
  1512. }
  1513. &:hover {
  1514. box-shadow: var(--shadow);
  1515. --secondary-color: var(--accent-color);
  1516. }
  1517. }
  1518. #custom-context-menu ul {
  1519. list-style: none;
  1520. margin: 0;
  1521. padding: 0;
  1522. }
  1523. #custom-context-menu li {
  1524. padding: var(--margin-padding);
  1525. cursor: pointer;
  1526. list-style-type: none; /* 去除列表项标记 */
  1527. }
  1528. #custom-context-menu li:hover {
  1529. background-color: var(--focused-bg-color);
  1530. }`;
  1531. style.id = "addStyle";
  1532. doc.getElementsByTagName("HEAD").item(0).appendChild(style);
  1533. // 初始化元素
  1534. const contextMenu = doc.createElement("ul");
  1535. contextMenu.id = "custom-context-menu";
  1536. doc.body.appendChild(contextMenu);
  1537. // 监听全局右键点击事件
  1538. doc.addEventListener("contextmenu", function (e) {
  1539. // 阻止默认右键菜单
  1540. e.preventDefault();
  1541. // 获取被点击的元素
  1542. const target = e.target;
  1543. const selection = window.getSelection();
  1544. const hasSelection =
  1545. selection && selection.toString().trim().length > 0;
  1546. // 检查事件目标是否在选区内
  1547. let inSelection = false;
  1548. if (hasSelection && selection.rangeCount > 0) {
  1549. const range = selection.getRangeAt(0);
  1550. inSelection = range.intersectsNode(e.target);
  1551. }
  1552. // 如果有文本被选中且右键点击在选区内,显示默认文本操作菜单
  1553. if (hasSelection && inSelection) {
  1554. const defaultTextOptions = [
  1555. { label: "复制", action: "copy" },
  1556. { label: "剪切", action: "cut" },
  1557. { label: "粘贴", action: "paste" },
  1558. { label: "全选", action: "selectAll" },
  1559. ];
  1560. // 清空菜单
  1561. contextMenu.innerHTML = "";
  1562. // 生成菜单项
  1563. defaultTextOptions.forEach((option) => {
  1564. const li = doc.createElement("li");
  1565. li.textContent = option.label;
  1566. li.onclick = function () {
  1567. if (option.action === "copy") {
  1568. doc.execCommand("copy");
  1569. } else if (option.action === "cut") {
  1570. doc.execCommand("cut");
  1571. } else if (option.action === "paste") {
  1572. doc.execCommand("paste");
  1573. } else if (option.action === "selectAll") {
  1574. doc.execCommand("selectAll");
  1575. }
  1576. contextMenu.classList.remove("show");
  1577. inScreen(contextMenu);
  1578. };
  1579. contextMenu.appendChild(li);
  1580. });
  1581. // 显示菜单(确保在屏幕内)
  1582. translate.execute([contextMenu]);
  1583. contextMenu.classList.add("show");
  1584. // 获取菜单尺寸
  1585. const menuWidth = contextMenu.offsetWidth;
  1586. const menuHeight = contextMenu.offsetHeight;
  1587. // 计算调整后的位置
  1588. let adjustedLeft = e.pageX;
  1589. let adjustedTop = e.pageY;
  1590. // 如果靠近右边缘,向左偏移
  1591. if (window.innerWidth - e.pageX < menuWidth) {
  1592. adjustedLeft = e.pageX - menuWidth;
  1593. }
  1594. // 如果靠近下边缘,向上偏移
  1595. if (window.innerHeight - e.pageY < menuHeight) {
  1596. adjustedTop = e.pageY - menuHeight;
  1597. }
  1598. contextMenu.style.left = adjustedLeft + "px";
  1599. contextMenu.style.top = adjustedTop + "px";
  1600. }
  1601. // 否则检查元素的 data-menu-options 属性
  1602. else if (target.dataset.menuOptions) {
  1603. try {
  1604. // 解析 JSON 字符串
  1605. const menuOptions = JSON.parse(target.dataset.menuOptions);
  1606. // 清空菜单
  1607. contextMenu.innerHTML = "";
  1608. // 动态生成菜单项
  1609. menuOptions.forEach((option) => {
  1610. const li = doc.createElement("li");
  1611. li.textContent = option.label;
  1612. li.onclick = function () {
  1613. // 执行action
  1614. if (option.action) {
  1615. // 触发自定义事件
  1616. const event = new CustomEvent(
  1617. "custom-contextmenu-action",
  1618. {
  1619. detail: {
  1620. action: option.action,
  1621. target: target,
  1622. },
  1623. }
  1624. );
  1625. doc.dispatchEvent(event);
  1626. }
  1627. // 隐藏菜单
  1628. contextMenu.classList.remove("show");
  1629. inScreen(contextMenu);
  1630. };
  1631. contextMenu.appendChild(li);
  1632. });
  1633. // 显示菜单(确保在屏幕内)
  1634. translate.execute([contextMenu]);
  1635. contextMenu.classList.add("show");
  1636. // 获取菜单尺寸
  1637. const menuWidth = contextMenu.offsetWidth;
  1638. const menuHeight = contextMenu.offsetHeight;
  1639. // 计算调整后的位置
  1640. let adjustedLeft = e.pageX;
  1641. let adjustedTop = e.pageY;
  1642. // 如果靠近右边缘,向左偏移
  1643. if (window.innerWidth - e.pageX < menuWidth) {
  1644. adjustedLeft = e.pageX - menuWidth;
  1645. }
  1646. // 如果靠近下边缘,向上偏移
  1647. if (window.innerHeight - e.pageY < menuHeight) {
  1648. adjustedTop = e.pageY - menuHeight;
  1649. }
  1650. contextMenu.style.left = adjustedLeft + "px";
  1651. contextMenu.style.top = adjustedTop + "px";
  1652. } catch (error) {
  1653. console.error("解析菜单选项失败", error);
  1654. }
  1655. } else {
  1656. // 如果没有定义菜单选项,则隐藏菜单
  1657. contextMenu.classList.remove("show");
  1658. inScreen(contextMenu);
  1659. }
  1660. });
  1661. // 点击其他地方隐藏菜单
  1662. doc.addEventListener("click", function () {
  1663. contextMenu.classList.remove("show");
  1664. inScreen(contextMenu);
  1665. });
  1666. // 阻止菜单内部的点击事件冒泡
  1667. contextMenu.addEventListener("click", function (e) {
  1668. e.stopPropagation();
  1669. });
  1670. // 处理任务栏窗口按钮的右键菜单动作
  1671. doc.addEventListener("custom-contextmenu-action", function (e) {
  1672. const { action, target } = e.detail;
  1673. const windowId = target.dataset.windowId;
  1674. if (!windowId) return;
  1675. if (action === "move") {
  1676. wManager.moveWindow(windowId);
  1677. } else if (action === "minimize") {
  1678. wManager.minimizeWindow(windowId);
  1679. } else if (action === "maximize") {
  1680. wManager.maximizeWindow(windowId);
  1681. } else if (action === "close") {
  1682. wManager.closeWindow(windowId);
  1683. }
  1684. });
  1685. // 当视口大小改变(如浏览器窗口大小改变)时执行
  1686. window.addEventListener("resize", function () {
  1687. // 等待后居中 contextMenu
  1688. setTimeout(() => {
  1689. if (contextMenu.style.display === "none") {
  1690. inScreen(contextMenu);
  1691. }
  1692. }, 500);
  1693. });
  1694. }
  1695. initOptionMenu(document);
  1696. (async function init() {
  1697. // (async function desktop() {
  1698. // // 为桌面进程创建全屏无边框窗口(桌面背景)
  1699. // const desktopWin = wManager.createWindow("desktop", {
  1700. // css: {
  1701. // "z-index": "-1",
  1702. // "pointer-events": "none",
  1703. // },
  1704. // borderless: true,
  1705. // fullscreen: true,
  1706. // title: "桌面背景",
  1707. // tabs: [
  1708. // {
  1709. // title: "桌面",
  1710. // css: {
  1711. // position: "absolute",
  1712. // top: "0",
  1713. // left: "0",
  1714. // width: "100%",
  1715. // height: "100%",
  1716. // background: "linear-gradient(#EEE, #666)",
  1717. // "z-index": "-1",
  1718. // overflow: "hidden",
  1719. // },
  1720. // content: " ",
  1721. // },
  1722. // ],
  1723. // });
  1724. // })();
  1725. (async function taskBar() {
  1726. const taskBarProcess = await pManager.createProcess("taskBar");
  1727. const taskbarContainer =
  1728. document.querySelector("taskbar-container");
  1729. const taskBar = taskbarContainer.querySelector("task-bar");
  1730. (async function time() {
  1731. // 日期时间显示功能
  1732. const updateDateTime = () => {
  1733. const now = new Date();
  1734. const dateStr = now.toLocaleDateString("zh-CN", {
  1735. year: "numeric",
  1736. month: "2-digit",
  1737. day: "2-digit",
  1738. });
  1739. const timeStr = now.toLocaleTimeString("zh-CN", {
  1740. hour: "2-digit",
  1741. minute: "2-digit",
  1742. });
  1743. taskBar.querySelector(
  1744. ".date-time"
  1745. ).textContent = `${dateStr} ${timeStr}`;
  1746. };
  1747. // 初始更新并设置定时器
  1748. updateDateTime();
  1749. setInterval(updateDateTime, 1000);
  1750. })();
  1751. (async function power() {
  1752. // 电池状态功能(https://developer.mozilla.org/zh-CN/docs/Web/API/Battery_Status_API)
  1753. const powerButton = taskBar.querySelector(".power");
  1754. async function updateBatteryStatus() {
  1755. const battery_exclamation =
  1756. '<!-- Copyright (c) 2018-2025 Tabler --><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-battery-exclamation"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 17h8c1.105 0 2 -.895 2 -2v-.5c0 -.276 .224 -.5 .5 -.5s.5 -.224 .5 -.5v-3c0 -.276 -.224 -.5 -.5 -.5s-.5 -.224 -.5 -.5v-.5c0 -1.105 -.895 -2 -2 -2h-11c-1.105 0 -2 .895 -2 2v3" /><path d="M5 16v3" /><path d="M5 22v.01" /></svg>';
  1757. try {
  1758. if (!navigator.getBattery) {
  1759. powerButton.title = "电池状态不可用";
  1760. powerButton.innerHTML = battery_exclamation; // 感叹号图标
  1761. console.warn("浏览器不支持电池状态 API");
  1762. return;
  1763. }
  1764. const battery = await navigator.getBattery();
  1765. const level = Math.floor(battery.level * 100);
  1766. let statusText = `电量: ${level}%`;
  1767. let batteryIcon = battery_exclamation; // 默认感叹号图标
  1768. // 充电状态使用充电图标
  1769. if (battery.charging) {
  1770. batteryIcon =
  1771. '<!-- Copyright (c) 2018-2025 Tabler --><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-battery-charging-2"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 9a2 2 0 0 1 2 -2h11a2 2 0 0 1 2 2v.5a.5 .5 0 0 0 .5 .5a.5 .5 0 0 1 .5 .5v3a.5 .5 0 0 1 -.5 .5a.5 .5 0 0 0 -.5 .5v.5a2 2 0 0 1 -2 2h-4.5" /><path d="M3 15h6v2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2v-2z" /><path d="M6 22v-3" /><path d="M4 15v-2.5" /><path d="M8 15v-2.5" /></svg>';
  1772. statusText += " (充电中)";
  1773. if (battery.chargingTime < Infinity) {
  1774. statusText += ` | 充满时间: ${Math.floor(
  1775. battery.chargingTime / 60
  1776. )}分钟`;
  1777. }
  1778. }
  1779. // 非充电状态根据电量选择图标
  1780. else {
  1781. const icons = [
  1782. '<!-- Copyright (c) 2018-2025 Tabler --><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-battery"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 7h11a2 2 0 0 1 2 2v.5a.5 .5 0 0 0 .5 .5a.5 .5 0 0 1 .5 .5v3a.5 .5 0 0 1 -.5 .5a.5 .5 0 0 0 -.5 .5v.5a2 2 0 0 1 -2 2h-11a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2" /></svg>', // 0%
  1783. '<!-- Copyright (c) 2018-2025 Tabler --><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-battery-1"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 7h11a2 2 0 0 1 2 2v.5a.5 .5 0 0 0 .5 .5a.5 .5 0 0 1 .5 .5v3a.5 .5 0 0 1 -.5 .5a.5 .5 0 0 0 -.5 .5v.5a2 2 0 0 1 -2 2h-11a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2" /><path d="M7 10l0 4" /></svg>', // 25%
  1784. '<!-- Copyright (c) 2018-2025 Tabler --><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-battery-2"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 7h11a2 2 0 0 1 2 2v.5a.5 .5 0 0 0 .5 .5a.5 .5 0 0 1 .5 .5v3a.5 .5 0 0 1 -.5 .5a.5 .5 0 0 0 -.5 .5v.5a2 2 0 0 1 -2 2h-11a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2" /><path d="M7 10l0 4" /><path d="M10 10l0 4" /></svg>', // 50%
  1785. '<!-- Copyright (c) 2018-2025 Tabler --><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-battery-3"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 7h11a2 2 0 0 1 2 2v.5a.5 .5 0 0 0 .5 .5a.5 .5 0 0 1 .5 .5v3a.5 .5 0 0 1 -.5 .5a.5 .5 0 0 0 -.5 .5v.5a2 2 0 0 1 -2 2h-11a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2" /><path d="M7 10l0 4" /><path d="M10 10l0 4" /><path d="M13 10l0 4" /></svg>', // 75%
  1786. '<!-- Copyright (c) 2018-2025 Tabler --><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-battery-4"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 7h11a2 2 0 0 1 2 2v.5a.5 .5 0 0 0 .5 .5a.5 .5 0 0 1 .5 .5v3a.5 .5 0 0 1 -.5 .5a.5 .5 0 0 0 -.5 .5v.5a2 2 0 0 1 -2 2h-11a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2" /><path d="M7 10l0 4" /><path d="M10 10l0 4" /><path d="M13 10l0 4" /><path d="M16 10l0 4" /></svg>', // 100%
  1787. ];
  1788. const index = Math.min(Math.floor(level / 25), 4); // 25: 状态之间的间隔、4: 状态的个数减一
  1789. batteryIcon = level = icons[index];
  1790. if (battery.dischargingTime < Infinity) {
  1791. statusText += ` | 剩余时间: ${Math.floor(
  1792. battery.dischargingTime / 60
  1793. )}分钟`;
  1794. }
  1795. }
  1796. powerButton.innerHTML = batteryIcon;
  1797. powerButton.title = statusText;
  1798. powerButton.style.display = "block";
  1799. // 添加事件监听器
  1800. battery.addEventListener(
  1801. "chargingchange",
  1802. updateBatteryStatus
  1803. );
  1804. battery.addEventListener("levelchange", updateBatteryStatus);
  1805. battery.addEventListener(
  1806. "chargingtimechange",
  1807. updateBatteryStatus
  1808. );
  1809. battery.addEventListener(
  1810. "dischargingtimechange",
  1811. updateBatteryStatus
  1812. );
  1813. } catch (error) {
  1814. powerButton.innerHTML = battery_exclamation;
  1815. powerButton.title = "电池状态检测失败";
  1816. console.warn("获取电池状态失败:", error);
  1817. }
  1818. }
  1819. // 点击显示详细状态
  1820. powerButton.addEventListener("click", async () => {
  1821. try {
  1822. if (navigator.getBattery) {
  1823. const battery = await navigator.getBattery();
  1824. const statusDetails = [
  1825. `电量: ${Math.floor(battery.level * 100)}%`,
  1826. `充电状态: ${battery.charging ? "充电中" : "未充电"}`,
  1827. `充电时间: ${
  1828. battery.chargingTime === Infinity
  1829. ? "未知"
  1830. : Math.floor(battery.chargingTime / 60) + "分钟"
  1831. }`,
  1832. `放电时间: ${
  1833. battery.dischargingTime === Infinity
  1834. ? "未知"
  1835. : Math.floor(battery.dischargingTime / 60) + "分钟"
  1836. }`,
  1837. ].join("\n");
  1838. var e = document.createElement("pre");
  1839. e.textContent = statusDetails;
  1840. // 创建电池状态窗口
  1841. application("power-manager", [
  1842. {
  1843. title: "电池状态",
  1844. tabs: [
  1845. {
  1846. title: "详细信息",
  1847. content: e,
  1848. },
  1849. ],
  1850. },
  1851. ]);
  1852. }
  1853. } catch (error) {
  1854. var e = document.createElement("p");
  1855. e.style.color = "var(--danger-color)";
  1856. e.textContent = "无法获取电池详细信息" + error;
  1857. // 创建错误提示窗口
  1858. application("power-manager", [
  1859. {
  1860. title: "电池状态错误",
  1861. tabs: [
  1862. {
  1863. title: "提示",
  1864. content: e,
  1865. },
  1866. ],
  1867. },
  1868. ]);
  1869. }
  1870. });
  1871. // 初始化电池状态
  1872. updateBatteryStatus();
  1873. })();
  1874. })();
  1875. (function apps() {
  1876. document
  1877. .querySelector("taskbar-container bar-space .app-launcher")
  1878. .addEventListener("click", async () => {
  1879. try {
  1880. const launcherPath = "../../../packages/pageos-app-launcher/";
  1881. const response = await fetch(launcherPath + "versions.txt");
  1882. const versions = await response.text();
  1883. const version = versions.split("\n").pop();
  1884. const iframe = document.createElement("iframe");
  1885. iframe.style.cssText =
  1886. "width: 100%; height: 100%; border: none;";
  1887. iframe.src = `${launcherPath + version}/index.html`;
  1888. // 监听菜单 iframe 加载完成事件
  1889. iframe.addEventListener("load", function () {
  1890. // 获取 iframe 内部文档对象
  1891. const iframeDoc =
  1892. iframe.contentDocument || iframe.contentWindow.document;
  1893. // 初始化右键菜单
  1894. // initOptionMenu(iframeDoc);
  1895. // TODO: 翻译 iframe 内部文档元素
  1896. // 在 iframe 内部文档上绑定点击事件
  1897. iframeDoc.addEventListener("click", async function (event) {
  1898. const anchor = event.target.closest(
  1899. 'a[data-pageos="app"]'
  1900. );
  1901. if (
  1902. anchor &&
  1903. anchor.href &&
  1904. anchor.href.endsWith("metadata.json")
  1905. ) {
  1906. try {
  1907. event.preventDefault();
  1908. const response = await fetch(anchor.href);
  1909. const metadata = await response.json();
  1910. const newIframe = document.createElement("iframe");
  1911. newIframe.style.cssText =
  1912. "width: 100%; height: 100%; border: none;";
  1913. newIframe.src = new URL(
  1914. metadata.entry,
  1915. anchor.href
  1916. ).href;
  1917. // newIframe.addEventListener("load", function () {
  1918. // // 获取 iframe 内部文档对象
  1919. // const newIframeDoc =
  1920. // newIframe.contentDocument ||
  1921. // newIframe.contentWindow.document;
  1922. // });
  1923. application(metadata.id, [
  1924. {
  1925. icon: metadata.icon
  1926. ? `<img src="${
  1927. new URL(metadata.icon, anchor.href).href
  1928. }" />`
  1929. : metadata.id[0],
  1930. title: metadata.name,
  1931. width: window.innerWidth * 0.6,
  1932. height: window.innerHeight * 0.6,
  1933. x: window.innerWidth * 0.2,
  1934. y: window.innerHeight * 0.2,
  1935. tabs: [
  1936. {
  1937. css: { padding: 0 },
  1938. title: metadata.name,
  1939. content: newIframe,
  1940. },
  1941. ],
  1942. },
  1943. ]);
  1944. } catch (error) {
  1945. console.error("加载 metadata.json 失败:", error);
  1946. }
  1947. }
  1948. });
  1949. });
  1950. application("pageos-app-launcher", [
  1951. {
  1952. icon: `<img src="${
  1953. launcherPath + version
  1954. }/assets/icon.svg" />`,
  1955. title: "应用程序启动器",
  1956. width:
  1957. window.innerWidth * 0.9 > 1024
  1958. ? 1024
  1959. : window.innerWidth * 0.9,
  1960. height: window.innerHeight * 0.6,
  1961. x:
  1962. (window.innerWidth -
  1963. (window.innerWidth * 0.9 > 1024
  1964. ? 1024
  1965. : window.innerWidth * 0.9)) *
  1966. 0.5,
  1967. y: window.innerHeight * 0.25,
  1968. tabs: [
  1969. {
  1970. css: { padding: 0 },
  1971. title: "应用程序启动器",
  1972. content: iframe,
  1973. },
  1974. ],
  1975. },
  1976. ]);
  1977. } catch (e) {
  1978. d = document.createElement("div");
  1979. p0 = document.createElement("p");
  1980. p0.innerText = "启动程序启动器时出错:";
  1981. p1 = document.createElement("p");
  1982. p1.classList.add("error");
  1983. p1.innerText = e;
  1984. p2 = document.createElement("p");
  1985. p2.innerText = "建议检查当前页面是否在 PageOS 环境下运行。";
  1986. d.appendChild(p0);
  1987. d.appendChild(p1);
  1988. d.appendChild(p2);
  1989. application("error", [
  1990. {
  1991. title: "启动失败",
  1992. tabs: [
  1993. {
  1994. title: "提示",
  1995. content: d,
  1996. },
  1997. ],
  1998. },
  1999. ]);
  2000. }
  2001. });
  2002. })();
  2003. })();
  2004. })();
  2005. </script>
  2006. </body>
  2007. </html>