mobile.system 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689
  1. <html>
  2. <head>
  3. <title>ArozOS Mobile</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="manifest" href="manifest.webmanifest">
  7. <link rel="stylesheet" href="script/semantic/semantic.css">
  8. <link rel="stylesheet" href="script/ao.css">
  9. <script type="text/javascript" src="script/jquery.min.js"></script>
  10. <script type="text/javascript" src="script/semantic/semantic.js"></script>
  11. <script type="text/javascript" src="script/ao_module.js"></script>
  12. <script type="text/javascript" src="./script/applocale.js"></script>
  13. <style>
  14. body{
  15. height: 100%;
  16. }
  17. .themeColor{
  18. background-color:#1c1c1c;
  19. }
  20. .taskBar{
  21. position:fixed;
  22. top:0px;
  23. left:0px;
  24. width:30px;
  25. height:100%;
  26. overflow: visible !important;
  27. z-index:999;
  28. }
  29. #mainFrame{
  30. width: calc(100% - 30px);
  31. position:fixed;
  32. top:0px;
  33. right:0px;
  34. overflow: hidden;
  35. }
  36. .toggleTaskBar{
  37. position:absolute;
  38. bottom:0px;
  39. right:0px;
  40. margin-right:-20px;
  41. width:30px;
  42. height:90px;
  43. border-radius: 0px 10px 10px 0px;
  44. }
  45. #listMenu{
  46. z-index:1000;
  47. position:fixed;
  48. top:0px;
  49. left:0px;
  50. width:100%;
  51. height:100%;
  52. padding:12px;
  53. background-color: #fcffff;
  54. box-shadow: 3px 3px 5px 0px rgba(207, 207, 207, 0.37);
  55. }
  56. #listMenu .searchBar {
  57. width: 100%;
  58. border-bottom: 2px solid #34b7eb;
  59. }
  60. #listMenu .listItemWrapper {
  61. overflow: hidden;
  62. }
  63. #listMenu .listItemWrapper .groups {
  64. background-color: #f5f5f5;
  65. width: 120px;
  66. height: calc(100% - 40px);
  67. display: inline-block;
  68. overflow-y: auto;
  69. padding-top: 8px;
  70. }
  71. #listMenu .listItemWrapper .groups .item {
  72. padding-left: 7px;
  73. padding-bottom: 6px;
  74. padding-top: 6px;
  75. cursor: pointer;
  76. }
  77. #listMenu .listItemWrapper .groups .item.selected {
  78. color: #34b7eb;
  79. }
  80. #listMenu .listItemWrapper .groups .item:hover {
  81. background-color: #dedede;
  82. }
  83. #listMenuItem{
  84. width: calc(100% - 130px) !important;
  85. float: right;
  86. overflow-y: auto;
  87. height: calc(100% - 40px) !important;
  88. }
  89. #listMenuItem img{
  90. width: 50px;
  91. }
  92. .module.item{
  93. padding:8px;
  94. }
  95. .hideListMenuButton{
  96. position: absolute;
  97. bottom:22px;
  98. left:32px;
  99. cursor:pointer;
  100. }
  101. .hideListMenuButton img{
  102. left:12px;
  103. width:50px;
  104. }
  105. .listMenuLauncher{
  106. position:absolute;
  107. bottom:12px;
  108. left:12px;
  109. }
  110. .listMenuLauncher .functionbtn{
  111. cursor:pointer;
  112. }
  113. .blurred{
  114. filter: blur(3px);
  115. }
  116. #backdrop {
  117. background-repeat: no-repeat;
  118. background-size: cover;
  119. background-position: center;
  120. background-image: url('img/desktop/bg/init.jpg');
  121. width: 100%;
  122. height: 100%;
  123. overflow-x: hidden;
  124. pointer-events: none;
  125. }
  126. #windowButtonWrapper{
  127. padding-top:6px;
  128. }
  129. .floatWindowButton{
  130. padding: 5px;
  131. }
  132. .floatWindowButton .minimizedIcon{
  133. width: 20px;
  134. height:20px;
  135. }
  136. .floatWindowButton .normalElements{
  137. padding:8px;
  138. border-bottom: 1px solid #4a4a4a;
  139. cursor:pointer;
  140. vertical-align:middle;
  141. position: relative;
  142. }
  143. .floatWindowButton .normalizedIcon{
  144. width:40;
  145. height:40px;
  146. margin-right:12px;
  147. }
  148. .normalElements .windowTitle{
  149. display:inline-block;
  150. width:200px !important;
  151. vertical-align:middle;
  152. white-space: nowrap;
  153. overflow: hidden;
  154. text-overflow: ellipsis;
  155. }
  156. .fwtab{
  157. position: absolute;
  158. top:0px;
  159. right: 0px;
  160. width: 100%;
  161. height: 100%;
  162. }
  163. #windowWrapper{
  164. height: 100%;
  165. width: 100%;
  166. position: absolute;
  167. top:0px;
  168. right:0px;
  169. }
  170. .floatWindowWrapper{
  171. width: 100%;
  172. height: 100%;
  173. }
  174. .floatWindow{
  175. width: 100%;
  176. height: 100%;
  177. position: absolute;
  178. }
  179. .fwtab iframe{
  180. border: 0px solid transparent;
  181. height: 100%;
  182. }
  183. .floatWindowButton .closebutton{
  184. position: absolute;
  185. font-size: 120%;
  186. color:white;
  187. right: 0em;
  188. top: 0px;
  189. margin-top: -8px;
  190. margin-left: -4px;
  191. padding: 3px;
  192. }
  193. .floatWindowButton .externalbutton{
  194. position: absolute;
  195. font-size: 120%;
  196. color:white;
  197. right: 1.6em;
  198. top: 0px;
  199. margin-top: -8px;
  200. margin-left: -4px;
  201. padding: 3px;
  202. }
  203. #conndrop{
  204. padding: 0.5em;
  205. position: fixed;
  206. top: 0px;
  207. right: 0px;
  208. z-index: 115;
  209. width: 100px;
  210. display: none;
  211. justify-content: flex-end;
  212. pointer-events: none;
  213. }
  214. .extendOnly{
  215. display:none;
  216. }
  217. /* Magic css to make the connection logo blink */
  218. @-moz-keyframes blink {
  219. 0% {
  220. opacity:1;
  221. }
  222. 50% {
  223. opacity:0;
  224. }
  225. 100% {
  226. opacity:1;
  227. }
  228. }
  229. @-webkit-keyframes blink {
  230. 0% {
  231. opacity:1;
  232. }
  233. 50% {
  234. opacity:0;
  235. }
  236. 100% {
  237. opacity:1;
  238. }
  239. }
  240. /* IE */
  241. @-ms-keyframes blink {
  242. 0% {
  243. opacity:1;
  244. }
  245. 50% {
  246. opacity:0;
  247. }
  248. 100% {
  249. opacity:1;
  250. }
  251. }
  252. /* Opera and prob css3 final iteration */
  253. @keyframes blink {
  254. 0% {
  255. opacity:1;
  256. }
  257. 50% {
  258. opacity:0;
  259. }
  260. 100% {
  261. opacity:1;
  262. }
  263. }
  264. .blink-image {
  265. -moz-animation: blink normal 2s infinite ease-in-out; /* Firefox */
  266. -webkit-animation: blink normal 2s infinite ease-in-out; /* Webkit */
  267. -ms-animation: blink normal 2s infinite ease-in-out; /* IE */
  268. animation: blink normal 2s infinite ease-in-out; /* Opera and prob css3 final iteration */
  269. }
  270. #sidebarToggleOverlay{
  271. width: 100%;
  272. height: 100%;
  273. z-index: 995;
  274. position: fixed;
  275. top:0px;
  276. left:0px;
  277. display:none;
  278. }
  279. #userprofile{
  280. z-index: 90;
  281. position: fixed;
  282. top: 0px;
  283. left: 3em;
  284. right: 3em;
  285. background-color: rgba(255,255,255,0.95);
  286. backdrop-filter: blur(4px);
  287. border-bottom-left-radius: 20px;
  288. border-bottom-right-radius: 20px;
  289. padding-left: 1.2em;
  290. padding-right: 1.2em;
  291. padding-top: 1.2em;
  292. display:none;
  293. box-shadow: 6px 8px 5px 2px rgba(0,0,0,0.2);
  294. -webkit-box-shadow: 6px 8px 5px 2px rgba(0,0,0,0.2);
  295. -moz-box-shadow: 6px 8px 5px 2px rgba(0,0,0,0.2);
  296. }
  297. .clock{
  298. position: fixed;
  299. left: 0px;
  300. width: 100%;
  301. top: 0px;
  302. padding-top: 0.3em;
  303. padding-bottom: 0.7em;
  304. color: white;
  305. text-align: center;
  306. pointer-events: none;
  307. background: rgb(255,255,255);
  308. background: linear-gradient(0deg, rgba(255,255,255,0) 2%, rgba(6,6,6,0.4479635060791801) 44%, rgba(29,29,29,1) 100%);
  309. }
  310. #shortcuts{
  311. position: absolute;
  312. bottom: 0px;
  313. right: 0px;
  314. width: calc(100% - 20px);
  315. padding: 1em;
  316. }
  317. #shortcuts .clickable.image{
  318. cursor: pointer;
  319. border-radius: 10px;
  320. padding: 0.1em;
  321. }
  322. .disabled{
  323. pointer-events: none;
  324. }
  325. #alternativeAccountList{
  326. padding-bottom: 0.6em;
  327. }
  328. .alternativeAccount{
  329. padding-top: 0.6em !important;
  330. padding-bottom: 0.6em !important;
  331. margin: 0;
  332. }
  333. .alternativeAccount .usericon{
  334. width: 35px !important;
  335. }
  336. .alternativeAccount .username{
  337. font-weight: 400;
  338. }
  339. </style>
  340. </head>
  341. <body>
  342. <div class="taskBar themeColor" >
  343. <div class="toggleTaskBar themeColor" shown="false" onclick="toggleTaskBar(this);">
  344. <img class="ui image sidebararrow" style="margin-top:8px; margin-left: -10px;" src="img/mobile/keyboard_arrow_right-white-48dp.svg"></img>
  345. </div>
  346. <div class="listMenuLauncher">
  347. <img onclick="showListMenu();" class="functionbtn" src="img/mobile/apps-white-48dp.svg" style="width: 30px;"/>
  348. <img onclick="showProfileInfo();" class="functionbtn extendOnly" src="img/mobile/account_circle_white_48dp.svg" style="width: 30px;"/>
  349. <img onclick="openDesktopCustomization();" class="functionbtn extendOnly" src="img/mobile/palette_white_48dp.svg" style="width: 30px;"/>
  350. <img onclick="openDesktopAsFolder();" class="functionbtn extendOnly" src="img/mobile/folder_open_white_24dp.svg" style="width: 30px;"/>
  351. <img onclick="fullscreen();" class="functionbtn extendOnly" src="img/mobile/fullscreen_white_48dp.svg" style="width: 30px;"/>
  352. <img onclick="openSystemSettings();" class="functionbtn extendOnly" src="img/mobile/tune_white_24dp.svg" style="width: 30px;"/>
  353. <img onclick="showDesktop();" class="functionbtn extendOnly" src="img/mobile/layers_clear_white_48dp.svg" style="width: 30px;"/>
  354. </div>
  355. <div id="windowButtonWrapper">
  356. </div>
  357. </div>
  358. <div id="userprofile">
  359. <div class="ui minimal comments">
  360. <div class="ui comment">
  361. <div class="avatar" style="height: 2.5em">
  362. <img class="usericon" src="img/desktop/system_icon/user.svg">
  363. </div>
  364. <div class="content">
  365. <dic class="author" id="username" style="font-weight: 600 !important;">User</dic>
  366. <div class="text" id="usergroups" style="color: #616162;">@user</div>
  367. </div>
  368. </div>
  369. </div>
  370. <div class="ui divider"></div>
  371. <div id="alternativeAccountList">
  372. </div>
  373. <div class="ui fluid basic button" style="" onclick="openSwitchAccountPanel(); toggleProfileInfo();">
  374. <i class="ui blue user plus icon" style="margin-right: 0.6em;"></i> <span locale="account/switch/addAccount">Add another account</span>
  375. </div>
  376. <div id="signoutAllButton" style="margin-top: 0.6em; margin-bottom: 1.2em;" class="ui fluid basic black button" onclick="logoutAllAccounts();">
  377. <i class="log out icon icon" style="margin-right: 0.6em;"></i> <span locale="account/switch/signoutAll">Sign-out all accounts</span>
  378. </div>
  379. <button locale="quickAccess/logout" onclick="logout();" class="ui basic blue mini button" style="position: absolute; top: 1em; right: 1em;">Logout</button>
  380. <button onclick="toggleProfileInfo();" class="circular ui themecolor icon button" style="position: absolute; bottom: 0px; right: 0px; margin-bottom: -10px; margin-right: -10px; color: white;">
  381. <i class="remove icon"></i>
  382. </button>
  383. </div>
  384. <div id="listMenu" style="left:-100%;">
  385. <div class="searchBar" onkeydown="searchModule(event);">
  386. <div class="ui icon fluid input" style="border-radius: 0px !important;">
  387. <input id="searchBar" type="text" placeholder="Search">
  388. <i class="search icon"></i>
  389. </div>
  390. </div>
  391. <dib class="listItemWrapper">
  392. <div class="groups">
  393. <div locale="listmenu/catergory/searchResults" id="searchResults" class="item" style="display:none;">Search Results</div>
  394. <div locale="listmenu/catergory/all" class="item groupType selected" group="All">All</div>
  395. <div locale="listmenu/catergory/media" class="item groupType" group="Media">Media</div>
  396. <div locale="listmenu/catergory/office" class="item groupType" group="Office">Office</div>
  397. <div locale="listmenu/catergory/download" class="item groupType" group="Download">Download</div>
  398. <div locale="listmenu/catergory/files" class="item groupType" group="Files">Files</div>
  399. <div locale="listmenu/catergory/internet" class="item groupType" group="Internet">Internet</div>
  400. <div locale="listmenu/catergory/settings" class="item groupType" group="System Settings">System Settings</div>
  401. <div locale="listmenu/catergory/tools" class="item groupType" group="System Tools">System Tools</div>
  402. <div locale="listmenu/catergory/utils" class="item groupType" group="Utilities">Utilities</div>
  403. <div locale="listmenu/catergory/other" class="item groupType" group="Other">Other</div>
  404. <div class="hideListMenuButton" onclick="closeListMenu();">
  405. <img class="ui image" src="img/mobile/cancel-black-48dp.svg"></img>
  406. </div>
  407. </div>
  408. <div id="listMenuItem" class="items" align="left">
  409. </div>
  410. </div>
  411. </div>
  412. <div id="mainFrame">
  413. <div id="backdrop">
  414. </div>
  415. <div class="clock">
  416. ArozOS Desktop
  417. </div>
  418. <div id="windowWrapper">
  419. </div>
  420. <div id="shortcuts">
  421. <!-- System Shortcuts -->
  422. <div class="ui divider"></div>
  423. <div class="ui four column grid">
  424. <div class="column">
  425. <img id="shortcut1" module="" onclick="launchThisModule(this);" class="ui medium clickable image" src="img/mobile/pending.svg">
  426. </div>
  427. <div class="column">
  428. <img id="shortcut2" module="" onclick="launchThisModule(this);" class="ui medium clickable image" src="img/mobile/pending.svg">
  429. </div>
  430. <div class="column">
  431. <img id="shortcut3" module="" onclick="launchThisModule(this);" class="ui medium clickable image" src="img/mobile/pending.svg">
  432. </div>
  433. <div class="column">
  434. <img id="shortcut4" module="" onclick="launchThisModule(this);" class="ui medium clickable image" src="img/mobile/pending.svg">
  435. </div>
  436. </div>
  437. </div>
  438. <div id="conndrop">
  439. <img class="ui mini image blink-image" src="SystemAO/desktop/icons/connlost.svg">
  440. </div>
  441. </div>
  442. <div id="sidebarToggleOverlay"></div>
  443. <script>
  444. /*
  445. ArOZ Online Mobile Interfacae
  446. This script must maintain compatibility to the desktop.system interface
  447. regarding all cross iframe access functions.
  448. */
  449. var isDesktopMode = true; //Try to emulate Desktop mode
  450. var moduleInstalled = []; //List of installed modules on the system
  451. var desktopThemeList = []; //List of themes installed, same as desktop theme
  452. var listMenuShown = false;
  453. var hostInfo;
  454. //IME mockup
  455. window.ime = null;
  456. //Clock related
  457. var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  458. var daysNames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  459. //initiation Functions
  460. initHostInfo();
  461. initModuleList();
  462. bindGroupTypeEvents();
  463. initBackdropImage();
  464. initUserDefinedThemeColor();
  465. bindBackgroundClickActions();
  466. initStartupSounds();
  467. initDesktopUserInfo();
  468. initShortcuts();
  469. //Bind background click
  470. function bindBackgroundClickActions(){
  471. $("#mainFrame").on("touchstart click", function(evt){
  472. if ($(this).hasClass("blurred") && $(".taskBar").find(".toggleTaskBar").attr("shown") == "true"){
  473. //hide the taskbar
  474. hideTaskBar();
  475. }
  476. });
  477. $("#sidebarToggleOverlay").on("touchstart click", function(evt){
  478. if ($(".taskBar").find(".toggleTaskBar").attr("shown") == "true"){
  479. //hide the taskbar
  480. evt.preventDefault();
  481. hideTaskBar();
  482. }
  483. });
  484. }
  485. //Check and prepare localization
  486. if (applocale){
  487. //Applocale found. Do localization
  488. applocale.init("./SystemAO/locale/desktop.json", function(){
  489. applocale.translate();
  490. });
  491. }else{
  492. //Applocale not found. Is this a trim down version of ArozOS?
  493. var applocale = {
  494. getString: function(key, original){
  495. return original;
  496. }
  497. }
  498. }
  499. //Connection check
  500. setInterval(function() {
  501. $.ajax({
  502. url: 'system/auth/checkLogin',
  503. success: function(data) {
  504. if (data == true) {
  505. //Continue session
  506. } else {
  507. //Session timeout. Redirect to system index
  508. window.location.href = "index.html";
  509. }
  510. $("#conndrop").hide();
  511. $("#conndrop").css("display", "none");
  512. },
  513. error: function(evt) {
  514. //Server closed or freezed?
  515. $("#conndrop").show();
  516. $("#conndrop").css("display", "flex");
  517. },
  518. timeout: 15000
  519. });
  520. }, 15000);
  521. //Initiate the host information
  522. function initHostInfo(){
  523. $.get("system/desktop/host",function(data){
  524. hostInfo = data;
  525. document.title = hostInfo.Hostname;
  526. });
  527. }
  528. //Initialize background image
  529. function initBackdropImage(){
  530. $.get("system/desktop/theme", function(data) {
  531. //Return a list of theme stored on the system
  532. desktopThemeList = data;
  533. $.get("system/desktop/theme?get=true", function(data) {
  534. //Get the user theme settings
  535. changeDesktopTheme(data);
  536. });
  537. });
  538. }
  539. function initUserDefinedThemeColor(){
  540. $.ajax({
  541. url: "system/desktop/preference",
  542. data: {preference: "themecolor"},
  543. method: "POST",
  544. success: function(data){
  545. console.log(data);
  546. if (data.error == undefined && data != ""){
  547. setThemeColor(data);
  548. }
  549. }
  550. });
  551. }
  552. function changeDesktopTheme(themename){
  553. //Match the given theme to the themename
  554. if (themename.includes(":/") == false){
  555. //This is a path
  556. for (var i =0; i < desktopThemeList.length ; i++){
  557. if (desktopThemeList[i].Theme == themename){
  558. var targetImage = desktopThemeList[i].Bglist[0];
  559. $("#backdrop").css("background-image", `url(img/desktop/bg/${themename}/${targetImage})`)
  560. }
  561. }
  562. }else{
  563. //This is a path (user defined background folder)
  564. $.get("system/desktop/theme?load=" + themename, function(data){
  565. if (data.error !== undefined){
  566. //The folder is gone. Use default instead
  567. console.log(data.error);
  568. changeDesktopTheme("default");
  569. }else{
  570. $("#backdrop").css("background-image", `url(media/?file=${data[0]})`)
  571. }
  572. });
  573. }
  574. }
  575. function toggleFullScreen() {
  576. var doc = window.document;
  577. var docEl = doc.documentElement;
  578. var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
  579. var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;
  580. if(!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
  581. requestFullScreen.call(docEl);
  582. }
  583. else {
  584. cancelFullScreen.call(doc);
  585. }
  586. }
  587. //Sidebar
  588. function toggleTaskBar(obj){
  589. if ($(obj).attr("shown") == "true"){
  590. hideTaskBar();
  591. }else{
  592. showTaskBar();
  593. }
  594. }
  595. function hideTaskBar(){
  596. //Hide the taskBar
  597. $(".taskBar").animate({
  598. width: "30px"
  599. },300, "swing");
  600. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_right-white-48dp.svg");
  601. $(".taskBar").find(".toggleTaskBar").attr("shown","false");
  602. $("#mainFrame").removeClass("blurred");
  603. //Minimize all fwbuttons
  604. $(".floatWindowButton").each(function(){
  605. $(this).find(".minimizedElements").show();
  606. $(this).find(".normalElements").hide();
  607. });
  608. $("#sidebarToggleOverlay").hide();
  609. $(".extendOnly").slideUp("fast");
  610. //Check the number of floatWindow
  611. if ($(".floatWindowWrapper").length == 0){
  612. //Reaching desktop layer
  613. showShortcuts();
  614. }else{
  615. //Check if all float windows are hidden
  616. var allHidden = $(".floatWindowWrapper").is(":hidden");
  617. if (!allHidden){
  618. hideShortcuts();
  619. }
  620. }
  621. }
  622. function showTaskBar(){
  623. //Show the taskbar
  624. $(".taskBar").animate({
  625. width: "300px"
  626. }, 300, "swing", function(){
  627. //Switch all fwbuttons to normal size
  628. $(".floatWindowButton").each(function(){
  629. $(this).find(".minimizedElements").hide();
  630. $(this).find(".normalElements").show();
  631. });
  632. $(".extendOnly").slideDown("fast");
  633. });
  634. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_left-white-48dp.svg");
  635. $(".taskBar").find(".toggleTaskBar").attr("shown","true");
  636. $("#mainFrame").addClass("blurred");
  637. $("#sidebarToggleOverlay").show();
  638. }
  639. //List all modules
  640. function initModuleList(){
  641. $.ajax({
  642. url: "system/modules/list",
  643. success: function(data) {
  644. moduleInstalled = data;
  645. listModulesType("All");
  646. }
  647. });
  648. }
  649. //ListMenu group classification events
  650. function bindGroupTypeEvents(){
  651. $(".groupType").on("click",function(evt){
  652. //Clear all serach results
  653. $("#searchResults").slideUp('fast');
  654. listModulesType($(this).attr("group"));
  655. $(".groupType.selected").removeClass("selected");
  656. $(this).addClass("selected");
  657. /*
  658. var classificationObject = this;
  659. if ($(this).attr("group") == "All"){
  660. $('.item.module').show();
  661. } else if ($(this).attr("group") == "Other"){
  662. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilties"];
  663. $('.item.module').each(function(){
  664. if (excludeList.includes($(this).attr("group")) == false){
  665. $(this).show();
  666. }else{
  667. $(this).hide();
  668. }
  669. });
  670. }else{
  671. $('.item.module').each(function(){
  672. if ($(this).attr("group") == $(classificationObject).attr("group")){
  673. $(this).show();
  674. }else{
  675. $(this).hide();
  676. }
  677. });
  678. }
  679. */
  680. });
  681. }
  682. function searchModule(event) {
  683. if (event.which == 13) {
  684. var keyword = $("#searchBar").val().toLowerCase();
  685. var results = [];
  686. var lessAccurateResults = [];
  687. $(".groupType.selected").removeClass("selected");
  688. $("#searchResults").addClass("selected").slideDown('fast');
  689. //Load all search results
  690. for (var i = 0; i < moduleInstalled.length; i++) {
  691. var thisModule = moduleInstalled[i];
  692. var pathInfo = thisModule["StartDir"].split("/");
  693. for (var j = 0; j < pathInfo.length; j++) {
  694. pathInfo[j] = pathInfo[j].toLowerCase();
  695. }
  696. if (thisModule["Name"].toLowerCase().includes(keyword)) {
  697. results.push(thisModule);
  698. } else if (pathInfo.includes(keyword.toLowerCase()) || pathInfo.includes(keyword.split(" ").join("_").toLowerCase())) {
  699. lessAccurateResults.push(thisModule);
  700. }
  701. }
  702. results = results.concat(lessAccurateResults);
  703. //Append the results to list
  704. $("#listMenuItem").html("");
  705. for (var i = 0; i < results.length; i++) {
  706. generateListMenuItem(results[i]);
  707. }
  708. if (results.length == 0) {
  709. //Append a custom no results div to the content
  710. $("#listMenuItem").append(`<div class="item module"><span><img class="ui middle aligned tiny image" src="img/system/not found.png" style="padding-right: 12px;">No Results</span></div>`);
  711. }
  712. }
  713. }
  714. function listModulesType(groupType) {
  715. var listingItems = [];
  716. if (groupType == "All") {
  717. //List all of the items
  718. for (var i = 0; i < moduleInstalled.length; i++) {
  719. if (moduleInstalled[i]["StartDir"] != "") {
  720. listingItems.push(moduleInstalled[i]);
  721. }
  722. }
  723. } else if (groupType == "Other") {
  724. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilties"];
  725. //List the Other groups
  726. for (var i = 0; i < moduleInstalled.length; i++) {
  727. if (excludeList.includes(moduleInstalled[i]["Group"]) == false && moduleInstalled[i]["StartDir"] != "") {
  728. listingItems.push(moduleInstalled[i]);
  729. }
  730. }
  731. } else {
  732. //List the given group
  733. for (var i = 0; i < moduleInstalled.length; i++) {
  734. if (moduleInstalled[i]["Group"] == groupType && moduleInstalled[i]["StartDir"] != "") {
  735. listingItems.push(moduleInstalled[i]);
  736. }
  737. }
  738. }
  739. //List the item to the listmenu
  740. $("#listMenuItem").html("");
  741. for (var i = 0; i < listingItems.length; i++) {
  742. var thisModule = listingItems[i];
  743. generateListMenuItem(thisModule);
  744. }
  745. if (listingItems.length == 0) {
  746. $("#listMenuItem").html(`<div class="item module"><span><img class="ui middle aligned tiny image" src="img/system/not found.png" style="padding-right: 12px;">No WebApp found</span></div>`)
  747. }
  748. }
  749. function generateListMenuItem(thisModule) {
  750. var icon = thisModule["IconPath"];
  751. if (icon == "") {
  752. //Use default system icon
  753. icon = "img/system/service.png";
  754. }
  755. var name = thisModule["Name"];
  756. var startdir = thisModule["StartDir"];
  757. var group = thisModule["Group"];
  758. var fwsupport = "false";
  759. if (thisModule["SupportFW"]) {
  760. fwsupport = "true";
  761. }
  762. $("#listMenuItem").append(`<div class="item module" module="${name}" startdir="${startdir}" fw="${fwsupport}" group="${group}" onclick="openModuleFromMenu(this);">
  763. <span>
  764. <img class="ui middle aligned tiny image" src="${icon}" style="padding-right: 12px;"></img>
  765. ${name}
  766. </span>
  767. </div>`);
  768. }
  769. function closeListMenu(callback = undefined){
  770. if (listMenuShown == false){
  771. //Already closed
  772. if (typeof callback != "undefined"){
  773. callback();
  774. }
  775. return;
  776. }
  777. $("#listMenu").animate({
  778. left: window.innerWidth * -1
  779. },300,"swing", function(){
  780. $(".taskBar").animate({
  781. width: "300px",
  782. },300,"swing", function(){
  783. if (typeof callback != "undefined"){
  784. callback();
  785. }else{
  786. $(".extendOnly").slideDown("fast");
  787. }
  788. });
  789. });
  790. listMenuShown = false;
  791. }
  792. //Bind swip events
  793. document.addEventListener('touchstart', handleTouchStart, false);
  794. document.addEventListener('touchmove', handleTouchMove, false);
  795. var xDown = null;
  796. var yDown = null;
  797. var swipeTarget = null;
  798. var targetType = "fw";
  799. function getTouches(evt) {
  800. return evt.touches || // browser API
  801. evt.originalEvent.touches; // jQuery
  802. }
  803. function handleTouchStart(evt) {
  804. const firstTouch = getTouches(evt)[0];
  805. if ($(evt.target).hasClass("taskBar")){
  806. swipeTarget = evt.target;
  807. targetType = "taskbar"
  808. }else if ($(evt.target).hasClass("toggleTaskBar")){
  809. }else{
  810. if (evt.path != undefined){
  811. swipeTarget = getFloatWindowObjectFromPath(evt.path);
  812. }
  813. }
  814. xDown = firstTouch.clientX;
  815. yDown = firstTouch.clientY;
  816. };
  817. function getFloatWindowObjectFromPath(path){
  818. var targetObject = undefined;
  819. targetType = undefined
  820. path.forEach(object => {
  821. if ($(object).hasClass("floatWindowButton")){
  822. targetObject = object
  823. targetType = "fw"
  824. }
  825. })
  826. return targetObject;
  827. }
  828. function handleTouchMove(evt) {
  829. if ( ! xDown || ! yDown ) {
  830. return;
  831. }
  832. var xUp = evt.touches[0].clientX;
  833. var yUp = evt.touches[0].clientY;
  834. var xDiff = xDown - xUp;
  835. var yDiff = yDown - yUp;
  836. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  837. if ( xDiff > 0 ) {
  838. /* left swipe */
  839. if (swipeTarget !== undefined && targetType == "fw"){
  840. closeFloatWindow($(swipeTarget).attr("windowId"));
  841. }else if (swipeTarget !== undefined && targetType == "taskbar"){
  842. hideTaskBar();
  843. }
  844. } else {
  845. /* right swipe */
  846. if (swipeTarget !== undefined && targetType == "fw"){
  847. //Allow left or right swipe to remove fw
  848. closeFloatWindow($(swipeTarget).attr("windowId"));
  849. }else if (swipeTarget !== undefined && targetType == "taskbar"){
  850. //Right swipe on taskbar
  851. if ($(swipeTarget).find(".toggleTaskBar").attr("shown") == "true"){
  852. //Already shown. Toggle list menu
  853. showListMenu();
  854. }else{
  855. showTaskBar();
  856. }
  857. }
  858. }
  859. } else {
  860. if ( yDiff > 0 ) {
  861. /* up swipe */
  862. } else {
  863. /* down swipe */
  864. }
  865. }
  866. /* reset values */
  867. xDown = null;
  868. yDown = null;
  869. swipeTarget = null;
  870. };
  871. function showListMenu(callback = undefined){
  872. if ($(".taskBar").find(".toggleTaskBar").attr("shown") == "false"){
  873. $(".taskBar").find(".toggleTaskBar").attr("shown", "true");
  874. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_left-white-48dp.svg");
  875. $("#mainFrame").addClass("blurred");
  876. }
  877. $(".taskBar").animate({
  878. width: window.innerWidth,
  879. },300, "swing", function(){
  880. //Switch all fwbuttons to normal size
  881. $(".floatWindowButton").each(function(){
  882. $(this).find(".minimizedElements").hide();
  883. $(this).find(".normalElements").show();
  884. });
  885. //Show list menu
  886. $("#listMenu").animate({
  887. left: 0
  888. },300,"swing", function(){
  889. if (typeof callback != "undefined"){
  890. callback();
  891. }
  892. });
  893. });
  894. listMenuShown = true;
  895. $("#sidebarToggleOverlay").show();
  896. }
  897. function openModule(moduleName) {
  898. $.get("system/modules/getLaunchPara?module=" + moduleName, function(data) {
  899. console.log(data);
  900. if (data.error !== undefined) {
  901. //Something went wrong.
  902. console.log("Unable to open module " + moduleName);
  903. if (data.error == "Not logged in."){
  904. //Session expired
  905. window.location.href = "login.system";
  906. }
  907. }else {
  908. //Launch the given module
  909. var url = data["StartDir"];
  910. var size = [undefined, undefined];
  911. var icon = "img/system/favicon.png";
  912. if (data["IconPath"] != "") {
  913. icon = data["IconPath"];
  914. }
  915. var title = data["Name"];
  916. //Check if the module support fw mode. If yes, launch with fwmode url. IF not, launch to index
  917. if (data["SupportFW"] == true) {
  918. if (data["LaunchFWDir"] != null) {
  919. url = data["LaunchFWDir"];
  920. }
  921. if (data["InitFWSize"] != null) {
  922. size = data["InitFWSize"];
  923. }
  924. }
  925. //Launch the given module
  926. newFloatWindow({
  927. url: url,
  928. width: size[0],
  929. height: size[1],
  930. appicon: icon,
  931. title: title
  932. });
  933. closeListMenu(function(){
  934. hideTaskBar();
  935. });
  936. }
  937. });
  938. }
  939. function openModuleFromMenu(object) {
  940. var moduleName = $(object).attr("module");
  941. openModule(moduleName);
  942. }
  943. //In mobile interface, there will be some option ignored by default
  944. function newFloatWindow(options){
  945. //Hide all other floatWindows
  946. $(".floatWindowWrapper").fadeOut("fast");
  947. //Hide shortcuts
  948. hideShortcuts();
  949. //Construct the new window
  950. var windowID = Date.now();
  951. var parent = options.parent || "";
  952. var callback = options.callback || "";
  953. //Create a new iframe
  954. $("#windowWrapper").append(` <div class="floatWindowWrapper" windowId="${windowID}">
  955. <div class="floatWindow" windowId="${windowID}" parent="${parent}" callback="${callback}">
  956. <div class="fwtab">
  957. <iframe src="${options.url}" style="width: 100%; height: 100%;"></iframe>
  958. </div>
  959. </div>
  960. </div>`);
  961. //Create the button
  962. var title = options.title || "New FloatWindow";
  963. $("#windowButtonWrapper").append(`
  964. <div class="floatWindowButton" windowID="${windowID}" onclick="focusTab(this)">
  965. <div class="minimizedElements">
  966. <img class="minimizedIcon" src="${options.appicon}">
  967. </div>
  968. <div class="normalElements" style="display:none;">
  969. <img class="ui normalizedIcon middle aligned image" src="${options.appicon}">
  970. <span class="windowTitle" style="color:white;">${title}</span>
  971. <div class="closebutton" onclick="closefw(this);"><i class="remove icon"></i></div>
  972. <div class="externalbutton" onclick="openfwInNewTab(this);"><i class="external icon"></i></div>
  973. </div>
  974. </div>
  975. `);
  976. }
  977. ///Functions realted to window resize and auto scaling
  978. function updateWindowDimensions(){
  979. $("#backdrop").css({
  980. width: window.innerWidth,
  981. height: window.innerHeight
  982. });
  983. if (!listMenuShown){
  984. $("#listMenu").css("left", window.innerWidth * -1);
  985. }
  986. }
  987. updateWindowDimensions();
  988. $(window).on("resize", function(data){
  989. updateWindowDimensions();
  990. })
  991. //Float Window APIs
  992. function setFloatWindowTitle(id, title){
  993. $(".floatWindowButton").each(function(){
  994. if ($(this).attr("windowId") == id){
  995. $(this).find(".windowTitle").text(title);
  996. }
  997. })
  998. }
  999. function getFloatWindowByID(id){
  1000. var targetObejct = undefined;
  1001. $(".floatWindowWrapper").each(function(){
  1002. if ($(this).attr("windowId") == id){
  1003. targetObejct = $(this);
  1004. }
  1005. });
  1006. return targetObejct;
  1007. }
  1008. function MoveFloatWindowToTop(targetfw){
  1009. //Check if this windows is already topped
  1010. if ($(targetfw).is(":visible")){
  1011. //Already topped
  1012. return;
  1013. }
  1014. $(".floatWindowWrapper").each(function(){
  1015. $(this).fadeOut("fast");
  1016. });
  1017. console.log(targetfw);
  1018. $(targetfw).parent().fadeIn("fast");
  1019. }
  1020. function focusTab(object){
  1021. var windowID = $(object).attr("windowId");
  1022. //Hide all other flowWindows
  1023. $(".floatWindowWrapper").fadeOut("fast");
  1024. //Show the target fw
  1025. var fw = getFloatWindowByID(windowID);
  1026. hideShortcuts();
  1027. fw.fadeIn("fast", function(){
  1028. hideTaskBar();
  1029. });
  1030. }
  1031. function getFloatWindowByID(id){
  1032. var targetObejct = undefined;
  1033. $(".floatWindowWrapper").each(function(){
  1034. if ($(this).attr("windowId") == id){
  1035. targetObejct = $(this);
  1036. }
  1037. });
  1038. return targetObejct;
  1039. }
  1040. function setFloatWindowResizePolicy(id, allowResize){
  1041. //Disabled in mobile mode
  1042. }
  1043. function setFloatWindowSize(id, width, height){
  1044. //Disabled in mobile mode
  1045. }
  1046. function closeFloatWindow(windowID){
  1047. //Get the content iframe with that windowID
  1048. var contentWindow = getFloatWindowByID(windowID);
  1049. if (contentWindow == undefined){
  1050. return;
  1051. }
  1052. contentWindow = contentWindow.find("iframe")[0].contentWindow;
  1053. try {
  1054. if (contentWindow.ao_module_close === undefined) {
  1055. //This module do not use ao_module wrapper. Close it directly.
  1056. closeFwProcess(windowID);
  1057. } else {
  1058. //Pass the closing events to the window itself
  1059. contentWindow.ao_module_close();
  1060. }
  1061. } catch (ex) {
  1062. //Problems of closing floatWindow. Force closing.
  1063. closeFwProcess(windowID);
  1064. }
  1065. }
  1066. function closefw(object){
  1067. var windowID = $(object).parent().parent().attr("windowID");
  1068. closeFloatWindow(windowID);
  1069. }
  1070. function openfwInNewTab(object){
  1071. event.preventDefault();
  1072. event.stopImmediatePropagation();
  1073. var windowID = $(object).parent().parent().attr("windowID");
  1074. var targetFloatWindow = null;
  1075. $(".floatWindowWrapper").each(function(){
  1076. if ($(this).attr("windowid") == windowID){
  1077. targetFloatWindow = $(this);
  1078. }
  1079. });
  1080. if (targetFloatWindow == null){
  1081. return;
  1082. }
  1083. var iframe = $(targetFloatWindow).find("iframe");
  1084. var url = $(iframe)[0].contentWindow.location.href;
  1085. window.open(url);
  1086. }
  1087. //Get the window below this window id, can return null if there is no window
  1088. function getPreviousWindowObject(windowID){
  1089. var previousWindowID = null;
  1090. var result = null;
  1091. $(".floatWindowButton").each(function(){
  1092. if ($(this).attr("windowid") == windowID){
  1093. result = previousWindowID;
  1094. }else{
  1095. let thisWindowID = $(this).attr("windowid");
  1096. previousWindowID = thisWindowID;
  1097. }
  1098. });
  1099. return result;
  1100. }
  1101. function closeFwProcess(windowID){
  1102. //Get the previous window object
  1103. var previousWindowID = getPreviousWindowObject(windowID);
  1104. //Remove the window object
  1105. $(".floatWindowWrapper").each(function(){
  1106. if ($(this).attr("windowId") == windowID){
  1107. $(this).fadeOut("fast",function(){
  1108. $(this).remove();
  1109. });
  1110. }
  1111. });
  1112. //Remove the button object
  1113. $(".floatWindowButton").each(function(){
  1114. if ($(this).attr("windowId") == windowID){
  1115. $(this).fadeOut("fast",function(){
  1116. $(this).remove();
  1117. });
  1118. }
  1119. });
  1120. //Focus the window behind if exists
  1121. setTimeout(function(){
  1122. if (previousWindowID != null){
  1123. //Hide all other flowWindows
  1124. $(".floatWindowWrapper").fadeOut("fast");
  1125. //Show the target fw
  1126. var fw = getFloatWindowByID(previousWindowID);
  1127. console.log(fw);
  1128. fw.fadeIn("fast", function(){
  1129. });
  1130. }
  1131. }, 100);
  1132. }
  1133. function bindObjectToIMEEvents(object){
  1134. console.log("IME not supported in mobile desktop mode")
  1135. };
  1136. function openFileWithModule(moduleLaunchInfo, openFileList) {
  1137. var url = moduleLaunchInfo["StartDir"];
  1138. var size = [undefined, undefined];
  1139. var title = moduleLaunchInfo["Name"];
  1140. var icon = "img/system/favicon.png";
  1141. if (moduleLaunchInfo["IconPath"] != "") {
  1142. icon = moduleLaunchInfo["IconPath"];
  1143. }
  1144. //Use floatWindow if exists
  1145. if (moduleLaunchInfo["SupportFW"] == true && moduleLaunchInfo["LaunchFWDir"] != "") {
  1146. url = moduleLaunchInfo["LaunchFWDir"];
  1147. if (moduleLaunchInfo["InitFWSize"] !== null) {
  1148. size = moduleLaunchInfo["InitFWSize"]
  1149. }
  1150. }
  1151. //Use embedded mode if exists
  1152. if (moduleLaunchInfo["SupportEmb"] == true && moduleLaunchInfo["LaunchEmb"] != "") {
  1153. url = moduleLaunchInfo["LaunchEmb"];
  1154. if (moduleLaunchInfo["InitEmbSize"] !== null) {
  1155. size = moduleLaunchInfo["InitEmbSize"]
  1156. }
  1157. }
  1158. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  1159. //Add launch files info and launch floatWindow
  1160. newFloatWindow({
  1161. url: url + "#" + openParamter,
  1162. width: size[0],
  1163. height: size[1],
  1164. appicon: icon,
  1165. title: title
  1166. });
  1167. }
  1168. //Mobile interface do not support pin function yet
  1169. function PinFloatWindowToTopMostMode(object){
  1170. }
  1171. function UnpinFloatWindowFromTopMostMode(object){
  1172. }
  1173. /*
  1174. List Menu Specific function groups
  1175. */
  1176. function openDesktopAsFolder(){
  1177. newFloatWindow({
  1178. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent("user:/Desktop/"),
  1179. appicon: "SystemAO/file_system/img/small_icon.png",
  1180. width:1080,
  1181. height:580,
  1182. title: "File Manager"
  1183. });
  1184. hideTaskBar();
  1185. }
  1186. function openDesktopCustomization(){
  1187. newFloatWindow({
  1188. url: "SystemAO/desktop/personalization.html",
  1189. appicon: "SystemAO/desktop/img/personalization.png",
  1190. width:640,
  1191. height:480,
  1192. title: "Personalization"
  1193. });
  1194. hideTaskBar();
  1195. }
  1196. function showDesktop(){
  1197. $(".floatWindowWrapper").fadeOut("fast");
  1198. hideTaskBar();
  1199. showShortcuts();
  1200. }
  1201. //Theme color placeholder functions
  1202. function setThemeColor(color){
  1203. $(".themeColor").css("background-color", color);
  1204. }
  1205. //Startup sound
  1206. function initStartupSounds(){
  1207. $.ajax({
  1208. url: "../../system/desktop/preference",
  1209. method: "POST",
  1210. data: {preference: "startup-audio"},
  1211. success: function(data){
  1212. if (data == undefined || data == ""){
  1213. return;
  1214. }
  1215. var currentGlobalVol = localStorage.getItem("global_volume");
  1216. if (currentGlobalVol != null && currentGlobalVol != undefined && currentGlobalVol != ""){
  1217. }else{
  1218. currentGlobalVol = 0;
  1219. }
  1220. var audio = new Audio("media?file=" + data);
  1221. audio.volume = currentGlobalVol;
  1222. audio.play();
  1223. }
  1224. });
  1225. }
  1226. function fullscreen() {
  1227. //Opening full screen will lead to hidden of all iframe for unknown reasons
  1228. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
  1229. (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
  1230. (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
  1231. (document.msFullscreenElement && document.msFullscreenElement !== null);
  1232. var elem = document.documentElement;
  1233. if (!isInFullScreen) {
  1234. if (elem.requestFullscreen) {
  1235. elem.requestFullscreen();
  1236. } else if (elem.mozRequestFullScreen) { /* Firefox */
  1237. elem.mozRequestFullScreen();
  1238. } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
  1239. elem.webkitRequestFullscreen();
  1240. } else if (elem.msRequestFullscreen) { /* IE/Edge */
  1241. elem.msRequestFullscreen();
  1242. }
  1243. } else {
  1244. if (document.exitFullscreen) {
  1245. document.exitFullscreen();
  1246. } else if (document.webkitExitFullscreen) {
  1247. document.webkitExitFullscreen();
  1248. } else if (document.mozCancelFullScreen) {
  1249. document.mozCancelFullScreen();
  1250. } else if (document.msExitFullscreen) {
  1251. document.msExitFullscreen();
  1252. }
  1253. }
  1254. hideTaskBar();
  1255. }
  1256. function initDesktopUserInfo(){
  1257. $.get("system/desktop/user", function(data){
  1258. if (data.error !== undefined){
  1259. alert(data.error);
  1260. }else{
  1261. userInfo = data;
  1262. //Update the user tag
  1263. $("#username").text(userInfo.Username);
  1264. $("#usergroups").text("@" + userInfo.UserGroups.join("/"));
  1265. $("#usergroups").attr("title",userInfo.UserGroups.join(" / "));
  1266. if (data.UserIcon !== ""){
  1267. $(".usericon").attr("src",data.UserIcon);
  1268. }
  1269. listAllStoredAccounts();
  1270. }
  1271. });
  1272. }
  1273. function showProfileInfo(){
  1274. hideTaskBar();
  1275. setTimeout(function(){
  1276. toggleProfileInfo();
  1277. }, 500);
  1278. }
  1279. function initShortcuts(){
  1280. initShortcut(1, $("#shortcut1"));
  1281. initShortcut(2, $("#shortcut2"));
  1282. initShortcut(3, $("#shortcut3"));
  1283. initShortcut(4, $("#shortcut4"));
  1284. }
  1285. function initShortcut(id, displayTarget){
  1286. getStorage("ao/mobile/shorcut/" + id, function(data){
  1287. if (data != ""){
  1288. $.get("system/modules/getLaunchPara?module=" + data, function(para){
  1289. displayTarget.attr("src", para.IconPath);
  1290. if (para.StartDir == ""){
  1291. displayTarget.addClass("disabled");
  1292. }else{
  1293. displayTarget.attr("module", encodeURIComponent(JSON.stringify(para.Name)));
  1294. }
  1295. });
  1296. }else{
  1297. //No data for this shortcut
  1298. displayTarget.attr("src", "img/desktop/system_icon/bad_shortcut.png");
  1299. displayTarget.addClass("disabled");
  1300. }
  1301. });
  1302. }
  1303. function showShortcuts(){
  1304. $("#shortcuts").slideDown("fast");
  1305. }
  1306. function hideShortcuts(){
  1307. $("#shortcuts").slideUp("fast");
  1308. }
  1309. function launchThisModule(object){
  1310. var moduleName = JSON.parse(decodeURIComponent($(object).attr("module")));
  1311. if (moduleName != ""){
  1312. openModule(moduleName);
  1313. }
  1314. }
  1315. function toggleProfileInfo(){
  1316. $("#userprofile").transition('drop');
  1317. }
  1318. function openSystemSettings(){
  1319. openModule("System Setting");
  1320. }
  1321. function logout() {
  1322. loggingOut = true;
  1323. if (confirm("Exiting Session. Confirm?")){
  1324. $.get("system/auth/logout", function() {
  1325. window.location.href = "/";
  1326. });
  1327. toggleProfileInfo();
  1328. }
  1329. }
  1330. function setStorage(key, value, callback = undefined) {
  1331. $.ajax({
  1332. url: "system/desktop/preference",
  1333. data: {preference: key, value: value},
  1334. method: "POST",
  1335. success: function(data) {
  1336. if (data.error !== undefined) {
  1337. console.log(data.error);
  1338. } else {
  1339. if (callback !== undefined) {
  1340. callback();
  1341. }
  1342. }
  1343. }
  1344. });
  1345. }
  1346. function getStorage(key, callback) {
  1347. $.ajax({
  1348. url: "system/desktop/preference",
  1349. data: {preference: key},
  1350. method: "POST",
  1351. success: callback
  1352. });
  1353. }
  1354. //Keep the clock updated
  1355. setInterval(function(){
  1356. updateClockTime();
  1357. },5000);
  1358. updateClockTime();
  1359. function updateClockTime(){
  1360. var d = new Date();
  1361. var display = monthNames[d.getMonth()] + " " + d.getDate() + " " + zeropad(d.getHours(),2) + ":" + zeropad(d.getMinutes(),2);
  1362. if ($(".notification.object").length > 0){
  1363. display += `<span style="color: #f54242; margin-left: 8px; float: center;"><i class="notice circle icon"></i></span>`;
  1364. }
  1365. $(".clock").html(display);
  1366. var largedate = monthNames[d.getMonth()] + " " + d.getDate() + " " + d.getFullYear()
  1367. $("#largedate").text(largedate);
  1368. var dow = daysNames[d.getDay()];
  1369. $("#dayofweek").text(dow);
  1370. }
  1371. function zeropad(n, width, z) {
  1372. z = z || '0';
  1373. n = n + '';
  1374. return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
  1375. }
  1376. /*
  1377. Account switching functions
  1378. */
  1379. function listAllStoredAccounts(){
  1380. $("#alternativeAccountList").empty();
  1381. //Request server side for the account pool
  1382. $.get("system/auth/u/list", function(data){
  1383. if (data.error != undefined){
  1384. $("#signoutAllButton").addClass('disabled');
  1385. $("#alternativeAccountList").append(`<div class="ui message">
  1386. <i class="ui green check circle icon"></i> ${applocale.getString("account/switch/noAlternative", "No other account stored on this browser")}
  1387. </div>`);
  1388. return;
  1389. }else{
  1390. if (data.length > 1){
  1391. data.forEach(function(account){
  1392. if (account.Username == userInfo.Username){
  1393. //Skip
  1394. return;
  1395. }
  1396. $.get("system/desktop/user?target=" + account.Username, function(data){
  1397. let userIcon = data.UserIcon;
  1398. if (userIcon == ""){
  1399. userIcon = "img/desktop/system_icon/user.svg"
  1400. }
  1401. $("#alternativeAccountList").append(`
  1402. <div class="alternativeAccount ${account.IsExpired?"expired":""}" acname="${account.Username}" onclick="switchAccount(this);">
  1403. <div class="ui header">
  1404. <img class="usericon" src="${userIcon}">
  1405. <div class="content" style="font-size: 95% !important;">
  1406. <span class="username">${account.Username}</span> ${(data.IsAdmin)?'<i style="margin-left: 0.4em; color: rgb(38, 50, 56);" class="small shield alternate icon themed text isAdminIcon"></i>':""}
  1407. <div class="sub header usergroup">${!account.IsExpired?"<i class='ui green check circle icon' style='margin-right: 0px;'></i> " + applocale.getString("account/switch/sessionValid", "Session Valid"):"<i class='ui red times circle icon' style='margin-right: 0px;'></i> " + applocale.getString("account/switch/sessionExpired", "Session Expired")}</div>
  1408. </div>
  1409. </div>
  1410. </div>
  1411. `);
  1412. });
  1413. });
  1414. $("#signoutAllButton").removeClass('disabled');
  1415. }else{
  1416. $("#signoutAllButton").addClass('disabled');
  1417. $("#alternativeAccountList").append(`<div class="ui message">
  1418. <i class="ui green check circle icon"></i> ${applocale.getString("account/switch/noAlternative", "No other account stored on this browser")}
  1419. </div>`);
  1420. return;
  1421. }
  1422. }
  1423. })
  1424. }
  1425. function switchAccount(object){
  1426. let targetUsername = $(object).attr("acname");
  1427. if (targetUsername == undefined || targetUsername == ""){
  1428. console.log("Unable to load username from element")
  1429. return;
  1430. }
  1431. //Check if it is expired
  1432. if ($(object).hasClass("expired")){
  1433. openSwitchAccountPanel();
  1434. return;
  1435. }
  1436. $.ajax({
  1437. url: "system/auth/u/switch",
  1438. data: {
  1439. "username": targetUsername,
  1440. },
  1441. success: function(data){
  1442. if (data.error != undefined){
  1443. alert(data.error);
  1444. }else{
  1445. window.location.reload();
  1446. }
  1447. }
  1448. })
  1449. }
  1450. function openSwitchAccountPanel(){
  1451. var uuid = newFloatWindow({
  1452. url: 'SystemAO/advance/switchAccount.html',
  1453. width: 470,
  1454. height: 680,
  1455. appicon: "SystemAO/desktop/img/account-switch.png",
  1456. title: "Switch Account"
  1457. });
  1458. }
  1459. function logoutAllAccounts(){
  1460. if (confirm(applocale.getString("account/switch/logout/confirm", "This will logout all other accounts from this browser. Confirm?"))){
  1461. $.ajax({
  1462. url: "system/auth/u/logoutAll",
  1463. success: function(data){
  1464. if (data.error != undefined){
  1465. alert(data.error);
  1466. }else{
  1467. //Reset the browser pool id
  1468. localStorage.removeItem("ao_acc");
  1469. listAllStoredAccounts();
  1470. toggleProfileInfo();
  1471. }
  1472. }
  1473. })
  1474. }
  1475. }
  1476. //mobile mode not support re-initialization. Refresh page.
  1477. function initDesktop(){
  1478. window.location.reload();
  1479. }
  1480. </script>
  1481. </body>
  1482. </html>