desktop.system 248 KB

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