desktop.system 221 KB

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