desktop.system 259 KB

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