desktop.system 196 KB

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