desktop.system 208 KB

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