desktop.system 267 KB

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