desktop.system 202 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983
  1. <html>
  2. <head>
  3. <title>ArozOS Desktop</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="stylesheet" href="script/tocas/tocas.css">
  7. <link id="fwcss" rel="stylesheet" href="script/ao.css">
  8. <link rel="stylesheet" href="SystemAO/desktop/script/jsCalendar/source/jsCalendar.css">
  9. <script type="text/javascript" src="script/tocas/tocas.js"></script>
  10. <script type="text/javascript" src="script/jquery.min.js"></script>
  11. <script type="text/javascript" src="script/ao_module.js"></script>
  12. <script type="text/javascript" src="SystemAO/desktop/script/jsCalendar/source/jsCalendar.js"></script>
  13. <style>
  14. body {
  15. background-repeat: no-repeat;
  16. background-size: cover;
  17. background-position: center;
  18. background-image: url('img/desktop/bg/init.jpg');
  19. width: 100%;
  20. height: 100%;
  21. }
  22. .backgroundFrame {
  23. height: 100%;
  24. min-width: 100%;
  25. background-repeat: no-repeat;
  26. background-size: cover;
  27. border: 0px solid transparent;
  28. background-position: center;
  29. position: absolute;
  30. opacity: 0;
  31. top: 0;
  32. left: 0;
  33. -webkit-transition: opacity 2s ease-in-out;
  34. -moz-transition: opacity 2s ease-in-out;
  35. -o-transition: opacity 2s ease-in-out;
  36. transition: opacity 2s ease-in-out;
  37. }
  38. .background-wrapper {
  39. border: 0px solid transparent;
  40. overflow: hidden;
  41. width: 100%;
  42. height: 100%;
  43. position: fixed;
  44. left: 0px;
  45. top: 0px;
  46. user-select: none;
  47. -moz-user-select: none;
  48. -webkit-user-drag: none;
  49. -webkit-user-select: none;
  50. -ms-user-select: none;
  51. }
  52. .showBackground {
  53. opacity: 1;
  54. }
  55. .icon-wrapper {
  56. height: 100%;
  57. width: 100%;
  58. position: fixed;
  59. top: 0px;
  60. left: 0px;
  61. padding: 5px;
  62. }
  63. .launchIcon {
  64. position: fixed;
  65. cursor: pointer;
  66. padding: 2px;
  67. }
  68. .launchIconImage.small {
  69. width: 48px;
  70. height: 48px;
  71. }
  72. .launchIconImage.medium {
  73. width: 68px;
  74. height: 68px;
  75. }
  76. .launchIconImage.big {
  77. width: 82px;
  78. height: 82px;
  79. }
  80. .launchIconWrapper {
  81. height: 100%;
  82. width: 100%;
  83. border-radius: 3px;
  84. }
  85. .launchIconWrapper.selected {
  86. background: rgba(250, 250, 250, 0.4) !important;
  87. }
  88. .launchIconText {
  89. color: white;
  90. text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
  91. text-align: center;
  92. text-overflow: ellipsis;
  93. overflow: hidden;
  94. word-break: break-all;
  95. width: 100%;
  96. font-variant-numeric: tabular-nums lining-nums;
  97. }
  98. .launchIconWrapper:hover {
  99. background: rgba(250, 250, 250, 0.2);
  100. }
  101. .launchIconText.small {
  102. margin-top: -3px;
  103. font-size: 70%;
  104. line-height: 1.55em;
  105. /*
  106. Fixed the issue of text being trimmed off due to lineheight setting
  107. */
  108. font-family: sans-serif !important;
  109. }
  110. .launchIconText.medium {
  111. margin-top: -2px;
  112. font-size: 90%;
  113. line-height: 1.2em;
  114. }
  115. .launchIconText.big {
  116. margin-top: -6px;
  117. font-size: 110%;
  118. }
  119. .navimenu {
  120. position: fixed;
  121. z-index: 1110;
  122. width: 100%;
  123. height: 36px;
  124. left: 0px;
  125. bottom: 0px;
  126. padding-left: 8px;
  127. padding-right: 8px;
  128. }
  129. .themeColor {
  130. background-color: rgba(14,14,14,0.5);
  131. backdrop-filter: blur(4px);
  132. }
  133. .themeColorSolid{
  134. background-color: rgba(14,14,14,0.9);
  135. backdrop-filter: blur(4px);
  136. }
  137. .navimenu .item {
  138. height: 36px;
  139. display: inline-block;
  140. vertical-align: top;
  141. }
  142. .navimenu .item.padding {
  143. display: inline-block;
  144. width: 12px;
  145. }
  146. .navimenu .item.clickable:hover {
  147. background-color: rgba(250, 250, 250, 0.2);
  148. cursor: pointer;
  149. }
  150. /* Floatwindow control button related css*/
  151. .navimenu .item.floatWindowButton {
  152. padding: 8px;
  153. padding-top: 10px;
  154. vertical-align: top;
  155. width: 200px;
  156. overflow: hidden;
  157. font-size: 90%;
  158. text-overflow: ellipsis;
  159. white-space: nowrap;
  160. word-break: break-all;
  161. color: white;
  162. }
  163. .navimenu .item.floatWindowButton .floatWindowAppIcon {
  164. height: 20px;
  165. margin-top: -2px;
  166. margin-right: 8px;
  167. display: inline-block;
  168. }
  169. .navimenu .item.floatWindowButton .floatWindowTitle {
  170. display: inline;
  171. color: white;
  172. padding-top: 5px;
  173. vertical-align: top;
  174. }
  175. .navimenu .item.floatWindowButton.hideText {
  176. width: 36px;
  177. }
  178. .navimenu .item.floatWindowButton.hideText .floatWindowTitle {
  179. display: none;
  180. }
  181. .navimenu .item.floatWindowButton.hideText .floatWindowAppIcon {
  182. margin-right: 0px;
  183. }
  184. #fwdragpanel {
  185. position: fixed;
  186. width: 100%;
  187. height: 100%;
  188. top: 0px;
  189. left: 0px;
  190. z-index: 100;
  191. display: none;
  192. }
  193. #tfwdragpanel{
  194. position: fixed;
  195. width: 100%;
  196. height: 100%;
  197. top: 0px;
  198. left: 0px;
  199. z-index: 500;
  200. display: none;
  201. }
  202. #stackedWindowList {
  203. position: fixed;
  204. z-index: 1112;
  205. left: 0px;
  206. bottom: 36px;
  207. width: 300px;
  208. padding-bottom: 4px;
  209. display: none;
  210. }
  211. #stackedWindowList .item {
  212. padding: 6px;
  213. display: inline-block;
  214. color: white;
  215. width: 100%;
  216. }
  217. #stackedWindowList .item img {
  218. display: inline-block;
  219. vertical-align: bottom;
  220. width: 20px;
  221. height: 20px;
  222. margin-right: 12px;
  223. margin-top: 0px;
  224. margin-left: 4px;
  225. }
  226. #stackedWindowList .item span {
  227. overflow: hidden;
  228. word-break: break-all;
  229. text-overflow: ellipsis;
  230. white-space: nowrap;
  231. width: calc(100% - 4px);
  232. }
  233. #stackedWindowList .item.clickable:hover {
  234. background-color: rgba(250, 250, 250, 0.2);
  235. cursor: pointer;
  236. }
  237. #stackedWindowList .item .closebtn {
  238. position: absolute;
  239. right: 0px;
  240. top: 8px;
  241. }
  242. #stackedWindowList .item .closebtn>img {
  243. height: 15px;
  244. width: 15px;
  245. }
  246. #listMenu {
  247. position: fixed;
  248. bottom: 36px;
  249. left: 0px;
  250. height: 500px;
  251. width: 400px;
  252. background-color: #fcffff;
  253. box-shadow: 3px 3px 5px 0px rgba(207, 207, 207, 0.37);
  254. z-index: 1113;
  255. }
  256. #listMenu.darkTheme{
  257. background-color: #242330;
  258. color: white;
  259. -webkit-box-shadow: 7px -6px 7px -1px rgba(92,92,92,0.2);
  260. -moz-box-shadow: 7px -6px 7px -1px rgba(92,92,92,0.2);
  261. box-shadow: 7px -6px 7px -1px rgba(92,92,92,0.2);
  262. }
  263. #listMenu .searchBar{
  264. width: 100%;
  265. border-bottom: 2px solid #34b7eb;
  266. }
  267. #listMenu.darkTheme .searchBar input{
  268. background-color: #17161f !important;
  269. color: white !important;
  270. border: 1px solid #17161f;
  271. }
  272. #listMenu .listItemWrapper {
  273. overflow: hidden;
  274. }
  275. #listMenu .listItemWrapper .groups {
  276. background-color: #f5f5f5;
  277. width: 120px;
  278. height: 457px;
  279. display: inline-block;
  280. overflow-y: auto;
  281. padding-top: 8px;
  282. }
  283. #listMenu.darkTheme .listItemWrapper .groups {
  284. background-color: #17161f;
  285. color: white;
  286. }
  287. #listMenu .listItemWrapper .groups .item {
  288. padding-left: 7px;
  289. padding-bottom: 6px;
  290. padding-top: 6px;
  291. cursor: pointer;
  292. }
  293. #listMenu .listItemWrapper .groups .item.selected {
  294. color: #34b7eb;
  295. }
  296. #listMenu .listItemWrapper .groups .item:hover {
  297. background-color: #dedede;
  298. }
  299. #listMenu.darkTheme .listItemWrapper .groups .item:hover {
  300. background-color: #242330;
  301. }
  302. #listMenu .listItemWrapper .items {
  303. height: 457px;
  304. width: calc(100% - 120px - 5px);
  305. display: inline-block;
  306. overflow-y: auto;
  307. padding-top: 8px;
  308. box-shadow: -2px 0px 5px 0px rgba(194, 194, 194, 0.5);
  309. vertical-align: top;
  310. }
  311. #listMenu.darkTheme .listItemWrapper .items {
  312. box-shadow: 0px 0px 0px 0px transparent;
  313. }
  314. #listMenu .listItemWrapper .items .item {
  315. padding-left: 12px;
  316. padding-top: 8px;
  317. padding-bottom: 8px;
  318. cursor: pointer;
  319. }
  320. #listMenu .listItemWrapper .items .item:hover {
  321. background-color: #f5f5f5;
  322. }
  323. #listMenu.darkTheme .listItemWrapper .items .item:hover {
  324. background-color: #17161f !important;
  325. margin-right: 5px;
  326. }
  327. #listMenu .listItemWrapper .items .item img {
  328. width: 26px;
  329. margin-right: 12px;
  330. vertical-align: middle;
  331. }
  332. #listMenu .poweroption {
  333. position: absolute;
  334. bottom: 0px;
  335. left: 0px;
  336. padding: 6px;
  337. padding-left: 7px;
  338. width: 100%;
  339. cursor: pointer;
  340. }
  341. #listMenu .poweroption:hover {
  342. background-color: #dedede;
  343. }
  344. #listMenu.darkTheme .poweroption:hover {
  345. background-color: #242330;
  346. }
  347. #contextmenu {
  348. position: fixed;
  349. z-index: 3000;
  350. left: 20px;
  351. top: 20px;
  352. }
  353. #contextmenu .item {
  354. padding: 0.6em 1em !important;
  355. }
  356. #subcontextmenu .item {
  357. padding: 0.6em 1em !important;
  358. }
  359. #selectionPanel {
  360. background-color: rgba(39, 108, 227, 0.3);
  361. border: 1px solid #276ce3;
  362. position: fixed;
  363. height: 100px;
  364. width: 100px;
  365. display: none;
  366. }
  367. .renameInput {
  368. background-color: white;
  369. border: 1px solid black;
  370. width: 100%;
  371. position: absolute;
  372. }
  373. .renameInput.big {
  374. bottom: 0px;
  375. left: 0px;
  376. font-size: 16px;
  377. line-height: 1;
  378. }
  379. .renameInput.medium {
  380. bottom: 8px;
  381. left: 0px;
  382. height: 32px;
  383. font-size: 12px;
  384. line-height: 1;
  385. }
  386. .renameInput.small {
  387. bottom: 3px;
  388. left: 0px;
  389. height: 24px;
  390. font-size: 11px;
  391. line-height: 1;
  392. }
  393. #statusbar{
  394. position:absolute;
  395. z-index:0;
  396. width:100%;
  397. height:28px;
  398. background-color: rgba(0,0,0,0.9);
  399. color:white;
  400. backdrop-filter: blur(4px);
  401. text-align:center;
  402. display: table;
  403. }
  404. .statusbarpadding{
  405. padding:4px;
  406. }
  407. .hostname{
  408. display: table-cell;
  409. text-align:left;
  410. width:100px;
  411. pointer-events:none;
  412. padding-left:18px;
  413. white-space: nowrap;
  414. user-select: none;
  415. }
  416. .quicktools{
  417. display: table-cell;
  418. text-align:right;
  419. width:45px;
  420. }
  421. .qtwrapper{
  422. padding:4px;
  423. padding-right: 8px;
  424. cursor:pointer;
  425. }
  426. .qtwrapper:hover{
  427. background-color: rgba(240,240,240,0.2);
  428. }
  429. .notificationbar{
  430. position: absolute;
  431. top:28px;
  432. width:100%;
  433. height: calc(100% - 28px);
  434. z-index:1114;
  435. }
  436. .notificationbar .content{
  437. background-color:white;
  438. margin-top:6px;
  439. margin-left: auto;
  440. margin-right: auto;
  441. width:30%;
  442. min-width:650px;
  443. height:400px;
  444. z-index:1115;
  445. padding: 3px;
  446. border-radius: 5px;
  447. }
  448. .notificationbar .cover{
  449. backdrop-filter: blur(2px);
  450. -webkit-backdrop-filter: blur(2px);
  451. position:absolute;
  452. top:0px;
  453. left:0px;
  454. width:100%;
  455. height: calc(100%);
  456. }
  457. @supports not (backdrop-filter: blur(2px)) {
  458. .notificationbar .cover{
  459. /*
  460. //Replaced with Javascript implementation on Firefox
  461. background-color: rgba(24,24,24,0.3);
  462. */
  463. }
  464. #bgwrapper{
  465. transition: all 0.5s ease;
  466. }
  467. #iconwrapper{
  468. transition: all 0.5s ease;
  469. }
  470. #navimenu{
  471. transition: all 0.5s ease;
  472. }
  473. }
  474. .notification .title{
  475. font-weight:bold;
  476. font-size:120%;
  477. }
  478. .notification .notifycontent{
  479. margin-top:-12px;
  480. }
  481. .notificationbar .clearall{
  482. position:absolute;
  483. top:0px;
  484. right:4px;
  485. cursor:pointer;
  486. }
  487. .nonotification{
  488. opacity: 0.3;
  489. pointer-events:none;
  490. position:absolute;
  491. margin-top:9em;
  492. width:100%;
  493. user-select: none;
  494. }
  495. .notification.object .closebtn{
  496. position:absolute;
  497. top:3px;
  498. right:3px;
  499. cursor:pointer;
  500. }
  501. .notification.object{
  502. padding-left:7px;
  503. border-left: 3px solid transparent;
  504. cursor:pointer;
  505. }
  506. .notification.object:hover{
  507. /*
  508. border-left: 3px solid #83D8FF;
  509. */
  510. }
  511. .blured{
  512. filter: blur(2px);
  513. }
  514. #quickAccessPanel{
  515. background-color:white;
  516. position:absolute;
  517. top:28px;
  518. right:4px;
  519. z-index:114;
  520. width:300px;
  521. border-radius: 10px;
  522. border-top-right-radius: 0px;
  523. border-top-left-radius: 0px;
  524. border: 1px solid #ebebeb;
  525. padding-top:8px;
  526. padding-bottom:8px;
  527. }
  528. #quickAccessPanel .item{
  529. padding-left:12px;
  530. padding-right:12px;
  531. padding-top:6px;
  532. padding-bottom:2px;
  533. cursor:pointer;
  534. border-left: 3px solid transparent;
  535. }
  536. #quickAccessPanel .item:hover{
  537. background-color:#fafafa;
  538. }
  539. /*
  540. Handle dark theme for the quick access panel
  541. */
  542. #quickAccessPanel.darkTheme{
  543. background-color: #242330;
  544. color: white;
  545. border: 1px solid transparent;
  546. -webkit-box-shadow: -5px 4px 7px -1px rgba(92,92,92,0.2);
  547. -moz-box-shadow: -5px 4px 7px -1px rgba(92,92,92,0.2);
  548. box-shadow: -5px 4px 7px -1px rgba(92,92,92,0.2);
  549. }
  550. #quickAccessPanel.darkTheme .item:hover{
  551. background-color:#17161f;
  552. }
  553. #quickAccessPanel.darkTheme .header{
  554. color: white;
  555. }
  556. #quickAccessPanel.darkTheme .progress{
  557. background-color: #0c0c0f;
  558. }
  559. #quickAccessPanel.darkTheme .header{
  560. color: white;
  561. }
  562. #quickAccessPanel.darkTheme .inverted.button{
  563. background-color: #17161f;
  564. border: 1px solid black;
  565. }
  566. .item.module{
  567. cursor:pointer;
  568. }
  569. .item.module:hover{
  570. background-color:#f5f5f5 !important;
  571. }
  572. /*
  573. Z-index layering
  574. Layer -1 : Background Images
  575. Layer 0 - 99: Not focused tab
  576. Layer 100: Focused tab drag drop layer
  577. Layer 101: Focused Tab
  578. ...
  579. Layer 400 - 499: Non-focused top most FloatWindows
  580. Layer 500: Top Mot FloatWindow drag drop layer
  581. Layer 501: Top Most FloatWindow
  582. ...
  583. Layer 1110: Navigation Bar
  584. Layer 1112: Stacked Window List
  585. Layer 1113: List Menu
  586. Layer 1114: Notification Bar background bluring layer
  587. Layer 1115: Notification Bar
  588. ...
  589. Layer 3000: contextmenu
  590. */
  591. </style>
  592. <script>
  593. //Force redirection if it is on mobile
  594. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  595. window.location.href = "mobile.system";
  596. }
  597. </script>
  598. </head>
  599. <body style="background-color:black;">
  600. <!-- Background frames-->
  601. <div id="bgwrapper" class="background-wrapper" allowdrop="true" ondrop="drop(event)" ondragstart="return false;" onclick="event.preventDefault(); hideAllContextMenus();" ondblclick="event.preventDefault();event.stopImmediatePropagation();" ondragover="allowDrop(event);"
  602. align="center" draggable="false">
  603. </div>
  604. <!-- Top Status Bar -->
  605. <div id="statusbar" align="center">
  606. <div class="hostname statusbarpadding">
  607. Welcome
  608. </div>
  609. <div class="clock statusbarpadding" style="display: table-cell; cursor:pointer; user-select: none;" onclick="toggleNotification();" ontouchstart="toggleNotification();">
  610. ArOZ Online Desktop
  611. </div>
  612. <div class="quicktools" onclick="showToolPanel();" ontouchend="showToolPanel();">
  613. <div class="qtwrapper">
  614. <i class="content icon"></i>
  615. </div>
  616. </div>
  617. </div>
  618. <!-- Calendar and Notification -->
  619. <div class="notificationbar" style="display:none;">
  620. <div class="content">
  621. <div id="notificationlist" style="width: calc(100% - 302px); padding:8px; margin-top:5px; padding-top:22px; overflow-y:auto; overflow-x:hidden; height: calc(100% - 12px);">
  622. <div class="nonotification">
  623. <h4 class="ts center aligned icon header">
  624. <i class="bell icon"></i>No Notification
  625. </h4>
  626. </div>
  627. <a class="clearall" onclick="clearAllNotification();">Clear All</a>
  628. </div>
  629. <div style="position:absolute; right:3px; top:3px; padding-top:8px;">
  630. <div class="ts header" style="padding-left:22px;">
  631. <div id="dayofweek" class="sub header"></div>
  632. <span id="largedate" style="font-size:120%;"></span>
  633. </div>
  634. <div class="auto-jsCalendar blue"></div>
  635. </div>
  636. </div>
  637. <div class="cover" onclick='toggleNotification("hide");' ontouchstart='toggleNotification("hide");'>
  638. </div>
  639. </div>
  640. <!-- Desktop icons-->
  641. <div id="iconwrapper">
  642. </div>
  643. <!-- Navigation Menu-->
  644. <div id="navimenu" class="navimenu themeColor">
  645. <div class="item clickable system" onclick="toggleListMenu();" ontouchstart="toggleListMenu();" >
  646. <img style="height:36px;" src="img/desktop/system_icon/list.png"></img>
  647. </div>
  648. <div class="item padding system"></div>
  649. </div>
  650. <!-- floatWindow dragging panel-->
  651. <div id="fwdragpanel"></div>
  652. <div id="tfwdragpanel"></div>
  653. <!-- Selection panel-->
  654. <div id="selectionPanel"></div>
  655. <!-- Stacked windows listing container-->
  656. <div id="stackedWindowList" class="themeColor"></div>
  657. <!-- List menu -->
  658. <div id="listMenu" class="" style="display:none;">
  659. <div class="searchBar" onkeydown="searchModule(event);">
  660. <div class="ts icon fluid input" style="border-radius: 0px !important;">
  661. <input id="searchBar" type="text" placeholder="Search">
  662. <i class="search icon"></i>
  663. </div>
  664. </div>
  665. <dib class="listItemWrapper">
  666. <div class="groups">
  667. <div id="searchResults" class="item" style="display:none;">Search Results</div>
  668. <div class="item groupType selected" group="All">All</div>
  669. <div class="item groupType" group="Media">Media</div>
  670. <div class="item groupType" group="Office">Office</div>
  671. <div class="item groupType" group="Download">Download</div>
  672. <div class="item groupType" group="Files">Files</div>
  673. <div class="item groupType" group="Internet">Internet</div>
  674. <div class="item groupType" group="System Settings">System Settings</div>
  675. <div class="item groupType" group="System Tools">System Tools</div>
  676. <div class="item groupType" group="Utilities">Utilities</div>
  677. <div class="item groupType" group="Other">Other</div>
  678. <div class="poweroption">
  679. <img id="powerIcon" style="width:18px; vertical-align: top; margin-right:4px;" src="img/system/power.svg"></img> Exit
  680. </div>
  681. </div>
  682. <div id="listMenuItem" class="items">
  683. </div>
  684. </dib>
  685. </div>
  686. <div id="contextmenu" class="ts tiny contextmenu visible" style="display:none;">
  687. </div>
  688. <div id="subcontextmenu" class="ts tiny contextmenu visible" style="display:none;">
  689. </div>
  690. <!-- Disconnected. Reconnecting interface -->
  691. <div id="connectionLost" class="ts active dimmer" style="display:none; z-index:999;">
  692. <div class="ts text indeterminate loader">Connection Lost<br>
  693. Reconnecting...</div>
  694. </div>
  695. <div id="quickAccessPanel" class="" style="display:none;">
  696. <div class="ts small single line items">
  697. <div class="item">
  698. <div class="ts mini image">
  699. <img class="usericon" src="img/desktop/system_icon/user.svg">
  700. </div>
  701. <div class="content">
  702. <div id="username" class="header">User</div>
  703. <div class="meta">
  704. <div id="usergroups">@Users</div>
  705. </div>
  706. </div>
  707. <div class="actions">
  708. <div class="ts button" onclick="logout(); hideToolPanel();">
  709. <i class="log out icon"></i> Logout
  710. </div>
  711. </div>
  712. </div>
  713. </div>
  714. <div class="item" style="padding-bottom:12px;">
  715. <i class="volume up icon"></i> System Global Volume
  716. <div class="ts fluid small progress" style="margin-top:8px; cursor:pointer;" onclick="updateVolume(this,event);" >
  717. <div id="volumebar" class="bar" style="width: 0%; background-color:#52C9FF; cursor:pointer;"></div>
  718. </div>
  719. </div>
  720. <div class="item" id="settingButton" onclick="showSystemSettings(); hideToolPanel();" ontouchend="showSystemSettings(); hideToolPanel();">
  721. <i class="setting icon"></i> System Settings
  722. <!-- <div style="float:right;"><i class="caret right icon"></i></div> -->
  723. </div>
  724. <div class="item" onclick="fullscreen(); hideToolPanel();" ontouchend="fullscreen(); hideToolPanel();">
  725. <i class="maximize icon"></i> Toggle Fullscreen
  726. </div>
  727. <div class="ts divider"></div>
  728. <!--
  729. <div class="item" onclick="logout(); hideToolPanel();">
  730. <i class="log out icon"></i> Logout
  731. </div>
  732. -->
  733. <div class="item hardware" onclick="restart(); hideToolPanel();" ontouchend="restart(); hideToolPanel();">
  734. <i class="repeat icon"></i> Restart
  735. </div>
  736. <div class="item hardware" style="color:#b51d1d;" onclick="shutdown(); hideToolPanel();" ontouchend="shutdown(); hideToolPanel();">
  737. <i class="power icon"></i> Power Off
  738. </div>
  739. </div>
  740. <script>
  741. /*
  742. ArOZ Online Desktop Interface
  743. This script maintain the usability of the desktop environment.
  744. This is not identical to the previous Desktop environment used in ArOZ Online BETA.
  745. */
  746. //System environment variables
  747. var isDesktopMode = true;
  748. var loggingOut = false;
  749. //Desktop background related
  750. var desktopThemeList = []; //Storing the list of background installed
  751. var currentBackgroundList = []; //Current list of background files
  752. var currentUserTheme = ""; //The theme for current user.
  753. var backgroundCrossfadeInterval = 30000; //Time between the crossfade of each background image
  754. var nextSlideshowIndex = 0; //The next background image index to be shown
  755. var backgroundIntervalCounter; //The interval object for background changer
  756. var desktopThemeColor = ""; //The current desktop theme color, which renders to the status bar and suchs
  757. //Desktop icon realted
  758. var desktopIconSize = "medium"; //Size of desktop icons. Allow {small / medium / big}
  759. var desktopIconPack = "default"; //Desktop icon pack to be used. Located under desktop/file_icon/{pack-name}
  760. var desktopGrids = []; //Reference virtual grid for icons on desktop
  761. var iconSize = []; //Defined the icon size for the desktop icons
  762. var desktopFileList = []; //Temperature storage of desktop filenames
  763. var startDragRelatuve = []; //Relative location of where the icon being start dragging
  764. var iconOffsetXY = [0,20]; //Pixel to offset for the icon location
  765. //Float window related
  766. var focusedWindow;
  767. const maxWindowCount = 100;
  768. var movingWindow = false;
  769. var resizingWindow = false;
  770. var resizingEdgeID = 0; //Resizing edge. {0, 1, 2, 3, 4, 5} => None, Right, Right Bottom Corner, Bottom, Left Bottom Corner, Left
  771. var stackedFloatWindowListShwon = false;
  772. //Laucnh icon related
  773. var multiSelecting = false;
  774. var multiSelectionStartPoint = [-1, -1];
  775. var clickDownOffset = [-1, -1];
  776. var renameMode = false;
  777. var operationTargetLaunchIcon;
  778. //Document key bindings
  779. var ctrlHold = false;
  780. var shiftHold = false;
  781. //ListMenu Related Paramters
  782. var moduleInstalled = [];
  783. var listMenuShown = false;
  784. //Context Menu variables
  785. var menuStartLocation = [0, 0];
  786. //Others
  787. var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  788. var daysNames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  789. var hostInfo = {};
  790. var userInfo = {};
  791. var hardwareman = false;
  792. var downloadMode = false;
  793. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  794. //Initiation functions
  795. initDesktopTheme();
  796. initDesktopHostInfo();
  797. initDesktopUserInfo();
  798. initBackgroundSwitchingAnimation();
  799. //initDesktopFiles(); //Will be called in initDesktopIconPreference() -> refresh()
  800. initModuleList();
  801. initDesktopIconPreference()
  802. initUserDefinedThemeColor();
  803. hookFloatWindowEvents();
  804. hookLaunchMenuEvents();
  805. initTheme();
  806. //Login cookie expire check
  807. setInterval(function() {
  808. $.ajax({
  809. url: 'system/auth/checkLogin',
  810. success: function(data) {
  811. if (data == true) {
  812. //Continue session
  813. } else {
  814. //Session timeout. Redirect to system index
  815. loggingOut = true;
  816. window.location.href = "index.html";
  817. }
  818. $("#connectionLost").hide();
  819. document.title = hostInfo.Hostname;
  820. },
  821. error: function(evt) {
  822. //Server closed or freezed?
  823. $("#connectionLost").show();
  824. document.title = "Reconnecting...";
  825. },
  826. timeout: 15000
  827. });
  828. }, 15000);
  829. //Keep the clock updated
  830. setInterval(function(){
  831. updateClockTime();
  832. },5000);
  833. updateClockTime();
  834. function updateClockTime(){
  835. var d = new Date();
  836. var display = monthNames[d.getMonth()] + " " + d.getDate() + " " + zeropad(d.getHours(),2) + ":" + zeropad(d.getMinutes(),2);
  837. if ($(".notification.object").length > 0){
  838. display += `<span style="color: #f54242; margin-left: 8px; float: center;"><i class="notice circle icon"></i></span>`;
  839. }
  840. $(".clock").html(display);
  841. var largedate = monthNames[d.getMonth()] + " " + d.getDate() + " " + d.getFullYear()
  842. $("#largedate").text(largedate);
  843. var dow = daysNames[d.getDay()];
  844. $("#dayofweek").text(dow);
  845. }
  846. function zeropad(n, width, z) {
  847. z = z || '0';
  848. n = n + '';
  849. return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
  850. }
  851. function showToolPanel(){
  852. $("#quickAccessPanel").slideToggle("fast");
  853. }
  854. function hideToolPanel(){
  855. $("#quickAccessPanel").slideUp("fast");
  856. }
  857. function initDesktopUserInfo(){
  858. $.get("system/desktop/user", function(data){
  859. if (data.error !== undefined){
  860. alert(data.error);
  861. }else{
  862. userInfo = data;
  863. if (data.IsAdmin == false){
  864. //Hide the power buttons
  865. $(".hardware").hide();
  866. }
  867. //Update the user tag
  868. $("#username").text(userInfo.Username);
  869. $("#usergroups").text("@" + userInfo.UserGroups.join("/"));
  870. $("#usergroups").attr("title",userInfo.UserGroups.join(" / "));
  871. if (data.UserIcon !== ""){
  872. $(".usericon").attr("src",data.UserIcon);
  873. }
  874. }
  875. });
  876. }
  877. function initDesktopHostInfo(){
  878. //Load the data into variable
  879. $.get("system/desktop/host",function(data){
  880. hostInfo = data;
  881. //Update the ui element as well
  882. $(".hostname").text(hostInfo.Hostname);
  883. document.title = hostInfo.Hostname;
  884. });
  885. //Setup volume bar
  886. var currentGlobalVol = localStorage.getItem("global_volume");
  887. if (currentGlobalVol != null && currentGlobalVol != undefined && currentGlobalVol != ""){
  888. $("#volumebar").css("width", currentGlobalVol * 100 + "%");
  889. }else{
  890. currentGlobalVol = 0;
  891. localStorage.setItem("global_volume",currentGlobalVol);
  892. }
  893. //Check if hardware management mode is enabled. Hide buttons if needed
  894. $.get("system/power/accessCheck",function(data){
  895. if (data == true){
  896. //Hardware management mode is on
  897. hardwareman = true;
  898. }else{
  899. //Hardware management mode is off
  900. $(".item.hardware").hide();
  901. hardwareman = false;
  902. }
  903. });
  904. }
  905. function toggleNotification(action=undefined){
  906. var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  907. if (typeof action == "undefined"){
  908. $(".notificationbar").stop().finish().fadeToggle("fast", function(){
  909. if ($(this).is(":visible")){
  910. if (isFirefox){
  911. $("#bgwrapper").addClass("blured");
  912. $("#iconwrapper").addClass("blured");
  913. $("#navimenu").addClass("blured");
  914. $(".floatWindow").addClass("blured");
  915. $("#listMenu").addClass("blured");
  916. }
  917. }else{
  918. if (isFirefox){
  919. $("#bgwrapper").removeClass("blured");
  920. $("#iconwrapper").removeClass("blured");
  921. $("#navimenu").removeClass("blured");
  922. $(".floatWindow").removeClass("blured");
  923. $("#listMenu").removeClass("blured");
  924. }
  925. }
  926. });
  927. }else{
  928. if (action == "hide"){
  929. $(".notificationbar").stop().finish().fadeOut("fast");
  930. if (isFirefox){
  931. $("#bgwrapper").removeClass("blured");
  932. $("#iconwrapper").removeClass("blured");
  933. $("#navimenu").removeClass("blured");
  934. $(".floatWindow").removeClass("blured");
  935. $("#listMenu").removeClass("blured");
  936. }
  937. }else if (action == "show"){
  938. $(".notificationbar").stop().finish().fadeIn("fast");
  939. if (isFirefox){
  940. $("#bgwrapper").addClass("blured");
  941. $("#iconwrapper").addClass("blured");
  942. $("#navimenu").addClass("blured");
  943. $(".floatWindow").addClass("blured");
  944. $("#listMenu").addClass("blured");
  945. }
  946. }
  947. }
  948. }
  949. // ===================== LIST MENU EVENTS FUNCTIONS ===============
  950. function toggleListMenu() {
  951. $("#listMenu").stop().finish().animate({
  952. height: "toggle"
  953. }, 300, function() {
  954. if ($("#listMenu").offset().top == 0) {
  955. listMenuShown = false;
  956. } else {
  957. listMenuShown = true;
  958. }
  959. });
  960. }
  961. function initDesktopIconPreference() {
  962. getStorage("iconsize", function(catergory) {
  963. if (["small", "medium", "big"].includes(catergory)) {
  964. desktopIconSize = catergory;
  965. }
  966. refresh();
  967. hideAllContextMenus();
  968. });
  969. }
  970. function hideListMenu() {
  971. if (listMenuShown) {
  972. $("#listMenu").animate({
  973. height: "hide"
  974. }, 300);
  975. listMenuShown = false;
  976. }
  977. }
  978. function initModuleList() {
  979. $.ajax({
  980. url: "system/modules/list",
  981. success: function(data) {
  982. moduleInstalled = data;
  983. listModulesType("All");
  984. checkFileSystemAccess();
  985. //Hide the system setting button if access is denied
  986. var allowSettingAccess = false;
  987. moduleInstalled.forEach(thismod => {
  988. if (thismod.Name == "System Setting"){
  989. allowSettingAccess = true;
  990. }
  991. });
  992. if (!allowSettingAccess){
  993. $("#settingButton").hide();
  994. }
  995. }
  996. });
  997. }
  998. function hookLaunchMenuEvents(){
  999. $(".groupType").on("click touchstart",function(){
  1000. moduleTypeButtonClicked(this);
  1001. });
  1002. $(".poweroption").on("click touchstart",function(){
  1003. logout();
  1004. });
  1005. }
  1006. function moduleTypeButtonClicked(object) {
  1007. var groupType = $(object).attr("group");
  1008. listModulesType(groupType);
  1009. $(".groupType.selected").removeClass("selected");
  1010. $(object).addClass("selected");
  1011. $("#searchResults").slideUp('fast');
  1012. $("#searchBar").val("");
  1013. }
  1014. function listModulesType(groupType) {
  1015. var listingItems = [];
  1016. if (groupType == "All") {
  1017. //List all of the items
  1018. for (var i = 0; i < moduleInstalled.length; i++) {
  1019. if (moduleInstalled[i]["StartDir"] != "") {
  1020. listingItems.push(moduleInstalled[i]);
  1021. }
  1022. }
  1023. } else if (groupType == "Other") {
  1024. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilities"];
  1025. //List the Other groups
  1026. for (var i = 0; i < moduleInstalled.length; i++) {
  1027. if (excludeList.includes(moduleInstalled[i]["Group"]) == false && moduleInstalled[i]["StartDir"] != "") {
  1028. console.log(moduleInstalled[i]["Group"]);
  1029. listingItems.push(moduleInstalled[i]);
  1030. }
  1031. }
  1032. } else {
  1033. //List the given group
  1034. for (var i = 0; i < moduleInstalled.length; i++) {
  1035. if (moduleInstalled[i]["Group"] == groupType && moduleInstalled[i]["StartDir"] != "") {
  1036. listingItems.push(moduleInstalled[i]);
  1037. }
  1038. }
  1039. }
  1040. //List the item to the listmenu
  1041. $("#listMenuItem").html("");
  1042. for (var i = 0; i < listingItems.length; i++) {
  1043. var thisModule = listingItems[i];
  1044. generateListMenuItem(thisModule);
  1045. }
  1046. if (listingItems.length == 0) {
  1047. $("#listMenuItem").html(`<div class="item module"><span><img src="img/system/not found.png">No WebApp found</span></div>`)
  1048. }
  1049. }
  1050. //Given a module information and generate a selectable item in the list menu
  1051. function generateListMenuItem(thisModule) {
  1052. var icon = thisModule["IconPath"];
  1053. if (icon == "") {
  1054. //Use default system icon
  1055. icon = "img/system/service.png";
  1056. }
  1057. var name = thisModule["Name"];
  1058. var startdir = thisModule["StartDir"];
  1059. var fwsupport = "false";
  1060. if (thisModule["SupportFW"]) {
  1061. fwsupport = "true";
  1062. }
  1063. $("#listMenuItem").append(`<div class="item module" module="${name}" startdir="${startdir}" fw="${fwsupport}" onclick="openModuleFromMenu(this);" ontouchstart="openModuleFromMenu(this);">
  1064. <span>
  1065. <img src="${icon}"></img>
  1066. ${name}
  1067. </span>
  1068. </div>`);
  1069. }
  1070. function searchModule(event) {
  1071. if (event.which == 13) {
  1072. var keyword = $("#searchBar").val().toLowerCase();
  1073. var results = [];
  1074. var lessAccurateResults = [];
  1075. $(".groupType.selected").removeClass("selected");
  1076. $("#searchResults").addClass("selected").slideDown('fast');
  1077. //Load all search results
  1078. for (var i = 0; i < moduleInstalled.length; i++) {
  1079. var thisModule = moduleInstalled[i];
  1080. if (thisModule["StartDir"] == ""){
  1081. continue;
  1082. }
  1083. var pathInfo = thisModule["StartDir"].split("/");
  1084. for (var j = 0; j < pathInfo.length; j++) {
  1085. pathInfo[j] = pathInfo[j].toLowerCase();
  1086. }
  1087. if (thisModule["Name"].toLowerCase().includes(keyword)) {
  1088. results.push(thisModule);
  1089. } else if (pathInfo.includes(keyword.toLowerCase()) || pathInfo.includes(keyword.split(" ").join("_").toLowerCase())) {
  1090. lessAccurateResults.push(thisModule);
  1091. }
  1092. }
  1093. results = results.concat(lessAccurateResults);
  1094. //Append the results to list
  1095. $("#listMenuItem").html("");
  1096. for (var i = 0; i < results.length; i++) {
  1097. generateListMenuItem(results[i]);
  1098. }
  1099. if (results.length == 0) {
  1100. //Append a custom no results div to the content
  1101. $("#listMenuItem").append(` <div class="item">
  1102. <span>
  1103. <img src="img/system/not found.png"></img>
  1104. No Result
  1105. </span>
  1106. </div>`);
  1107. }
  1108. }
  1109. }
  1110. function openModuleFromMenu(object) {
  1111. var moduleName = $(object).attr("module");
  1112. openModule(moduleName);
  1113. }
  1114. function openModule(moduleName, callback=undefined) {
  1115. $.get("system/modules/getLaunchPara?module=" + moduleName, function(data) {
  1116. if (data.error !== undefined) {
  1117. //Something went wrong.
  1118. console.log("Unable to open module " + moduleName);
  1119. if (data.error == "Not logged in."){
  1120. //Session expired
  1121. window.location.href = "login.system";
  1122. }
  1123. } else {
  1124. //Launch the given module
  1125. var url = data["StartDir"];
  1126. var size = [undefined, undefined];
  1127. var icon = "img/system/favicon.png";
  1128. if (data["IconPath"] != "") {
  1129. icon = data["IconPath"];
  1130. }
  1131. var title = data["Name"];
  1132. //Check if the module support fw mode. If yes, launch with fwmode url. IF not, launch to index
  1133. if (data["SupportFW"] == true) {
  1134. if (data["LaunchFWDir"] != null) {
  1135. url = data["LaunchFWDir"];
  1136. }
  1137. if (data["InitFWSize"] != null) {
  1138. size = data["InitFWSize"];
  1139. }
  1140. }
  1141. //Launch the given module
  1142. var uuid = newFloatWindow({
  1143. url: url,
  1144. width: size[0],
  1145. height: size[1],
  1146. appicon: icon,
  1147. title: title
  1148. });
  1149. if (callback !== undefined){
  1150. callback();
  1151. }
  1152. hideListMenu();
  1153. }
  1154. });
  1155. }
  1156. // ===================== FLOAT WINDOWS EVENTS =====================
  1157. function hookFloatWindowEvents() {
  1158. //Handle floatWindow mouse drag events
  1159. $(".fwdragger").off("mousedown").on("mousedown", function(evt) {
  1160. evt.preventDefault();
  1161. evt.stopImmediatePropagation();
  1162. fwdown($(this).parent(), evt);
  1163. });
  1164. $(".fwdragger").off("mousemove").on("mousemove", function(evt) {
  1165. evt.preventDefault();
  1166. evt.stopImmediatePropagation();
  1167. fwmove($(this).parent(), evt);
  1168. });
  1169. $(".fwdragger").off("mouseup").on("mouseup", function(evt) {
  1170. evt.preventDefault();
  1171. evt.stopImmediatePropagation();
  1172. fwup($(this).parent(), evt);
  1173. });
  1174. $(".fwdragger").off("touchstart").on("touchstart", function(evt) {
  1175. evt.preventDefault();
  1176. evt.stopImmediatePropagation();
  1177. fwdown($(this).parent(), evt);
  1178. });
  1179. $(".fwdragger").off("touchmove").on("touchmove", function(evt) {
  1180. evt.preventDefault();
  1181. evt.stopImmediatePropagation();
  1182. fwmove($(this).parent(), evt);
  1183. });
  1184. $(".fwdragger").off("touchend").on("touchend", function(evt) {
  1185. evt.preventDefault();
  1186. evt.stopImmediatePropagation();
  1187. fwup($(this).parent(), evt);
  1188. });
  1189. $(".fwdragger").off("dblclick").on("dblclick", function(evt) {
  1190. //Activate full screen
  1191. evt.preventDefault();
  1192. evt.stopImmediatePropagation();
  1193. //Emulate keypress on maximize btn
  1194. toggleMax($(this).parent().find(".maxToogleButton").parent()[0], evt);
  1195. });
  1196. //Floatwindow operations for touch devices
  1197. $(".maxtoggle").off("touchstart").on("touchstart",function(evt){
  1198. evt.preventDefault();
  1199. evt.stopImmediatePropagation();
  1200. toggleMax(this, evt);
  1201. });
  1202. $(".mintoggle").off("touchstart").on("touchstart",function(evt){
  1203. evt.preventDefault();
  1204. evt.stopImmediatePropagation();
  1205. min(this, evt);
  1206. });
  1207. $(".closetoggle").off("touchstart").on("touchstart",function(evt){
  1208. evt.preventDefault();
  1209. evt.stopImmediatePropagation();
  1210. closeFloatWindow(this,evt);
  1211. });
  1212. //floatWindow events for mouse
  1213. $(".maxtoggle").off("mousedown").on("mousedown",function(evt){
  1214. evt.preventDefault();
  1215. evt.stopImmediatePropagation();
  1216. toggleMax(this, evt);
  1217. });
  1218. $(".mintoggle").off("mousedown").on("mousedown",function(evt){
  1219. evt.preventDefault();
  1220. evt.stopImmediatePropagation();
  1221. min(this, evt);
  1222. });
  1223. $(".closetoggle").off("mousedown").on("mousedown",function(evt){
  1224. evt.preventDefault();
  1225. evt.stopImmediatePropagation();
  1226. closeFloatWindow(this,evt);
  1227. });
  1228. //Float Window events for resizing
  1229. $(".iframewrapper").off("mousedown").on("mousedown", function(evt) {
  1230. evt.preventDefault();
  1231. evt.stopImmediatePropagation();
  1232. if ($(this).parent().hasClass("fixedsize")) {
  1233. return false;
  1234. }
  1235. resizeDown($(this).parent(), evt);
  1236. });
  1237. $(".iframewrapper").off("mousemove").on("mousemove", function(evt) {
  1238. evt.preventDefault();
  1239. evt.stopImmediatePropagation();
  1240. if (resizingWindow == true) {
  1241. //Resizeing Move
  1242. resizeMove($(this).parent(), evt);
  1243. } else {
  1244. //Dragdropping move
  1245. fwmove($(this).parent(), evt);
  1246. }
  1247. });
  1248. $(".iframewrapper").off("mouseup").on("mouseup", function(evt) {
  1249. evt.preventDefault();
  1250. evt.stopImmediatePropagation();
  1251. resizeUp($(this).parent(), evt);
  1252. });
  1253. $(".iframewrapper").off("mouseover").on("mouseover", function(evt) {
  1254. var object = $(this).parent();
  1255. if ($(object).hasClass("fixedsize")) {
  1256. return false;
  1257. }
  1258. var dx = event.pageX - $(object).find(".iframewrapper").offset().left;
  1259. var dy = event.pageY - $(object).offset().top;
  1260. if (dx < 10 && dy > $(object).height() - 10) {
  1261. //Left Bottom Corner
  1262. $(".iframewrapper").attr("class", "iframewrapper leftCorner");
  1263. } else if (dx > $(object).width() - 10 && dy > $(object).height() - 10) {
  1264. //Right Bottom Corner
  1265. $(".iframewrapper").attr("class", "iframewrapper rightCorner");
  1266. } else if (dx < 10) {
  1267. //Dragging left edge
  1268. $(".iframewrapper").attr("class", "iframewrapper widthHover");
  1269. } else if (dx > $(object).width() - 10) {
  1270. //Dragging right edge
  1271. $(".iframewrapper").attr("class", "iframewrapper widthHover");
  1272. } else if (dy > $(object).height() - 10) {
  1273. //Bottom Edge
  1274. $(".iframewrapper").attr("class", "iframewrapper heighHover");
  1275. } else {
  1276. //???
  1277. $(".iframewrapper").attr("class", "iframewrapper");
  1278. }
  1279. });
  1280. //Hook events on the floatWindow button
  1281. $(".floatWindowButton").off("click touchstart").on("click touchstart", function(event) {
  1282. event.preventDefault();
  1283. event.stopImmediatePropagation();
  1284. $("#stackedWindowList").css("left", $(this).offset().left);
  1285. //Generate the stackedWindowList
  1286. var windowIdList = JSON.parse(decodeURIComponent($(this).attr("windowidgroup")));
  1287. if (windowIdList.length == 1) {
  1288. //There are only one window in this group. Show it anyway
  1289. var targetFW = getFloatWindowByID(windowIdList[0]);
  1290. $(targetFW).fadeIn(100);
  1291. MoveFloatWindowToTop(targetFW);
  1292. stackedFloatWindowListShwon = false;
  1293. $("#stackedWindowList").hide();
  1294. } else {
  1295. //Get icon for each windows and build the list objects
  1296. $("#stackedWindowList").html("");
  1297. for (var i = 0; i < windowIdList.length; i++) {
  1298. var iconURL = getFloatWindowIconByID(windowIdList[i]);
  1299. var title = getFloatWindowTitleByID(windowIdList[i]);
  1300. $("#stackedWindowList").append(`<div class="item clickable" windowId="${windowIdList[i]}" onclick="bringFloatWindowToFrontByFWB(this,event);" ontouchstart="bringFloatWindowToFrontByFWB(this,event);"><span><img src="${iconURL}"></img>${title}</span><div class="closebtn" onclick="closeFWviaFWB(this,event);"><img src="img/system/close.png"></img></div></div>`);
  1301. }
  1302. $("#stackedWindowList").show();
  1303. stackedFloatWindowListShwon = true;
  1304. }
  1305. });
  1306. }
  1307. var tapedTwiceTouch = false;
  1308. var timeoutObject;
  1309. var tappingTarget = undefined;
  1310. function doubleTouchHandler(object, event, callback) {
  1311. if(!tapedTwiceTouch) {
  1312. tapedTwiceTouch = true;
  1313. tappingTarget = object;
  1314. timeoutObject = setTimeout( function() { tapedTwiceTouch = false; }, 300 );
  1315. return false;
  1316. }
  1317. if (tappingTarget == object){
  1318. //Double click on the same icon
  1319. event.preventDefault();
  1320. callback(object, event);
  1321. tappingTarget = undefined;
  1322. }else{
  1323. //Although it touch twice within 300ms, but it is on different target
  1324. //Update the tab target instead.
  1325. tappingTarget = object;
  1326. tapedTwiceTouch = true;
  1327. clearTimeout(timeoutObject);
  1328. timeoutObject = setTimeout( function() { tapedTwiceTouch = false; }, 300 );
  1329. }
  1330. }
  1331. function openViaTouch(object, event){
  1332. iconDoubleClicked(object,event);
  1333. }
  1334. //Handle focus through floatWindow taskbar button
  1335. function bringFloatWindowToFrontByFWB(object, event) {
  1336. event.preventDefault();
  1337. event.stopImmediatePropagation();
  1338. var targetWFID = $(object).attr("windowId");
  1339. var targetFW = getFloatWindowByID(targetWFID);
  1340. $(targetFW).fadeIn(100);
  1341. MoveFloatWindowToTop(targetFW);
  1342. stackedFloatWindowListShwon = false;
  1343. $("#stackedWindowList").hide();
  1344. }
  1345. function closeFWviaFWB(object, event) {
  1346. event.preventDefault();
  1347. event.stopImmediatePropagation();
  1348. var targetWFID = $(object).parent().attr("windowId");
  1349. var targetFW = getFloatWindowByID(targetWFID);
  1350. closeFloatWindow(targetFW.find(".close"), event);
  1351. $(object).parent().remove();
  1352. if ($("#stackedWindowList").find(".item").length == 0) {
  1353. //There are no more things in this tab. Close this list as well.
  1354. stackedFloatWindowListShwon = false;
  1355. $("#stackedWindowList").hide();
  1356. }
  1357. }
  1358. //Handle floatWindow resize events
  1359. let resizingWindowTarget;
  1360. let resizingMinX = 0;
  1361. let minxWidth = 120;
  1362. let minHeight = 100;
  1363. function resizeDown(object, event) {
  1364. //Mouse down, start resizing
  1365. resizingWindow = true;
  1366. resizingWindowTarget = object;
  1367. resizingMinX = $(object).offset().left + $(object).width() - minxWidth;
  1368. MoveFloatWindowToTop(object);
  1369. if ($(object).hasClass("topmost")){
  1370. //Top most windows
  1371. $("#tfwdragpanel").show();
  1372. }else{
  1373. //Normal Windows
  1374. $('.floatWindow.topmost').css("pointer-events", "none");
  1375. $('.floatWindow.topmost').css("opacity", 0.7);
  1376. $("#fwdragpanel").show();
  1377. }
  1378. $(object).find(".iframecover").show();
  1379. //Check which edge is the user dragging
  1380. var dx = event.pageX - $(object).find(".iframewrapper").offset().left;
  1381. var dy = event.pageY - $(object).offset().top;
  1382. if (dx < 10 && dy > $(object).height() - 10) {
  1383. //Left Bottom Corner
  1384. resizingEdgeID = 4;
  1385. $(object).find(".iframewrapper").css('cursor', 'sw-resize');
  1386. } else if (dx > $(object).width() - 10 && dy > $(object).height() - 10) {
  1387. //Right Bottom Corner
  1388. resizingEdgeID = 2;
  1389. $(object).find(".iframewrapper").css('cursor', 'se-resize');
  1390. } else if (dx < 10) {
  1391. //Dragging left edge
  1392. resizingEdgeID = 5;
  1393. $(object).find(".iframewrapper").css('cursor', 'w-resize');
  1394. } else if (dx > $(object).width() - 10) {
  1395. //Dragging right edge
  1396. resizingEdgeID = 1;
  1397. $(object).find(".iframewrapper").css('cursor', 'w-resize');
  1398. } else if (dy > $(object).height() - 10) {
  1399. //Bottom Edge
  1400. resizingEdgeID = 3;
  1401. $(object).find(".iframewrapper").css('cursor', 's-resize');
  1402. }
  1403. }
  1404. function resizeMove(object, event) {
  1405. var posX = event.pageX;
  1406. var posY = event.pageY;
  1407. if (resizingWindow == true && resizingEdgeID != 0) {
  1408. if (resizingEdgeID == 1) {
  1409. //Width = posX - floatWindow width + 2 (for border width)
  1410. var newWidth = posX - $(object).offset().left + 2;
  1411. $(object).css("width", Math.max(newWidth, minxWidth));
  1412. } else if (resizingEdgeID == 2) {
  1413. var newWidth = posX - $(object).offset().left + 2;
  1414. var newHeight = posY - $(object).offset().top + 2;
  1415. $(object).css({
  1416. width: Math.max(newWidth, minxWidth),
  1417. height: Math.max(newHeight, minHeight)
  1418. });
  1419. } else if (resizingEdgeID == 3) {
  1420. var newHeight = posY - $(object).offset().top + 2;
  1421. $(object).css("height", Math.max(newHeight,minHeight));
  1422. } else if (resizingEdgeID == 4) {
  1423. var newWidth = $(object).offset().left - posX + $(object).width();
  1424. var newHeight = posY - $(object).offset().top + 2;
  1425. if (newWidth < minxWidth){
  1426. posX = resizingMinX;
  1427. }
  1428. $(object).css({
  1429. width: Math.max(newWidth, minxWidth),
  1430. height: Math.max(newHeight, minHeight),
  1431. left: posX
  1432. });
  1433. } else if (resizingEdgeID == 5) {
  1434. var newWidth = $(object).offset().left - posX + $(object).width();
  1435. if (newWidth < minxWidth){
  1436. posX = resizingMinX;
  1437. }
  1438. $(object).css({
  1439. width: Math.max(newWidth, minxWidth),
  1440. left: posX
  1441. });
  1442. }
  1443. }
  1444. }
  1445. function resizeUp(object, event) {
  1446. resizingWindow = false;
  1447. resizingEdgeID = 0;
  1448. $("#fwdragpanel").hide();
  1449. $("#tfwdragpanel").hide();
  1450. $('.floatWindow.topmost').css("pointer-events", "auto");
  1451. $('.floatWindow.topmost').css("opacity", 1);
  1452. $(object).find(".iframecover").hide();
  1453. $(object).find(".iframewrapper").css('cursor', '');
  1454. //Force minmium width and height on any floatWindow objects
  1455. if ($(object).width() < 120) {
  1456. $(object).css("width", "120px");
  1457. }
  1458. if ($(object).height() < 120) {
  1459. $(object).css("height", "120px");
  1460. }
  1461. resizingWindowTarget = undefined;
  1462. $(".topmost").show();
  1463. }
  1464. //Hook body mousemove assistant events
  1465. $("body").on("mousemove", function(evt) {
  1466. if (focusedWindow !== undefined && movingWindow == true) {
  1467. fwmove(focusedWindow, evt);
  1468. } else if (focusedWindow !== undefined && resizingWindow == true) {
  1469. resizeMove(focusedWindow, evt);
  1470. } else if (multiSelecting == true) {
  1471. movingMultiSelectionArea(evt);
  1472. }
  1473. });
  1474. //Hook body clicke vents
  1475. $("body").on("click", function(evt) {
  1476. if (stackedFloatWindowListShwon == true) {
  1477. //Hide the stacked Float Window list if it is shown
  1478. $("#stackedWindowList").hide();
  1479. stackedFloatWindowListShwon = false;
  1480. }
  1481. if (renameMode == true){
  1482. //Exit rename mode if the target is not on the editing launchIcon
  1483. console.log(evt.target);
  1484. if ($(evt.target).is("body")){
  1485. //End rename mode
  1486. exitRenameMode();
  1487. }
  1488. }
  1489. });
  1490. //Convert touch events to click events
  1491. function mapEventFromTouch(event){
  1492. if (typeof event.originalEvent == "undefined"){
  1493. //Mouse click / down / up events
  1494. return event;
  1495. }
  1496. try{
  1497. //Touch events
  1498. if (typeof event.pageX == "undefined"){
  1499. event.pageX = event.originalEvent.touches[0].pageX;
  1500. }
  1501. if (typeof event.pageY == "undefined"){
  1502. event.pageY = event.originalEvent.touches[0].pageY;
  1503. }
  1504. return event;
  1505. }catch{
  1506. return event;
  1507. }
  1508. }
  1509. //Please pass in the floatWindow object instead of the dragger
  1510. function fwdown(object, event) {
  1511. event = mapEventFromTouch(event);
  1512. //Hide all contenxt menus
  1513. hideAllContextMenus();
  1514. //Move the window to the top layer
  1515. MoveFloatWindowToTop(object);
  1516. //Show the background drag panel
  1517. if ($(object).hasClass("topmost")){
  1518. $("#tfwdragpanel").show();
  1519. }else{
  1520. $('.floatWindow.topmost').css("pointer-events", "none");
  1521. $('.floatWindow.topmost').css("opacity", 0.7);
  1522. $("#fwdragpanel").show();
  1523. }
  1524. //Get the relative click offset of the down event
  1525. clickDownOffset = [event.pageX - $(object).offset().left, event.pageY - $(object).offset().top];
  1526. movingWindow = true;
  1527. $(object).find(".iframecover").show();
  1528. }
  1529. function fwmove(object, event) {
  1530. event = mapEventFromTouch(event);
  1531. if (movingWindow == true) {
  1532. //Check if the object is maximized. If yes, minimized it
  1533. if ($(object).attr("max") == "true") {
  1534. var originalSize = JSON.parse(decodeURIComponent($(object).attr("orgsize")));
  1535. $(object).attr("max", "false");
  1536. $(object).attr("orgsize", "");
  1537. //Calculate new left right offsets
  1538. var clickRatio = event.pageX / window.innerWidth;
  1539. var newLeft = event.pageX - (clickRatio * originalSize[0]);
  1540. originalSize
  1541. $(object).css({
  1542. width: originalSize[0],
  1543. height: originalSize[1],
  1544. left: newLeft,
  1545. top: event.Y - 2
  1546. });
  1547. clickDownOffset[0] = clickRatio * originalSize[0];
  1548. clickDownOffset[1] = 2;
  1549. //Restore the maximize icon
  1550. $(object).find(".maxToogleButton").attr('src', "img/system/max.png")
  1551. }
  1552. $(object).css("left", event.pageX - clickDownOffset[0]);
  1553. $(object).css("top", event.pageY - clickDownOffset[1]);
  1554. }
  1555. }
  1556. function fwup(object, event) {
  1557. event = mapEventFromTouch(event);
  1558. if (movingWindow) {
  1559. $("#fwdragpanel").hide();
  1560. $("#tfwdragpanel").hide();
  1561. $('.floatWindow.topmost').css("pointer-events", "auto");
  1562. $('.floatWindow.topmost').css("opacity", 1);
  1563. $(object).find(".iframecover").hide();
  1564. movingWindow = false;
  1565. //Check if the window location is drag to the edge of the screen. If yes, toggle half screen fullscreen
  1566. //Not need to check for if max because it must be minimized during drag move
  1567. var dockMode = false;
  1568. if (event.pageX < 10) {
  1569. //Dock to left
  1570. var originalSize = [$(object).width(), $(object).height(), $(object).offset().left, $(object).offset().top];
  1571. $(object).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1572. $(object).css({
  1573. width: "50%",
  1574. height: "calc(100% - 36px)",
  1575. left: "0px",
  1576. top: "0px"
  1577. });
  1578. $(object).attr("max", "true");
  1579. $(object).find(".maxToogleButton").attr('src', "img/system/restore.png");
  1580. } else if (event.pageX > window.innerWidth - 10) {
  1581. //Dock to right
  1582. var originalSize = [$(object).width(), $(object).height(), $(object).offset().left, $(object).offset().top];
  1583. $(object).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1584. $(object).css({
  1585. width: "50%",
  1586. height: "calc(100% - 36px)",
  1587. left: (window.innerWidth / 2) + "px",
  1588. top: "0px"
  1589. });
  1590. $(object).attr("max", "true");
  1591. $(object).find(".maxToogleButton").attr('src', "img/system/restore.png");
  1592. }
  1593. }
  1594. }
  1595. //Handle floatWindow min, max and close
  1596. function min(object, event) {
  1597. event.preventDefault();
  1598. event.stopImmediatePropagation();
  1599. if (event.type == "mousedown" && event.which != 1) {
  1600. //Ignore right mouse down
  1601. return;
  1602. }
  1603. var fw = $(object).parent().parent().parent();
  1604. $(fw).fadeOut(100);
  1605. }
  1606. function toggleMax(object, event) {
  1607. event.preventDefault();
  1608. event.stopImmediatePropagation();
  1609. event = mapEventFromTouch(event);
  1610. if (event.type == "mousedown" && event.which != 1) {
  1611. //Ignore right mouse down
  1612. return;
  1613. }
  1614. if ($(object).css('display') == 'none'){
  1615. //This windows do not allow resizing.
  1616. return;
  1617. }
  1618. var fw = $(object).parent().parent().parent();
  1619. var maxedAlready = $(fw).attr('max');
  1620. MoveFloatWindowToTop(fw);
  1621. //Add transition animation
  1622. $(fw).css({
  1623. "transition": "width 0.3s ease-out, height 0.3s ease-out, top 0.3s ease-out, left 0.3s ease-out"
  1624. });
  1625. //Remove transition animation after complete wth 50ms buffer
  1626. setTimeout(function(){
  1627. $(fw).css({
  1628. "transition": ""
  1629. });
  1630. }, 350);
  1631. if (maxedAlready == "true") {
  1632. //Resize to original
  1633. console.log($(fw));
  1634. var originalSize = JSON.parse(decodeURIComponent($(fw).attr("orgsize")));
  1635. $(fw).attr("max", "false");
  1636. $(fw).attr("orgsize", "");
  1637. $(fw).css({
  1638. width: originalSize[0],
  1639. height: originalSize[1],
  1640. left: originalSize[2],
  1641. top: originalSize[3]
  1642. });
  1643. $(fw).find(".maxToogleButton").attr('src', "img/system/max.png");
  1644. } else {
  1645. //Maxmize
  1646. var originalSize = [$(fw).width(), $(fw).height(), $(fw).offset().left, $(fw).offset().top];
  1647. $(fw).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1648. $(fw).css({
  1649. width: "100%",
  1650. height: "calc(100% - 36px)",
  1651. left: "0px",
  1652. top: "0px"
  1653. });
  1654. $(fw).attr("max", "true");
  1655. $(fw).find(".maxToogleButton").attr('src', "img/system/restore.png")
  1656. }
  1657. }
  1658. function closeFloatWindow(object, event) {
  1659. if (event.type == "mousedown" && event.which != 1) {
  1660. //Ignore right mouse down on close buttons
  1661. return;
  1662. }
  1663. event.preventDefault();
  1664. event.stopImmediatePropagation();
  1665. if ($(object).is("img")) {
  1666. object = $(object).panret();
  1667. }
  1668. var fw = $(object).parent().parent().parent();
  1669. var contentWindow = $(fw).find("iframe")[0].contentWindow;
  1670. try {
  1671. if (contentWindow.ao_module_close === undefined) {
  1672. //This module do not use ao_module wrapper. Close it directly.
  1673. closeFwProcess($(fw).attr("windowId"));
  1674. } else {
  1675. //Pass the closing events to the window itself
  1676. contentWindow.ao_module_close();
  1677. }
  1678. } catch (ex) {
  1679. //Problems of closing floatWindow. Force closing.
  1680. closeFwProcess($(fw).attr("windowId"));
  1681. }
  1682. //Find the btn object that contains the windowID
  1683. var closingWindowID = $(fw).attr("windowId");
  1684. resizeAllFloatWindowButtons();
  1685. hideAllContextMenus();
  1686. }
  1687. function findFloatWindowButtonWithID(windowID) {
  1688. var targetButtonObject;
  1689. $(".floatWindowButton").each(function() {
  1690. var originalIDlist = JSON.parse(decodeURIComponent($(this).attr('windowIDGroup')));
  1691. originalIDlist = originalIDlist.map(String);
  1692. if (originalIDlist.includes(windowID)) {
  1693. targetButtonObject = $(this);
  1694. }
  1695. });
  1696. return targetButtonObject;
  1697. }
  1698. function closeFwProcess(windowID) {
  1699. //Close the floatwindow process
  1700. $(".floatWindow").each(function() {
  1701. if ($(this).attr("windowId") == windowID) {
  1702. $(this).remove();
  1703. }
  1704. });
  1705. //Remove the button from menu as well
  1706. var targetTab = findFloatWindowButtonWithID(windowID);
  1707. var originalIDlist = JSON.parse(decodeURIComponent($(targetTab).attr('windowIDGroup')));
  1708. originalIDlist = originalIDlist.map(String);
  1709. if (originalIDlist.length > 1) {
  1710. //There are more than 1 floatWindow in this tab.
  1711. var newIDList = [];
  1712. for (var i = 0; i < originalIDlist.length; i++) {
  1713. if (originalIDlist[i] != windowID) {
  1714. newIDList.push(originalIDlist[i]);
  1715. }
  1716. }
  1717. newIDListAttr = encodeURIComponent(JSON.stringify(newIDList));
  1718. //console.log("Newlist",newIDList);
  1719. $(targetTab).attr("windowIDGroup", newIDListAttr);
  1720. } else {
  1721. //This is the only floatWindow in this tab. Remove the tab itself.
  1722. $(targetTab).remove();
  1723. }
  1724. }
  1725. function PinFloatWindowToTopMostMode(object){
  1726. if ($(".floatwindow.topmost").length >= 100){
  1727. //Cannot add more topmost fw
  1728. console.log("Max number of top most floatWindow reached")
  1729. return
  1730. }
  1731. //Move the current fw to top, its z index is now 101
  1732. MoveFloatWindowToTop(object);
  1733. var windowID = $(object).attr("windowId");
  1734. console.log("Pinning window " + windowID)
  1735. //Move this to fixed layer position
  1736. $(object).addClass("topmost");
  1737. $(object).css("z-index", 501);
  1738. }
  1739. function MoveFloatWindowToTop(object) {
  1740. var windowID = $(object).attr("windowId");
  1741. var windowZindex = $(object).css("z-index");
  1742. //Shift down all floatWindows that has z-index higher than this window by 2
  1743. if (windowID == $(focusedWindow).attr("windowId")) {
  1744. //This window already at the top
  1745. return;
  1746. }
  1747. if ($(focusedWindow).hasClass("topmost")){
  1748. //The previous focused windows is topmost. Move it to layer 109
  1749. $(focusedWindow).css("z-index", 500);
  1750. $(".floatWindow.topmost").each(function(){
  1751. var thisWindowZIndex = $(this).css("z-index");
  1752. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1753. if ($(this).attr("windowId") != windowID) {
  1754. $(this).css("z-index", thisWindowZIndex - 1);
  1755. }
  1756. }
  1757. });
  1758. }else{
  1759. //The previous focused windows is normal windows. Move it to 100
  1760. $(focusedWindow).css("z-index", 100);
  1761. //Shift all the other windows down
  1762. $(".floatWindow").each(function() {
  1763. if ($(this).hasClass("topmost")){
  1764. return;
  1765. }
  1766. var thisWindowZIndex = $(this).css("z-index");
  1767. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1768. if ($(this).attr("windowId") != windowID) {
  1769. $(this).css("z-index", thisWindowZIndex - 1);
  1770. //console.log($(this).attr("windowId"), $(this).css("z-index"));
  1771. }
  1772. }
  1773. });
  1774. }
  1775. if ($(object).hasClass("topmost")){
  1776. //The new windows is a topmost window
  1777. $(object).css("z-index", 501);
  1778. }else{
  1779. $(object).css("z-index", 101);
  1780. }
  1781. focusedWindow = $(object);
  1782. //Check if this div is hidden. If not, fade it in.
  1783. if ($(object).is(":hidden")) {
  1784. $(object).fadeIn(100);
  1785. }
  1786. }
  1787. function newFloatWindow(config, callback=undefined) {
  1788. //Check if the number of floatWindow already reaching its maxmium
  1789. if ($(".floatWindow").length > maxWindowCount){
  1790. console.log("Max number of floatWindow reached.")
  1791. return;
  1792. }
  1793. //Generate new floatwindow startup config from object
  1794. var url = defaultOrKey(config, "about:blank", "url");
  1795. var uuid = defaultOrKey(config, (new Date()).getTime(), "uid");
  1796. var width = defaultOrKey(config, 854, "width");
  1797. var height = defaultOrKey(config, 480, "height");
  1798. var moduleIcon = defaultOrKey(config, "img/system/favicon.png", "appicon");
  1799. var title = defaultOrKey(config, "New floatWindow", "title");
  1800. var left = defaultOrKey(config, 100, "left");
  1801. var top = defaultOrKey(config, 100, "top");
  1802. var parentWindowID = defaultOrKey(config, "", "parent");
  1803. var callbackFunctionName = defaultOrKey(config, "", "callback");
  1804. var bgcolor = defaultOrKey(config, "", "background-color");
  1805. //Encode function name
  1806. callbackFunctionName = encodeURIComponent(callbackFunctionName);
  1807. //Validate paramters
  1808. if (width > window.innerWidth) {
  1809. width = window.innerWidth;
  1810. }
  1811. if (height > window.innerHeight) {
  1812. height = window.innerHeight;
  1813. }
  1814. if (left + width > window.innerWidth) {
  1815. left = 0;
  1816. }
  1817. if (top + height > window.innerHeight) {
  1818. top = 0;
  1819. }
  1820. //Check if the location already cotain any window
  1821. while (floatWindowLocationDuplicated(left, top)) {
  1822. left += 30;
  1823. top += 30;
  1824. }
  1825. //Check if the opening require a overwrite on background color
  1826. var backgroundStyle = "";
  1827. if (bgcolor !== ""){
  1828. backgroundStyle = `background-color: ${bgcolor};`;
  1829. }
  1830. //Check if the theme color is applied. If yes, generate the floatWindow with overwritten theem color
  1831. var overWriteThemeColor = "";
  1832. if (desktopThemeColor != ""){
  1833. overWriteThemeColor = `background-color: ${hexToRgbA(desktopThemeColor, 0.85)}`;
  1834. }
  1835. //Append the floatWindow into the body
  1836. $("body").append(`<div class="floatWindow" windowId="${uuid}" parent="${parentWindowID}" callback="${callbackFunctionName}" style="z-index:0; width:${width}px; height:${height}px; left:${left}px; top:${top}px;${backgroundStyle}">
  1837. <div class="controls fwdragger themeColorSolid" style="${overWriteThemeColor}">
  1838. <img class="moduleicon" src="${moduleIcon}"></img>
  1839. <div class="title">${title}</div>
  1840. <div class="fwcontrol">
  1841. <div class="buttons mintoggle">
  1842. <img src="img/system/min.png"></img>
  1843. </div>
  1844. <div class="buttons maxtoggle">
  1845. <img class="maxToogleButton" src="img/system/max.png"></img>
  1846. </div>
  1847. <div class="buttons closetoggle close">
  1848. <img src="img/system/close.png"></img>
  1849. </div>
  1850. </div>
  1851. </div>
  1852. <div class="iframewrapper">
  1853. <iframe src="${url}" allowfullscreen="true"></iframe>
  1854. <div class="iframecover"></div>
  1855. </div>
  1856. </div>`);
  1857. var newWindowObject = getFloatWindowByID(uuid);
  1858. //console.log(newWindowObject);
  1859. MoveFloatWindowToTop(newWindowObject);
  1860. //Append window to taskbar
  1861. var groupInfo = url.split("/");
  1862. var group = "";
  1863. if (groupInfo.length == 1) {
  1864. group = groupInfo[0];
  1865. } else {
  1866. groupInfo.pop();
  1867. group = groupInfo.join("/");
  1868. }
  1869. //File system windows require special grouping based on their filename
  1870. if (url.includes("SystemAO/file_system/")){
  1871. group = url.split("/").pop().split(".").join("_");
  1872. }else if (url.includes("SystemAO/utilities/")){
  1873. group = url.split("/").pop().split(".").join("_");
  1874. if (group.includes("#")){
  1875. group = group.split("#")[0];
  1876. }
  1877. }
  1878. //Check if the group already exists.
  1879. var groupExists = false;
  1880. var targetGroupingTab;
  1881. $(".floatWindowButton").each(function() {
  1882. if ($(this).attr("group") == group) {
  1883. groupExists = true;
  1884. targetGroupingTab = $(this);
  1885. }
  1886. });
  1887. //Check if the group is System Explorer and held special treatment if yes
  1888. if (group.split("/").shift() == "SystemAO") {
  1889. if (url.includes("file_explorer.html") && groupExists) {
  1890. //File Manager. Group them
  1891. group = "file_explorer";
  1892. }else if (url.includes("utilities") && groupExists){
  1893. //Allow grouping
  1894. } else {
  1895. //Do not group anything from SystemAO other than file explorer
  1896. groupExists = false;
  1897. }
  1898. }
  1899. if (groupExists == false) {
  1900. //Append the item to taskbar
  1901. var windowIDGroup = encodeURIComponent(JSON.stringify([uuid]));
  1902. var floatWindowButtonObject = ` <div class="item clickable floatWindowButton onscreen" group="${group}" windowIDGroup="${windowIDGroup}">
  1903. <img class="floatWindowAppIcon" src="${moduleIcon}"></img>
  1904. <p class="floatWindowTitle">${title}</p>
  1905. </div>`;
  1906. $(".navimenu").append(floatWindowButtonObject);
  1907. } else {
  1908. //Group already exists. Add tab into that group.
  1909. var originalIDlist = JSON.parse(decodeURIComponent($(targetGroupingTab).attr('windowIDGroup')));
  1910. originalIDlist.push(uuid);
  1911. //Encode and put the group list back to the object
  1912. var newIDList = encodeURIComponent(JSON.stringify(originalIDlist));
  1913. $(targetGroupingTab).attr("windowIDGroup", newIDList);
  1914. }
  1915. hookFloatWindowEvents();
  1916. resizeAllFloatWindowButtons();
  1917. if (callback !== undefined){
  1918. callback(uuid);
  1919. }
  1920. }
  1921. function resizeAllFloatWindowButtons() {
  1922. var fwbTotalWidth = $(".floatWindowButton").length * 200;
  1923. if (fwbTotalWidth > window.innerWidth * 0.7) {
  1924. $(".floatWindowButton").addClass("hideText");
  1925. } else {
  1926. $(".floatWindowButton").removeClass("hideText");
  1927. }
  1928. }
  1929. function floatWindowLocationDuplicated(left, top) {
  1930. var duplicated = false;
  1931. $(".floatWindow").each(function() {
  1932. if ($(this).offset().left == left && $(this).offset().top == top) {
  1933. duplicated = true;
  1934. }
  1935. });
  1936. return duplicated;
  1937. }
  1938. function defaultOrKey(object, defaultvalue, key) {
  1939. if (object[key] !== undefined) {
  1940. return object[key];
  1941. }
  1942. return defaultvalue;
  1943. }
  1944. function getFloatWindowByID(id) {
  1945. var targetWindow = undefined;
  1946. $(".floatWindow").each(function() {
  1947. if ($(this).attr("windowId") == id) {
  1948. targetWindow = $(this);
  1949. }
  1950. });
  1951. return targetWindow;
  1952. }
  1953. function getFloatWindowIconByID(id) {
  1954. var targetIconURL = "img/system/favicon.png";
  1955. $(".floatWindow").each(function() {
  1956. if ($(this).attr("windowId") == id) {
  1957. //This window ID matched the target fw
  1958. targetIconURL = $(this).find(".moduleicon").attr('src');
  1959. }
  1960. });
  1961. return targetIconURL;
  1962. }
  1963. function getFloatWindowTitleByID(id) {
  1964. var title = "";
  1965. $(".floatWindow").each(function() {
  1966. if ($(this).attr("windowId") == id) {
  1967. //This window ID matched the target fw
  1968. title = $(this).find(".title").text();
  1969. }
  1970. });
  1971. return title;
  1972. }
  1973. function setFloatWindowResizePolicy(targetFWId, resizble = true) {
  1974. var targetfw = getFloatWindowByID(targetFWId);
  1975. if (resizble) {
  1976. $(targetfw).find(".maxtoggle").show();
  1977. $(targetfw).removeClass("fixedsize");
  1978. } else {
  1979. $(targetfw).find(".maxtoggle").hide();
  1980. $(targetfw).addClass("fixedsize");
  1981. }
  1982. }
  1983. function setFloatWindowSize(targetFWId, newWidth, newHeight) {
  1984. var targetfw = getFloatWindowByID(targetFWId);
  1985. $(targetfw).css({
  1986. height: newHeight,
  1987. width: newWidth
  1988. });
  1989. }
  1990. function setFloatWindowTitle(targetFWId, newTitle) {
  1991. var targetfw = getFloatWindowByID(targetFWId);
  1992. $(targetfw).find(".title").text(newTitle);
  1993. }
  1994. function openFileWithModule(moduleLaunchInfo, openFileList) {
  1995. var url = moduleLaunchInfo["StartDir"];
  1996. var size = [undefined, undefined];
  1997. var title = moduleLaunchInfo["Name"];
  1998. var icon = "img/system/favicon.png";
  1999. if (moduleLaunchInfo["IconPath"] != "") {
  2000. icon = moduleLaunchInfo["IconPath"];
  2001. }
  2002. //Use floatWindow if exists
  2003. if (moduleLaunchInfo["SupportFW"] == true && moduleLaunchInfo["LaunchFWDir"] != "") {
  2004. url = moduleLaunchInfo["LaunchFWDir"];
  2005. if (moduleLaunchInfo["InitFWSize"] !== null) {
  2006. size = moduleLaunchInfo["InitFWSize"]
  2007. }
  2008. }
  2009. //Use embedded mode if exists
  2010. if (moduleLaunchInfo["SupportEmb"] == true && moduleLaunchInfo["LaunchEmb"] != "") {
  2011. url = moduleLaunchInfo["LaunchEmb"];
  2012. if (moduleLaunchInfo["InitEmbSize"] !== null) {
  2013. size = moduleLaunchInfo["InitEmbSize"]
  2014. }
  2015. }
  2016. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  2017. //Add launch files info and launch floatWindow
  2018. parent.newFloatWindow({
  2019. url: url + "#" + openParamter,
  2020. width: size[0],
  2021. height: size[1],
  2022. appicon: icon,
  2023. title: title
  2024. });
  2025. }
  2026. //====================== DESKTOP THEME RELATED FUNCTIONS =====================
  2027. //Initiate desktop theme list and user current theme
  2028. function initDesktopTheme() {
  2029. //Update 1 April 2021: Check if the user customize the desktop with the given path
  2030. $.get("system/desktop/theme", function(data) {
  2031. //Return a list of theme stored on the system
  2032. desktopThemeList = data;
  2033. $.get("system/desktop/theme?get=true", function(data) {
  2034. //Get the user theme settings
  2035. changeDesktopTheme(data);
  2036. });
  2037. });
  2038. }
  2039. function setDesktopTheme(themeName) {
  2040. $.get("system/desktop/theme?set=" + themeName, function(data) {
  2041. //Get the user theme settings
  2042. changeDesktopTheme(themeName);
  2043. if (data.includes("Error")) {
  2044. console.log(data);
  2045. }
  2046. });
  2047. }
  2048. //Actiave background cross fade changing animation
  2049. function initBackgroundSwitchingAnimation() {
  2050. if (localStorage.getItem("ao/desktop/backgroundInterval") !== null && !isNaN(parseInt(localStorage.getItem("ao/desktop/backgroundInterval")))){
  2051. //Localstorage has interval setting that is not NaN
  2052. backgroundCrossfadeInterval = parseInt(localStorage.getItem("ao/desktop/backgroundInterval")) * 1000;
  2053. }
  2054. backgroundIntervalCounter = setInterval(function() {
  2055. $("body").css("background-image", "none").css({
  2056. 'background-color': '#000000'
  2057. });
  2058. $(".showBackground").removeClass("showBackground");
  2059. $($(".backgroundFrame")[nextSlideshowIndex]).addClass("showBackground");
  2060. nextSlideshowIndex++;
  2061. if (nextSlideshowIndex > currentBackgroundList.length - 1) {
  2062. nextSlideshowIndex = 0;
  2063. }
  2064. }, backgroundCrossfadeInterval);
  2065. }
  2066. //Function for changing the desktop theme
  2067. function changeDesktopTheme(targetThemeName) {
  2068. currentUserTheme = targetThemeName;
  2069. if (currentUserTheme.includes(":/") == false){
  2070. //This is default theme pack name
  2071. for (var i = 0; i < desktopThemeList.length; i++) {
  2072. var thisTheme = desktopThemeList[i];
  2073. if (thisTheme["Theme"] == targetThemeName) {
  2074. //Use this config as the target theme
  2075. currentBackgroundList = thisTheme["Bglist"];
  2076. break;
  2077. }
  2078. }
  2079. //Initiate the background image.
  2080. $("#bgwrapper").html("");
  2081. for (var i = 0; i < currentBackgroundList.length; i++) {
  2082. var id = "dbg" + i;
  2083. var thisImage = "img/desktop/bg/" + currentUserTheme + "/" + currentBackgroundList[i];
  2084. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2085. }
  2086. setTimeout(function() {
  2087. $("#dbg0").addClass("showBackground");
  2088. }, 300);
  2089. if (currentBackgroundList.length == 1) {
  2090. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2091. nextSlideshowIndex = 0;
  2092. }else if (currentBackgroundList.length == 0){
  2093. //Background no longer exists. Change to default
  2094. changeDesktopTheme("default");
  2095. } else {
  2096. nextSlideshowIndex = 1;
  2097. }
  2098. }else{
  2099. //This is user defined photo file
  2100. $.get("system/desktop/theme?load=" + targetThemeName, function(data){
  2101. if (data.error !== undefined){
  2102. //The folder is gone. Use default instead
  2103. console.log(data.error);
  2104. changeDesktopTheme("default");
  2105. }else{
  2106. //OK! Load it
  2107. currentBackgroundList = data;
  2108. $("#bgwrapper").html("");
  2109. for (var i = 0; i < currentBackgroundList.length; i++) {
  2110. var id = "dbg" + i;
  2111. var thisImage = "media/?file=" + currentBackgroundList[i];
  2112. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2113. }
  2114. setTimeout(function() {
  2115. $("#dbg0").addClass("showBackground");
  2116. }, 300);
  2117. if (currentBackgroundList.length == 1) {
  2118. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2119. nextSlideshowIndex = 0;
  2120. }else if (currentBackgroundList.length == 0){
  2121. //Background no longer exists. Change to default
  2122. changeDesktopTheme("default");
  2123. } else {
  2124. nextSlideshowIndex = 1;
  2125. }
  2126. }
  2127. });
  2128. }
  2129. }
  2130. $("#bgwrapper").on("click", function(evt) {
  2131. evt.preventDefault();
  2132. });
  2133. //================== DESKTOP FILE LOCATION FUNCTIONS ====================
  2134. function initDesktopFiles(optionObject = {}, callback = undefined) {
  2135. $.get("system/desktop/listDesktop", function(data) {
  2136. //Prase optionObject
  2137. var noflash = false;
  2138. if (typeof optionObject.noflash !== "undefined"){
  2139. noflash = optionObject.noflash;
  2140. }
  2141. if (noflash){
  2142. //Only clean out those object that not exists in the new filelist
  2143. var existsingFilepaths = [];
  2144. if (data != null){
  2145. for (var i =0; i < data.length; i++){
  2146. existsingFilepaths.push(data[i].Filepath);
  2147. }
  2148. }else{
  2149. //Nothing on desktop
  2150. }
  2151. //console.log(existsingFilepaths);
  2152. //If the launchIcon path is not in the latest list, remove it from desktop
  2153. $(".launchIcon").each(function(){
  2154. if (existsingFilepaths.includes($(this).attr("filepath")) == false){
  2155. $(this).remove();
  2156. }
  2157. });
  2158. }else{
  2159. //Cleanup all previous icons
  2160. $("#iconwrapper").html("");
  2161. }
  2162. //Allocate new items location
  2163. var iheight = 106;
  2164. var iwidth = 70;
  2165. var padding = 16;
  2166. if (desktopIconSize == "small") {
  2167. iheight = 82;
  2168. iwidth = 50;
  2169. } else if (desktopIconSize == "medium") {
  2170. iheight = 106;
  2171. iwidth = 70;
  2172. } else if (desktopIconSize == "big") {
  2173. iheight = 124;
  2174. iwidth = 84;
  2175. }
  2176. iconSize = [iwidth, iheight];
  2177. var screenHeight = window.innerHeight;
  2178. var screenWidth = window.innerWidth;
  2179. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2180. var hc = Math.floor((screenWidth - padding) / iwidth);
  2181. var slots = []; //A 2D array for storing relative to absolute locations
  2182. for (var j = 0; j < hc; j++) {
  2183. var thisLocationList = [];
  2184. for (var i = 0; i < vc; i++) {
  2185. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2186. thisLocationList.push(thisLocation);
  2187. }
  2188. slots.push(thisLocationList);
  2189. }
  2190. //Store the root position (0,0) in rootPosition
  2191. let rootPosition = JSON.parse(JSON.stringify(slots[0][0]));
  2192. desktopGrids = JSON.parse(JSON.stringify(slots));
  2193. //Assign items to desktop
  2194. var unallocatedFiles = [];
  2195. let remainingSlots = JSON.parse(JSON.stringify(slots));
  2196. desktopFileList = [];
  2197. if (data === null){
  2198. //No files on desktop
  2199. return;
  2200. }
  2201. for (var i = 0; i < data.length; i++) {
  2202. var thisFile = data[i];
  2203. desktopFileList.push(JSON.parse(JSON.stringify(thisFile.Filename)));
  2204. //Get icon from the icon list
  2205. var location = [thisFile.IconX, thisFile.IconY];
  2206. if (location[0] == -1 && location[1] == -1) {
  2207. //This file is not located. Push it into unallocatedFileList
  2208. unallocatedFiles.push(thisFile);
  2209. } else if (location[0] >= slots.length || location[1] >= slots[0].length) {
  2210. //This file is outside of the screen area. Set to be be unallocatedFiles as well
  2211. unallocatedFiles.push(thisFile);
  2212. } else {
  2213. //This file is already located. Push it location into occupiedSlots
  2214. //var screenX = location[0] * iwidth + padding/2;
  2215. //var screenY = location[1] * iheight + padding/2;
  2216. var screenLocation = slots[location[0]][location[1]];
  2217. //Remove this object from remaining slots
  2218. remainingSlots[location[0]][location[1]] = undefined;
  2219. //console.log(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth);
  2220. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2221. }
  2222. }
  2223. //Foreach remaining files, assign a location for it.
  2224. var walk = [slots.length, slots[0].length];
  2225. var current = [0, 0];
  2226. for (var i = 0; i < unallocatedFiles.length; i++) {
  2227. var thisFile = unallocatedFiles[i];
  2228. try{
  2229. while (typeof(remainingSlots[current[0]][current[1]]) == "undefined") {
  2230. //This slot is not usabled. Next slot.
  2231. current[1] += 1;
  2232. if (current[1] >= walk[1]) {
  2233. current[1] = 0;
  2234. current[0] += 1;
  2235. }
  2236. if (typeof(remainingSlots[current[0]]) == "undefined"){
  2237. //Not enough space to fit the item. Move it to 0 0 instead
  2238. current = [-1,-1];
  2239. console.log(current);
  2240. break;
  2241. }
  2242. }
  2243. }catch{
  2244. //Something went wrong while assigning positions. Set at root location
  2245. current = [-1,-1];
  2246. }
  2247. //Append the icon to screen
  2248. if (current[0] == -1 && current[1] == -1){
  2249. //Screen overflow. Stack the file at (0,0)
  2250. screenLocation = [rootPosition[0], rootPosition[1]];
  2251. console.log(screenLocation);
  2252. }else{
  2253. screenLocation = remainingSlots[current[0]][current[1]];
  2254. remainingSlots[current[0]][current[1]] = undefined;
  2255. }
  2256. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2257. //Save the icon location to server
  2258. $.ajax({
  2259. url: "system/desktop/files",
  2260. method: "POST",
  2261. data: {"set": thisFile.Filename, "x": current[0], "y": current[1]},
  2262. success: function(data) {
  2263. if (data.includes("Error")) {
  2264. console.log(data);
  2265. }
  2266. }
  2267. });
  2268. }
  2269. if (callback !== undefined) {
  2270. //console.log(callback);
  2271. callback();
  2272. }
  2273. });
  2274. }
  2275. //Handle desktop file multi selection and dragging
  2276. $("#bgwrapper").on("mousedown", function(evt) {
  2277. initMultiSelection(evt);
  2278. });
  2279. $("#bgwrapper").on("touchstart", function(evt) {
  2280. initMultiSelection(evt);
  2281. });
  2282. $("body").on("mouseup", function(evt) {
  2283. mainWindowMouseup(evt);
  2284. });
  2285. $("body").on("touchend", function(evt) {
  2286. mainWindowMouseup(evt);
  2287. });
  2288. $("#selectionPanel").on("mouseup", function(event) {
  2289. });
  2290. function mainWindowMouseup(event) {
  2291. if (event.pageX == multiSelectionStartPoint[0] && event.pageY == multiSelectionStartPoint[1]) {
  2292. //Pressdown and up at the same location
  2293. $(".launchIconWrapper.selected").removeClass("selected");
  2294. endMultiSelection(event);
  2295. } else {
  2296. //Press down and up at different location
  2297. endMultiSelection(event);
  2298. }
  2299. if (resizingWindow){
  2300. //Resizing floatWindow out of the window bound (aka someone don't know how to resize a window correctly)
  2301. resizingWindow = false;
  2302. resizingEdgeID = 0;
  2303. $("#fwdragpanel").hide();
  2304. $("#tfwdragpanel").hide();
  2305. $('.floatWindow.topmost').css("pointer-events", "auto");
  2306. $('.floatWindow.topmost').css("opacity", 1);
  2307. $(resizingWindowTarget).find(".iframecover").hide();
  2308. $(resizingWindowTarget).find(".iframewrapper").css('cursor', '');
  2309. }
  2310. }
  2311. function initMultiSelection(event) {
  2312. event.preventDefault();
  2313. multiSelecting = true;
  2314. hideAllContextMenus();
  2315. $("#selectionPanel").css({
  2316. left: event.pageX,
  2317. top: event.pageY,
  2318. width: 0,
  2319. height: 0
  2320. });
  2321. $("#selectionPanel").show();
  2322. multiSelectionStartPoint = [event.pageX, event.pageY];
  2323. }
  2324. function movingMultiSelectionArea(event) {
  2325. event.preventDefault();
  2326. var sx = multiSelectionStartPoint[0];
  2327. var sy = multiSelectionStartPoint[1];
  2328. var ex = event.pageX;
  2329. var ey = event.pageY;
  2330. var newleft = sx;
  2331. if (ex < sx) {
  2332. newleft = ex;
  2333. }
  2334. var newtop = sy;
  2335. if (ey < sy) {
  2336. newtop = ey;
  2337. }
  2338. var newWidth = Math.abs(sx - ex);
  2339. var newHeight = Math.abs(sy - ey);
  2340. $("#selectionPanel").css({
  2341. left: newleft,
  2342. top: newtop,
  2343. width: newWidth,
  2344. height: newHeight
  2345. });
  2346. //Select all the launch icon selected
  2347. selectAllLaunchIconInRange(newleft, newleft + newWidth, newtop, newtop + newHeight);
  2348. }
  2349. function endMultiSelection(event) {
  2350. event.preventDefault();
  2351. multiSelecting = false;
  2352. multiSelectionStartPoint = [-1, -1];
  2353. $("#selectionPanel").hide();
  2354. }
  2355. function selectAllLaunchIconInRange(minX, maxX, minY, maxY) {
  2356. //Select launch icons from its center point
  2357. var xOffset = iconSize[0] / 2;
  2358. var yOffset = iconSize[1] / 2;
  2359. $(".launchIconWrapper.selected").removeClass("selected");
  2360. $(".launchIcon").each(function() {
  2361. //Calculate center point for this icon
  2362. var thisX = $(this).offset().left + xOffset;
  2363. var thisY = $(this).offset().top + yOffset;
  2364. if (thisX > minX && thisX < maxX) {
  2365. if (thisY > minY && thisY < maxY) {
  2366. $(this).find(".launchIconWrapper").addClass("selected");
  2367. }
  2368. }
  2369. });
  2370. }
  2371. function redrawDesktopGrids() {
  2372. var iheight = 106;
  2373. var iwidth = 70;
  2374. var padding = 16;
  2375. if (desktopIconSize == "small") {
  2376. iheight = 82;
  2377. iwidth = 50;
  2378. } else if (desktopIconSize == "medium") {
  2379. iheight = 106;
  2380. iwidth = 70;
  2381. } else if (desktopIconSize == "big") {
  2382. iheight = 124;
  2383. iwidth = 84;
  2384. }
  2385. iconSize = [iwidth, iheight];
  2386. var screenHeight = window.innerHeight;
  2387. var screenWidth = window.innerWidth;
  2388. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2389. var hc = Math.floor((screenWidth - padding) / iwidth);
  2390. var slots = []; //A 2D array for storing relative to absolute locations
  2391. for (var j = 0; j < hc; j++) {
  2392. var thisLocationList = [];
  2393. for (var i = 0; i < vc; i++) {
  2394. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2395. thisLocationList.push(thisLocation);
  2396. }
  2397. slots.push(thisLocationList);
  2398. }
  2399. desktopGrids = JSON.parse(JSON.stringify(slots));
  2400. }
  2401. function appendIconAtLocation(filedata, screenX, screenY, iheight, iwidth, updateMode=false) {
  2402. //Get the icon from extension
  2403. var icon = ao_module_utils.getIconFromExt(filedata.Ext.substring(1, filedata.Ext.length));
  2404. var imagePath = "img/desktop/files_icon/" + desktopIconPack + "/" + icon + ".png";
  2405. //Handle special icon types here
  2406. var size = desktopIconSize;
  2407. var filename = JSON.parse(JSON.stringify(filedata.Filename));
  2408. var filepath = JSON.parse(JSON.stringify(filedata.Filepath));
  2409. var isDir = JSON.parse(JSON.stringify(filedata.IsDir));
  2410. var isEmptyDir = JSON.parse(JSON.stringify(filedata.IsEmptyDir));
  2411. var maxlength = 12;
  2412. var type = "file";
  2413. let shortenedName = filename;
  2414. screenX += iconOffsetXY[0];
  2415. screenY += iconOffsetXY[1];
  2416. if (isDir) {
  2417. //Folder objects
  2418. icon = "folder outline";
  2419. if (isEmptyDir){
  2420. imagePath = "img/desktop/system_icon/folder.png";
  2421. }else{
  2422. imagePath = "img/desktop/system_icon/folder-with-content.png";
  2423. }
  2424. type = "folder";
  2425. } else if (isDir == false && icon == "folder outline") {
  2426. icon = "file outline";
  2427. imagePath = "img/desktop/files_icon/" + desktopIconPack + "/file outline.png";
  2428. type = "file";
  2429. } else if (filedata.Ext == ".exe" || filedata.Ext == ".elf") {
  2430. //Executable objects
  2431. imagePath = "img/desktop/system_icon/script.png";
  2432. type = "executable";
  2433. } else if (filedata.Ext == ".shortcut") {
  2434. //Shortcut
  2435. var shortcutImage = filedata.ShortcutImage;
  2436. shortenedName = JSON.parse(JSON.stringify(filedata.ShortcutName));
  2437. imagePath = shortcutImage;
  2438. type = "shortcut";
  2439. }
  2440. //Check if filename is english only.
  2441. if (/^[a-zA-Z\d .-=+]+$/.test(filename)) {
  2442. maxlength = 20;
  2443. }else{
  2444. //Check if it is under small text mode
  2445. if (size == "small"){
  2446. maxlength = 10;
  2447. }
  2448. }
  2449. if (type != "shortcut" && filename.length > maxlength) {
  2450. shortenedName = filename.substring(0, maxlength) + "...";
  2451. }
  2452. var compressedFiledata = ao_module_utils.objectToAttr(filedata);
  2453. if (updateMode){
  2454. //Update the content that already exists for the same filepath object
  2455. var updateObject = undefined;
  2456. $(".launchIcon").each(function(){
  2457. if ($(this).attr("filedata") == compressedFiledata){
  2458. updateObject = $(this);
  2459. }
  2460. });
  2461. if (updateObject !== undefined){
  2462. //Check if content identical. If yes, skip rewrite
  2463. if (updateObject.attr("filedata") == compressedFiledata){
  2464. //Identical. Skipping
  2465. }else{
  2466. //Update its contents
  2467. updateObject.attr("type", type);
  2468. updateObject.attr("filename", filename);
  2469. updateObject.attr("filepath", filepath);
  2470. updateObject.attr("filedata", compressedFiledata);
  2471. updateObject.css("width", iwidth + "px");
  2472. updateObject.css("height", iheight + "px");
  2473. updateObject.css("left", screenX + "px");
  2474. updateObject.css("top", screenY + "px");
  2475. }
  2476. }else{
  2477. //No exists. Append to wrapper
  2478. appendDesktopIcon($("#iconwrapper"),{
  2479. type: type,
  2480. filename: filename,
  2481. filepath: filepath,
  2482. compressedFiledata: compressedFiledata,
  2483. iwidth: iwidth,
  2484. iheight: iheight,
  2485. screenX: screenX,
  2486. screenY: screenY,
  2487. size: size,
  2488. imagePath: imagePath,
  2489. shortenedName: shortenedName,
  2490. });
  2491. }
  2492. }else{
  2493. //Append into the desktop
  2494. appendDesktopIcon($("#iconwrapper"),{
  2495. type: type,
  2496. filename: filename,
  2497. filepath: filepath,
  2498. compressedFiledata: compressedFiledata,
  2499. iwidth: iwidth,
  2500. iheight: iheight,
  2501. screenX: screenX,
  2502. screenY: screenY,
  2503. size: size,
  2504. imagePath: imagePath,
  2505. shortenedName: shortenedName,
  2506. });
  2507. }
  2508. }
  2509. /*
  2510. Main function to append desktop icon to desktop
  2511. Usage: Pass in the target (as jquery object, usually $("#iconwrapper")) and properties with the following object
  2512. properties = {
  2513. type: "",
  2514. filename: "",
  2515. filepath: "",
  2516. compressedFiledata: "",
  2517. iwidth: "",
  2518. iheight: "",
  2519. screenX: "",
  2520. screenY: "",
  2521. size: "",
  2522. imagePath: "",
  2523. shortenedName: "",
  2524. }
  2525. Where the enmty string is the value that require filling in
  2526. */
  2527. function appendDesktopIcon(target, properties){
  2528. var htmlType = "div";
  2529. var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  2530. if (properties.type == "file" && isChrome){
  2531. htmlType = "a";
  2532. }
  2533. var thisIcon = $(`<${htmlType} href="javascript:void(0);" class="launchIcon"
  2534. type="${properties.type}"
  2535. draggable="true"
  2536. ondragover="allowDrop(event)"
  2537. ondrop="drop(event)"
  2538. ondragstart="drag(event)"
  2539. onmousedown="iconClicked(this,event);"
  2540. ondblclick="iconDoubleClicked(this,event);"
  2541. ontouchstart="iconClicked(this,event); doubleTouchHandler(this, event,openViaTouch);"
  2542. filename="${properties.filename}"
  2543. filepath="${properties.filepath}"
  2544. filedata="${properties.compressedFiledata}"
  2545. style="width:${properties.iwidth}px; height:${properties.iheight}px;left:${properties.screenX}px; top:${properties.screenY}px;">
  2546. <span class="launchIconWrapper"><img class="launchIconImage ${properties.size}" src="${properties.imagePath}" draggable="false"></img>
  2547. <p class="launchIconText ${properties.size} ">${properties.shortenedName}</p></span>
  2548. </${htmlType}>`);
  2549. $(target).append(thisIcon);
  2550. if (properties.type == "file" && isChrome){
  2551. console.log(isChrome);
  2552. let thisFilepath = properties.filepath;
  2553. $(thisIcon)[0].addEventListener("dragstart",function(evt){
  2554. //var filecontent = toDataUrl("media/?file=" + thisFilepath);
  2555. //var fileBase64 = window.btoa(filecontent);
  2556. var targetMime = "plain/text";
  2557. $.ajax({
  2558. url: "media/getMime/?file=" + encodeURIComponent(properties.filepath),
  2559. success: function(data){
  2560. if (data.error !== undefined){
  2561. targetMime = "text/directory";
  2562. }else{
  2563. targetMime = data;
  2564. }
  2565. },
  2566. async: false
  2567. });
  2568. evt.dataTransfer.setData("DownloadURL",targetMime+":"+ properties.filename +":"+ location.protocol + "//" + location.hostname + ":" + location.port + "/media/?file=" + encodeURIComponent(properties.filepath));
  2569. //evt.dataTransfer.setData("DownloadURL","video/mp4"+":"+"test.mp4"+":"+"data:"+"video/mp4"+";base64,"+fileBase64);
  2570. },false);
  2571. }
  2572. }
  2573. // ========================== LAUNCH ICON OPERATIONS ================
  2574. //This function start all the launchicon related events
  2575. function drag(ev) {
  2576. //If rename mode, disable drag drop
  2577. if (renameMode){
  2578. return false;
  2579. }
  2580. var target = ev.target;
  2581. if (!($(ev.target).is("div") || $(ev.target).is("a"))) {
  2582. target = $(target).parent();
  2583. }
  2584. //Parse the standard filename / filepath data
  2585. var filename = $(target).attr("filename");
  2586. var filepath = $(target).attr('filepath');
  2587. ev.dataTransfer.setData("filename", filename);
  2588. ev.dataTransfer.setData("filepath", filepath);
  2589. //Parse multifile selection filedata
  2590. var filelist = [];
  2591. if ($(".launchIconWrapper.selected").length > 0){
  2592. if (ctrlHold || $(".launchIconWrapper.selected").length > 1){
  2593. //Include all objects selected
  2594. $(".launchIconWrapper.selected").each(function(){
  2595. var fd = $(this).parent().attr("filedata");
  2596. fd = JSON.parse(decodeURIComponent(fd));
  2597. filelist.push({
  2598. filename: fd.Filename,
  2599. filepath: fd.Filepath,
  2600. hostUUID: hostInfo.DeviceUUID
  2601. });
  2602. });
  2603. }else{
  2604. //Only push the one selected
  2605. filelist.push({
  2606. filename: filename,
  2607. filepath: filepath,
  2608. hostUUID: hostInfo.DeviceUUID
  2609. });
  2610. }
  2611. }else{
  2612. //There is no selected item on desktop. Use the drag drop one
  2613. filelist.push({
  2614. filename: filename,
  2615. filepath: filepath
  2616. });
  2617. }
  2618. //console.log(filelist);
  2619. ev.dataTransfer.setData("filedata", JSON.stringify(filelist));
  2620. console.log(filelist);
  2621. //Set a flag on the drag events that these files are from Desktop GUI
  2622. ev.dataTransfer.setData("desktopflag", "true");
  2623. //Record the start drop relative position of the icon object
  2624. var dx = ev.pageX - $(target).offset().left;
  2625. var dy = ev.pageY - $(target).offset().top;
  2626. startDragRelatuve = [dx, dy];
  2627. ev.stopPropagation();
  2628. }
  2629. function drop(ev) {
  2630. ev.preventDefault();
  2631. ev.stopImmediatePropagation();
  2632. var target = $(ev.target);
  2633. if (!(target.is("div") || target.is("a"))) {
  2634. target = $(target).parent();
  2635. }
  2636. if (target.hasClass("launchIconWrapper")) {
  2637. target = target.parent();
  2638. }
  2639. var thisFilepath = $(target).attr("filepath");
  2640. if (thisFilepath == ev.dataTransfer.getData("filepath")) {
  2641. //Drag and drop on the same item. Ignore it
  2642. return;
  2643. }
  2644. var sourceFilename = ev.dataTransfer.getData("filename");
  2645. var sourceFilepath = ev.dataTransfer.getData("filepath");
  2646. //To handle multiple file transfer from file explorer
  2647. var sourceFilelist = ev.dataTransfer.getData("filedata");
  2648. console.log(target)
  2649. console.log(sourceFilename);
  2650. console.log(sourceFilepath);
  2651. if (sourceFilelist !== ""){
  2652. sourceFilelist = JSON.parse(sourceFilelist);
  2653. }
  2654. console.log(sourceFilelist);
  2655. //Drop opererations
  2656. if (target.attr("id") == "bgwrapper") {
  2657. if (sourceFilename == "" && sourceFilepath == "" && ev.dataTransfer.files.length > 0){
  2658. //Drag drop from external source. Upload to desktop
  2659. //Assign the locations for the objects
  2660. var files = ev.dataTransfer.files;
  2661. var gridMaxX = desktopGrids.length;
  2662. var gridMaxY = desktopGrids[0].length;
  2663. var targetLocation = findClosestGrid((ev.clientX), (ev.clientY), false);
  2664. var targetGridLocation = targetLocation[1];
  2665. var locations = [];
  2666. for (var k =0; k < files.length; k++){
  2667. var thisLocation = JSON.parse(JSON.stringify(targetGridLocation));
  2668. //Add k to y axis of the list.
  2669. thisLocation[1] += k;
  2670. if (thisLocation[1] >= gridMaxY){
  2671. thisLocation[0]++;
  2672. thisLocation[1] = 0;
  2673. }
  2674. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2675. //Desktop full. Force put to 0 0
  2676. thisLocation[0] = 0;
  2677. thisLocation[1] = 0;
  2678. break;
  2679. }
  2680. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  2681. thisLocation[1] += 1;
  2682. if (thisLocation[1] >= gridMaxY){
  2683. //Over the screen. Shift to the row on the right
  2684. thisLocation[0]++;
  2685. thisLocation[1] = 0;
  2686. }
  2687. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2688. //Desktop full. Force put to 0 0
  2689. thisLocation[0] = 0;
  2690. thisLocation[1] = 0;
  2691. break;
  2692. }
  2693. }
  2694. locations.push(thisLocation)
  2695. }
  2696. console.log(locations, ev.dataTransfer.files);
  2697. //Register file locations
  2698. for (var j =0; j < locations.length; j++){
  2699. let thisFile = files[j];
  2700. let thisFilename = files[j].name;
  2701. let x = parseInt(locations[j][0]);
  2702. let y = parseInt(locations[j][1]);
  2703. uploadFile(thisFile,function(){
  2704. console.log("Uploader callback");
  2705. $.ajax({
  2706. url: "system/desktop/files",
  2707. method: "POST",
  2708. data: {"set": thisFilename, "x": x, "y": y},
  2709. success: function(data) {
  2710. //Refresh the desktop
  2711. refresh(undefined, true);
  2712. }
  2713. });
  2714. });
  2715. }
  2716. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  2717. //Drag drop multiple files from desktop or file explorer to desktop
  2718. var desktopFlag = ev.dataTransfer.getData("desktopflag");
  2719. if (desktopFlag == "" || desktopFlag === undefined || desktopFlag == null){
  2720. //This is a file drag drop from not desktop to desktop
  2721. var filelist = ev.dataTransfer.getData("filedata");
  2722. if (filelist != ""){
  2723. filelist = JSON.parse(filelist);
  2724. if (filelist.length == 0){
  2725. return
  2726. }
  2727. //Get the position for this drop events and arrange grid locations
  2728. var gridPosition = gridPositionAllocate(ev.clientX, ev.clientY, filelist.length);
  2729. console.log(gridPosition)
  2730. //Check if source is also from user:/
  2731. var srcVroot = filelist[0].filepath.split(":/").shift();
  2732. var mode = "copy"
  2733. var title = "Copying "
  2734. if (srcVroot == "user"){
  2735. //Move
  2736. mode = "move"
  2737. title = "Moving "
  2738. }
  2739. //Check if any of the files already exists on desktop
  2740. /*
  2741. var duplicateFound = false;
  2742. filelist.forEach(file => {
  2743. var thisFilename = file.filename;
  2744. desktopFileList.forEach(desktopFile => {
  2745. if (desktopFile == thisFilename){
  2746. //Diplicate
  2747. duplicateFound = true;
  2748. }
  2749. });
  2750. });
  2751. */
  2752. var filepathList = [];
  2753. filelist.forEach(file => {
  2754. filepathList.push(file.filepath)
  2755. });
  2756. //Start the file operation dialog
  2757. var oprConfig = {
  2758. opr: mode,
  2759. src: filepathList,
  2760. dest: "user:/Desktop/",
  2761. overwriteMode: "ask"
  2762. }
  2763. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2764. //Genreate window title
  2765. title = title + filepathList.length;
  2766. if (filepathList.length > 1){
  2767. title += " files";
  2768. }else{
  2769. title += " file";
  2770. }
  2771. parent.newFloatWindow({
  2772. url: "SystemAO/file_system/file_operation.html#" + configHash,
  2773. width: 400,
  2774. height: 220,
  2775. appicon: "SystemAO/file_system/img/selector.png",
  2776. title: title
  2777. });
  2778. }
  2779. }else{
  2780. //This is a file drag event from desktop, but more than one files.
  2781. //Pin the final location for the drag drop object
  2782. var sourceObject = getObjectFromPath(sourceFilepath);
  2783. var dx = startDragRelatuve[0];
  2784. var dy = startDragRelatuve[1];
  2785. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  2786. var closestLocation = targetLocation[0];
  2787. var duplicateObject = getObjectFromLocation(closestLocation[0] + iconOffsetXY[0], closestLocation[1] + iconOffsetXY[1]);
  2788. if (duplicateObject !== undefined) {
  2789. //There are already object there. Do nothing
  2790. console.log("Drop location duplicated!")
  2791. return;
  2792. }
  2793. //Get other objects that is not the one drag dropped
  2794. var iconOffset = {};
  2795. for (var i =0; i < sourceFilelist.length; i++){
  2796. var thisFile = sourceFilelist[i];
  2797. if (thisFile.filepath != sourceFilepath){
  2798. //Calculate the x y offset of this icon to the drag drop one
  2799. var thisIconObject = getObjectFromPath(thisFile.filepath);
  2800. iconOffset[thisFile.filepath] = {
  2801. dx: $(sourceObject).offset().left - $(thisIconObject).offset().left,
  2802. dy: $(sourceObject).offset().top - $(thisIconObject).offset().top
  2803. }
  2804. //console.log(thisFile.filename, iconOffset[thisFile.filepath]);
  2805. }
  2806. }
  2807. //Move the drag drop object to the desiged location
  2808. $(sourceObject).css({
  2809. left: closestLocation[0] + iconOffsetXY[0],
  2810. top: closestLocation[1] + iconOffsetXY[1]
  2811. });
  2812. //Save the drag item location
  2813. $.ajax({
  2814. url: "system/desktop/files",
  2815. method: "POST",
  2816. data: {"set": sourceFilename, "x": targetLocation[1][0], "y": targetLocation[1][1]},
  2817. success: function(data) {
  2818. //console.log(data);
  2819. }
  2820. });
  2821. //Move all the relative files to the main object
  2822. var relocatePendingObjects = [];
  2823. for (const [filepath, offset] of Object.entries(iconOffset)) {
  2824. let thisIconObject = getObjectFromPath(filepath);
  2825. let caluclatedLocation = [$(sourceObject).offset().left - offset.dx, $(sourceObject).offset().top - offset.dy];
  2826. let finalIconLocation = findClosestGrid(caluclatedLocation[0], caluclatedLocation[1]);
  2827. //Check for duplication
  2828. /*
  2829. var duplicateObject = getObjectFromLocation(finalIconLocation[0][0] + iconOffsetXY[0], finalIconLocation[0][1] + iconOffsetXY[1]);
  2830. if (duplicateObject !== undefined) {
  2831. //There are already object there. Relocate this object later
  2832. relocatePendingObjects.push(duplicateObject)
  2833. }
  2834. */
  2835. //Move this icon to designed location
  2836. $(thisIconObject).css({
  2837. left: finalIconLocation[0][0] + iconOffsetXY[0],
  2838. top: finalIconLocation[0][1] + iconOffsetXY[1]
  2839. });
  2840. let thisIconFileData = JSON.parse(decodeURIComponent($(thisIconObject).attr("filedata")));
  2841. //Record this in database
  2842. $.ajax({
  2843. url: "system/desktop/files",
  2844. method: "POST",
  2845. data: {"set": thisIconFileData.Filename, "x": finalIconLocation[1][0], "y": finalIconLocation[1][1]},
  2846. success: function(data) {
  2847. //console.log(data);
  2848. }
  2849. });
  2850. }
  2851. //Get duplication objects
  2852. for (const [filepath, offset] of Object.entries(iconOffset)) {
  2853. let thisIconObject = getObjectFromPath(filepath);
  2854. //Check for duplication
  2855. var iconLocation = [$(thisIconObject).offset().left, $(thisIconObject).offset().top];
  2856. $(".launchIcon").each(function(){
  2857. if ($(this).offset().left == iconLocation[0] && $(this).offset().top == iconLocation[1]){
  2858. //This icon is at the target icon location
  2859. if ($(this).attr("filepath") != filepath){
  2860. relocatePendingObjects.push($(this));
  2861. }
  2862. }
  2863. });
  2864. }
  2865. //Relocate objects that is in the way of moving
  2866. for (var i = 0; i < relocatePendingObjects.length; i++){
  2867. var thisObject = relocatePendingObjects[i];
  2868. console.log(thisObject);
  2869. var thisX = $(thisObject).offset().left;
  2870. var thisY = $(thisObject).offset().top;
  2871. var nextEmptyGrid = findClostestEmptyGridLocation(thisX, thisY);
  2872. //Move this file to the next empty grid location
  2873. $(thisObject).css({
  2874. left: nextEmptyGrid[0][0] + iconOffsetXY[0],
  2875. top: nextEmptyGrid[0][1] + iconOffsetXY[1]
  2876. });
  2877. //Save move record to db
  2878. let thisIconFileData = JSON.parse(decodeURIComponent($(thisObject).attr("filedata")));
  2879. $.ajax({
  2880. url: "system/desktop/files",
  2881. method: "POST",
  2882. data: {"set": thisIconFileData.Filename, "x": nextEmptyGrid[1][0], "y": nextEmptyGrid[1][1]},
  2883. success: function(data) {
  2884. //console.log(data);
  2885. }
  2886. });
  2887. }
  2888. }
  2889. }else{
  2890. //Dropping a file onto other place on desktop
  2891. var sourceObject = getObjectFromPath(sourceFilepath);
  2892. var dx = startDragRelatuve[0];
  2893. var dy = startDragRelatuve[1];
  2894. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  2895. var closestLocation = targetLocation[0];
  2896. //Check if there are objects already at that location
  2897. var duplicateObject = getObjectFromLocation(closestLocation[0], closestLocation[1]);
  2898. if (duplicateObject !== undefined) {
  2899. //There are already object there. Do nothing
  2900. console.log("Drop location duplicated!")
  2901. return;
  2902. }
  2903. var closestGridIndex = targetLocation[1];
  2904. $(sourceObject).css({
  2905. left: closestLocation[0] + iconOffsetXY[0],
  2906. top: closestLocation[1] + iconOffsetXY[1]
  2907. });
  2908. $.ajax({
  2909. url: "system/desktop/files",
  2910. method: "POST",
  2911. data: {"set": sourceFilename, "x": closestGridIndex[0], "y": closestGridIndex[1]},
  2912. success: function(data) {
  2913. //console.log(data);
  2914. }
  2915. });
  2916. }
  2917. } else if (target.attr("type") == "folder") {
  2918. //Move this file or folder into the target folder
  2919. //WIP
  2920. } else if (target.attr("type") == "shortcut") {
  2921. //Opening with the shortcut
  2922. //Check shortcut type
  2923. let shortcutData = JSON.parse(decodeURIComponent($(target).attr("filedata")));
  2924. var shortcutType = shortcutData["ShortcutType"];
  2925. if (shortcutType == "module") {
  2926. //Open the source file with this module
  2927. let openFileList = [];
  2928. if ($(".launchiconwrapper.selected").length > 0 && !Array.isArray(sourceFilelist)) {
  2929. $(".launchiconwrapper.selected").each(function() {
  2930. let thisFileData = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  2931. openFileList.push({
  2932. filename: thisFileData["Filename"],
  2933. filepath: thisFileData["Filepath"]
  2934. });
  2935. });
  2936. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  2937. //Open file that is transfered from file explorer.
  2938. openFileList = sourceFilelist;
  2939. console.log(openFileList);
  2940. } else {
  2941. //Only pass in the current selected file.
  2942. openFileList.push({
  2943. filename: sourceFilename,
  2944. filepath: sourceFilepath
  2945. });
  2946. }
  2947. var shortcutModule = getModuleFromShortcutInfo(shortcutData);
  2948. //console.log(openFileList);
  2949. if (shortcutModule === undefined){
  2950. //This shortcut module is not found on this server
  2951. return;
  2952. }
  2953. openFileWithModule(shortcutModule, openFileList);
  2954. } else if (shortcutType == "folder") {
  2955. //Move the source file into this folder
  2956. }
  2957. } else {
  2958. console.log("Unknown reaction type: ", target.attr("type"));
  2959. }
  2960. }
  2961. function getModuleFromShortcutInfo(shortcutInfo) {
  2962. var ShortcutPath = shortcutInfo["ShortcutPath"];
  2963. if (ShortcutPath.includes("/") == false) {
  2964. //Legacy defination. Append /index.html at the back.
  2965. ShortcutPath = ShortcutPath + "/index.html";
  2966. }
  2967. //Try to match it with the module installed
  2968. for (var i = 0; i < moduleInstalled.length; i++) {
  2969. if (moduleInstalled[i]["StartDir"] == ShortcutPath || moduleInstalled[i]["Name"] == shortcutInfo["ShortcutName"]) {
  2970. //This is the correct module to be loaded
  2971. return moduleInstalled[i];
  2972. }
  2973. }
  2974. }
  2975. //Allocate the given number of grids from desktop
  2976. function gridPositionAllocate(posx, posy, numberOfGridNeeded=1){
  2977. var gridMaxX = desktopGrids.length;
  2978. var gridMaxY = desktopGrids[0].length;
  2979. var targetLocation = findClosestGrid(posx, posy, false);
  2980. var targetGridLocation = targetLocation[1];
  2981. var previousEmptyGridPosition = targetGridLocation;
  2982. var locations = [];
  2983. for (var k =0; k < numberOfGridNeeded; k++){
  2984. var thisLocation = JSON.parse(JSON.stringify(previousEmptyGridPosition));
  2985. //Add k to y axis of the list.
  2986. thisLocation[1] += k;
  2987. if (thisLocation[1] >= gridMaxY){
  2988. thisLocation[0]++;
  2989. thisLocation[1] = 0;
  2990. }
  2991. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2992. //Desktop full. Force put to 0 0
  2993. thisLocation[0] = 0;
  2994. thisLocation[1] = 0;
  2995. break;
  2996. }
  2997. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  2998. thisLocation[1] += 1;
  2999. if (thisLocation[1] >= gridMaxY){
  3000. //Over the screen. Shift to the row on the right
  3001. thisLocation[0]++;
  3002. thisLocation[1] = 0;
  3003. }
  3004. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3005. //Desktop full. Force put to 0 0
  3006. thisLocation[0] = 0;
  3007. thisLocation[1] = 0;
  3008. break;
  3009. }
  3010. }
  3011. previousEmptyGridPosition = JSON.parse(JSON.stringify(thisLocation))
  3012. locations.push(thisLocation)
  3013. }
  3014. return locations
  3015. }
  3016. function setIconDesktopLocation(sourceFilename, gridIndexX, gridIndexY, callback = undefined) {
  3017. $.ajax({
  3018. url: "system/desktop/files",
  3019. method: "POST",
  3020. data: {"set": sourceFilename, "x": gridIndexX, "y": gridIndexY},
  3021. success: function(data) {
  3022. if (data.error !== undefined) {
  3023. console.log(data.error);
  3024. } else {
  3025. if (callback !== undefined) {
  3026. callback();
  3027. }
  3028. }
  3029. }
  3030. });
  3031. }
  3032. //THIS FUNCTION IS NEEDED. DO NOT DELETE ALLOWDROP FUNCTION
  3033. function allowDrop(ev) {
  3034. ev.preventDefault();
  3035. }
  3036. //Pass in the object fullpath and return the icon object onscreen
  3037. function getObjectFromPath(path) {
  3038. var object;
  3039. $(".launchIcon").each(function() {
  3040. if ($(this).attr("filepath") == path) {
  3041. object = $(this);
  3042. }
  3043. });
  3044. return object;
  3045. }
  3046. //Pass in the coordinate and check if there is another object at the same location
  3047. function getObjectFromLocation(x, y) {
  3048. var object;
  3049. $(".launchIcon").each(function() {
  3050. if ($(this).position().left == x && $(this).position().top == y) {
  3051. object = $(this);
  3052. }
  3053. });
  3054. return object;
  3055. }
  3056. //Similar function to getObjectFromLocation but using grid coordinate instead of pixel coordinate
  3057. function getObjectFromGridLocation(gx, gy){
  3058. var pos = JSON.parse(JSON.stringify(desktopGrids[gx][gy]));
  3059. pos[0] = pos[0] + iconOffsetXY[0];
  3060. pos[1] = pos[1] + iconOffsetXY[1];
  3061. return getObjectFromLocation(pos[0],pos[1]);
  3062. }
  3063. //Find the clostest empty grid, prioirty given to y first then x
  3064. function findClostestEmptyGridLocation(x, y){
  3065. //Reduce icon offset to the x y on screen coordinate
  3066. x = x - iconOffsetXY[0];
  3067. y = y - iconOffsetXY[1];
  3068. //Get the grid index from absolute coordinate
  3069. var currentGridLocation = getGridIndexFromLocation(x,y);
  3070. console.log(currentGridLocation);
  3071. //Search for the next empty location
  3072. var targetLocation = [[-1,-1],[-1,-1]];
  3073. for (var i = currentGridLocation[0]; i < desktopGrids.length; i++){
  3074. var yStart = 0;
  3075. if (i == currentGridLocation[0]){
  3076. yStart = currentGridLocation[1];
  3077. }
  3078. for (k = yStart; k < desktopGrids[i].length; k++){
  3079. var thisLocation = JSON.parse(JSON.stringify(desktopGrids[i][k]));
  3080. var offsetedLocation = [thisLocation[0], thisLocation[1]];
  3081. var possibleDuplication = getObjectFromGridLocation(i,k);
  3082. //console.log( [i,k], offsetedLocation, possibleDuplication)
  3083. if (possibleDuplication === undefined){
  3084. //This is an empty slot
  3085. targetLocation = [offsetedLocation, [i,k]];
  3086. return targetLocation;
  3087. }
  3088. }
  3089. }
  3090. return targetLocation;
  3091. }
  3092. function getGridIndexFromLocation(x,y){
  3093. var gridIndex = [-1,-1];
  3094. for (var i = 0; i < desktopGrids.length; i++){
  3095. var thisXAxis = desktopGrids[i];
  3096. if (thisXAxis[0][0] == x){
  3097. //This x matches. Match y
  3098. gridIndex[0] = i;
  3099. for (var k = 0; k < thisXAxis.length; k++){
  3100. var thisYAxis = thisXAxis[k];
  3101. if (thisYAxis[1] == y){
  3102. gridIndex[1] = k;
  3103. return gridIndex;
  3104. }
  3105. }
  3106. }
  3107. }
  3108. return gridIndex;
  3109. }
  3110. //Set allow overshoot to allow drop point to get closest grid with x / y > cursor posx /y
  3111. function findClosestGrid(x, y, allowOvershoot = true) {
  3112. var minDx = window.innerWidth;
  3113. var minDy = window.innerHeight;
  3114. var finalLocation = [-1, -1];
  3115. var gridLocation = [-1, -1];
  3116. for (var i = 0; i < desktopGrids.length; i++) {
  3117. for (var j = 0; j < desktopGrids[0].length; j++) {
  3118. var thisGridLocation = desktopGrids[i][j];
  3119. var dx = x - thisGridLocation[0];
  3120. var dy = y - thisGridLocation[1];
  3121. if (allowOvershoot) {
  3122. if (Math.abs(dx) < minDx) {
  3123. minDx = Math.abs(x - thisGridLocation[0]);
  3124. finalLocation[0] = thisGridLocation[0];
  3125. gridLocation[0] = i;
  3126. }
  3127. if (Math.abs(dy) < minDy) {
  3128. minDy = Math.abs(y - thisGridLocation[1]);
  3129. finalLocation[1] = thisGridLocation[1];
  3130. gridLocation[1] = j;
  3131. }
  3132. } else {
  3133. if (dx < minDx && dx > 0) {
  3134. minDx = Math.abs(x - thisGridLocation[0]);
  3135. finalLocation[0] = thisGridLocation[0];
  3136. gridLocation[0] = i;
  3137. }
  3138. if (dy < minDy && dy > 0) {
  3139. minDy = Math.abs(y - thisGridLocation[1]);
  3140. finalLocation[1] = thisGridLocation[1];
  3141. gridLocation[1] = j;
  3142. }
  3143. }
  3144. }
  3145. }
  3146. return [finalLocation, gridLocation];
  3147. }
  3148. //Ask for confirmation before window close
  3149. //Update 16 Feb 2021: Disabled confirmation and use a new method of implementing this later
  3150. /*
  3151. function myConfirmation() {
  3152. if (!loggingOut){
  3153. return 'Your data might not been saved. Are you sure you want to quit?';
  3154. }
  3155. }
  3156. window.onbeforeunload = myConfirmation;
  3157. */
  3158. function iconClicked(object, evt) {
  3159. if (renameMode){
  3160. //Exit rename mode if icon is clicked during renaming
  3161. if ($(object).find(".renameInput").length == 0){
  3162. exitRenameMode();
  3163. }
  3164. }
  3165. //Clicked on a launch icon.
  3166. var alreadyHighlighted = $(object).find(".launchIconWrapper").hasClass("selected");
  3167. if (alreadyHighlighted){
  3168. //Already selected
  3169. if (ctrlHold) {
  3170. //Selection
  3171. $(object).find(".launchIconWrapper").removeClass("selected");
  3172. }
  3173. }else{
  3174. //Not selected yet
  3175. if (ctrlHold) {
  3176. //Add this into selection
  3177. $(object).find(".launchIconWrapper").addClass("selected");
  3178. }else{
  3179. //Remove all others and select this
  3180. $(".launchIconWrapper.selected").removeClass("selected");
  3181. $(object).find(".launchIconWrapper").addClass("selected");
  3182. }
  3183. }
  3184. }
  3185. function iconDoubleClicked(object, evt=undefined) {
  3186. //Don't allow opening when renaming
  3187. if (renameMode){
  3188. return;
  3189. }
  3190. //Double click on a launch icon, tries to open it
  3191. var filedata = ao_module_utils.attrToObject($(object).attr("filedata"));
  3192. //console.log(filedata);
  3193. if (filedata.IsDir) {
  3194. //This is a directory. Open with file explorer
  3195. newFloatWindow({
  3196. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(filedata.Filepath),
  3197. appicon: "SystemAO/file_system/img/small_icon.png",
  3198. width: 1080,
  3199. height: 580,
  3200. title: "File Manager"
  3201. });
  3202. } else if (filedata.IsShortcut) {
  3203. //This is a shortcut. Open the target endpoint
  3204. var stype = filedata["ShortcutType"];
  3205. if (stype == "module") {
  3206. //Open the target module
  3207. openModule(filedata.ShortcutPath);
  3208. } else if (stype == "folder") {
  3209. //Open the target folder
  3210. openFolder(filedata.ShortcutPath)
  3211. }else if (stype == "url"){
  3212. //Open the target webpage in a new tab
  3213. window.open(filedata.ShortcutPath);
  3214. }else{
  3215. console.log(filedata);
  3216. }
  3217. } else {
  3218. //This is a file. Open it with default opener
  3219. $.ajax({
  3220. url: "system/modules/getDefault",
  3221. method: "GET",
  3222. data: {
  3223. opr: "launch",
  3224. ext: filedata.Ext,
  3225. mode: "launch"
  3226. },
  3227. success: function(data) {
  3228. if (data.error !== undefined) {
  3229. //No default opener assigned
  3230. var url = "SystemAO/file_system/defaultOpener.html";
  3231. var icon = "SystemAO/file_system/img/opener.png";
  3232. var title = "Select an opener WebApp: "
  3233. var openFileList = [];
  3234. var openFileObject = {
  3235. filepath: filedata.Filepath,
  3236. filename: filedata.Filename
  3237. }
  3238. openFileList.push(openFileObject);
  3239. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  3240. newFloatWindow({
  3241. url: url + "#" + openParamter,
  3242. width: 320,
  3243. height: 510,
  3244. appicon: icon,
  3245. title: title
  3246. });
  3247. } else {
  3248. //Assigned. Launch with given paramter
  3249. var url = data["StartDir"];
  3250. var size = [undefined, undefined];
  3251. var title = data["Name"];
  3252. var icon = "img/system/favicon.png";
  3253. if (data["IconPath"] != "") {
  3254. icon = data["IconPath"];
  3255. }
  3256. //Use floatWindow if exists
  3257. if (data["SupportFW"] == true && data["LaunchFWDir"] != "") {
  3258. url = data["LaunchFWDir"];
  3259. if (data["InitFWSize"] !== null) {
  3260. size = data["InitFWSize"]
  3261. }
  3262. }
  3263. //Use embedded mode if exists
  3264. if (data["SupportEmb"] == true && data["LaunchEmb"] != "") {
  3265. url = data["LaunchEmb"];
  3266. if (data["InitEmbSize"] !== null) {
  3267. size = data["InitEmbSize"]
  3268. }
  3269. }
  3270. //Build open File Hash Data Format
  3271. var openFileList = [];
  3272. var openFileObject = {
  3273. filepath: filedata.Filepath,
  3274. filename: filedata.Filename
  3275. }
  3276. openFileList.push(openFileObject);
  3277. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  3278. //Add launch files info and launch floatWindow
  3279. newFloatWindow({
  3280. url: url + "#" + openParamter,
  3281. width: size[0],
  3282. height: size[1],
  3283. appicon: icon,
  3284. title: title
  3285. });
  3286. }
  3287. }
  3288. })
  3289. }
  3290. }
  3291. $(window).on("resize", function(event) {
  3292. redrawDesktopGrids();
  3293. resizeAllFloatWindowButtons();
  3294. })
  3295. // ======================= DOCUMENT KEY BINDING =====================
  3296. $(document).keydown(function(event) {
  3297. if (event.which == "17") {
  3298. //Pressdown of Ctrl key
  3299. ctrlHold = true;
  3300. } else if (event.which == "16") {
  3301. //Pressdown of Shift key
  3302. shiftHold = true;
  3303. }else if (event.which == "27"){
  3304. //Cancel all floatwindow events and key events
  3305. $("#fwdragpanel").hide();
  3306. $("#tfwdragpanel").hide();
  3307. $(".floatWindow").find(".iframecover").hide();
  3308. movingWindow = false;
  3309. resizingWindow = false;
  3310. resizingEdgeID = 0;
  3311. multiSelecting = false;
  3312. ctrlHold = false;
  3313. shiftHold = false;
  3314. }else if (event.which == "46"){
  3315. //Delete key
  3316. if (renameMode){
  3317. //Deleting content in textarea. Ignore delte action
  3318. return true
  3319. }
  3320. var deleteFilelist = [];
  3321. var deleteFilenameList = [];
  3322. $(".launchIconWrapper.selected").each(function(){
  3323. var fileObject = $(this).parent();
  3324. var fd = JSON.parse(decodeURIComponent((fileObject).attr("filedata")));
  3325. deleteFilelist.push(fd.Filepath);
  3326. deleteFilenameList.push(fd.Filename)
  3327. });
  3328. //Prase the filelist and pass to trash module
  3329. console.log(deleteFilelist);
  3330. $.ajax({
  3331. url: "system/file_system/fileOpr",
  3332. method:"POST",
  3333. data: {opr: "recycle", src: JSON.stringify(deleteFilelist)},
  3334. success: function(data){
  3335. if (data.error !== undefined){
  3336. alert(data.error);
  3337. }else{
  3338. refresh(undefined, true);
  3339. }
  3340. }
  3341. });
  3342. //Delete the file's desktop location
  3343. deleteFilenameList.forEach(file => {
  3344. $.ajax({
  3345. url: "system/desktop/files",
  3346. data: {del: file},
  3347. success: function(data){
  3348. if (data.error !== undefined){
  3349. console.log(data.error);
  3350. }
  3351. }
  3352. });
  3353. })
  3354. }else if (event.which == "13"){
  3355. //Enter key
  3356. if (!renameMode){
  3357. //Open selected object by emulating double click
  3358. $(".launchIconWrapper.selected").each(function(){
  3359. var object = $(this).parent();
  3360. iconDoubleClicked(object);
  3361. });
  3362. }else if (renameMode){
  3363. event.preventDefault();
  3364. exitRenameMode();
  3365. }
  3366. }else{
  3367. //console.log(event.which);
  3368. }
  3369. });
  3370. $(document).keyup(function(event) {
  3371. if (event.which == "17") {
  3372. ctrlHold = false;
  3373. } else if (event.which == "16") {
  3374. shiftHold = false;
  3375. }
  3376. });
  3377. $("#bgwrapper").on("mouseup", function(event) {
  3378. //Deselect all selected icons
  3379. event.preventDefault();
  3380. event.stopImmediatePropagation();
  3381. mainWindowMouseup(event);
  3382. });
  3383. function openFolder(virtualPath){
  3384. newFloatWindow({
  3385. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(virtualPath),
  3386. appicon: "SystemAO/file_system/img/small_icon.png",
  3387. width:1080,
  3388. height:580,
  3389. title: "File Manager"
  3390. });
  3391. }
  3392. function logout() {
  3393. loggingOut = true;
  3394. if (confirm("Exiting Session. Confirm?")){
  3395. $.get("system/auth/logout", function() {
  3396. window.location.href = "/";
  3397. });
  3398. }
  3399. hideAllContextMenus();
  3400. }
  3401. // ======================= CONTEXT MENU =============================
  3402. window.addEventListener("contextmenu",
  3403. function(e) {
  3404. e.preventDefault();
  3405. e.stopPropagation();
  3406. var clickTarget = $(e.target);
  3407. hideAllContextMenus();
  3408. showMenu = false;
  3409. $("#contextmenu").html("");
  3410. if (clickTarget.hasClass("launchIcon") || clickTarget.hasClass("launchIconImage") || clickTarget.hasClass("launchIconText")) {
  3411. //Click on an object on destkop
  3412. if (clickTarget.hasClass("launchIcon") == false) {
  3413. clickTarget = $(clickTarget).parent().parent();
  3414. }
  3415. if (!ctrlHold && !$(clickTarget).find(".launchIconWrapper").hasClass("selected")){
  3416. $(".launchIconWrapper.selected").removeClass("selected");
  3417. }
  3418. //Select this object
  3419. $(clickTarget).find(".launchIconWrapper").addClass("selected");
  3420. var objectType = $(clickTarget).attr("type");
  3421. operationTargetLaunchIcon = $(clickTarget);
  3422. //Check if selected more than one object
  3423. if ($(".launchIconWrapper.selected").length > 1){
  3424. //When the user selected more than one item on desktop
  3425. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3426. addContextMenuItem($("#contextmenu"), 'Open With', "<i class='caret right icon'></i>", "handleOpenWith", true);
  3427. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3428. addContextMenuSeperator($("#contextmenu"));
  3429. addContextMenuItem($("#contextmenu"), 'Download in Zip', "<i class='download icon'></i>", "downloadFile", false);
  3430. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='copy icon'></i>", "handleCloning", false);
  3431. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3432. addContextMenuSeperator($("#contextmenu"));
  3433. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3434. }else{
  3435. //When the user only selected one item
  3436. if (objectType == "file") {
  3437. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3438. addContextMenuItem($("#contextmenu"), 'Open With', "<i class='caret right icon'></i>", "handleOpenWith", true);
  3439. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3440. addContextMenuSeperator($("#contextmenu"));
  3441. addContextMenuItem($("#contextmenu"), 'Download', "<i class='download icon'></i>", "downloadFile", false);
  3442. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='copy icon'></i>", "handleCloning", false);
  3443. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3444. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3445. addContextMenuSeperator($("#contextmenu"));
  3446. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3447. } else if (objectType == "folder") {
  3448. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3449. addContextMenuItem($("#contextmenu"), 'Zip here', "<i class='zip icon'></i>", "handleZipFolder", false);
  3450. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3451. addContextMenuSeperator($("#contextmenu"));
  3452. addContextMenuItem($("#contextmenu"), 'Download as Zip', "<i class='download icon'></i>", "downloadFile", false);
  3453. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='caret right icon'></i>", "handleCloning", false);
  3454. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3455. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3456. addContextMenuSeperator($("#contextmenu"));
  3457. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3458. } else if (objectType == "shortcut") {
  3459. var fd = JSON.parse(decodeURIComponent($(clickTarget).attr("filedata")));
  3460. console.log(fd);
  3461. if (fd.ShortcutType == "module"){
  3462. //Public WebApp
  3463. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3464. addContextMenuItem($("#contextmenu"), 'Open in New Tab', "<i class='external icon'></i>", "openWebAppInNewTab", false);
  3465. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3466. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3467. }else if (fd.ShortcutType == "folder"){
  3468. //Folder
  3469. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3470. addContextMenuItem($("#contextmenu"), 'Open File Location', "<i class='folder open icon'></i>", "handleShortcutFolderOpen", false);
  3471. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3472. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3473. addContextMenuSeperator($("#contextmenu"));
  3474. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3475. }else{
  3476. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3477. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3478. }
  3479. }else{
  3480. console.log("Opening context menu on unknown type: ", objectType);
  3481. }
  3482. }
  3483. showMenu = true;
  3484. } else if (clickTarget.hasClass("backgroundFrame") || (isSafari && $(clickTarget).attr("id") == "selectionPanel")) {
  3485. //Click on the background. Load background context menu.
  3486. addContextMenuItem($("#contextmenu"), 'New', "<i class='caret right icon'></i>", "newitemmenu", true);
  3487. addContextMenuItem($("#contextmenu"), 'Refresh', "<i class='refresh icon'></i>", "handleMenuRefresh", false);
  3488. addContextMenuItem($("#contextmenu"), 'Open File Manager', undefined, "openfm", false);
  3489. //addContextMenuItem($("#contextmenu"), 'Get File from URL', "<i class='download icon'></i>", "downloadURL", false);
  3490. addContextMenuItem($("#contextmenu"), 'Personalization', "<i class='paint brush icon'></i>", "personalization", false);
  3491. addContextMenuItem($("#contextmenu"), 'Background', "<i class='caret right icon'></i>", "background", true);
  3492. addContextMenuItem($("#contextmenu"), 'Icon Size', "<i class='caret right icon'></i>", "listIconsize", true);
  3493. addContextMenuItem($("#contextmenu"), 'Toggle FullScreen', "<i class='maximize icon'></i>", "fullscreen", false);
  3494. addContextMenuItem($("#contextmenu"), 'Exit', undefined, "logout", false);
  3495. showMenu = true;
  3496. }else if (clickTarget.hasClass("fwdragger") || (clickTarget.hasClass("title") && clickTarget.parent().hasClass("fwdragger"))){
  3497. //Click on the floatWindow object
  3498. addContextMenuItem($("#contextmenu"), 'Open in New Tab', "<i class='external icon'></i>", "openSelectedFloatWindowInNewTab", false);
  3499. addContextMenuItem($("#contextmenu"), 'Refresh', "<i class='refresh icon'></i>", "refreshSelectedFloatWindow", false);
  3500. addContextMenuSeperator($("#contextmenu"));
  3501. addContextMenuItem($("#contextmenu"), 'Minimize', "<i class='window minimize icon'></i>", "minimizeSelectedFloatWindow", false);
  3502. if ($(clickTarget).parent().hasClass("fixedsize") == false && $(clickTarget).parent().parent().hasClass("fixedsize") == false){
  3503. //This FloatWindow is resizable
  3504. console.log($(clickTarget).parent());
  3505. if ($(clickTarget).parent().attr("max") !== undefined && $(clickTarget).parent().attr("max") == "true"){
  3506. addContextMenuItem($("#contextmenu"), 'Restore', "<i class='window window restore icon'></i>", "maximizeSelectedFloatWindow", false);
  3507. }else{
  3508. addContextMenuItem($("#contextmenu"), 'Maximize', "<i class='window maximize icon'></i>", "maximizeSelectedFloatWindow", false);
  3509. }
  3510. }
  3511. addContextMenuItem($("#contextmenu"), 'Close', "<i class='remove icon'></i>", "closeSelectedFloatWindow", false);
  3512. showMenu = true;
  3513. }
  3514. if (showMenu){
  3515. //Toggle context menu
  3516. $("#contextmenu").show();
  3517. var startX = e.pageX;
  3518. var startY = e.pageY;
  3519. if (e.pageX > window.innerWidth / 2){
  3520. startX = e.pageX - $("#contextmenu").width();
  3521. }
  3522. if (e.pageY > window.innerHeight / 2){
  3523. startY = e.pageY - $("#contextmenu").height();
  3524. }
  3525. $("#contextmenu").css({
  3526. left: startX,
  3527. top: startY
  3528. });
  3529. menuStartLocation = [e.pageX, e.pageY];
  3530. }
  3531. }, true);
  3532. function handleMenuRefresh() {
  3533. //This function is here to remove the object and event passed in from menu pressed object
  3534. refresh();
  3535. }
  3536. function newshortcut(){
  3537. //Show the new shortcut creation tool
  3538. newFloatWindow({
  3539. url: "SystemAO/desktop/shortcutCreator.html",
  3540. appicon: "img/desktop/system_icon/shortcut.png",
  3541. width:815,
  3542. height:485,
  3543. title: "New Shortcut"
  3544. });
  3545. hideAllContextMenus();
  3546. }
  3547. function openIconViaMenu(target, event){
  3548. $(".launchIconWrapper.selected").each(function(){
  3549. iconObject = $(this).parent();
  3550. //Emulate a doubleclick on icon
  3551. iconDoubleClicked(iconObject, event);
  3552. });
  3553. hideAllContextMenus();
  3554. }
  3555. //Opening a shortcut module from desktop to new tab
  3556. function openWebAppInNewTab(target, event){
  3557. $(".launchIconWrapper.selected").each(function(){
  3558. var fd = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3559. $.get("system/modules/getLaunchPara?module=" + fd.ShortcutPath, function(data) {
  3560. if (data.error !== undefined) {
  3561. console.log(data.error);
  3562. }else{
  3563. //Open in new tab
  3564. window.open(data.StartDir)
  3565. }
  3566. });
  3567. });
  3568. }
  3569. function downloadFile(target, event){
  3570. if ( $(".launchIconWrapper.selected").length == 1){
  3571. //Download this file directly
  3572. var rawfiledata = $(".launchIconWrapper.selected").parent().attr("filedata");
  3573. var filedata = JSON.parse(decodeURIComponent(rawfiledata));
  3574. var filepath = filedata.Filepath;
  3575. //Resolve the link to media download link
  3576. var downloadLink = "media?file=" + filepath + "&download=true";
  3577. window.open(downloadLink)
  3578. }else if ($(".launchIconWrapper.selected").length > 1){
  3579. //Create a zip file using the fs api
  3580. var filelist = [];
  3581. $(".launchIconWrapper.selected").each(function(){
  3582. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3583. var filepath = filedata.Filepath;
  3584. filelist.push(filepath);
  3585. });
  3586. $.ajax({
  3587. url: "system/file_system/zipHandler",
  3588. data: {opr: "tmpzip", src: JSON.stringify(filelist), dest: ""},
  3589. method: "POST",
  3590. success: function(data){
  3591. if (data.error !== undefined){
  3592. alert(data.error);
  3593. }else{
  3594. //Zip completed.
  3595. window.open("media?file=" + data + "&download=true");
  3596. }
  3597. }
  3598. });
  3599. }
  3600. hideAllContextMenus();
  3601. }
  3602. function handleZipFolder(){
  3603. var filelist = [];
  3604. var filename = "desktop_" + new Date().getTime() + ".zip"
  3605. if ($(".launchIconWrapper.selected").length == 1){
  3606. filename = $(".launchIconWrapper.selected").parent().attr('filename') + ".zip";
  3607. }
  3608. $(".launchIconWrapper.selected").each(function(){
  3609. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3610. var filepath = filedata.Filepath;
  3611. if (filedata.IsDir == true){
  3612. filelist.push(filepath);
  3613. }
  3614. });
  3615. $.ajax({
  3616. url: "system/file_system/zipHandler",
  3617. data: {opr: "zip", src: JSON.stringify(filelist), dest: "user:/Desktop/" + filename},
  3618. method: "POST",
  3619. success: function(data){
  3620. if (data.error !== undefined){
  3621. alert(data.error);
  3622. }else{
  3623. //Zip completed.
  3624. console.log(data);
  3625. }
  3626. }
  3627. });
  3628. //console.log(filelist);
  3629. hideAllContextMenus();
  3630. }
  3631. function handleOpenWith(target, event){
  3632. $("#subcontextmenu").html("");
  3633. $.get("system/modules/list",function(data){
  3634. if (data.error !== undefined){
  3635. alert(data.error);
  3636. }else{
  3637. var supportedModuleCount = 0;
  3638. var openWithTargets = [];
  3639. for (var i =0; i < data.length; i++){
  3640. var thisModule = data[i];
  3641. if (thisModule.SupportEmb == true){
  3642. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  3643. }
  3644. }
  3645. }
  3646. showSubContextMenu(target);
  3647. });
  3648. }
  3649. function openObjectProperty(target, object){
  3650. var filelist = [];
  3651. $(".launchIconWrapper.selected").each(function(){
  3652. var filepath = $(this).parent().attr("filepath");
  3653. filelist.push(filepath);
  3654. });
  3655. var hashPassthrough = encodeURIComponent(JSON.stringify(filelist));
  3656. newFloatWindow({
  3657. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  3658. width: 340,
  3659. height: 480,
  3660. appicon: "SystemAO/file_system/img/properties.png",
  3661. title: "File Properties",
  3662. });
  3663. hideAllContextMenus();
  3664. }
  3665. function openSelectedWith(target, event){
  3666. var targetModulename = $(target).text().trim();
  3667. var openFileList = [];
  3668. $(".selected.launchIconWrapper").each(function(){
  3669. var thisFiledata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3670. openFileList.push({
  3671. filename: thisFiledata.Filename,
  3672. filepath: thisFiledata.Filepath
  3673. });
  3674. });
  3675. //Find the launch info of the module
  3676. var targetModuleInfo = undefined;
  3677. for (var i =0; i < moduleInstalled.length; i++){
  3678. if (moduleInstalled[i].Name == targetModulename){
  3679. targetModuleInfo = JSON.parse(JSON.stringify(moduleInstalled[i]));
  3680. }
  3681. }
  3682. //Open the files with the given module
  3683. openFileWithModule(targetModuleInfo, openFileList);
  3684. hideAllContextMenus();
  3685. }
  3686. function getModuleInfoFromName(moduleName){
  3687. for (var i = 0; i < moduleInstalled.length; i++){
  3688. if (moduleInstalled[i].Name == moduleName){
  3689. return moduleInstalled[i];
  3690. }
  3691. }
  3692. return false
  3693. }
  3694. function addContextMenuItem(target, keyword, hotkey = undefined, functionName, containSubMenu = false) {
  3695. var itemClass = "item";
  3696. if (containSubMenu) {
  3697. itemClass = "item submenu";
  3698. }
  3699. if (hotkey !== undefined) {
  3700. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);">
  3701. ${keyword}
  3702. <span class="description">${hotkey}</span>
  3703. </div>`);
  3704. } else {
  3705. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);">
  3706. ${keyword}
  3707. </div>`);
  3708. }
  3709. }
  3710. function listIconsize(target, event) {
  3711. $("#subcontextmenu").html("");
  3712. var smallCheckmark = undefined;
  3713. var mediumCheckmark = undefined;
  3714. var bigCheckmark = undefined;
  3715. if (desktopIconSize == "small") {
  3716. smallCheckmark = "<i class='checkmark icon'></i>";
  3717. }
  3718. if (desktopIconSize == "medium") {
  3719. mediumCheckmark = "<i class='checkmark icon'></i>";
  3720. }
  3721. if (desktopIconSize == "big") {
  3722. bigCheckmark = "<i class='checkmark icon'></i>";
  3723. }
  3724. addContextMenuItem($("#subcontextmenu"), "Small", smallCheckmark, "setDesktopIconSize", false);
  3725. addContextMenuItem($("#subcontextmenu"), "Medium", mediumCheckmark, "setDesktopIconSize", false);
  3726. addContextMenuItem($("#subcontextmenu"), "Big", bigCheckmark, "setDesktopIconSize", false);
  3727. showSubContextMenu(target);
  3728. }
  3729. function setDesktopIconSize(target, evt) {
  3730. var targetSize = $(target).text().trim().toLowerCase();
  3731. if (["small", "medium", "big"].includes(targetSize)) {
  3732. desktopIconSize = targetSize;
  3733. }
  3734. refresh();
  3735. setStorage("iconsize", desktopIconSize);
  3736. hideAllContextMenus();
  3737. }
  3738. function addContextMenuSeperator(target) {
  3739. $(target).append(`<div class="divider"></div>`);
  3740. }
  3741. function downloadURL() {
  3742. alert("WIP");
  3743. hideAllContextMenus();
  3744. }
  3745. function background(target, evt) {
  3746. $("#subcontextmenu").html('<div class="item"><i class="loading spinning icon"></i> Loading</div>');
  3747. $.get("system/desktop/theme", function(data) {
  3748. $("#subcontextmenu").html("");
  3749. for (var i = 0; i < data.length; i++) {
  3750. if (currentUserTheme == data[i].Theme) {
  3751. addContextMenuItem($("#subcontextmenu"), data[i].Theme, "<i class='checkmark icon'></i>", "setTheme", false);
  3752. } else {
  3753. addContextMenuItem($("#subcontextmenu"), data[i].Theme, undefined, "setTheme", false);
  3754. }
  3755. }
  3756. });
  3757. showSubContextMenu(target);
  3758. }
  3759. //Set theme from button click
  3760. function setTheme(target, evt) {
  3761. var theme = $(target).text().trim();
  3762. setDesktopTheme(theme);
  3763. hideAllContextMenus();
  3764. }
  3765. function personalization() {
  3766. //Show the personalization window
  3767. newFloatWindow({
  3768. url: "SystemAO/desktop/personalization.html",
  3769. appicon: "SystemAO/desktop/img/personalization.png",
  3770. width:640,
  3771. height:480,
  3772. title: "Personalization"
  3773. });
  3774. hideAllContextMenus();
  3775. }
  3776. //New folder on the menu start location
  3777. function newfolder(object, event) {
  3778. var closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  3779. let closestPixelLocation = closestLocation[0];
  3780. let closestGridIndexLocation = closestLocation[1];
  3781. //Generate new foldername
  3782. var newFolderName = "New Folder";
  3783. var counter = 1;
  3784. while (desktopFileList.includes(newFolderName)) {
  3785. newFolderName = `New Folder(${counter})`;
  3786. counter++;
  3787. }
  3788. //Check if there are already another object at that locaton
  3789. var duplicateObject = getObjectFromLocation(closestPixelLocation[0], closestPixelLocation[1]);
  3790. var createObjectLocation = true;
  3791. if (duplicateObject !== undefined) {
  3792. //Ignore create position. Let it settle on next new slot.
  3793. createObjectLocation = false;
  3794. }
  3795. //Create the folder
  3796. $.post("system/file_system/newItem", {
  3797. type: "folder",
  3798. src: "user:/Desktop/",
  3799. filename: newFolderName
  3800. }).done(function(data) {
  3801. if (data.error !== undefined) {
  3802. console.log(data.error);
  3803. } else {
  3804. if (createObjectLocation) {
  3805. setIconDesktopLocation(newFolderName, closestGridIndexLocation[0], closestGridIndexLocation[1], function() {
  3806. //After set Desktop icon, refresh the page
  3807. refresh(function() {
  3808. //After refresh the page, highlight the new folder and set it to rename mode
  3809. var targetFolderObject = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  3810. console.log(targetFolderObject);
  3811. enableRenameOnLaunchIconObject(targetFolderObject);
  3812. });
  3813. });
  3814. }
  3815. }
  3816. });
  3817. /*
  3818. //Open new folder creation window
  3819. var existsingFileList = [];
  3820. for (var i =0; i < desktopFileList.length; i++){
  3821. existsingFileList.push({
  3822. filename: desktopFileList[i],
  3823. filepath: "user:/Desktop/" + desktopFileList[i]
  3824. });
  3825. }
  3826. newFloatWindow({
  3827. url: "SystemAO/file_system/newFolder.html#" + encodeURIComponent(JSON.stringify(existsingFileList)),
  3828. appicon: "SystemAO/file_system/img/new folder.png",
  3829. width:560,
  3830. height:340,
  3831. title: "New Folder"
  3832. });
  3833. */
  3834. hideAllContextMenus();
  3835. }
  3836. function enableRenameOnLaunchIconObject(object) {
  3837. renameMode = true;
  3838. $(".launchIcon").attr("draggable", "false");
  3839. var filedata = JSON.parse(decodeURIComponent($(object).attr("filedata")));
  3840. var originalName = filedata.Filename;
  3841. if (filedata.IsShortcut){
  3842. //Shortcut. Use its display name instead
  3843. originalName = filedata.ShortcutName;
  3844. }
  3845. $(object).find(".launchIconText").hide();
  3846. $(object).append(`<textarea class="renameInput ${desktopIconSize}" type="text" ondragstart="return false;" dblclick="event.stopImmediatePropagation(); event.stopImmediatePropagation();"maxlength="32">${originalName}</textarea>`);
  3847. $(object).find(".renameInput")[0].select();
  3848. var index = originalName.lastIndexOf(".");
  3849. console.log(index);
  3850. if( index >= 0){
  3851. $(object).find(".renameInput")[0].setSelectionRange(0, index);
  3852. }
  3853. }
  3854. function exitRenameMode() {
  3855. if (renameMode) {
  3856. $(".launchIcon").attr("draggable", "true");
  3857. $(".launchIcon").find(".launchIconText").show();
  3858. //Update the folder to textarea content
  3859. $(".renameInput").each(function() {
  3860. if ($(this).text() == "") {
  3861. //Ignore this update
  3862. } else {
  3863. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3864. var filepath = filedata.Filepath;
  3865. var newFilename = $(this).val();
  3866. if (filedata.IsShortcut == true){
  3867. //Shortcut. Edit the shortcut content name
  3868. let currentInputTextArea = $(this);
  3869. $.ajax({
  3870. url: "/system/desktop/opr/renameShortcut",
  3871. data: {src: filepath, new: newFilename},
  3872. success: function(data){
  3873. if (data.error !== undefined){
  3874. //Cancel the operation
  3875. console.log("*ERROR* " + data.error);
  3876. currentInputTextArea.remove();
  3877. }else{
  3878. //No need to update the shortcut position (as its name not changed)
  3879. refresh(function() {
  3880. //Refresh the desktop
  3881. });
  3882. }
  3883. }
  3884. })
  3885. }else{
  3886. //Normal typed files / folder. Rename the object
  3887. let currentInputTextArea = $(this);
  3888. $.ajax({
  3889. url: "./system/file_system/fileOpr",
  3890. method: "POST",
  3891. data: {opr: "rename", src: JSON.stringify([filepath]), new: JSON.stringify([newFilename])},
  3892. success: function(data){
  3893. if (data.error !== undefined){
  3894. //Cancel the operation
  3895. console.log("*ERROR* " + data.error);
  3896. currentInputTextArea.remove();
  3897. }else{
  3898. //Update the new file position
  3899. let closestLocation = findClosestGrid($(currentInputTextArea).parent().offset().left, $(currentInputTextArea).parent().offset().top);
  3900. let closestGridIndexLocation = closestLocation[1];
  3901. setIconDesktopLocation(newFilename, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  3902. //Callback after setting location
  3903. refresh(function() {
  3904. //Refresh the desktop
  3905. });
  3906. });
  3907. }
  3908. }
  3909. });
  3910. }
  3911. }
  3912. });
  3913. renameMode = false;
  3914. }
  3915. }
  3916. //Handle opening shortcut folder location
  3917. function handleShortcutFolderOpen(object, event){
  3918. var openPendingFolders = [];
  3919. $(".launchIconWrapper.selected").each(function(){
  3920. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3921. console.log(filedata);
  3922. if (filedata.IsShortcut == true){
  3923. if (filedata.ShortcutType == "folder"){
  3924. openPendingFolders.push(filedata.ShortcutPath);
  3925. }else if (filedata.ShortcutType == "module"){
  3926. openPendingFolders.push("web:/" + filedata.ShortcutPath);
  3927. }
  3928. }
  3929. });
  3930. //Open all folders
  3931. openPendingFolders.forEach(folder => {
  3932. newFloatWindow({
  3933. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(folder),
  3934. appicon: "SystemAO/file_system/img/small_icon.png",
  3935. width:1080,
  3936. height:580,
  3937. title: "File Manager"
  3938. });
  3939. })
  3940. hideAllContextMenus();
  3941. }
  3942. //Handle basic desktop file operations
  3943. function handleFileDelete(object, event){
  3944. var deleteFileList = [];
  3945. $(".launchIconWrapper.selected").each(function(){
  3946. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3947. deleteFileList.push(filedata.Filepath);
  3948. });
  3949. console.log(deleteFileList);
  3950. $.ajax({
  3951. url: "system/file_system/fileOpr",
  3952. method:"POST",
  3953. data: {opr: "recycle", src: JSON.stringify(deleteFileList)},
  3954. success: function(data){
  3955. if (data.error !== undefined){
  3956. alert(data.error);
  3957. }else{
  3958. refresh(undefined, true);
  3959. }
  3960. }
  3961. });
  3962. hideAllContextMenus();
  3963. }
  3964. //File Rename
  3965. let renamingItems = [];
  3966. function handleRename(object, event){
  3967. if ($('.launchIconWrapper.selected').length > 0){
  3968. //Enter rename mode
  3969. renamingItems = $('.launchIconWrapper.selected');
  3970. let renameTarget = $('.launchIconWrapper.selected')[0]
  3971. let fileObject = $(renameTarget).parent();
  3972. enableRenameOnLaunchIconObject(fileObject);
  3973. }
  3974. hideAllContextMenus();
  3975. }
  3976. //New item menus.
  3977. function newitemmenu(target, event) {
  3978. $("#subcontextmenu").html("");
  3979. //Append the new folder option first
  3980. addContextMenuItem($("#subcontextmenu"), 'Folder', "<i class='folder icon'></i>", "newfolder", true);
  3981. addContextMenuItem($("#subcontextmenu"), 'Shortcut', "<i class='external icon'></i>", "newshortcut", true);
  3982. addContextMenuSeperator($("#subcontextmenu"));
  3983. $.get("system/file_system/newItem", function(data) {
  3984. for (var i = 0; i < data.length; i++) {
  3985. var thisNewFile = data[i];
  3986. var icon = ao_module_utils.getIconFromExt(thisNewFile.Ext);
  3987. addContextMenuItem($("#subcontextmenu"), `<i class="${icon} icon" ext="${thisNewFile.Ext}"></i> ${thisNewFile.Desc}`, undefined, "newitem");
  3988. }
  3989. //Show sub-context menu
  3990. showSubContextMenu(target);
  3991. });
  3992. }
  3993. function showSubContextMenu(target) {
  3994. $("#subcontextmenu").show();
  3995. var targetLeft = $("#contextmenu").offset().left + $("#contextmenu").width() + 2;
  3996. var targetTop = $(target).offset().top - 1;
  3997. if (targetLeft + $("#subcontextmenu").width() > window.innerWidth){
  3998. //Overflow. Swtich to the left side of the menu
  3999. targetLeft = $("#contextmenu").offset().left - $("#subcontextmenu").width() - 2;
  4000. }
  4001. $("#subcontextmenu").css({
  4002. left: targetLeft,
  4003. top: targetTop
  4004. });
  4005. }
  4006. //Create new file item with that filename
  4007. function newitem(object, event) {
  4008. var extension = $(object).find("i").attr("ext");
  4009. //Generate a newfile name
  4010. var newfn = "NewFile" + "." + extension;
  4011. var counter = 1;
  4012. while (desktopFileList.includes(newfn)){
  4013. newfn = "NewFile (" + counter + ")." + extension;
  4014. counter++;
  4015. }
  4016. //Get the location position
  4017. let closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4018. let closestGridIndexLocation = closestLocation[1];
  4019. //Request backend to generate the new file
  4020. $.ajax({
  4021. url: "system/file_system/newItem",
  4022. data: {type: "file",src: "user:/Desktop/",filename: newfn},
  4023. success: function(data){
  4024. if (data.error !== undefined){
  4025. alert(data.error);
  4026. }else{
  4027. //Set the icon location
  4028. setIconDesktopLocation(newfn, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4029. //Refresh the desktop
  4030. refresh();
  4031. });
  4032. }
  4033. }
  4034. });
  4035. hideAllContextMenus();
  4036. }
  4037. document.getElementById("volumebar").parentNode.addEventListener("touchstart", function(e){
  4038. updateVolume( document.getElementById("volumebar").parentNode, e);
  4039. });
  4040. function getCoordinateFromEvent(e){
  4041. var x = -1;
  4042. var y = -1;
  4043. if (e.originalEvent == undefined){
  4044. e.originalEvent = e;
  4045. }
  4046. if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){
  4047. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  4048. x = touch.pageX;
  4049. y = touch.pageY;
  4050. } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
  4051. x = e.clientX;
  4052. y = e.clientY;
  4053. }else{
  4054. x = e.clientX;
  4055. y = e.clientY;
  4056. }
  4057. return [x,y];
  4058. }
  4059. function updateVolume(object, event){
  4060. var width = $(object).width();
  4061. var left = $(object).offset().left;
  4062. var clickPosition = getCoordinateFromEvent(event)[0];
  4063. var clickRel = clickPosition - left;
  4064. var percentage = clickRel / width * 100;
  4065. if (percentage < 0){
  4066. percentage = 0;
  4067. }else if (percentage > 100){
  4068. percentage = 100;
  4069. }
  4070. //Update the global volume
  4071. $(object).find(".bar").css("width",percentage + "%");
  4072. localStorage.setItem("global_volume", clickRel / width);
  4073. }
  4074. function refresh(callback = undefined, noflash=false) {
  4075. //Refresh desktop contents
  4076. let launchOption = {};
  4077. if (noflash){
  4078. launchOption = {
  4079. noflash: true
  4080. };
  4081. }else{
  4082. $(".launchIcon").remove();
  4083. }
  4084. if (callback == undefined) {
  4085. initDesktopFiles(launchOption);
  4086. } else {
  4087. initDesktopFiles(launchOption, callback);
  4088. }
  4089. hideAllContextMenus();
  4090. }
  4091. function openfm() {
  4092. //Open file explorer on desktop
  4093. newFloatWindow({
  4094. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent("user:/Desktop"),
  4095. appicon: "SystemAO/file_system/img/small_icon.png",
  4096. width: 1080,
  4097. height: 580,
  4098. title: "File Manager"
  4099. });
  4100. hideAllContextMenus();
  4101. }
  4102. /*
  4103. Notification and Notification bar related functions
  4104. Usage:
  4105. title -> The title of the notification
  4106. content -> The content of the notification
  4107. icon (optional) -> The icon of the notification
  4108. windowOpenOption (optional) -> The window opening option for user onclick redirection
  4109. */
  4110. function sendNotification(title, content, icon="notice circle", windowOpenOption=null){
  4111. if (content.length > 100){
  4112. shortenContent = content.substring(0,100) + "...";
  4113. }else{
  4114. shortenContent = content;
  4115. }
  4116. onClickOpenWindowOption = encodeURIComponent(JSON.parse(windowOpenOption));
  4117. $("#notificationlist").append(` <div class="notification object" originalcontent="${content}" redirect="${onClickOpenWindowOption}" onclick="openNotification(this);">
  4118. <p class="title"><i class="${icon} icon"></i> ${title}</p>
  4119. <p class="notifycontent">${shortenContent}</p>
  4120. <div class="closebtn" onclick="event.stopImmediatePropagation(); closeThisNotification(this);"><i class="remove icon"></i></div>
  4121. <div class="ts divider"></div>
  4122. </div>`);
  4123. $(".nonotification").hide();
  4124. }
  4125. function openNotification(obj){
  4126. newWindowOpeningOption = JSON.parse(decodeURIComponent($(obj).attr("redirect")));
  4127. if (newWindowOpeningOption == null){
  4128. //Ignore
  4129. }else{
  4130. //Start a floatWindow to the given target
  4131. newFloatWindow(newWindowOpeningOption);
  4132. }
  4133. //Clear the notiication
  4134. closeThisNotification($(obj).find(".closebtn"));
  4135. }
  4136. function closeThisNotification(obj){
  4137. $(obj).parent().slideUp("fast",function(data){
  4138. $(this).remove();
  4139. if ($(".notification.object").length == 0){
  4140. $(".nonotification").show();
  4141. }
  4142. });
  4143. }
  4144. function clearAllNotification(){
  4145. $(".notification.object").slideUp('fast',function(data){
  4146. $(this).remove();
  4147. $(".nonotification").show();
  4148. });
  4149. }
  4150. function hideAllContextMenus() {
  4151. $("#subcontextmenu").hide();
  4152. $("#contextmenu").hide()
  4153. $("#quickAccessPanel").slideUp("fast");
  4154. }
  4155. function restart(){
  4156. if (!hardwareman){
  4157. return
  4158. }
  4159. if (confirm("Confirm Restart?")){
  4160. $.ajax({
  4161. url: "system/power/restart",
  4162. success: function(data){
  4163. if (data.error !== undefined){
  4164. alert(data.error);
  4165. }
  4166. },
  4167. error: function(){
  4168. }
  4169. });
  4170. }
  4171. }
  4172. function shutdown(){
  4173. if (!hardwareman){
  4174. return
  4175. }
  4176. if (confirm("Confirm Poweroff?")){
  4177. $.ajax({
  4178. url: "system/power/shutdown",
  4179. success: function(data){
  4180. if (data.error !== undefined){
  4181. alert(data.error);
  4182. }else{
  4183. //Shutdown suceed
  4184. }
  4185. },
  4186. error: function(){
  4187. //Shutdown suceed
  4188. }
  4189. });
  4190. }
  4191. }
  4192. function uploadFile(file, callback=undefined) {
  4193. let url = 'system/file_system/upload'
  4194. let uploadCurrentPath = "user:/Desktop/";
  4195. let formData = new FormData()
  4196. let xhr = new XMLHttpRequest()
  4197. formData.append('file', file);
  4198. formData.append('path', uploadCurrentPath);
  4199. xhr.open('POST', url, true)
  4200. xhr.upload.addEventListener("progress", function(e) {
  4201. console.log((e.loaded * 100.0 / e.total) || 100)
  4202. })
  4203. xhr.addEventListener('readystatechange', function(e) {
  4204. if (xhr.readyState == 4 && xhr.status == 200) {
  4205. if (callback !== undefined){
  4206. callback(e.target.response);
  4207. }
  4208. }
  4209. else if (xhr.readyState == 4 && xhr.status != 200) {
  4210. console.log("Upload failed :" + xhr.status);
  4211. }
  4212. })
  4213. xhr.send(formData);
  4214. }
  4215. function setStorage(key, value, callback = undefined) {
  4216. $.get("system/desktop/preference?preference=" + key + "&value=" + value, function(data) {
  4217. if (data.error !== undefined) {
  4218. console.log(data.error);
  4219. } else {
  4220. if (callback !== undefined) {
  4221. callback();
  4222. }
  4223. }
  4224. });
  4225. }
  4226. function getStorage(key, callback) {
  4227. $.get("system/desktop/preference?preference=" + key, callback);
  4228. }
  4229. function showSystemSettings(){
  4230. var hasAccessToSetting = false;
  4231. moduleInstalled.forEach(thismod => {
  4232. if (thismod.Name == "System Setting"){
  4233. openModule("System Setting");
  4234. }
  4235. })
  4236. }
  4237. function initTheme(targetTheme=undefined){
  4238. if (targetTheme == undefined){
  4239. $.get("../../system/file_system/preference?key=file_explorer/theme", function(data){
  4240. if (data == "darkTheme"){
  4241. setDarkTheme();
  4242. }
  4243. });
  4244. }else{
  4245. //Manual override mode
  4246. if (targetTheme == "darkTheme"){
  4247. setDarkTheme();
  4248. }else if (targetTheme == "whiteTheme"){
  4249. setWhiteTheme();
  4250. }
  4251. }
  4252. }
  4253. function setFloatWindowTheme(fwid, theme="dark"){
  4254. var targetFW = getFloatWindowByID(fwid);
  4255. if (theme == "dark"){
  4256. $(targetFW).removeClass("white");
  4257. }else if (theme == "white"){
  4258. $(targetFW).addClass("white");
  4259. }
  4260. }
  4261. function checkFileSystemAccess(){
  4262. var allowReadWrite = false;
  4263. moduleInstalled.forEach(thisModule => {
  4264. if (thisModule.Name == "File Manager"){
  4265. //This user has read write access to file system
  4266. allowReadWrite = true;
  4267. }
  4268. });
  4269. if (!allowReadWrite){
  4270. sendNotification("READ ONLY Account", "This account is read only. You cannot perform any file operations on this desktop.");
  4271. }
  4272. }
  4273. function setDarkTheme(){
  4274. $("#listMenu").addClass("darkTheme");
  4275. $("#powerIcon").attr("src","img/system/power-white.svg");
  4276. $("#quickAccessPanel").addClass("darkTheme");
  4277. $("#quickAccessPanel").find(".button").addClass("inverted");
  4278. }
  4279. function setWhiteTheme(){
  4280. $("#listMenu").removeClass("darkTheme");
  4281. $("#powerIcon").attr("src","img/system/power.svg");
  4282. $("#quickAccessPanel").removeClass("darkTheme");
  4283. $("#quickAccessPanel").find(".button").removeClass("inverted");
  4284. }
  4285. function hexToRgbA(hex, transparent=1){
  4286. var c;
  4287. if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
  4288. c= hex.substring(1).split('');
  4289. if(c.length== 3){
  4290. c= [c[0], c[0], c[1], c[1], c[2], c[2]];
  4291. }
  4292. c= '0x'+c.join('');
  4293. return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',' + transparent + ')';
  4294. }
  4295. throw new Error('Bad Hex');
  4296. }
  4297. function setThemeColor(newThemeColor){
  4298. //Update the global theme color
  4299. desktopThemeColor = newThemeColor;
  4300. //Update the related elements
  4301. $("#statusbar").css("background-color",newThemeColor);
  4302. $("#navimenu").css("background-color",hexToRgbA(newThemeColor, 0.5));
  4303. $(".floatWindow .controls").css("background-color",hexToRgbA(newThemeColor, 0.85));
  4304. //List menu theme color bar
  4305. $("#listMenu").find(".searchBar").css("border-bottom", "2px solid " + newThemeColor);
  4306. $("#volumebar").css("background-color", newThemeColor);
  4307. }
  4308. //Load the user define theme color to overwrite the default color if exists
  4309. function initUserDefinedThemeColor(){
  4310. $.ajax({
  4311. url: "../../system/file_system/preference",
  4312. data: {key: "themecolor"},
  4313. success: function(data){
  4314. if (data.error == undefined && data != ""){
  4315. setThemeColor(data);
  4316. }
  4317. }
  4318. });
  4319. }
  4320. //Float Window context menu
  4321. function getFocusedFloatWindowID(){
  4322. var targetFloatWindowId = "";
  4323. $(".floatWindow").each(function() {
  4324. var thisWindowZIndex = $(this).css("z-index");
  4325. if (parseInt(thisWindowZIndex) == 101){
  4326. targetFloatWindowId = $(this).attr("windowid");
  4327. }
  4328. });
  4329. return targetFloatWindowId;
  4330. }
  4331. function getFocusedFloatWindow(){
  4332. var focusedFwId = getFocusedFloatWindowID();
  4333. if (focusedFwId != ""){
  4334. var fw = getFloatWindowByID(focusedFwId);
  4335. return fw;
  4336. }else{
  4337. return undefined;
  4338. }
  4339. }
  4340. function refreshSelectedFloatWindow(target, event){
  4341. var fw = getFocusedFloatWindow();
  4342. if (fw != undefined){
  4343. $(fw).find("iframe")[0].contentWindow.location.reload();
  4344. }
  4345. hideAllContextMenus();
  4346. }
  4347. function maximizeSelectedFloatWindow(target, event){
  4348. var fw = getFocusedFloatWindow();
  4349. if (fw != undefined){
  4350. toggleMax($(fw).find(".buttons.maxtoggle"),event);
  4351. }
  4352. hideAllContextMenus();
  4353. }
  4354. function minimizeSelectedFloatWindow(target, event){
  4355. var fw = getFocusedFloatWindow();
  4356. if (fw != undefined){
  4357. min($(fw).find(".buttons.mintoggle"),event);
  4358. }
  4359. hideAllContextMenus();
  4360. }
  4361. function openSelectedFloatWindowInNewTab(){
  4362. var fw = getFocusedFloatWindow();
  4363. if (fw != undefined){
  4364. var currentURL = $(fw).find("iframe")[0].contentWindow.location;
  4365. window.open(currentURL);
  4366. }
  4367. hideAllContextMenus();
  4368. }
  4369. function closeSelectedFloatWindow(target, event){
  4370. var fw = getFocusedFloatWindow();
  4371. if (fw != undefined){
  4372. closeFloatWindow($(fw).find(".buttons.closetoggle"),event);
  4373. }
  4374. hideAllContextMenus();
  4375. }
  4376. function fullscreen() {
  4377. //Opening full screen will lead to hidden of all iframe for unknown reasons
  4378. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
  4379. (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
  4380. (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
  4381. (document.msFullscreenElement && document.msFullscreenElement !== null);
  4382. var elem = document.documentElement;
  4383. if (!isInFullScreen) {
  4384. if (elem.requestFullscreen) {
  4385. elem.requestFullscreen();
  4386. } else if (elem.mozRequestFullScreen) { /* Firefox */
  4387. elem.mozRequestFullScreen();
  4388. } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
  4389. elem.webkitRequestFullscreen();
  4390. } else if (elem.msRequestFullscreen) { /* IE/Edge */
  4391. elem.msRequestFullscreen();
  4392. }
  4393. } else {
  4394. if (document.exitFullscreen) {
  4395. document.exitFullscreen();
  4396. } else if (document.webkitExitFullscreen) {
  4397. document.webkitExitFullscreen();
  4398. } else if (document.mozCancelFullScreen) {
  4399. document.mozCancelFullScreen();
  4400. } else if (document.msExitFullscreen) {
  4401. document.msExitFullscreen();
  4402. }
  4403. }
  4404. hideAllContextMenus();
  4405. }
  4406. /*
  4407. Background services for keeping desktop files updated
  4408. Same mechanism is used as file explorer
  4409. */
  4410. let desktopFileHash = "";
  4411. setInterval(function(){
  4412. getDesktopHash(function(hash){
  4413. if (desktopFileHash == ""){
  4414. //Initialization
  4415. desktopFileHash = hash;
  4416. }else if (desktopFileHash != hash){
  4417. //Changed on desktop files. Refresh
  4418. refresh();
  4419. desktopFileHash = hash;
  4420. }
  4421. //Else, no file change on desktop
  4422. });
  4423. }, 15000);
  4424. function getDesktopHash(callback){
  4425. $.ajax({
  4426. url: "../../system/file_system/listDirHash",
  4427. data: {dir: "user:/Desktop/"},
  4428. success: function(data){
  4429. if (data.error !== undefined){
  4430. }
  4431. callback(data);
  4432. }
  4433. })
  4434. }
  4435. </script>
  4436. </body>
  4437. </html>