desktop.system 194 KB

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