desktop.system 207 KB

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