desktop.system 246 KB

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