desktop.system 197 KB

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