index.html 81 KB

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