desktop.system 203 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992
  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 UnpinFloatWindowFromTopMostMode(object){
  1740. $(object).removeClass("topmost");
  1741. if (focusedWindow == object){
  1742. focusedWindow = undefined;
  1743. $(object).css("z-index", 1);
  1744. }
  1745. MoveFloatWindowToTop(object);
  1746. }
  1747. function MoveFloatWindowToTop(object) {
  1748. var windowID = $(object).attr("windowId");
  1749. var windowZindex = $(object).css("z-index");
  1750. //Shift down all floatWindows that has z-index higher than this window by 2
  1751. if (windowID == $(focusedWindow).attr("windowId")) {
  1752. //This window already at the top
  1753. return;
  1754. }
  1755. if ($(focusedWindow).hasClass("topmost")){
  1756. //The previous focused windows is topmost. Move it to layer 109
  1757. $(focusedWindow).css("z-index", 500);
  1758. $(".floatWindow.topmost").each(function(){
  1759. var thisWindowZIndex = $(this).css("z-index");
  1760. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1761. if ($(this).attr("windowId") != windowID) {
  1762. $(this).css("z-index", thisWindowZIndex - 1);
  1763. }
  1764. }
  1765. });
  1766. }else{
  1767. //The previous focused windows is normal windows. Move it to 100
  1768. $(focusedWindow).css("z-index", 100);
  1769. //Shift all the other windows down
  1770. $(".floatWindow").each(function() {
  1771. if ($(this).hasClass("topmost")){
  1772. return;
  1773. }
  1774. var thisWindowZIndex = $(this).css("z-index");
  1775. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1776. if ($(this).attr("windowId") != windowID) {
  1777. $(this).css("z-index", thisWindowZIndex - 1);
  1778. //console.log($(this).attr("windowId"), $(this).css("z-index"));
  1779. }
  1780. }
  1781. });
  1782. }
  1783. if ($(object).hasClass("topmost")){
  1784. //The new windows is a topmost window
  1785. $(object).css("z-index", 501);
  1786. }else{
  1787. $(object).css("z-index", 101);
  1788. }
  1789. focusedWindow = $(object);
  1790. //Check if this div is hidden. If not, fade it in.
  1791. if ($(object).is(":hidden")) {
  1792. $(object).fadeIn(100);
  1793. }
  1794. }
  1795. function newFloatWindow(config, callback=undefined) {
  1796. //Check if the number of floatWindow already reaching its maxmium
  1797. if ($(".floatWindow").length > maxWindowCount){
  1798. console.log("Max number of floatWindow reached.")
  1799. return;
  1800. }
  1801. //Generate new floatwindow startup config from object
  1802. var url = defaultOrKey(config, "about:blank", "url");
  1803. var uuid = defaultOrKey(config, (new Date()).getTime(), "uid");
  1804. var width = defaultOrKey(config, 854, "width");
  1805. var height = defaultOrKey(config, 480, "height");
  1806. var moduleIcon = defaultOrKey(config, "img/system/favicon.png", "appicon");
  1807. var title = defaultOrKey(config, "New floatWindow", "title");
  1808. var left = defaultOrKey(config, 100, "left");
  1809. var top = defaultOrKey(config, 100, "top");
  1810. var parentWindowID = defaultOrKey(config, "", "parent");
  1811. var callbackFunctionName = defaultOrKey(config, "", "callback");
  1812. var bgcolor = defaultOrKey(config, "", "background-color");
  1813. //Encode function name
  1814. callbackFunctionName = encodeURIComponent(callbackFunctionName);
  1815. //Validate paramters
  1816. if (width > window.innerWidth) {
  1817. width = window.innerWidth;
  1818. }
  1819. if (height > window.innerHeight) {
  1820. height = window.innerHeight;
  1821. }
  1822. if (left + width > window.innerWidth) {
  1823. left = 0;
  1824. }
  1825. if (top + height > window.innerHeight) {
  1826. top = 0;
  1827. }
  1828. //Check if the location already cotain any window
  1829. while (floatWindowLocationDuplicated(left, top)) {
  1830. left += 30;
  1831. top += 30;
  1832. }
  1833. //Check if the opening require a overwrite on background color
  1834. var backgroundStyle = "";
  1835. if (bgcolor !== ""){
  1836. backgroundStyle = `background-color: ${bgcolor};`;
  1837. }
  1838. //Check if the theme color is applied. If yes, generate the floatWindow with overwritten theem color
  1839. var overWriteThemeColor = "";
  1840. if (desktopThemeColor != ""){
  1841. overWriteThemeColor = `background-color: ${hexToRgbA(desktopThemeColor, 0.85)}`;
  1842. }
  1843. //Append the floatWindow into the body
  1844. $("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}">
  1845. <div class="controls fwdragger themeColorSolid" style="${overWriteThemeColor}">
  1846. <img class="moduleicon" src="${moduleIcon}"></img>
  1847. <div class="title">${title}</div>
  1848. <div class="fwcontrol">
  1849. <div class="buttons mintoggle">
  1850. <img src="img/system/min.png"></img>
  1851. </div>
  1852. <div class="buttons maxtoggle">
  1853. <img class="maxToogleButton" src="img/system/max.png"></img>
  1854. </div>
  1855. <div class="buttons closetoggle close">
  1856. <img src="img/system/close.png"></img>
  1857. </div>
  1858. </div>
  1859. </div>
  1860. <div class="iframewrapper">
  1861. <iframe src="${url}" allowfullscreen="true"></iframe>
  1862. <div class="iframecover"></div>
  1863. </div>
  1864. </div>`);
  1865. var newWindowObject = getFloatWindowByID(uuid);
  1866. //console.log(newWindowObject);
  1867. MoveFloatWindowToTop(newWindowObject);
  1868. //Append window to taskbar
  1869. var groupInfo = url.split("/");
  1870. var group = "";
  1871. if (groupInfo.length == 1) {
  1872. group = groupInfo[0];
  1873. } else {
  1874. groupInfo.pop();
  1875. group = groupInfo.join("/");
  1876. }
  1877. //File system windows require special grouping based on their filename
  1878. if (url.includes("SystemAO/file_system/")){
  1879. group = url.split("/").pop().split(".").join("_");
  1880. }else if (url.includes("SystemAO/utilities/")){
  1881. group = url.split("/").pop().split(".").join("_");
  1882. if (group.includes("#")){
  1883. group = group.split("#")[0];
  1884. }
  1885. }
  1886. //Check if the group already exists.
  1887. var groupExists = false;
  1888. var targetGroupingTab;
  1889. $(".floatWindowButton").each(function() {
  1890. if ($(this).attr("group") == group) {
  1891. groupExists = true;
  1892. targetGroupingTab = $(this);
  1893. }
  1894. });
  1895. //Check if the group is System Explorer and held special treatment if yes
  1896. if (group.split("/").shift() == "SystemAO") {
  1897. if (url.includes("file_explorer.html") && groupExists) {
  1898. //File Manager. Group them
  1899. group = "file_explorer";
  1900. }else if (url.includes("utilities") && groupExists){
  1901. //Allow grouping
  1902. } else {
  1903. //Do not group anything from SystemAO other than file explorer
  1904. groupExists = false;
  1905. }
  1906. }
  1907. if (groupExists == false) {
  1908. //Append the item to taskbar
  1909. var windowIDGroup = encodeURIComponent(JSON.stringify([uuid]));
  1910. var floatWindowButtonObject = ` <div class="item clickable floatWindowButton onscreen" group="${group}" windowIDGroup="${windowIDGroup}">
  1911. <img class="floatWindowAppIcon" src="${moduleIcon}"></img>
  1912. <p class="floatWindowTitle">${title}</p>
  1913. </div>`;
  1914. $(".navimenu").append(floatWindowButtonObject);
  1915. } else {
  1916. //Group already exists. Add tab into that group.
  1917. var originalIDlist = JSON.parse(decodeURIComponent($(targetGroupingTab).attr('windowIDGroup')));
  1918. originalIDlist.push(uuid);
  1919. //Encode and put the group list back to the object
  1920. var newIDList = encodeURIComponent(JSON.stringify(originalIDlist));
  1921. $(targetGroupingTab).attr("windowIDGroup", newIDList);
  1922. }
  1923. hookFloatWindowEvents();
  1924. resizeAllFloatWindowButtons();
  1925. if (callback !== undefined){
  1926. callback(uuid);
  1927. }
  1928. }
  1929. function resizeAllFloatWindowButtons() {
  1930. var fwbTotalWidth = $(".floatWindowButton").length * 200;
  1931. if (fwbTotalWidth > window.innerWidth * 0.7) {
  1932. $(".floatWindowButton").addClass("hideText");
  1933. } else {
  1934. $(".floatWindowButton").removeClass("hideText");
  1935. }
  1936. }
  1937. function floatWindowLocationDuplicated(left, top) {
  1938. var duplicated = false;
  1939. $(".floatWindow").each(function() {
  1940. if ($(this).offset().left == left && $(this).offset().top == top) {
  1941. duplicated = true;
  1942. }
  1943. });
  1944. return duplicated;
  1945. }
  1946. function defaultOrKey(object, defaultvalue, key) {
  1947. if (object[key] !== undefined) {
  1948. return object[key];
  1949. }
  1950. return defaultvalue;
  1951. }
  1952. function getFloatWindowByID(id) {
  1953. var targetWindow = undefined;
  1954. $(".floatWindow").each(function() {
  1955. if ($(this).attr("windowId") == id) {
  1956. targetWindow = $(this);
  1957. }
  1958. });
  1959. return targetWindow;
  1960. }
  1961. function getFloatWindowIconByID(id) {
  1962. var targetIconURL = "img/system/favicon.png";
  1963. $(".floatWindow").each(function() {
  1964. if ($(this).attr("windowId") == id) {
  1965. //This window ID matched the target fw
  1966. targetIconURL = $(this).find(".moduleicon").attr('src');
  1967. }
  1968. });
  1969. return targetIconURL;
  1970. }
  1971. function getFloatWindowTitleByID(id) {
  1972. var title = "";
  1973. $(".floatWindow").each(function() {
  1974. if ($(this).attr("windowId") == id) {
  1975. //This window ID matched the target fw
  1976. title = $(this).find(".title").text();
  1977. }
  1978. });
  1979. return title;
  1980. }
  1981. function setFloatWindowResizePolicy(targetFWId, resizble = true) {
  1982. var targetfw = getFloatWindowByID(targetFWId);
  1983. if (resizble) {
  1984. $(targetfw).find(".maxtoggle").show();
  1985. $(targetfw).removeClass("fixedsize");
  1986. } else {
  1987. $(targetfw).find(".maxtoggle").hide();
  1988. $(targetfw).addClass("fixedsize");
  1989. }
  1990. }
  1991. function setFloatWindowSize(targetFWId, newWidth, newHeight) {
  1992. var targetfw = getFloatWindowByID(targetFWId);
  1993. $(targetfw).css({
  1994. height: newHeight,
  1995. width: newWidth
  1996. });
  1997. }
  1998. function setFloatWindowTitle(targetFWId, newTitle) {
  1999. var targetfw = getFloatWindowByID(targetFWId);
  2000. $(targetfw).find(".title").text(newTitle);
  2001. }
  2002. function openFileWithModule(moduleLaunchInfo, openFileList) {
  2003. var url = moduleLaunchInfo["StartDir"];
  2004. var size = [undefined, undefined];
  2005. var title = moduleLaunchInfo["Name"];
  2006. var icon = "img/system/favicon.png";
  2007. if (moduleLaunchInfo["IconPath"] != "") {
  2008. icon = moduleLaunchInfo["IconPath"];
  2009. }
  2010. //Use floatWindow if exists
  2011. if (moduleLaunchInfo["SupportFW"] == true && moduleLaunchInfo["LaunchFWDir"] != "") {
  2012. url = moduleLaunchInfo["LaunchFWDir"];
  2013. if (moduleLaunchInfo["InitFWSize"] !== null) {
  2014. size = moduleLaunchInfo["InitFWSize"]
  2015. }
  2016. }
  2017. //Use embedded mode if exists
  2018. if (moduleLaunchInfo["SupportEmb"] == true && moduleLaunchInfo["LaunchEmb"] != "") {
  2019. url = moduleLaunchInfo["LaunchEmb"];
  2020. if (moduleLaunchInfo["InitEmbSize"] !== null) {
  2021. size = moduleLaunchInfo["InitEmbSize"]
  2022. }
  2023. }
  2024. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  2025. //Add launch files info and launch floatWindow
  2026. parent.newFloatWindow({
  2027. url: url + "#" + openParamter,
  2028. width: size[0],
  2029. height: size[1],
  2030. appicon: icon,
  2031. title: title
  2032. });
  2033. }
  2034. //====================== DESKTOP THEME RELATED FUNCTIONS =====================
  2035. //Initiate desktop theme list and user current theme
  2036. function initDesktopTheme() {
  2037. //Update 1 April 2021: Check if the user customize the desktop with the given path
  2038. $.get("system/desktop/theme", function(data) {
  2039. //Return a list of theme stored on the system
  2040. desktopThemeList = data;
  2041. $.get("system/desktop/theme?get=true", function(data) {
  2042. //Get the user theme settings
  2043. changeDesktopTheme(data);
  2044. });
  2045. });
  2046. }
  2047. function setDesktopTheme(themeName) {
  2048. $.get("system/desktop/theme?set=" + themeName, function(data) {
  2049. //Get the user theme settings
  2050. changeDesktopTheme(themeName);
  2051. if (data.includes("Error")) {
  2052. console.log(data);
  2053. }
  2054. });
  2055. }
  2056. //Actiave background cross fade changing animation
  2057. function initBackgroundSwitchingAnimation() {
  2058. if (localStorage.getItem("ao/desktop/backgroundInterval") !== null && !isNaN(parseInt(localStorage.getItem("ao/desktop/backgroundInterval")))){
  2059. //Localstorage has interval setting that is not NaN
  2060. backgroundCrossfadeInterval = parseInt(localStorage.getItem("ao/desktop/backgroundInterval")) * 1000;
  2061. }
  2062. backgroundIntervalCounter = setInterval(function() {
  2063. $("body").css("background-image", "none").css({
  2064. 'background-color': '#000000'
  2065. });
  2066. $(".showBackground").removeClass("showBackground");
  2067. $($(".backgroundFrame")[nextSlideshowIndex]).addClass("showBackground");
  2068. nextSlideshowIndex++;
  2069. if (nextSlideshowIndex > currentBackgroundList.length - 1) {
  2070. nextSlideshowIndex = 0;
  2071. }
  2072. }, backgroundCrossfadeInterval);
  2073. }
  2074. //Function for changing the desktop theme
  2075. function changeDesktopTheme(targetThemeName) {
  2076. currentUserTheme = targetThemeName;
  2077. if (currentUserTheme.includes(":/") == false){
  2078. //This is default theme pack name
  2079. for (var i = 0; i < desktopThemeList.length; i++) {
  2080. var thisTheme = desktopThemeList[i];
  2081. if (thisTheme["Theme"] == targetThemeName) {
  2082. //Use this config as the target theme
  2083. currentBackgroundList = thisTheme["Bglist"];
  2084. break;
  2085. }
  2086. }
  2087. //Initiate the background image.
  2088. $("#bgwrapper").html("");
  2089. for (var i = 0; i < currentBackgroundList.length; i++) {
  2090. var id = "dbg" + i;
  2091. var thisImage = "img/desktop/bg/" + currentUserTheme + "/" + currentBackgroundList[i];
  2092. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2093. }
  2094. setTimeout(function() {
  2095. $("#dbg0").addClass("showBackground");
  2096. }, 300);
  2097. if (currentBackgroundList.length == 1) {
  2098. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2099. nextSlideshowIndex = 0;
  2100. }else if (currentBackgroundList.length == 0){
  2101. //Background no longer exists. Change to default
  2102. changeDesktopTheme("default");
  2103. } else {
  2104. nextSlideshowIndex = 1;
  2105. }
  2106. }else{
  2107. //This is user defined photo file
  2108. $.get("system/desktop/theme?load=" + targetThemeName, function(data){
  2109. if (data.error !== undefined){
  2110. //The folder is gone. Use default instead
  2111. console.log(data.error);
  2112. changeDesktopTheme("default");
  2113. }else{
  2114. //OK! Load it
  2115. currentBackgroundList = data;
  2116. $("#bgwrapper").html("");
  2117. for (var i = 0; i < currentBackgroundList.length; i++) {
  2118. var id = "dbg" + i;
  2119. var thisImage = "media/?file=" + currentBackgroundList[i];
  2120. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2121. }
  2122. setTimeout(function() {
  2123. $("#dbg0").addClass("showBackground");
  2124. }, 300);
  2125. if (currentBackgroundList.length == 1) {
  2126. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2127. nextSlideshowIndex = 0;
  2128. }else if (currentBackgroundList.length == 0){
  2129. //Background no longer exists. Change to default
  2130. changeDesktopTheme("default");
  2131. } else {
  2132. nextSlideshowIndex = 1;
  2133. }
  2134. }
  2135. });
  2136. }
  2137. }
  2138. $("#bgwrapper").on("click", function(evt) {
  2139. evt.preventDefault();
  2140. });
  2141. //================== DESKTOP FILE LOCATION FUNCTIONS ====================
  2142. function initDesktopFiles(optionObject = {}, callback = undefined) {
  2143. $.get("system/desktop/listDesktop", function(data) {
  2144. //Prase optionObject
  2145. var noflash = false;
  2146. if (typeof optionObject.noflash !== "undefined"){
  2147. noflash = optionObject.noflash;
  2148. }
  2149. if (noflash){
  2150. //Only clean out those object that not exists in the new filelist
  2151. var existsingFilepaths = [];
  2152. if (data != null){
  2153. for (var i =0; i < data.length; i++){
  2154. existsingFilepaths.push(data[i].Filepath);
  2155. }
  2156. }else{
  2157. //Nothing on desktop
  2158. }
  2159. //console.log(existsingFilepaths);
  2160. //If the launchIcon path is not in the latest list, remove it from desktop
  2161. $(".launchIcon").each(function(){
  2162. if (existsingFilepaths.includes($(this).attr("filepath")) == false){
  2163. $(this).remove();
  2164. }
  2165. });
  2166. }else{
  2167. //Cleanup all previous icons
  2168. $("#iconwrapper").html("");
  2169. }
  2170. //Allocate new items location
  2171. var iheight = 106;
  2172. var iwidth = 70;
  2173. var padding = 16;
  2174. if (desktopIconSize == "small") {
  2175. iheight = 82;
  2176. iwidth = 50;
  2177. } else if (desktopIconSize == "medium") {
  2178. iheight = 106;
  2179. iwidth = 70;
  2180. } else if (desktopIconSize == "big") {
  2181. iheight = 124;
  2182. iwidth = 84;
  2183. }
  2184. iconSize = [iwidth, iheight];
  2185. var screenHeight = window.innerHeight;
  2186. var screenWidth = window.innerWidth;
  2187. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2188. var hc = Math.floor((screenWidth - padding) / iwidth);
  2189. var slots = []; //A 2D array for storing relative to absolute locations
  2190. for (var j = 0; j < hc; j++) {
  2191. var thisLocationList = [];
  2192. for (var i = 0; i < vc; i++) {
  2193. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2194. thisLocationList.push(thisLocation);
  2195. }
  2196. slots.push(thisLocationList);
  2197. }
  2198. //Store the root position (0,0) in rootPosition
  2199. let rootPosition = JSON.parse(JSON.stringify(slots[0][0]));
  2200. desktopGrids = JSON.parse(JSON.stringify(slots));
  2201. //Assign items to desktop
  2202. var unallocatedFiles = [];
  2203. let remainingSlots = JSON.parse(JSON.stringify(slots));
  2204. desktopFileList = [];
  2205. if (data === null){
  2206. //No files on desktop
  2207. return;
  2208. }
  2209. for (var i = 0; i < data.length; i++) {
  2210. var thisFile = data[i];
  2211. desktopFileList.push(JSON.parse(JSON.stringify(thisFile.Filename)));
  2212. //Get icon from the icon list
  2213. var location = [thisFile.IconX, thisFile.IconY];
  2214. if (location[0] == -1 && location[1] == -1) {
  2215. //This file is not located. Push it into unallocatedFileList
  2216. unallocatedFiles.push(thisFile);
  2217. } else if (location[0] >= slots.length || location[1] >= slots[0].length) {
  2218. //This file is outside of the screen area. Set to be be unallocatedFiles as well
  2219. unallocatedFiles.push(thisFile);
  2220. } else {
  2221. //This file is already located. Push it location into occupiedSlots
  2222. //var screenX = location[0] * iwidth + padding/2;
  2223. //var screenY = location[1] * iheight + padding/2;
  2224. var screenLocation = slots[location[0]][location[1]];
  2225. //Remove this object from remaining slots
  2226. remainingSlots[location[0]][location[1]] = undefined;
  2227. //console.log(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth);
  2228. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2229. }
  2230. }
  2231. //Foreach remaining files, assign a location for it.
  2232. var walk = [slots.length, slots[0].length];
  2233. var current = [0, 0];
  2234. for (var i = 0; i < unallocatedFiles.length; i++) {
  2235. var thisFile = unallocatedFiles[i];
  2236. try{
  2237. while (typeof(remainingSlots[current[0]][current[1]]) == "undefined") {
  2238. //This slot is not usabled. Next slot.
  2239. current[1] += 1;
  2240. if (current[1] >= walk[1]) {
  2241. current[1] = 0;
  2242. current[0] += 1;
  2243. }
  2244. if (typeof(remainingSlots[current[0]]) == "undefined"){
  2245. //Not enough space to fit the item. Move it to 0 0 instead
  2246. current = [-1,-1];
  2247. console.log(current);
  2248. break;
  2249. }
  2250. }
  2251. }catch{
  2252. //Something went wrong while assigning positions. Set at root location
  2253. current = [-1,-1];
  2254. }
  2255. //Append the icon to screen
  2256. if (current[0] == -1 && current[1] == -1){
  2257. //Screen overflow. Stack the file at (0,0)
  2258. screenLocation = [rootPosition[0], rootPosition[1]];
  2259. console.log(screenLocation);
  2260. }else{
  2261. screenLocation = remainingSlots[current[0]][current[1]];
  2262. remainingSlots[current[0]][current[1]] = undefined;
  2263. }
  2264. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2265. //Save the icon location to server
  2266. $.ajax({
  2267. url: "system/desktop/files",
  2268. method: "POST",
  2269. data: {"set": thisFile.Filename, "x": current[0], "y": current[1]},
  2270. success: function(data) {
  2271. if (data.includes("Error")) {
  2272. console.log(data);
  2273. }
  2274. }
  2275. });
  2276. }
  2277. if (callback !== undefined) {
  2278. //console.log(callback);
  2279. callback();
  2280. }
  2281. });
  2282. }
  2283. //Handle desktop file multi selection and dragging
  2284. $("#bgwrapper").on("mousedown", function(evt) {
  2285. initMultiSelection(evt);
  2286. });
  2287. $("#bgwrapper").on("touchstart", function(evt) {
  2288. initMultiSelection(evt);
  2289. });
  2290. $("body").on("mouseup", function(evt) {
  2291. mainWindowMouseup(evt);
  2292. });
  2293. $("body").on("touchend", function(evt) {
  2294. mainWindowMouseup(evt);
  2295. });
  2296. $("#selectionPanel").on("mouseup", function(event) {
  2297. });
  2298. function mainWindowMouseup(event) {
  2299. if (event.pageX == multiSelectionStartPoint[0] && event.pageY == multiSelectionStartPoint[1]) {
  2300. //Pressdown and up at the same location
  2301. $(".launchIconWrapper.selected").removeClass("selected");
  2302. endMultiSelection(event);
  2303. } else {
  2304. //Press down and up at different location
  2305. endMultiSelection(event);
  2306. }
  2307. if (resizingWindow){
  2308. //Resizing floatWindow out of the window bound (aka someone don't know how to resize a window correctly)
  2309. resizingWindow = false;
  2310. resizingEdgeID = 0;
  2311. $("#fwdragpanel").hide();
  2312. $("#tfwdragpanel").hide();
  2313. $('.floatWindow.topmost').css("pointer-events", "auto");
  2314. $('.floatWindow.topmost').css("opacity", 1);
  2315. $(resizingWindowTarget).find(".iframecover").hide();
  2316. $(resizingWindowTarget).find(".iframewrapper").css('cursor', '');
  2317. }
  2318. }
  2319. function initMultiSelection(event) {
  2320. event.preventDefault();
  2321. multiSelecting = true;
  2322. hideAllContextMenus();
  2323. $("#selectionPanel").css({
  2324. left: event.pageX,
  2325. top: event.pageY,
  2326. width: 0,
  2327. height: 0
  2328. });
  2329. $("#selectionPanel").show();
  2330. multiSelectionStartPoint = [event.pageX, event.pageY];
  2331. }
  2332. function movingMultiSelectionArea(event) {
  2333. event.preventDefault();
  2334. var sx = multiSelectionStartPoint[0];
  2335. var sy = multiSelectionStartPoint[1];
  2336. var ex = event.pageX;
  2337. var ey = event.pageY;
  2338. var newleft = sx;
  2339. if (ex < sx) {
  2340. newleft = ex;
  2341. }
  2342. var newtop = sy;
  2343. if (ey < sy) {
  2344. newtop = ey;
  2345. }
  2346. var newWidth = Math.abs(sx - ex);
  2347. var newHeight = Math.abs(sy - ey);
  2348. $("#selectionPanel").css({
  2349. left: newleft,
  2350. top: newtop,
  2351. width: newWidth,
  2352. height: newHeight
  2353. });
  2354. //Select all the launch icon selected
  2355. selectAllLaunchIconInRange(newleft, newleft + newWidth, newtop, newtop + newHeight);
  2356. }
  2357. function endMultiSelection(event) {
  2358. event.preventDefault();
  2359. multiSelecting = false;
  2360. multiSelectionStartPoint = [-1, -1];
  2361. $("#selectionPanel").hide();
  2362. }
  2363. function selectAllLaunchIconInRange(minX, maxX, minY, maxY) {
  2364. //Select launch icons from its center point
  2365. var xOffset = iconSize[0] / 2;
  2366. var yOffset = iconSize[1] / 2;
  2367. $(".launchIconWrapper.selected").removeClass("selected");
  2368. $(".launchIcon").each(function() {
  2369. //Calculate center point for this icon
  2370. var thisX = $(this).offset().left + xOffset;
  2371. var thisY = $(this).offset().top + yOffset;
  2372. if (thisX > minX && thisX < maxX) {
  2373. if (thisY > minY && thisY < maxY) {
  2374. $(this).find(".launchIconWrapper").addClass("selected");
  2375. }
  2376. }
  2377. });
  2378. }
  2379. function redrawDesktopGrids() {
  2380. var iheight = 106;
  2381. var iwidth = 70;
  2382. var padding = 16;
  2383. if (desktopIconSize == "small") {
  2384. iheight = 82;
  2385. iwidth = 50;
  2386. } else if (desktopIconSize == "medium") {
  2387. iheight = 106;
  2388. iwidth = 70;
  2389. } else if (desktopIconSize == "big") {
  2390. iheight = 124;
  2391. iwidth = 84;
  2392. }
  2393. iconSize = [iwidth, iheight];
  2394. var screenHeight = window.innerHeight;
  2395. var screenWidth = window.innerWidth;
  2396. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2397. var hc = Math.floor((screenWidth - padding) / iwidth);
  2398. var slots = []; //A 2D array for storing relative to absolute locations
  2399. for (var j = 0; j < hc; j++) {
  2400. var thisLocationList = [];
  2401. for (var i = 0; i < vc; i++) {
  2402. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2403. thisLocationList.push(thisLocation);
  2404. }
  2405. slots.push(thisLocationList);
  2406. }
  2407. desktopGrids = JSON.parse(JSON.stringify(slots));
  2408. }
  2409. function appendIconAtLocation(filedata, screenX, screenY, iheight, iwidth, updateMode=false) {
  2410. //Get the icon from extension
  2411. var icon = ao_module_utils.getIconFromExt(filedata.Ext.substring(1, filedata.Ext.length));
  2412. var imagePath = "img/desktop/files_icon/" + desktopIconPack + "/" + icon + ".png";
  2413. //Handle special icon types here
  2414. var size = desktopIconSize;
  2415. var filename = JSON.parse(JSON.stringify(filedata.Filename));
  2416. var filepath = JSON.parse(JSON.stringify(filedata.Filepath));
  2417. var isDir = JSON.parse(JSON.stringify(filedata.IsDir));
  2418. var isEmptyDir = JSON.parse(JSON.stringify(filedata.IsEmptyDir));
  2419. var maxlength = 12;
  2420. var type = "file";
  2421. let shortenedName = filename;
  2422. screenX += iconOffsetXY[0];
  2423. screenY += iconOffsetXY[1];
  2424. if (isDir) {
  2425. //Folder objects
  2426. icon = "folder outline";
  2427. if (isEmptyDir){
  2428. imagePath = "img/desktop/system_icon/folder.png";
  2429. }else{
  2430. imagePath = "img/desktop/system_icon/folder-with-content.png";
  2431. }
  2432. type = "folder";
  2433. } else if (isDir == false && icon == "folder outline") {
  2434. icon = "file outline";
  2435. imagePath = "img/desktop/files_icon/" + desktopIconPack + "/file outline.png";
  2436. type = "file";
  2437. } else if (filedata.Ext == ".exe" || filedata.Ext == ".elf") {
  2438. //Executable objects
  2439. imagePath = "img/desktop/system_icon/script.png";
  2440. type = "executable";
  2441. } else if (filedata.Ext == ".shortcut") {
  2442. //Shortcut
  2443. var shortcutImage = filedata.ShortcutImage;
  2444. shortenedName = JSON.parse(JSON.stringify(filedata.ShortcutName));
  2445. imagePath = shortcutImage;
  2446. type = "shortcut";
  2447. }
  2448. //Check if filename is english only.
  2449. if (/^[a-zA-Z\d .-=+]+$/.test(filename)) {
  2450. maxlength = 20;
  2451. }else{
  2452. //Check if it is under small text mode
  2453. if (size == "small"){
  2454. maxlength = 10;
  2455. }
  2456. }
  2457. if (type != "shortcut" && filename.length > maxlength) {
  2458. shortenedName = filename.substring(0, maxlength) + "...";
  2459. }
  2460. var compressedFiledata = ao_module_utils.objectToAttr(filedata);
  2461. if (updateMode){
  2462. //Update the content that already exists for the same filepath object
  2463. var updateObject = undefined;
  2464. $(".launchIcon").each(function(){
  2465. if ($(this).attr("filedata") == compressedFiledata){
  2466. updateObject = $(this);
  2467. }
  2468. });
  2469. if (updateObject !== undefined){
  2470. //Check if content identical. If yes, skip rewrite
  2471. if (updateObject.attr("filedata") == compressedFiledata){
  2472. //Identical. Skipping
  2473. }else{
  2474. //Update its contents
  2475. updateObject.attr("type", type);
  2476. updateObject.attr("filename", filename);
  2477. updateObject.attr("filepath", filepath);
  2478. updateObject.attr("filedata", compressedFiledata);
  2479. updateObject.css("width", iwidth + "px");
  2480. updateObject.css("height", iheight + "px");
  2481. updateObject.css("left", screenX + "px");
  2482. updateObject.css("top", screenY + "px");
  2483. }
  2484. }else{
  2485. //No exists. Append to wrapper
  2486. appendDesktopIcon($("#iconwrapper"),{
  2487. type: type,
  2488. filename: filename,
  2489. filepath: filepath,
  2490. compressedFiledata: compressedFiledata,
  2491. iwidth: iwidth,
  2492. iheight: iheight,
  2493. screenX: screenX,
  2494. screenY: screenY,
  2495. size: size,
  2496. imagePath: imagePath,
  2497. shortenedName: shortenedName,
  2498. });
  2499. }
  2500. }else{
  2501. //Append into the desktop
  2502. appendDesktopIcon($("#iconwrapper"),{
  2503. type: type,
  2504. filename: filename,
  2505. filepath: filepath,
  2506. compressedFiledata: compressedFiledata,
  2507. iwidth: iwidth,
  2508. iheight: iheight,
  2509. screenX: screenX,
  2510. screenY: screenY,
  2511. size: size,
  2512. imagePath: imagePath,
  2513. shortenedName: shortenedName,
  2514. });
  2515. }
  2516. }
  2517. /*
  2518. Main function to append desktop icon to desktop
  2519. Usage: Pass in the target (as jquery object, usually $("#iconwrapper")) and properties with the following object
  2520. properties = {
  2521. type: "",
  2522. filename: "",
  2523. filepath: "",
  2524. compressedFiledata: "",
  2525. iwidth: "",
  2526. iheight: "",
  2527. screenX: "",
  2528. screenY: "",
  2529. size: "",
  2530. imagePath: "",
  2531. shortenedName: "",
  2532. }
  2533. Where the enmty string is the value that require filling in
  2534. */
  2535. function appendDesktopIcon(target, properties){
  2536. var htmlType = "div";
  2537. var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  2538. if (properties.type == "file" && isChrome){
  2539. htmlType = "a";
  2540. }
  2541. var thisIcon = $(`<${htmlType} href="javascript:void(0);" class="launchIcon"
  2542. type="${properties.type}"
  2543. draggable="true"
  2544. ondragover="allowDrop(event)"
  2545. ondrop="drop(event)"
  2546. ondragstart="drag(event)"
  2547. onmousedown="iconClicked(this,event);"
  2548. ondblclick="iconDoubleClicked(this,event);"
  2549. ontouchstart="iconClicked(this,event); doubleTouchHandler(this, event,openViaTouch);"
  2550. filename="${properties.filename}"
  2551. filepath="${properties.filepath}"
  2552. filedata="${properties.compressedFiledata}"
  2553. style="width:${properties.iwidth}px; height:${properties.iheight}px;left:${properties.screenX}px; top:${properties.screenY}px;">
  2554. <span class="launchIconWrapper"><img class="launchIconImage ${properties.size}" src="${properties.imagePath}" draggable="false"></img>
  2555. <p class="launchIconText ${properties.size} ">${properties.shortenedName}</p></span>
  2556. </${htmlType}>`);
  2557. $(target).append(thisIcon);
  2558. if (properties.type == "file" && isChrome){
  2559. console.log(isChrome);
  2560. let thisFilepath = properties.filepath;
  2561. $(thisIcon)[0].addEventListener("dragstart",function(evt){
  2562. //var filecontent = toDataUrl("media/?file=" + thisFilepath);
  2563. //var fileBase64 = window.btoa(filecontent);
  2564. var targetMime = "plain/text";
  2565. $.ajax({
  2566. url: "media/getMime/?file=" + encodeURIComponent(properties.filepath),
  2567. success: function(data){
  2568. if (data.error !== undefined){
  2569. targetMime = "text/directory";
  2570. }else{
  2571. targetMime = data;
  2572. }
  2573. },
  2574. async: false
  2575. });
  2576. evt.dataTransfer.setData("DownloadURL",targetMime+":"+ properties.filename +":"+ location.protocol + "//" + location.hostname + ":" + location.port + "/media/?file=" + encodeURIComponent(properties.filepath));
  2577. //evt.dataTransfer.setData("DownloadURL","video/mp4"+":"+"test.mp4"+":"+"data:"+"video/mp4"+";base64,"+fileBase64);
  2578. },false);
  2579. }
  2580. }
  2581. // ========================== LAUNCH ICON OPERATIONS ================
  2582. //This function start all the launchicon related events
  2583. function drag(ev) {
  2584. //If rename mode, disable drag drop
  2585. if (renameMode){
  2586. return false;
  2587. }
  2588. var target = ev.target;
  2589. if (!($(ev.target).is("div") || $(ev.target).is("a"))) {
  2590. target = $(target).parent();
  2591. }
  2592. //Parse the standard filename / filepath data
  2593. var filename = $(target).attr("filename");
  2594. var filepath = $(target).attr('filepath');
  2595. ev.dataTransfer.setData("filename", filename);
  2596. ev.dataTransfer.setData("filepath", filepath);
  2597. //Parse multifile selection filedata
  2598. var filelist = [];
  2599. if ($(".launchIconWrapper.selected").length > 0){
  2600. if (ctrlHold || $(".launchIconWrapper.selected").length > 1){
  2601. //Include all objects selected
  2602. $(".launchIconWrapper.selected").each(function(){
  2603. var fd = $(this).parent().attr("filedata");
  2604. fd = JSON.parse(decodeURIComponent(fd));
  2605. filelist.push({
  2606. filename: fd.Filename,
  2607. filepath: fd.Filepath,
  2608. hostUUID: hostInfo.DeviceUUID
  2609. });
  2610. });
  2611. }else{
  2612. //Only push the one selected
  2613. filelist.push({
  2614. filename: filename,
  2615. filepath: filepath,
  2616. hostUUID: hostInfo.DeviceUUID
  2617. });
  2618. }
  2619. }else{
  2620. //There is no selected item on desktop. Use the drag drop one
  2621. filelist.push({
  2622. filename: filename,
  2623. filepath: filepath
  2624. });
  2625. }
  2626. //console.log(filelist);
  2627. ev.dataTransfer.setData("filedata", JSON.stringify(filelist));
  2628. console.log(filelist);
  2629. //Set a flag on the drag events that these files are from Desktop GUI
  2630. ev.dataTransfer.setData("desktopflag", "true");
  2631. //Record the start drop relative position of the icon object
  2632. var dx = ev.pageX - $(target).offset().left;
  2633. var dy = ev.pageY - $(target).offset().top;
  2634. startDragRelatuve = [dx, dy];
  2635. ev.stopPropagation();
  2636. }
  2637. function drop(ev) {
  2638. ev.preventDefault();
  2639. ev.stopImmediatePropagation();
  2640. var target = $(ev.target);
  2641. if (!(target.is("div") || target.is("a"))) {
  2642. target = $(target).parent();
  2643. }
  2644. if (target.hasClass("launchIconWrapper")) {
  2645. target = target.parent();
  2646. }
  2647. var thisFilepath = $(target).attr("filepath");
  2648. if (thisFilepath == ev.dataTransfer.getData("filepath")) {
  2649. //Drag and drop on the same item. Ignore it
  2650. return;
  2651. }
  2652. var sourceFilename = ev.dataTransfer.getData("filename");
  2653. var sourceFilepath = ev.dataTransfer.getData("filepath");
  2654. //To handle multiple file transfer from file explorer
  2655. var sourceFilelist = ev.dataTransfer.getData("filedata");
  2656. console.log(target)
  2657. console.log(sourceFilename);
  2658. console.log(sourceFilepath);
  2659. if (sourceFilelist !== ""){
  2660. sourceFilelist = JSON.parse(sourceFilelist);
  2661. }
  2662. console.log(sourceFilelist);
  2663. //Drop opererations
  2664. if (target.attr("id") == "bgwrapper") {
  2665. if (sourceFilename == "" && sourceFilepath == "" && ev.dataTransfer.files.length > 0){
  2666. //Drag drop from external source. Upload to desktop
  2667. //Assign the locations for the objects
  2668. var files = ev.dataTransfer.files;
  2669. var gridMaxX = desktopGrids.length;
  2670. var gridMaxY = desktopGrids[0].length;
  2671. var targetLocation = findClosestGrid((ev.clientX), (ev.clientY), false);
  2672. var targetGridLocation = targetLocation[1];
  2673. var locations = [];
  2674. for (var k =0; k < files.length; k++){
  2675. var thisLocation = JSON.parse(JSON.stringify(targetGridLocation));
  2676. //Add k to y axis of the list.
  2677. thisLocation[1] += k;
  2678. if (thisLocation[1] >= gridMaxY){
  2679. thisLocation[0]++;
  2680. thisLocation[1] = 0;
  2681. }
  2682. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2683. //Desktop full. Force put to 0 0
  2684. thisLocation[0] = 0;
  2685. thisLocation[1] = 0;
  2686. break;
  2687. }
  2688. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  2689. thisLocation[1] += 1;
  2690. if (thisLocation[1] >= gridMaxY){
  2691. //Over the screen. Shift to the row on the right
  2692. thisLocation[0]++;
  2693. thisLocation[1] = 0;
  2694. }
  2695. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2696. //Desktop full. Force put to 0 0
  2697. thisLocation[0] = 0;
  2698. thisLocation[1] = 0;
  2699. break;
  2700. }
  2701. }
  2702. locations.push(thisLocation)
  2703. }
  2704. console.log(locations, ev.dataTransfer.files);
  2705. //Register file locations
  2706. for (var j =0; j < locations.length; j++){
  2707. let thisFile = files[j];
  2708. let thisFilename = files[j].name;
  2709. let x = parseInt(locations[j][0]);
  2710. let y = parseInt(locations[j][1]);
  2711. uploadFile(thisFile,function(){
  2712. console.log("Uploader callback");
  2713. $.ajax({
  2714. url: "system/desktop/files",
  2715. method: "POST",
  2716. data: {"set": thisFilename, "x": x, "y": y},
  2717. success: function(data) {
  2718. //Refresh the desktop
  2719. refresh(undefined, true);
  2720. }
  2721. });
  2722. });
  2723. }
  2724. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  2725. //Drag drop multiple files from desktop or file explorer to desktop
  2726. var desktopFlag = ev.dataTransfer.getData("desktopflag");
  2727. if (desktopFlag == "" || desktopFlag === undefined || desktopFlag == null){
  2728. //This is a file drag drop from not desktop to desktop
  2729. var filelist = ev.dataTransfer.getData("filedata");
  2730. if (filelist != ""){
  2731. filelist = JSON.parse(filelist);
  2732. if (filelist.length == 0){
  2733. return
  2734. }
  2735. //Get the position for this drop events and arrange grid locations
  2736. var gridPosition = gridPositionAllocate(ev.clientX, ev.clientY, filelist.length);
  2737. console.log(gridPosition)
  2738. //Check if source is also from user:/
  2739. var srcVroot = filelist[0].filepath.split(":/").shift();
  2740. var mode = "copy"
  2741. var title = "Copying "
  2742. if (srcVroot == "user"){
  2743. //Move
  2744. mode = "move"
  2745. title = "Moving "
  2746. }
  2747. //Check if any of the files already exists on desktop
  2748. /*
  2749. var duplicateFound = false;
  2750. filelist.forEach(file => {
  2751. var thisFilename = file.filename;
  2752. desktopFileList.forEach(desktopFile => {
  2753. if (desktopFile == thisFilename){
  2754. //Diplicate
  2755. duplicateFound = true;
  2756. }
  2757. });
  2758. });
  2759. */
  2760. var filepathList = [];
  2761. filelist.forEach(file => {
  2762. filepathList.push(file.filepath)
  2763. });
  2764. //Start the file operation dialog
  2765. var oprConfig = {
  2766. opr: mode,
  2767. src: filepathList,
  2768. dest: "user:/Desktop/",
  2769. overwriteMode: "ask"
  2770. }
  2771. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2772. //Genreate window title
  2773. title = title + filepathList.length;
  2774. if (filepathList.length > 1){
  2775. title += " files";
  2776. }else{
  2777. title += " file";
  2778. }
  2779. parent.newFloatWindow({
  2780. url: "SystemAO/file_system/file_operation.html#" + configHash,
  2781. width: 400,
  2782. height: 220,
  2783. appicon: "SystemAO/file_system/img/selector.png",
  2784. title: title
  2785. });
  2786. }
  2787. }else{
  2788. //This is a file drag event from desktop, but more than one files.
  2789. //Pin the final location for the drag drop object
  2790. var sourceObject = getObjectFromPath(sourceFilepath);
  2791. var dx = startDragRelatuve[0];
  2792. var dy = startDragRelatuve[1];
  2793. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  2794. var closestLocation = targetLocation[0];
  2795. var duplicateObject = getObjectFromLocation(closestLocation[0] + iconOffsetXY[0], closestLocation[1] + iconOffsetXY[1]);
  2796. if (duplicateObject !== undefined) {
  2797. //There are already object there. Do nothing
  2798. console.log("Drop location duplicated!")
  2799. return;
  2800. }
  2801. //Get other objects that is not the one drag dropped
  2802. var iconOffset = {};
  2803. for (var i =0; i < sourceFilelist.length; i++){
  2804. var thisFile = sourceFilelist[i];
  2805. if (thisFile.filepath != sourceFilepath){
  2806. //Calculate the x y offset of this icon to the drag drop one
  2807. var thisIconObject = getObjectFromPath(thisFile.filepath);
  2808. iconOffset[thisFile.filepath] = {
  2809. dx: $(sourceObject).offset().left - $(thisIconObject).offset().left,
  2810. dy: $(sourceObject).offset().top - $(thisIconObject).offset().top
  2811. }
  2812. //console.log(thisFile.filename, iconOffset[thisFile.filepath]);
  2813. }
  2814. }
  2815. //Move the drag drop object to the desiged location
  2816. $(sourceObject).css({
  2817. left: closestLocation[0] + iconOffsetXY[0],
  2818. top: closestLocation[1] + iconOffsetXY[1]
  2819. });
  2820. //Save the drag item location
  2821. $.ajax({
  2822. url: "system/desktop/files",
  2823. method: "POST",
  2824. data: {"set": sourceFilename, "x": targetLocation[1][0], "y": targetLocation[1][1]},
  2825. success: function(data) {
  2826. //console.log(data);
  2827. }
  2828. });
  2829. //Move all the relative files to the main object
  2830. var relocatePendingObjects = [];
  2831. for (const [filepath, offset] of Object.entries(iconOffset)) {
  2832. let thisIconObject = getObjectFromPath(filepath);
  2833. let caluclatedLocation = [$(sourceObject).offset().left - offset.dx, $(sourceObject).offset().top - offset.dy];
  2834. let finalIconLocation = findClosestGrid(caluclatedLocation[0], caluclatedLocation[1]);
  2835. //Check for duplication
  2836. /*
  2837. var duplicateObject = getObjectFromLocation(finalIconLocation[0][0] + iconOffsetXY[0], finalIconLocation[0][1] + iconOffsetXY[1]);
  2838. if (duplicateObject !== undefined) {
  2839. //There are already object there. Relocate this object later
  2840. relocatePendingObjects.push(duplicateObject)
  2841. }
  2842. */
  2843. //Move this icon to designed location
  2844. $(thisIconObject).css({
  2845. left: finalIconLocation[0][0] + iconOffsetXY[0],
  2846. top: finalIconLocation[0][1] + iconOffsetXY[1]
  2847. });
  2848. let thisIconFileData = JSON.parse(decodeURIComponent($(thisIconObject).attr("filedata")));
  2849. //Record this in database
  2850. $.ajax({
  2851. url: "system/desktop/files",
  2852. method: "POST",
  2853. data: {"set": thisIconFileData.Filename, "x": finalIconLocation[1][0], "y": finalIconLocation[1][1]},
  2854. success: function(data) {
  2855. //console.log(data);
  2856. }
  2857. });
  2858. }
  2859. //Get duplication objects
  2860. for (const [filepath, offset] of Object.entries(iconOffset)) {
  2861. let thisIconObject = getObjectFromPath(filepath);
  2862. //Check for duplication
  2863. var iconLocation = [$(thisIconObject).offset().left, $(thisIconObject).offset().top];
  2864. $(".launchIcon").each(function(){
  2865. if ($(this).offset().left == iconLocation[0] && $(this).offset().top == iconLocation[1]){
  2866. //This icon is at the target icon location
  2867. if ($(this).attr("filepath") != filepath){
  2868. relocatePendingObjects.push($(this));
  2869. }
  2870. }
  2871. });
  2872. }
  2873. //Relocate objects that is in the way of moving
  2874. for (var i = 0; i < relocatePendingObjects.length; i++){
  2875. var thisObject = relocatePendingObjects[i];
  2876. console.log(thisObject);
  2877. var thisX = $(thisObject).offset().left;
  2878. var thisY = $(thisObject).offset().top;
  2879. var nextEmptyGrid = findClostestEmptyGridLocation(thisX, thisY);
  2880. //Move this file to the next empty grid location
  2881. $(thisObject).css({
  2882. left: nextEmptyGrid[0][0] + iconOffsetXY[0],
  2883. top: nextEmptyGrid[0][1] + iconOffsetXY[1]
  2884. });
  2885. //Save move record to db
  2886. let thisIconFileData = JSON.parse(decodeURIComponent($(thisObject).attr("filedata")));
  2887. $.ajax({
  2888. url: "system/desktop/files",
  2889. method: "POST",
  2890. data: {"set": thisIconFileData.Filename, "x": nextEmptyGrid[1][0], "y": nextEmptyGrid[1][1]},
  2891. success: function(data) {
  2892. //console.log(data);
  2893. }
  2894. });
  2895. }
  2896. }
  2897. }else{
  2898. //Dropping a file onto other place on desktop
  2899. var sourceObject = getObjectFromPath(sourceFilepath);
  2900. var dx = startDragRelatuve[0];
  2901. var dy = startDragRelatuve[1];
  2902. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  2903. var closestLocation = targetLocation[0];
  2904. //Check if there are objects already at that location
  2905. var duplicateObject = getObjectFromLocation(closestLocation[0], closestLocation[1]);
  2906. if (duplicateObject !== undefined) {
  2907. //There are already object there. Do nothing
  2908. console.log("Drop location duplicated!")
  2909. return;
  2910. }
  2911. var closestGridIndex = targetLocation[1];
  2912. $(sourceObject).css({
  2913. left: closestLocation[0] + iconOffsetXY[0],
  2914. top: closestLocation[1] + iconOffsetXY[1]
  2915. });
  2916. $.ajax({
  2917. url: "system/desktop/files",
  2918. method: "POST",
  2919. data: {"set": sourceFilename, "x": closestGridIndex[0], "y": closestGridIndex[1]},
  2920. success: function(data) {
  2921. //console.log(data);
  2922. }
  2923. });
  2924. }
  2925. } else if (target.attr("type") == "folder") {
  2926. //Move this file or folder into the target folder
  2927. //WIP
  2928. } else if (target.attr("type") == "shortcut") {
  2929. //Opening with the shortcut
  2930. //Check shortcut type
  2931. let shortcutData = JSON.parse(decodeURIComponent($(target).attr("filedata")));
  2932. var shortcutType = shortcutData["ShortcutType"];
  2933. if (shortcutType == "module") {
  2934. //Open the source file with this module
  2935. let openFileList = [];
  2936. if ($(".launchiconwrapper.selected").length > 0 && !Array.isArray(sourceFilelist)) {
  2937. $(".launchiconwrapper.selected").each(function() {
  2938. let thisFileData = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  2939. openFileList.push({
  2940. filename: thisFileData["Filename"],
  2941. filepath: thisFileData["Filepath"]
  2942. });
  2943. });
  2944. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  2945. //Open file that is transfered from file explorer.
  2946. openFileList = sourceFilelist;
  2947. console.log(openFileList);
  2948. } else {
  2949. //Only pass in the current selected file.
  2950. openFileList.push({
  2951. filename: sourceFilename,
  2952. filepath: sourceFilepath
  2953. });
  2954. }
  2955. var shortcutModule = getModuleFromShortcutInfo(shortcutData);
  2956. //console.log(openFileList);
  2957. if (shortcutModule === undefined){
  2958. //This shortcut module is not found on this server
  2959. return;
  2960. }
  2961. openFileWithModule(shortcutModule, openFileList);
  2962. } else if (shortcutType == "folder") {
  2963. //Move the source file into this folder
  2964. }
  2965. } else {
  2966. console.log("Unknown reaction type: ", target.attr("type"));
  2967. }
  2968. }
  2969. function getModuleFromShortcutInfo(shortcutInfo) {
  2970. var ShortcutPath = shortcutInfo["ShortcutPath"];
  2971. if (ShortcutPath.includes("/") == false) {
  2972. //Legacy defination. Append /index.html at the back.
  2973. ShortcutPath = ShortcutPath + "/index.html";
  2974. }
  2975. //Try to match it with the module installed
  2976. for (var i = 0; i < moduleInstalled.length; i++) {
  2977. if (moduleInstalled[i]["StartDir"] == ShortcutPath || moduleInstalled[i]["Name"] == shortcutInfo["ShortcutName"]) {
  2978. //This is the correct module to be loaded
  2979. return moduleInstalled[i];
  2980. }
  2981. }
  2982. }
  2983. //Allocate the given number of grids from desktop
  2984. function gridPositionAllocate(posx, posy, numberOfGridNeeded=1){
  2985. var gridMaxX = desktopGrids.length;
  2986. var gridMaxY = desktopGrids[0].length;
  2987. var targetLocation = findClosestGrid(posx, posy, false);
  2988. var targetGridLocation = targetLocation[1];
  2989. var previousEmptyGridPosition = targetGridLocation;
  2990. var locations = [];
  2991. for (var k =0; k < numberOfGridNeeded; k++){
  2992. var thisLocation = JSON.parse(JSON.stringify(previousEmptyGridPosition));
  2993. //Add k to y axis of the list.
  2994. thisLocation[1] += k;
  2995. if (thisLocation[1] >= gridMaxY){
  2996. thisLocation[0]++;
  2997. thisLocation[1] = 0;
  2998. }
  2999. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3000. //Desktop full. Force put to 0 0
  3001. thisLocation[0] = 0;
  3002. thisLocation[1] = 0;
  3003. break;
  3004. }
  3005. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  3006. thisLocation[1] += 1;
  3007. if (thisLocation[1] >= gridMaxY){
  3008. //Over the screen. Shift to the row on the right
  3009. thisLocation[0]++;
  3010. thisLocation[1] = 0;
  3011. }
  3012. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3013. //Desktop full. Force put to 0 0
  3014. thisLocation[0] = 0;
  3015. thisLocation[1] = 0;
  3016. break;
  3017. }
  3018. }
  3019. previousEmptyGridPosition = JSON.parse(JSON.stringify(thisLocation))
  3020. locations.push(thisLocation)
  3021. }
  3022. return locations
  3023. }
  3024. function setIconDesktopLocation(sourceFilename, gridIndexX, gridIndexY, callback = undefined) {
  3025. $.ajax({
  3026. url: "system/desktop/files",
  3027. method: "POST",
  3028. data: {"set": sourceFilename, "x": gridIndexX, "y": gridIndexY},
  3029. success: function(data) {
  3030. if (data.error !== undefined) {
  3031. console.log(data.error);
  3032. } else {
  3033. if (callback !== undefined) {
  3034. callback();
  3035. }
  3036. }
  3037. }
  3038. });
  3039. }
  3040. //THIS FUNCTION IS NEEDED. DO NOT DELETE ALLOWDROP FUNCTION
  3041. function allowDrop(ev) {
  3042. ev.preventDefault();
  3043. }
  3044. //Pass in the object fullpath and return the icon object onscreen
  3045. function getObjectFromPath(path) {
  3046. var object;
  3047. $(".launchIcon").each(function() {
  3048. if ($(this).attr("filepath") == path) {
  3049. object = $(this);
  3050. }
  3051. });
  3052. return object;
  3053. }
  3054. //Pass in the coordinate and check if there is another object at the same location
  3055. function getObjectFromLocation(x, y) {
  3056. var object;
  3057. $(".launchIcon").each(function() {
  3058. if ($(this).position().left == x && $(this).position().top == y) {
  3059. object = $(this);
  3060. }
  3061. });
  3062. return object;
  3063. }
  3064. //Similar function to getObjectFromLocation but using grid coordinate instead of pixel coordinate
  3065. function getObjectFromGridLocation(gx, gy){
  3066. var pos = JSON.parse(JSON.stringify(desktopGrids[gx][gy]));
  3067. pos[0] = pos[0] + iconOffsetXY[0];
  3068. pos[1] = pos[1] + iconOffsetXY[1];
  3069. return getObjectFromLocation(pos[0],pos[1]);
  3070. }
  3071. //Find the clostest empty grid, prioirty given to y first then x
  3072. function findClostestEmptyGridLocation(x, y){
  3073. //Reduce icon offset to the x y on screen coordinate
  3074. x = x - iconOffsetXY[0];
  3075. y = y - iconOffsetXY[1];
  3076. //Get the grid index from absolute coordinate
  3077. var currentGridLocation = getGridIndexFromLocation(x,y);
  3078. console.log(currentGridLocation);
  3079. //Search for the next empty location
  3080. var targetLocation = [[-1,-1],[-1,-1]];
  3081. for (var i = currentGridLocation[0]; i < desktopGrids.length; i++){
  3082. var yStart = 0;
  3083. if (i == currentGridLocation[0]){
  3084. yStart = currentGridLocation[1];
  3085. }
  3086. for (k = yStart; k < desktopGrids[i].length; k++){
  3087. var thisLocation = JSON.parse(JSON.stringify(desktopGrids[i][k]));
  3088. var offsetedLocation = [thisLocation[0], thisLocation[1]];
  3089. var possibleDuplication = getObjectFromGridLocation(i,k);
  3090. //console.log( [i,k], offsetedLocation, possibleDuplication)
  3091. if (possibleDuplication === undefined){
  3092. //This is an empty slot
  3093. targetLocation = [offsetedLocation, [i,k]];
  3094. return targetLocation;
  3095. }
  3096. }
  3097. }
  3098. return targetLocation;
  3099. }
  3100. function getGridIndexFromLocation(x,y){
  3101. var gridIndex = [-1,-1];
  3102. for (var i = 0; i < desktopGrids.length; i++){
  3103. var thisXAxis = desktopGrids[i];
  3104. if (thisXAxis[0][0] == x){
  3105. //This x matches. Match y
  3106. gridIndex[0] = i;
  3107. for (var k = 0; k < thisXAxis.length; k++){
  3108. var thisYAxis = thisXAxis[k];
  3109. if (thisYAxis[1] == y){
  3110. gridIndex[1] = k;
  3111. return gridIndex;
  3112. }
  3113. }
  3114. }
  3115. }
  3116. return gridIndex;
  3117. }
  3118. //Set allow overshoot to allow drop point to get closest grid with x / y > cursor posx /y
  3119. function findClosestGrid(x, y, allowOvershoot = true) {
  3120. var minDx = window.innerWidth;
  3121. var minDy = window.innerHeight;
  3122. var finalLocation = [-1, -1];
  3123. var gridLocation = [-1, -1];
  3124. for (var i = 0; i < desktopGrids.length; i++) {
  3125. for (var j = 0; j < desktopGrids[0].length; j++) {
  3126. var thisGridLocation = desktopGrids[i][j];
  3127. var dx = x - thisGridLocation[0];
  3128. var dy = y - thisGridLocation[1];
  3129. if (allowOvershoot) {
  3130. if (Math.abs(dx) < minDx) {
  3131. minDx = Math.abs(x - thisGridLocation[0]);
  3132. finalLocation[0] = thisGridLocation[0];
  3133. gridLocation[0] = i;
  3134. }
  3135. if (Math.abs(dy) < minDy) {
  3136. minDy = Math.abs(y - thisGridLocation[1]);
  3137. finalLocation[1] = thisGridLocation[1];
  3138. gridLocation[1] = j;
  3139. }
  3140. } else {
  3141. if (dx < minDx && dx > 0) {
  3142. minDx = Math.abs(x - thisGridLocation[0]);
  3143. finalLocation[0] = thisGridLocation[0];
  3144. gridLocation[0] = i;
  3145. }
  3146. if (dy < minDy && dy > 0) {
  3147. minDy = Math.abs(y - thisGridLocation[1]);
  3148. finalLocation[1] = thisGridLocation[1];
  3149. gridLocation[1] = j;
  3150. }
  3151. }
  3152. }
  3153. }
  3154. return [finalLocation, gridLocation];
  3155. }
  3156. //Ask for confirmation before window close
  3157. //Update 16 Feb 2021: Disabled confirmation and use a new method of implementing this later
  3158. /*
  3159. function myConfirmation() {
  3160. if (!loggingOut){
  3161. return 'Your data might not been saved. Are you sure you want to quit?';
  3162. }
  3163. }
  3164. window.onbeforeunload = myConfirmation;
  3165. */
  3166. function iconClicked(object, evt) {
  3167. if (renameMode){
  3168. //Exit rename mode if icon is clicked during renaming
  3169. if ($(object).find(".renameInput").length == 0){
  3170. exitRenameMode();
  3171. }
  3172. }
  3173. //Clicked on a launch icon.
  3174. var alreadyHighlighted = $(object).find(".launchIconWrapper").hasClass("selected");
  3175. if (alreadyHighlighted){
  3176. //Already selected
  3177. if (ctrlHold) {
  3178. //Selection
  3179. $(object).find(".launchIconWrapper").removeClass("selected");
  3180. }
  3181. }else{
  3182. //Not selected yet
  3183. if (ctrlHold) {
  3184. //Add this into selection
  3185. $(object).find(".launchIconWrapper").addClass("selected");
  3186. }else{
  3187. //Remove all others and select this
  3188. $(".launchIconWrapper.selected").removeClass("selected");
  3189. $(object).find(".launchIconWrapper").addClass("selected");
  3190. }
  3191. }
  3192. }
  3193. function iconDoubleClicked(object, evt=undefined) {
  3194. //Don't allow opening when renaming
  3195. if (renameMode){
  3196. return;
  3197. }
  3198. //Double click on a launch icon, tries to open it
  3199. var filedata = ao_module_utils.attrToObject($(object).attr("filedata"));
  3200. //console.log(filedata);
  3201. if (filedata.IsDir) {
  3202. //This is a directory. Open with file explorer
  3203. newFloatWindow({
  3204. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(filedata.Filepath),
  3205. appicon: "SystemAO/file_system/img/small_icon.png",
  3206. width: 1080,
  3207. height: 580,
  3208. title: "File Manager"
  3209. });
  3210. } else if (filedata.IsShortcut) {
  3211. //This is a shortcut. Open the target endpoint
  3212. var stype = filedata["ShortcutType"];
  3213. if (stype == "module") {
  3214. //Open the target module
  3215. openModule(filedata.ShortcutPath);
  3216. } else if (stype == "folder") {
  3217. //Open the target folder
  3218. openFolder(filedata.ShortcutPath)
  3219. }else if (stype == "url"){
  3220. //Open the target webpage in a new tab
  3221. window.open(filedata.ShortcutPath);
  3222. }else{
  3223. console.log(filedata);
  3224. }
  3225. } else {
  3226. //This is a file. Open it with default opener
  3227. $.ajax({
  3228. url: "system/modules/getDefault",
  3229. method: "GET",
  3230. data: {
  3231. opr: "launch",
  3232. ext: filedata.Ext,
  3233. mode: "launch"
  3234. },
  3235. success: function(data) {
  3236. if (data.error !== undefined) {
  3237. //No default opener assigned
  3238. var url = "SystemAO/file_system/defaultOpener.html";
  3239. var icon = "SystemAO/file_system/img/opener.png";
  3240. var title = "Select an opener WebApp: "
  3241. var openFileList = [];
  3242. var openFileObject = {
  3243. filepath: filedata.Filepath,
  3244. filename: filedata.Filename
  3245. }
  3246. openFileList.push(openFileObject);
  3247. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  3248. newFloatWindow({
  3249. url: url + "#" + openParamter,
  3250. width: 320,
  3251. height: 510,
  3252. appicon: icon,
  3253. title: title
  3254. });
  3255. } else {
  3256. //Assigned. Launch with given paramter
  3257. var url = data["StartDir"];
  3258. var size = [undefined, undefined];
  3259. var title = data["Name"];
  3260. var icon = "img/system/favicon.png";
  3261. if (data["IconPath"] != "") {
  3262. icon = data["IconPath"];
  3263. }
  3264. //Use floatWindow if exists
  3265. if (data["SupportFW"] == true && data["LaunchFWDir"] != "") {
  3266. url = data["LaunchFWDir"];
  3267. if (data["InitFWSize"] !== null) {
  3268. size = data["InitFWSize"]
  3269. }
  3270. }
  3271. //Use embedded mode if exists
  3272. if (data["SupportEmb"] == true && data["LaunchEmb"] != "") {
  3273. url = data["LaunchEmb"];
  3274. if (data["InitEmbSize"] !== null) {
  3275. size = data["InitEmbSize"]
  3276. }
  3277. }
  3278. //Build open File Hash Data Format
  3279. var openFileList = [];
  3280. var openFileObject = {
  3281. filepath: filedata.Filepath,
  3282. filename: filedata.Filename
  3283. }
  3284. openFileList.push(openFileObject);
  3285. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  3286. //Add launch files info and launch floatWindow
  3287. newFloatWindow({
  3288. url: url + "#" + openParamter,
  3289. width: size[0],
  3290. height: size[1],
  3291. appicon: icon,
  3292. title: title
  3293. });
  3294. }
  3295. }
  3296. })
  3297. }
  3298. }
  3299. $(window).on("resize", function(event) {
  3300. redrawDesktopGrids();
  3301. resizeAllFloatWindowButtons();
  3302. })
  3303. // ======================= DOCUMENT KEY BINDING =====================
  3304. $(document).keydown(function(event) {
  3305. if (event.which == "17") {
  3306. //Pressdown of Ctrl key
  3307. ctrlHold = true;
  3308. } else if (event.which == "16") {
  3309. //Pressdown of Shift key
  3310. shiftHold = true;
  3311. }else if (event.which == "27"){
  3312. //Cancel all floatwindow events and key events
  3313. $("#fwdragpanel").hide();
  3314. $("#tfwdragpanel").hide();
  3315. $(".floatWindow").find(".iframecover").hide();
  3316. movingWindow = false;
  3317. resizingWindow = false;
  3318. resizingEdgeID = 0;
  3319. multiSelecting = false;
  3320. ctrlHold = false;
  3321. shiftHold = false;
  3322. }else if (event.which == "46"){
  3323. //Delete key
  3324. if (renameMode){
  3325. //Deleting content in textarea. Ignore delte action
  3326. return true
  3327. }
  3328. var deleteFilelist = [];
  3329. var deleteFilenameList = [];
  3330. $(".launchIconWrapper.selected").each(function(){
  3331. var fileObject = $(this).parent();
  3332. var fd = JSON.parse(decodeURIComponent((fileObject).attr("filedata")));
  3333. deleteFilelist.push(fd.Filepath);
  3334. deleteFilenameList.push(fd.Filename)
  3335. });
  3336. //Prase the filelist and pass to trash module
  3337. console.log(deleteFilelist);
  3338. $.ajax({
  3339. url: "system/file_system/fileOpr",
  3340. method:"POST",
  3341. data: {opr: "recycle", src: JSON.stringify(deleteFilelist)},
  3342. success: function(data){
  3343. if (data.error !== undefined){
  3344. alert(data.error);
  3345. }else{
  3346. refresh(undefined, true);
  3347. }
  3348. }
  3349. });
  3350. //Delete the file's desktop location
  3351. deleteFilenameList.forEach(file => {
  3352. $.ajax({
  3353. url: "system/desktop/files",
  3354. data: {del: file},
  3355. success: function(data){
  3356. if (data.error !== undefined){
  3357. console.log(data.error);
  3358. }
  3359. }
  3360. });
  3361. })
  3362. }else if (event.which == "13"){
  3363. //Enter key
  3364. if (!renameMode){
  3365. //Open selected object by emulating double click
  3366. $(".launchIconWrapper.selected").each(function(){
  3367. var object = $(this).parent();
  3368. iconDoubleClicked(object);
  3369. });
  3370. }else if (renameMode){
  3371. event.preventDefault();
  3372. exitRenameMode();
  3373. }
  3374. }else{
  3375. //console.log(event.which);
  3376. }
  3377. });
  3378. $(document).keyup(function(event) {
  3379. if (event.which == "17") {
  3380. ctrlHold = false;
  3381. } else if (event.which == "16") {
  3382. shiftHold = false;
  3383. }
  3384. });
  3385. $("#bgwrapper").on("mouseup", function(event) {
  3386. //Deselect all selected icons
  3387. event.preventDefault();
  3388. event.stopImmediatePropagation();
  3389. mainWindowMouseup(event);
  3390. });
  3391. function openFolder(virtualPath){
  3392. newFloatWindow({
  3393. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(virtualPath),
  3394. appicon: "SystemAO/file_system/img/small_icon.png",
  3395. width:1080,
  3396. height:580,
  3397. title: "File Manager"
  3398. });
  3399. }
  3400. function logout() {
  3401. loggingOut = true;
  3402. if (confirm("Exiting Session. Confirm?")){
  3403. $.get("system/auth/logout", function() {
  3404. window.location.href = "/";
  3405. });
  3406. }
  3407. hideAllContextMenus();
  3408. }
  3409. // ======================= CONTEXT MENU =============================
  3410. window.addEventListener("contextmenu",
  3411. function(e) {
  3412. e.preventDefault();
  3413. e.stopPropagation();
  3414. var clickTarget = $(e.target);
  3415. hideAllContextMenus();
  3416. showMenu = false;
  3417. $("#contextmenu").html("");
  3418. if (clickTarget.hasClass("launchIcon") || clickTarget.hasClass("launchIconImage") || clickTarget.hasClass("launchIconText")) {
  3419. //Click on an object on destkop
  3420. if (clickTarget.hasClass("launchIcon") == false) {
  3421. clickTarget = $(clickTarget).parent().parent();
  3422. }
  3423. if (!ctrlHold && !$(clickTarget).find(".launchIconWrapper").hasClass("selected")){
  3424. $(".launchIconWrapper.selected").removeClass("selected");
  3425. }
  3426. //Select this object
  3427. $(clickTarget).find(".launchIconWrapper").addClass("selected");
  3428. var objectType = $(clickTarget).attr("type");
  3429. operationTargetLaunchIcon = $(clickTarget);
  3430. //Check if selected more than one object
  3431. if ($(".launchIconWrapper.selected").length > 1){
  3432. //When the user selected more than one item on desktop
  3433. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3434. addContextMenuItem($("#contextmenu"), 'Open With', "<i class='caret right icon'></i>", "handleOpenWith", true);
  3435. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3436. addContextMenuSeperator($("#contextmenu"));
  3437. addContextMenuItem($("#contextmenu"), 'Download in Zip', "<i class='download icon'></i>", "downloadFile", false);
  3438. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='copy icon'></i>", "handleCloning", false);
  3439. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3440. addContextMenuSeperator($("#contextmenu"));
  3441. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3442. }else{
  3443. //When the user only selected one item
  3444. if (objectType == "file") {
  3445. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3446. addContextMenuItem($("#contextmenu"), 'Open With', "<i class='caret right icon'></i>", "handleOpenWith", true);
  3447. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3448. addContextMenuSeperator($("#contextmenu"));
  3449. addContextMenuItem($("#contextmenu"), 'Download', "<i class='download icon'></i>", "downloadFile", false);
  3450. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='copy icon'></i>", "handleCloning", false);
  3451. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3452. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3453. addContextMenuSeperator($("#contextmenu"));
  3454. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3455. } else if (objectType == "folder") {
  3456. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3457. addContextMenuItem($("#contextmenu"), 'Zip here', "<i class='zip icon'></i>", "handleZipFolder", false);
  3458. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3459. addContextMenuSeperator($("#contextmenu"));
  3460. addContextMenuItem($("#contextmenu"), 'Download as Zip', "<i class='download icon'></i>", "downloadFile", false);
  3461. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='caret right icon'></i>", "handleCloning", false);
  3462. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3463. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3464. addContextMenuSeperator($("#contextmenu"));
  3465. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3466. } else if (objectType == "shortcut") {
  3467. var fd = JSON.parse(decodeURIComponent($(clickTarget).attr("filedata")));
  3468. console.log(fd);
  3469. if (fd.ShortcutType == "module"){
  3470. //Public WebApp
  3471. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3472. addContextMenuItem($("#contextmenu"), 'Open in New Tab', "<i class='external icon'></i>", "openWebAppInNewTab", false);
  3473. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3474. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3475. }else if (fd.ShortcutType == "folder"){
  3476. //Folder
  3477. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3478. addContextMenuItem($("#contextmenu"), 'Open File Location', "<i class='folder open icon'></i>", "handleShortcutFolderOpen", false);
  3479. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3480. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3481. addContextMenuSeperator($("#contextmenu"));
  3482. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3483. }else{
  3484. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3485. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3486. }
  3487. }else{
  3488. console.log("Opening context menu on unknown type: ", objectType);
  3489. }
  3490. }
  3491. showMenu = true;
  3492. } else if (clickTarget.hasClass("backgroundFrame") || (isSafari && $(clickTarget).attr("id") == "selectionPanel")) {
  3493. //Click on the background. Load background context menu.
  3494. addContextMenuItem($("#contextmenu"), 'New', "<i class='caret right icon'></i>", "newitemmenu", true);
  3495. addContextMenuItem($("#contextmenu"), 'Refresh', "<i class='refresh icon'></i>", "handleMenuRefresh", false);
  3496. addContextMenuItem($("#contextmenu"), 'Open File Manager', undefined, "openfm", false);
  3497. //addContextMenuItem($("#contextmenu"), 'Get File from URL', "<i class='download icon'></i>", "downloadURL", false);
  3498. addContextMenuItem($("#contextmenu"), 'Personalization', "<i class='paint brush icon'></i>", "personalization", false);
  3499. addContextMenuItem($("#contextmenu"), 'Background', "<i class='caret right icon'></i>", "background", true);
  3500. addContextMenuItem($("#contextmenu"), 'Icon Size', "<i class='caret right icon'></i>", "listIconsize", true);
  3501. addContextMenuItem($("#contextmenu"), 'Toggle FullScreen', "<i class='maximize icon'></i>", "fullscreen", false);
  3502. addContextMenuItem($("#contextmenu"), 'Exit', undefined, "logout", false);
  3503. showMenu = true;
  3504. }else if (clickTarget.hasClass("fwdragger") || (clickTarget.hasClass("title") && clickTarget.parent().hasClass("fwdragger"))){
  3505. //Click on the floatWindow object
  3506. addContextMenuItem($("#contextmenu"), 'Open in New Tab', "<i class='external icon'></i>", "openSelectedFloatWindowInNewTab", false);
  3507. addContextMenuItem($("#contextmenu"), 'Refresh', "<i class='refresh icon'></i>", "refreshSelectedFloatWindow", false);
  3508. addContextMenuSeperator($("#contextmenu"));
  3509. addContextMenuItem($("#contextmenu"), 'Minimize', "<i class='window minimize icon'></i>", "minimizeSelectedFloatWindow", false);
  3510. if ($(clickTarget).parent().hasClass("fixedsize") == false && $(clickTarget).parent().parent().hasClass("fixedsize") == false){
  3511. //This FloatWindow is resizable
  3512. console.log($(clickTarget).parent());
  3513. if ($(clickTarget).parent().attr("max") !== undefined && $(clickTarget).parent().attr("max") == "true"){
  3514. addContextMenuItem($("#contextmenu"), 'Restore', "<i class='window window restore icon'></i>", "maximizeSelectedFloatWindow", false);
  3515. }else{
  3516. addContextMenuItem($("#contextmenu"), 'Maximize', "<i class='window maximize icon'></i>", "maximizeSelectedFloatWindow", false);
  3517. }
  3518. }
  3519. addContextMenuItem($("#contextmenu"), 'Close', "<i class='remove icon'></i>", "closeSelectedFloatWindow", false);
  3520. showMenu = true;
  3521. }
  3522. if (showMenu){
  3523. //Toggle context menu
  3524. $("#contextmenu").show();
  3525. var startX = e.pageX;
  3526. var startY = e.pageY;
  3527. if (e.pageX > window.innerWidth / 2){
  3528. startX = e.pageX - $("#contextmenu").width();
  3529. }
  3530. if (e.pageY > window.innerHeight / 2){
  3531. startY = e.pageY - $("#contextmenu").height();
  3532. }
  3533. $("#contextmenu").css({
  3534. left: startX,
  3535. top: startY
  3536. });
  3537. menuStartLocation = [e.pageX, e.pageY];
  3538. }
  3539. }, true);
  3540. function handleMenuRefresh() {
  3541. //This function is here to remove the object and event passed in from menu pressed object
  3542. refresh();
  3543. }
  3544. function newshortcut(){
  3545. //Show the new shortcut creation tool
  3546. newFloatWindow({
  3547. url: "SystemAO/desktop/shortcutCreator.html",
  3548. appicon: "img/desktop/system_icon/shortcut.png",
  3549. width:815,
  3550. height:485,
  3551. title: "New Shortcut"
  3552. });
  3553. hideAllContextMenus();
  3554. }
  3555. function openIconViaMenu(target, event){
  3556. $(".launchIconWrapper.selected").each(function(){
  3557. iconObject = $(this).parent();
  3558. //Emulate a doubleclick on icon
  3559. iconDoubleClicked(iconObject, event);
  3560. });
  3561. hideAllContextMenus();
  3562. }
  3563. //Opening a shortcut module from desktop to new tab
  3564. function openWebAppInNewTab(target, event){
  3565. $(".launchIconWrapper.selected").each(function(){
  3566. var fd = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3567. $.get("system/modules/getLaunchPara?module=" + fd.ShortcutPath, function(data) {
  3568. if (data.error !== undefined) {
  3569. console.log(data.error);
  3570. }else{
  3571. //Open in new tab
  3572. window.open(data.StartDir)
  3573. }
  3574. });
  3575. });
  3576. }
  3577. function downloadFile(target, event){
  3578. if ( $(".launchIconWrapper.selected").length == 1){
  3579. //Download this file directly
  3580. var rawfiledata = $(".launchIconWrapper.selected").parent().attr("filedata");
  3581. var filedata = JSON.parse(decodeURIComponent(rawfiledata));
  3582. var filepath = filedata.Filepath;
  3583. //Resolve the link to media download link
  3584. var downloadLink = "media?file=" + filepath + "&download=true";
  3585. window.open(downloadLink)
  3586. }else if ($(".launchIconWrapper.selected").length > 1){
  3587. //Create a zip file using the fs api
  3588. var filelist = [];
  3589. $(".launchIconWrapper.selected").each(function(){
  3590. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3591. var filepath = filedata.Filepath;
  3592. filelist.push(filepath);
  3593. });
  3594. $.ajax({
  3595. url: "system/file_system/zipHandler",
  3596. data: {opr: "tmpzip", src: JSON.stringify(filelist), dest: ""},
  3597. method: "POST",
  3598. success: function(data){
  3599. if (data.error !== undefined){
  3600. alert(data.error);
  3601. }else{
  3602. //Zip completed.
  3603. window.open("media?file=" + data + "&download=true");
  3604. }
  3605. }
  3606. });
  3607. }
  3608. hideAllContextMenus();
  3609. }
  3610. function handleZipFolder(){
  3611. var filelist = [];
  3612. var filename = "desktop_" + new Date().getTime() + ".zip"
  3613. if ($(".launchIconWrapper.selected").length == 1){
  3614. filename = $(".launchIconWrapper.selected").parent().attr('filename') + ".zip";
  3615. }
  3616. $(".launchIconWrapper.selected").each(function(){
  3617. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3618. var filepath = filedata.Filepath;
  3619. if (filedata.IsDir == true){
  3620. filelist.push(filepath);
  3621. }
  3622. });
  3623. $.ajax({
  3624. url: "system/file_system/zipHandler",
  3625. data: {opr: "zip", src: JSON.stringify(filelist), dest: "user:/Desktop/" + filename},
  3626. method: "POST",
  3627. success: function(data){
  3628. if (data.error !== undefined){
  3629. alert(data.error);
  3630. }else{
  3631. //Zip completed.
  3632. console.log(data);
  3633. }
  3634. }
  3635. });
  3636. //console.log(filelist);
  3637. hideAllContextMenus();
  3638. }
  3639. function handleOpenWith(target, event){
  3640. $("#subcontextmenu").html("");
  3641. $.get("system/modules/list",function(data){
  3642. if (data.error !== undefined){
  3643. alert(data.error);
  3644. }else{
  3645. var supportedModuleCount = 0;
  3646. var openWithTargets = [];
  3647. for (var i =0; i < data.length; i++){
  3648. var thisModule = data[i];
  3649. if (thisModule.SupportEmb == true){
  3650. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  3651. }
  3652. }
  3653. }
  3654. showSubContextMenu(target);
  3655. });
  3656. }
  3657. function openObjectProperty(target, object){
  3658. var filelist = [];
  3659. $(".launchIconWrapper.selected").each(function(){
  3660. var filepath = $(this).parent().attr("filepath");
  3661. filelist.push(filepath);
  3662. });
  3663. var hashPassthrough = encodeURIComponent(JSON.stringify(filelist));
  3664. newFloatWindow({
  3665. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  3666. width: 340,
  3667. height: 480,
  3668. appicon: "SystemAO/file_system/img/properties.png",
  3669. title: "File Properties",
  3670. });
  3671. hideAllContextMenus();
  3672. }
  3673. function openSelectedWith(target, event){
  3674. var targetModulename = $(target).text().trim();
  3675. var openFileList = [];
  3676. $(".selected.launchIconWrapper").each(function(){
  3677. var thisFiledata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3678. openFileList.push({
  3679. filename: thisFiledata.Filename,
  3680. filepath: thisFiledata.Filepath
  3681. });
  3682. });
  3683. //Find the launch info of the module
  3684. var targetModuleInfo = undefined;
  3685. for (var i =0; i < moduleInstalled.length; i++){
  3686. if (moduleInstalled[i].Name == targetModulename){
  3687. targetModuleInfo = JSON.parse(JSON.stringify(moduleInstalled[i]));
  3688. }
  3689. }
  3690. //Open the files with the given module
  3691. openFileWithModule(targetModuleInfo, openFileList);
  3692. hideAllContextMenus();
  3693. }
  3694. function getModuleInfoFromName(moduleName){
  3695. for (var i = 0; i < moduleInstalled.length; i++){
  3696. if (moduleInstalled[i].Name == moduleName){
  3697. return moduleInstalled[i];
  3698. }
  3699. }
  3700. return false
  3701. }
  3702. function addContextMenuItem(target, keyword, hotkey = undefined, functionName, containSubMenu = false) {
  3703. var itemClass = "item";
  3704. if (containSubMenu) {
  3705. itemClass = "item submenu";
  3706. }
  3707. if (hotkey !== undefined) {
  3708. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);">
  3709. ${keyword}
  3710. <span class="description">${hotkey}</span>
  3711. </div>`);
  3712. } else {
  3713. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);">
  3714. ${keyword}
  3715. </div>`);
  3716. }
  3717. }
  3718. function listIconsize(target, event) {
  3719. $("#subcontextmenu").html("");
  3720. var smallCheckmark = undefined;
  3721. var mediumCheckmark = undefined;
  3722. var bigCheckmark = undefined;
  3723. if (desktopIconSize == "small") {
  3724. smallCheckmark = "<i class='checkmark icon'></i>";
  3725. }
  3726. if (desktopIconSize == "medium") {
  3727. mediumCheckmark = "<i class='checkmark icon'></i>";
  3728. }
  3729. if (desktopIconSize == "big") {
  3730. bigCheckmark = "<i class='checkmark icon'></i>";
  3731. }
  3732. addContextMenuItem($("#subcontextmenu"), "Small", smallCheckmark, "setDesktopIconSize", false);
  3733. addContextMenuItem($("#subcontextmenu"), "Medium", mediumCheckmark, "setDesktopIconSize", false);
  3734. addContextMenuItem($("#subcontextmenu"), "Big", bigCheckmark, "setDesktopIconSize", false);
  3735. showSubContextMenu(target);
  3736. }
  3737. function setDesktopIconSize(target, evt) {
  3738. var targetSize = $(target).text().trim().toLowerCase();
  3739. if (["small", "medium", "big"].includes(targetSize)) {
  3740. desktopIconSize = targetSize;
  3741. }
  3742. refresh();
  3743. setStorage("iconsize", desktopIconSize);
  3744. hideAllContextMenus();
  3745. }
  3746. function addContextMenuSeperator(target) {
  3747. $(target).append(`<div class="divider"></div>`);
  3748. }
  3749. function downloadURL() {
  3750. alert("WIP");
  3751. hideAllContextMenus();
  3752. }
  3753. function background(target, evt) {
  3754. $("#subcontextmenu").html('<div class="item"><i class="loading spinning icon"></i> Loading</div>');
  3755. $.get("system/desktop/theme", function(data) {
  3756. $("#subcontextmenu").html("");
  3757. for (var i = 0; i < data.length; i++) {
  3758. if (currentUserTheme == data[i].Theme) {
  3759. addContextMenuItem($("#subcontextmenu"), data[i].Theme, "<i class='checkmark icon'></i>", "setTheme", false);
  3760. } else {
  3761. addContextMenuItem($("#subcontextmenu"), data[i].Theme, undefined, "setTheme", false);
  3762. }
  3763. }
  3764. });
  3765. showSubContextMenu(target);
  3766. }
  3767. //Set theme from button click
  3768. function setTheme(target, evt) {
  3769. var theme = $(target).text().trim();
  3770. setDesktopTheme(theme);
  3771. hideAllContextMenus();
  3772. }
  3773. function personalization() {
  3774. //Show the personalization window
  3775. newFloatWindow({
  3776. url: "SystemAO/desktop/personalization.html",
  3777. appicon: "SystemAO/desktop/img/personalization.png",
  3778. width:640,
  3779. height:480,
  3780. title: "Personalization"
  3781. });
  3782. hideAllContextMenus();
  3783. }
  3784. //New folder on the menu start location
  3785. function newfolder(object, event) {
  3786. var closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  3787. let closestPixelLocation = closestLocation[0];
  3788. let closestGridIndexLocation = closestLocation[1];
  3789. //Generate new foldername
  3790. var newFolderName = "New Folder";
  3791. var counter = 1;
  3792. while (desktopFileList.includes(newFolderName)) {
  3793. newFolderName = `New Folder(${counter})`;
  3794. counter++;
  3795. }
  3796. //Check if there are already another object at that locaton
  3797. var duplicateObject = getObjectFromLocation(closestPixelLocation[0], closestPixelLocation[1]);
  3798. var createObjectLocation = true;
  3799. if (duplicateObject !== undefined) {
  3800. //Ignore create position. Let it settle on next new slot.
  3801. createObjectLocation = false;
  3802. }
  3803. //Create the folder
  3804. $.post("system/file_system/newItem", {
  3805. type: "folder",
  3806. src: "user:/Desktop/",
  3807. filename: newFolderName
  3808. }).done(function(data) {
  3809. if (data.error !== undefined) {
  3810. console.log(data.error);
  3811. } else {
  3812. if (createObjectLocation) {
  3813. setIconDesktopLocation(newFolderName, closestGridIndexLocation[0], closestGridIndexLocation[1], function() {
  3814. //After set Desktop icon, refresh the page
  3815. refresh(function() {
  3816. //After refresh the page, highlight the new folder and set it to rename mode
  3817. var targetFolderObject = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  3818. console.log(targetFolderObject);
  3819. enableRenameOnLaunchIconObject(targetFolderObject);
  3820. });
  3821. });
  3822. }
  3823. }
  3824. });
  3825. /*
  3826. //Open new folder creation window
  3827. var existsingFileList = [];
  3828. for (var i =0; i < desktopFileList.length; i++){
  3829. existsingFileList.push({
  3830. filename: desktopFileList[i],
  3831. filepath: "user:/Desktop/" + desktopFileList[i]
  3832. });
  3833. }
  3834. newFloatWindow({
  3835. url: "SystemAO/file_system/newFolder.html#" + encodeURIComponent(JSON.stringify(existsingFileList)),
  3836. appicon: "SystemAO/file_system/img/new folder.png",
  3837. width:560,
  3838. height:340,
  3839. title: "New Folder"
  3840. });
  3841. */
  3842. hideAllContextMenus();
  3843. }
  3844. function enableRenameOnLaunchIconObject(object) {
  3845. renameMode = true;
  3846. $(".launchIcon").attr("draggable", "false");
  3847. var filedata = JSON.parse(decodeURIComponent($(object).attr("filedata")));
  3848. var originalName = filedata.Filename;
  3849. if (filedata.IsShortcut){
  3850. //Shortcut. Use its display name instead
  3851. originalName = filedata.ShortcutName;
  3852. }
  3853. $(object).find(".launchIconText").hide();
  3854. $(object).append(`<textarea class="renameInput ${desktopIconSize}" type="text" ondragstart="return false;" dblclick="event.stopImmediatePropagation(); event.stopImmediatePropagation();"maxlength="32">${originalName}</textarea>`);
  3855. $(object).find(".renameInput")[0].select();
  3856. var index = originalName.lastIndexOf(".");
  3857. console.log(index);
  3858. if( index >= 0){
  3859. $(object).find(".renameInput")[0].setSelectionRange(0, index);
  3860. }
  3861. }
  3862. function exitRenameMode() {
  3863. if (renameMode) {
  3864. $(".launchIcon").attr("draggable", "true");
  3865. $(".launchIcon").find(".launchIconText").show();
  3866. //Update the folder to textarea content
  3867. $(".renameInput").each(function() {
  3868. if ($(this).text() == "") {
  3869. //Ignore this update
  3870. } else {
  3871. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3872. var filepath = filedata.Filepath;
  3873. var newFilename = $(this).val();
  3874. if (filedata.IsShortcut == true){
  3875. //Shortcut. Edit the shortcut content name
  3876. let currentInputTextArea = $(this);
  3877. $.ajax({
  3878. url: "/system/desktop/opr/renameShortcut",
  3879. data: {src: filepath, new: newFilename},
  3880. success: function(data){
  3881. if (data.error !== undefined){
  3882. //Cancel the operation
  3883. console.log("*ERROR* " + data.error);
  3884. currentInputTextArea.remove();
  3885. }else{
  3886. //No need to update the shortcut position (as its name not changed)
  3887. refresh(function() {
  3888. //Refresh the desktop
  3889. });
  3890. }
  3891. }
  3892. })
  3893. }else{
  3894. //Normal typed files / folder. Rename the object
  3895. let currentInputTextArea = $(this);
  3896. $.ajax({
  3897. url: "./system/file_system/fileOpr",
  3898. method: "POST",
  3899. data: {opr: "rename", src: JSON.stringify([filepath]), new: JSON.stringify([newFilename])},
  3900. success: function(data){
  3901. if (data.error !== undefined){
  3902. //Cancel the operation
  3903. console.log("*ERROR* " + data.error);
  3904. currentInputTextArea.remove();
  3905. }else{
  3906. //Update the new file position
  3907. let closestLocation = findClosestGrid($(currentInputTextArea).parent().offset().left, $(currentInputTextArea).parent().offset().top);
  3908. let closestGridIndexLocation = closestLocation[1];
  3909. setIconDesktopLocation(newFilename, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  3910. //Callback after setting location
  3911. refresh(function() {
  3912. //Refresh the desktop
  3913. });
  3914. });
  3915. }
  3916. }
  3917. });
  3918. }
  3919. }
  3920. });
  3921. renameMode = false;
  3922. }
  3923. }
  3924. //Handle opening shortcut folder location
  3925. function handleShortcutFolderOpen(object, event){
  3926. var openPendingFolders = [];
  3927. $(".launchIconWrapper.selected").each(function(){
  3928. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3929. console.log(filedata);
  3930. if (filedata.IsShortcut == true){
  3931. if (filedata.ShortcutType == "folder"){
  3932. openPendingFolders.push(filedata.ShortcutPath);
  3933. }else if (filedata.ShortcutType == "module"){
  3934. openPendingFolders.push("web:/" + filedata.ShortcutPath);
  3935. }
  3936. }
  3937. });
  3938. //Open all folders
  3939. openPendingFolders.forEach(folder => {
  3940. newFloatWindow({
  3941. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(folder),
  3942. appicon: "SystemAO/file_system/img/small_icon.png",
  3943. width:1080,
  3944. height:580,
  3945. title: "File Manager"
  3946. });
  3947. })
  3948. hideAllContextMenus();
  3949. }
  3950. //Handle basic desktop file operations
  3951. function handleFileDelete(object, event){
  3952. var deleteFileList = [];
  3953. $(".launchIconWrapper.selected").each(function(){
  3954. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3955. deleteFileList.push(filedata.Filepath);
  3956. });
  3957. console.log(deleteFileList);
  3958. $.ajax({
  3959. url: "system/file_system/fileOpr",
  3960. method:"POST",
  3961. data: {opr: "recycle", src: JSON.stringify(deleteFileList)},
  3962. success: function(data){
  3963. if (data.error !== undefined){
  3964. alert(data.error);
  3965. }else{
  3966. refresh(undefined, true);
  3967. }
  3968. }
  3969. });
  3970. hideAllContextMenus();
  3971. }
  3972. //File Rename
  3973. let renamingItems = [];
  3974. function handleRename(object, event){
  3975. if ($('.launchIconWrapper.selected').length > 0){
  3976. //Enter rename mode
  3977. renamingItems = $('.launchIconWrapper.selected');
  3978. let renameTarget = $('.launchIconWrapper.selected')[0]
  3979. let fileObject = $(renameTarget).parent();
  3980. enableRenameOnLaunchIconObject(fileObject);
  3981. }
  3982. hideAllContextMenus();
  3983. }
  3984. //New item menus.
  3985. function newitemmenu(target, event) {
  3986. $("#subcontextmenu").html("");
  3987. //Append the new folder option first
  3988. addContextMenuItem($("#subcontextmenu"), 'Folder', "<i class='folder icon'></i>", "newfolder", true);
  3989. addContextMenuItem($("#subcontextmenu"), 'Shortcut', "<i class='external icon'></i>", "newshortcut", true);
  3990. addContextMenuSeperator($("#subcontextmenu"));
  3991. $.get("system/file_system/newItem", function(data) {
  3992. for (var i = 0; i < data.length; i++) {
  3993. var thisNewFile = data[i];
  3994. var icon = ao_module_utils.getIconFromExt(thisNewFile.Ext);
  3995. addContextMenuItem($("#subcontextmenu"), `<i class="${icon} icon" ext="${thisNewFile.Ext}"></i> ${thisNewFile.Desc}`, undefined, "newitem");
  3996. }
  3997. //Show sub-context menu
  3998. showSubContextMenu(target);
  3999. });
  4000. }
  4001. function showSubContextMenu(target) {
  4002. $("#subcontextmenu").show();
  4003. var targetLeft = $("#contextmenu").offset().left + $("#contextmenu").width() + 2;
  4004. var targetTop = $(target).offset().top - 1;
  4005. if (targetLeft + $("#subcontextmenu").width() > window.innerWidth){
  4006. //Overflow. Swtich to the left side of the menu
  4007. targetLeft = $("#contextmenu").offset().left - $("#subcontextmenu").width() - 2;
  4008. }
  4009. $("#subcontextmenu").css({
  4010. left: targetLeft,
  4011. top: targetTop
  4012. });
  4013. }
  4014. //Create new file item with that filename
  4015. function newitem(object, event) {
  4016. var extension = $(object).find("i").attr("ext");
  4017. //Generate a newfile name
  4018. var newfn = "NewFile" + "." + extension;
  4019. var counter = 1;
  4020. while (desktopFileList.includes(newfn)){
  4021. newfn = "NewFile (" + counter + ")." + extension;
  4022. counter++;
  4023. }
  4024. //Get the location position
  4025. let closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4026. let closestGridIndexLocation = closestLocation[1];
  4027. //Request backend to generate the new file
  4028. $.ajax({
  4029. url: "system/file_system/newItem",
  4030. data: {type: "file",src: "user:/Desktop/",filename: newfn},
  4031. success: function(data){
  4032. if (data.error !== undefined){
  4033. alert(data.error);
  4034. }else{
  4035. //Set the icon location
  4036. setIconDesktopLocation(newfn, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4037. //Refresh the desktop
  4038. refresh();
  4039. });
  4040. }
  4041. }
  4042. });
  4043. hideAllContextMenus();
  4044. }
  4045. document.getElementById("volumebar").parentNode.addEventListener("touchstart", function(e){
  4046. updateVolume( document.getElementById("volumebar").parentNode, e);
  4047. });
  4048. function getCoordinateFromEvent(e){
  4049. var x = -1;
  4050. var y = -1;
  4051. if (e.originalEvent == undefined){
  4052. e.originalEvent = e;
  4053. }
  4054. if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){
  4055. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  4056. x = touch.pageX;
  4057. y = touch.pageY;
  4058. } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
  4059. x = e.clientX;
  4060. y = e.clientY;
  4061. }else{
  4062. x = e.clientX;
  4063. y = e.clientY;
  4064. }
  4065. return [x,y];
  4066. }
  4067. function updateVolume(object, event){
  4068. var width = $(object).width();
  4069. var left = $(object).offset().left;
  4070. var clickPosition = getCoordinateFromEvent(event)[0];
  4071. var clickRel = clickPosition - left;
  4072. var percentage = clickRel / width * 100;
  4073. if (percentage < 0){
  4074. percentage = 0;
  4075. }else if (percentage > 100){
  4076. percentage = 100;
  4077. }
  4078. //Update the global volume
  4079. $(object).find(".bar").css("width",percentage + "%");
  4080. localStorage.setItem("global_volume", clickRel / width);
  4081. }
  4082. function refresh(callback = undefined, noflash=false) {
  4083. //Refresh desktop contents
  4084. let launchOption = {};
  4085. if (noflash){
  4086. launchOption = {
  4087. noflash: true
  4088. };
  4089. }else{
  4090. $(".launchIcon").remove();
  4091. }
  4092. if (callback == undefined) {
  4093. initDesktopFiles(launchOption);
  4094. } else {
  4095. initDesktopFiles(launchOption, callback);
  4096. }
  4097. hideAllContextMenus();
  4098. }
  4099. function openfm() {
  4100. //Open file explorer on desktop
  4101. newFloatWindow({
  4102. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent("user:/Desktop"),
  4103. appicon: "SystemAO/file_system/img/small_icon.png",
  4104. width: 1080,
  4105. height: 580,
  4106. title: "File Manager"
  4107. });
  4108. hideAllContextMenus();
  4109. }
  4110. /*
  4111. Notification and Notification bar related functions
  4112. Usage:
  4113. title -> The title of the notification
  4114. content -> The content of the notification
  4115. icon (optional) -> The icon of the notification
  4116. windowOpenOption (optional) -> The window opening option for user onclick redirection
  4117. */
  4118. function sendNotification(title, content, icon="notice circle", windowOpenOption=null){
  4119. if (content.length > 100){
  4120. shortenContent = content.substring(0,100) + "...";
  4121. }else{
  4122. shortenContent = content;
  4123. }
  4124. onClickOpenWindowOption = encodeURIComponent(JSON.parse(windowOpenOption));
  4125. $("#notificationlist").append(` <div class="notification object" originalcontent="${content}" redirect="${onClickOpenWindowOption}" onclick="openNotification(this);">
  4126. <p class="title"><i class="${icon} icon"></i> ${title}</p>
  4127. <p class="notifycontent">${shortenContent}</p>
  4128. <div class="closebtn" onclick="event.stopImmediatePropagation(); closeThisNotification(this);"><i class="remove icon"></i></div>
  4129. <div class="ts divider"></div>
  4130. </div>`);
  4131. $(".nonotification").hide();
  4132. }
  4133. function openNotification(obj){
  4134. newWindowOpeningOption = JSON.parse(decodeURIComponent($(obj).attr("redirect")));
  4135. if (newWindowOpeningOption == null){
  4136. //Ignore
  4137. }else{
  4138. //Start a floatWindow to the given target
  4139. newFloatWindow(newWindowOpeningOption);
  4140. }
  4141. //Clear the notiication
  4142. closeThisNotification($(obj).find(".closebtn"));
  4143. }
  4144. function closeThisNotification(obj){
  4145. $(obj).parent().slideUp("fast",function(data){
  4146. $(this).remove();
  4147. if ($(".notification.object").length == 0){
  4148. $(".nonotification").show();
  4149. }
  4150. });
  4151. }
  4152. function clearAllNotification(){
  4153. $(".notification.object").slideUp('fast',function(data){
  4154. $(this).remove();
  4155. $(".nonotification").show();
  4156. });
  4157. }
  4158. function hideAllContextMenus() {
  4159. $("#subcontextmenu").hide();
  4160. $("#contextmenu").hide()
  4161. $("#quickAccessPanel").slideUp("fast");
  4162. }
  4163. function restart(){
  4164. if (!hardwareman){
  4165. return
  4166. }
  4167. if (confirm("Confirm Restart?")){
  4168. $.ajax({
  4169. url: "system/power/restart",
  4170. success: function(data){
  4171. if (data.error !== undefined){
  4172. alert(data.error);
  4173. }
  4174. },
  4175. error: function(){
  4176. }
  4177. });
  4178. }
  4179. }
  4180. function shutdown(){
  4181. if (!hardwareman){
  4182. return
  4183. }
  4184. if (confirm("Confirm Poweroff?")){
  4185. $.ajax({
  4186. url: "system/power/shutdown",
  4187. success: function(data){
  4188. if (data.error !== undefined){
  4189. alert(data.error);
  4190. }else{
  4191. //Shutdown suceed
  4192. }
  4193. },
  4194. error: function(){
  4195. //Shutdown suceed
  4196. }
  4197. });
  4198. }
  4199. }
  4200. function uploadFile(file, callback=undefined) {
  4201. let url = 'system/file_system/upload'
  4202. let uploadCurrentPath = "user:/Desktop/";
  4203. let formData = new FormData()
  4204. let xhr = new XMLHttpRequest()
  4205. formData.append('file', file);
  4206. formData.append('path', uploadCurrentPath);
  4207. xhr.open('POST', url, true)
  4208. xhr.upload.addEventListener("progress", function(e) {
  4209. console.log((e.loaded * 100.0 / e.total) || 100)
  4210. })
  4211. xhr.addEventListener('readystatechange', function(e) {
  4212. if (xhr.readyState == 4 && xhr.status == 200) {
  4213. if (callback !== undefined){
  4214. callback(e.target.response);
  4215. }
  4216. }
  4217. else if (xhr.readyState == 4 && xhr.status != 200) {
  4218. console.log("Upload failed :" + xhr.status);
  4219. }
  4220. })
  4221. xhr.send(formData);
  4222. }
  4223. function setStorage(key, value, callback = undefined) {
  4224. $.get("system/desktop/preference?preference=" + key + "&value=" + value, function(data) {
  4225. if (data.error !== undefined) {
  4226. console.log(data.error);
  4227. } else {
  4228. if (callback !== undefined) {
  4229. callback();
  4230. }
  4231. }
  4232. });
  4233. }
  4234. function getStorage(key, callback) {
  4235. $.get("system/desktop/preference?preference=" + key, callback);
  4236. }
  4237. function showSystemSettings(){
  4238. var hasAccessToSetting = false;
  4239. moduleInstalled.forEach(thismod => {
  4240. if (thismod.Name == "System Setting"){
  4241. openModule("System Setting");
  4242. }
  4243. })
  4244. }
  4245. function initTheme(targetTheme=undefined){
  4246. if (targetTheme == undefined){
  4247. $.get("../../system/file_system/preference?key=file_explorer/theme", function(data){
  4248. if (data == "darkTheme"){
  4249. setDarkTheme();
  4250. }
  4251. });
  4252. }else{
  4253. //Manual override mode
  4254. if (targetTheme == "darkTheme"){
  4255. setDarkTheme();
  4256. }else if (targetTheme == "whiteTheme"){
  4257. setWhiteTheme();
  4258. }
  4259. }
  4260. }
  4261. function setFloatWindowTheme(fwid, theme="dark"){
  4262. var targetFW = getFloatWindowByID(fwid);
  4263. if (theme == "dark"){
  4264. $(targetFW).removeClass("white");
  4265. }else if (theme == "white"){
  4266. $(targetFW).addClass("white");
  4267. }
  4268. }
  4269. function checkFileSystemAccess(){
  4270. var allowReadWrite = false;
  4271. moduleInstalled.forEach(thisModule => {
  4272. if (thisModule.Name == "File Manager"){
  4273. //This user has read write access to file system
  4274. allowReadWrite = true;
  4275. }
  4276. });
  4277. if (!allowReadWrite){
  4278. sendNotification("READ ONLY Account", "This account is read only. You cannot perform any file operations on this desktop.");
  4279. }
  4280. }
  4281. function setDarkTheme(){
  4282. $("#listMenu").addClass("darkTheme");
  4283. $("#powerIcon").attr("src","img/system/power-white.svg");
  4284. $("#quickAccessPanel").addClass("darkTheme");
  4285. $("#quickAccessPanel").find(".button").addClass("inverted");
  4286. }
  4287. function setWhiteTheme(){
  4288. $("#listMenu").removeClass("darkTheme");
  4289. $("#powerIcon").attr("src","img/system/power.svg");
  4290. $("#quickAccessPanel").removeClass("darkTheme");
  4291. $("#quickAccessPanel").find(".button").removeClass("inverted");
  4292. }
  4293. function hexToRgbA(hex, transparent=1){
  4294. var c;
  4295. if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
  4296. c= hex.substring(1).split('');
  4297. if(c.length== 3){
  4298. c= [c[0], c[0], c[1], c[1], c[2], c[2]];
  4299. }
  4300. c= '0x'+c.join('');
  4301. return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',' + transparent + ')';
  4302. }
  4303. throw new Error('Bad Hex');
  4304. }
  4305. function setThemeColor(newThemeColor){
  4306. //Update the global theme color
  4307. desktopThemeColor = newThemeColor;
  4308. //Update the related elements
  4309. $("#statusbar").css("background-color",newThemeColor);
  4310. $("#navimenu").css("background-color",hexToRgbA(newThemeColor, 0.5));
  4311. $(".floatWindow .controls").css("background-color",hexToRgbA(newThemeColor, 0.85));
  4312. //List menu theme color bar
  4313. $("#listMenu").find(".searchBar").css("border-bottom", "2px solid " + newThemeColor);
  4314. $("#volumebar").css("background-color", newThemeColor);
  4315. }
  4316. //Load the user define theme color to overwrite the default color if exists
  4317. function initUserDefinedThemeColor(){
  4318. $.ajax({
  4319. url: "../../system/file_system/preference",
  4320. data: {key: "themecolor"},
  4321. success: function(data){
  4322. if (data.error == undefined && data != ""){
  4323. setThemeColor(data);
  4324. }
  4325. }
  4326. });
  4327. }
  4328. //Float Window context menu
  4329. function getFocusedFloatWindowID(){
  4330. var targetFloatWindowId = "";
  4331. $(".floatWindow").each(function() {
  4332. var thisWindowZIndex = $(this).css("z-index");
  4333. if (parseInt(thisWindowZIndex) == 101){
  4334. targetFloatWindowId = $(this).attr("windowid");
  4335. }
  4336. });
  4337. return targetFloatWindowId;
  4338. }
  4339. function getFocusedFloatWindow(){
  4340. var focusedFwId = getFocusedFloatWindowID();
  4341. if (focusedFwId != ""){
  4342. var fw = getFloatWindowByID(focusedFwId);
  4343. return fw;
  4344. }else{
  4345. return undefined;
  4346. }
  4347. }
  4348. function refreshSelectedFloatWindow(target, event){
  4349. var fw = getFocusedFloatWindow();
  4350. if (fw != undefined){
  4351. $(fw).find("iframe")[0].contentWindow.location.reload();
  4352. }
  4353. hideAllContextMenus();
  4354. }
  4355. function maximizeSelectedFloatWindow(target, event){
  4356. var fw = getFocusedFloatWindow();
  4357. if (fw != undefined){
  4358. toggleMax($(fw).find(".buttons.maxtoggle"),event);
  4359. }
  4360. hideAllContextMenus();
  4361. }
  4362. function minimizeSelectedFloatWindow(target, event){
  4363. var fw = getFocusedFloatWindow();
  4364. if (fw != undefined){
  4365. min($(fw).find(".buttons.mintoggle"),event);
  4366. }
  4367. hideAllContextMenus();
  4368. }
  4369. function openSelectedFloatWindowInNewTab(){
  4370. var fw = getFocusedFloatWindow();
  4371. if (fw != undefined){
  4372. var currentURL = $(fw).find("iframe")[0].contentWindow.location;
  4373. window.open(currentURL);
  4374. }
  4375. hideAllContextMenus();
  4376. }
  4377. function closeSelectedFloatWindow(target, event){
  4378. var fw = getFocusedFloatWindow();
  4379. if (fw != undefined){
  4380. closeFloatWindow($(fw).find(".buttons.closetoggle"),event);
  4381. }
  4382. hideAllContextMenus();
  4383. }
  4384. function fullscreen() {
  4385. //Opening full screen will lead to hidden of all iframe for unknown reasons
  4386. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
  4387. (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
  4388. (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
  4389. (document.msFullscreenElement && document.msFullscreenElement !== null);
  4390. var elem = document.documentElement;
  4391. if (!isInFullScreen) {
  4392. if (elem.requestFullscreen) {
  4393. elem.requestFullscreen();
  4394. } else if (elem.mozRequestFullScreen) { /* Firefox */
  4395. elem.mozRequestFullScreen();
  4396. } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
  4397. elem.webkitRequestFullscreen();
  4398. } else if (elem.msRequestFullscreen) { /* IE/Edge */
  4399. elem.msRequestFullscreen();
  4400. }
  4401. } else {
  4402. if (document.exitFullscreen) {
  4403. document.exitFullscreen();
  4404. } else if (document.webkitExitFullscreen) {
  4405. document.webkitExitFullscreen();
  4406. } else if (document.mozCancelFullScreen) {
  4407. document.mozCancelFullScreen();
  4408. } else if (document.msExitFullscreen) {
  4409. document.msExitFullscreen();
  4410. }
  4411. }
  4412. hideAllContextMenus();
  4413. }
  4414. /*
  4415. Background services for keeping desktop files updated
  4416. Same mechanism is used as file explorer
  4417. */
  4418. let desktopFileHash = "";
  4419. setInterval(function(){
  4420. getDesktopHash(function(hash){
  4421. if (desktopFileHash == ""){
  4422. //Initialization
  4423. desktopFileHash = hash;
  4424. }else if (desktopFileHash != hash){
  4425. //Changed on desktop files. Refresh
  4426. refresh();
  4427. desktopFileHash = hash;
  4428. }
  4429. //Else, no file change on desktop
  4430. });
  4431. }, 15000);
  4432. function getDesktopHash(callback){
  4433. $.ajax({
  4434. url: "../../system/file_system/listDirHash",
  4435. data: {dir: "user:/Desktop/"},
  4436. success: function(data){
  4437. if (data.error !== undefined){
  4438. }
  4439. callback(data);
  4440. }
  4441. })
  4442. }
  4443. </script>
  4444. </body>
  4445. </html>