index.html 82 KB

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