desktop.system 193 KB

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