desktop.system 199 KB

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