desktop.system 244 KB

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