index.html 81 KB

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