desktop.system 239 KB

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