desktop.system 266 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457
  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")){
  2039. //The previous focused windows is topmost. Move it to layer 109
  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{
  2050. //The previous focused windows is normal windows. Move it to 100
  2051. $(focusedWindow).css("z-index", 100);
  2052. //Shift all the other windows down
  2053. $(".floatWindow").each(function() {
  2054. if ($(this).hasClass("topmost")){
  2055. return;
  2056. }
  2057. var thisWindowZIndex = $(this).css("z-index");
  2058. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  2059. if ($(this).attr("windowId") != windowID) {
  2060. $(this).css("z-index", thisWindowZIndex - 1);
  2061. //console.log($(this).attr("windowId"), $(this).css("z-index"));
  2062. }
  2063. }
  2064. });
  2065. }
  2066. if ($(object).hasClass("topmost")){
  2067. //The new windows is a topmost window
  2068. $(object).css("z-index", 501);
  2069. }else{
  2070. $(object).css("z-index", 101);
  2071. }
  2072. focusedWindow = $(object);
  2073. //Check if this div is hidden. If yes, fade it in.
  2074. if ($(object).is(":hidden")) {
  2075. $(object).fadeIn(100);
  2076. }
  2077. //Focus on the top most floatWindow
  2078. var iframe = focusedWindow.find("iframe")[0];
  2079. iframe.contentWindow.focus();
  2080. }
  2081. function newFloatWindow(config, callback=undefined) {
  2082. //Check if the number of floatWindow already reaching its maxmium
  2083. if ($(".floatWindow").length > maxWindowCount){
  2084. console.log("Max number of floatWindow reached.");
  2085. return;
  2086. }
  2087. //Generate new floatwindow startup config from object
  2088. var url = defaultOrKey(config, "about:blank", "url");
  2089. var uuid = defaultOrKey(config, (new Date()).getTime(), "uid");
  2090. var width = defaultOrKey(config, 854, "width");
  2091. var height = defaultOrKey(config, 480, "height");
  2092. var moduleIcon = defaultOrKey(config, "img/system/favicon.png", "appicon");
  2093. var title = defaultOrKey(config, "New floatWindow", "title");
  2094. var left = defaultOrKey(config, 100, "left");
  2095. var top = defaultOrKey(config, 100, "top");
  2096. var parentWindowID = defaultOrKey(config, "", "parent");
  2097. var callbackFunctionName = defaultOrKey(config, "", "callback");
  2098. var bgcolor = defaultOrKey(config, "", "background-color");
  2099. //Encode function name
  2100. callbackFunctionName = encodeURIComponent(callbackFunctionName);
  2101. //Validate paramters
  2102. if (width > window.innerWidth) {
  2103. width = window.innerWidth;
  2104. }
  2105. if (height > window.innerHeight) {
  2106. height = window.innerHeight;
  2107. }
  2108. if (left + width > window.innerWidth) {
  2109. left = 0;
  2110. }
  2111. if (top + height > window.innerHeight) {
  2112. top = 0;
  2113. }
  2114. //Check if the location already cotain any window
  2115. while (floatWindowLocationDuplicated(left, top)) {
  2116. left += 30;
  2117. top += 30;
  2118. }
  2119. //Check if the opening require a overwrite on background color
  2120. var backgroundStyle = "";
  2121. if (bgcolor !== ""){
  2122. backgroundStyle = `background-color: ${bgcolor};`;
  2123. }
  2124. //Check if the theme color is applied. If yes, generate the floatWindow with overwritten theem color
  2125. var overWriteThemeColor = "";
  2126. if (desktopThemeColor != ""){
  2127. overWriteThemeColor = `background-color: ${hexToRgbA(desktopThemeColor, 0.85)}`;
  2128. }
  2129. //Append the floatWindow into the body
  2130. $("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}">
  2131. <div class="controls fwdragger themeColorSolid" style="${overWriteThemeColor}">
  2132. <img class="moduleicon" src="${moduleIcon}"></img>
  2133. <div class="title">${title}</div>
  2134. <div class="fwcontrol">
  2135. <div class="buttons mintoggle">
  2136. <img src="img/system/min.png"></img>
  2137. </div>
  2138. <div class="buttons maxtoggle">
  2139. <img class="maxToogleButton" src="img/system/max.png"></img>
  2140. </div>
  2141. <div class="buttons closetoggle close">
  2142. <img src="img/system/close.png"></img>
  2143. </div>
  2144. </div>
  2145. </div>
  2146. <div class="iframewrapper">
  2147. <iframe src="${url}" allowfullscreen="true"></iframe>
  2148. <div class="iframecover"></div>
  2149. </div>
  2150. </div>`);
  2151. var newWindowObject = getFloatWindowByID(uuid);
  2152. //console.log(newWindowObject);
  2153. MoveFloatWindowToTop(newWindowObject);
  2154. //Append window to taskbar
  2155. var groupInfo = url.split("/");
  2156. var group = "";
  2157. if (groupInfo.length == 1) {
  2158. group = groupInfo[0];
  2159. } else {
  2160. groupInfo.pop();
  2161. group = groupInfo.join("/");
  2162. }
  2163. //File system windows require special grouping based on their filename
  2164. if (url.includes("SystemAO/file_system/")){
  2165. group = url.split("/").pop().split(".").join("_");
  2166. }else if (url.includes("SystemAO/utilities/")){
  2167. group = url.split("/").pop().split(".").join("_");
  2168. if (group.includes("#")){
  2169. group = group.split("#")[0];
  2170. }
  2171. }
  2172. //Check if the group already exists.
  2173. var groupExists = false;
  2174. var targetGroupingTab;
  2175. $(".floatWindowButton").each(function() {
  2176. if ($(this).attr("group") == group) {
  2177. groupExists = true;
  2178. targetGroupingTab = $(this);
  2179. }
  2180. });
  2181. //Check if the group is System Explorer and held special treatment if yes
  2182. if (group.split("/").shift() == "SystemAO") {
  2183. if (url.includes("file_explorer.html") && groupExists) {
  2184. //File Manager. Group them
  2185. group = "file_explorer";
  2186. }else if (url.includes("utilities") && groupExists){
  2187. //Allow grouping
  2188. } else {
  2189. //Do not group anything from SystemAO other than file explorer
  2190. groupExists = false;
  2191. }
  2192. }
  2193. if (groupExists == false) {
  2194. //Append the item to taskbar
  2195. var windowIDGroup = encodeURIComponent(JSON.stringify([uuid]));
  2196. var floatWindowButtonObject = ` <div class="item clickable floatWindowButton onscreen" group="${group}" windowIDGroup="${windowIDGroup}">
  2197. <img class="floatWindowAppIcon" src="${moduleIcon}"></img>
  2198. <p class="floatWindowTitle">${title}</p>
  2199. </div>`;
  2200. $(".navimenu").append(floatWindowButtonObject);
  2201. } else {
  2202. //Group already exists. Add tab into that group.
  2203. var originalIDlist = JSON.parse(decodeURIComponent($(targetGroupingTab).attr('windowIDGroup')));
  2204. originalIDlist.push(uuid);
  2205. //Encode and put the group list back to the object
  2206. var newIDList = encodeURIComponent(JSON.stringify(originalIDlist));
  2207. $(targetGroupingTab).attr("windowIDGroup", newIDList);
  2208. }
  2209. hookFloatWindowEvents();
  2210. resizeAllFloatWindowButtons();
  2211. if (callback !== undefined){
  2212. callback(uuid);
  2213. }
  2214. }
  2215. function resizeAllFloatWindowButtons() {
  2216. var fwbTotalWidth = $(".floatWindowButton").length * 200;
  2217. if (fwbTotalWidth > window.innerWidth * 0.7) {
  2218. $(".floatWindowButton").addClass("hideText");
  2219. } else {
  2220. $(".floatWindowButton").removeClass("hideText");
  2221. }
  2222. }
  2223. function floatWindowLocationDuplicated(left, top) {
  2224. var duplicated = false;
  2225. $(".floatWindow").each(function() {
  2226. if ($(this).offset().left == left && $(this).offset().top == top) {
  2227. duplicated = true;
  2228. }
  2229. });
  2230. return duplicated;
  2231. }
  2232. function defaultOrKey(object, defaultvalue, key) {
  2233. if (object[key] !== undefined) {
  2234. return object[key];
  2235. }
  2236. return defaultvalue;
  2237. }
  2238. function getFloatWindowByID(id) {
  2239. var targetWindow = undefined;
  2240. $(".floatWindow").each(function() {
  2241. if ($(this).attr("windowId") == id) {
  2242. targetWindow = $(this);
  2243. }
  2244. });
  2245. return targetWindow;
  2246. }
  2247. function getFloatWindowIconByID(id) {
  2248. var targetIconURL = "img/system/favicon.png";
  2249. $(".floatWindow").each(function() {
  2250. if ($(this).attr("windowId") == id) {
  2251. //This window ID matched the target fw
  2252. targetIconURL = $(this).find(".moduleicon").attr('src');
  2253. }
  2254. });
  2255. return targetIconURL;
  2256. }
  2257. function getFloatWindowTitleByID(id) {
  2258. var title = "";
  2259. $(".floatWindow").each(function() {
  2260. if ($(this).attr("windowId") == id) {
  2261. //This window ID matched the target fw
  2262. title = $(this).find(".title").text();
  2263. }
  2264. });
  2265. return title;
  2266. }
  2267. function setFloatWindowResizePolicy(targetFWId, resizble = true) {
  2268. var targetfw = getFloatWindowByID(targetFWId);
  2269. if (resizble) {
  2270. $(targetfw).find(".maxtoggle").show();
  2271. $(targetfw).removeClass("fixedsize");
  2272. } else {
  2273. $(targetfw).find(".maxtoggle").hide();
  2274. $(targetfw).addClass("fixedsize");
  2275. }
  2276. }
  2277. function setFloatWindowSize(targetFWId, newWidth, newHeight) {
  2278. var targetfw = getFloatWindowByID(targetFWId);
  2279. $(targetfw).css({
  2280. height: newHeight,
  2281. width: newWidth
  2282. });
  2283. }
  2284. function setFloatWindowTitle(targetFWId, newTitle) {
  2285. var targetfw = getFloatWindowByID(targetFWId);
  2286. $(targetfw).find(".title").text(newTitle);
  2287. }
  2288. function openFileWithModule(moduleLaunchInfo, openFileList) {
  2289. var url = moduleLaunchInfo["StartDir"];
  2290. var size = [undefined, undefined];
  2291. var title = moduleLaunchInfo["Name"];
  2292. var icon = "img/system/favicon.png";
  2293. if (moduleLaunchInfo["IconPath"] != "") {
  2294. icon = moduleLaunchInfo["IconPath"];
  2295. }
  2296. //Use floatWindow if exists
  2297. if (moduleLaunchInfo["SupportFW"] == true && moduleLaunchInfo["LaunchFWDir"] != "") {
  2298. url = moduleLaunchInfo["LaunchFWDir"];
  2299. if (moduleLaunchInfo["InitFWSize"] !== null) {
  2300. size = moduleLaunchInfo["InitFWSize"]
  2301. }
  2302. }
  2303. //Use embedded mode if exists
  2304. if (moduleLaunchInfo["SupportEmb"] == true && moduleLaunchInfo["LaunchEmb"] != "") {
  2305. url = moduleLaunchInfo["LaunchEmb"];
  2306. if (moduleLaunchInfo["InitEmbSize"] !== null) {
  2307. size = moduleLaunchInfo["InitEmbSize"]
  2308. }
  2309. }
  2310. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  2311. //Add launch files info and launch floatWindow
  2312. parent.newFloatWindow({
  2313. url: url + "#" + openParamter,
  2314. width: size[0],
  2315. height: size[1],
  2316. appicon: icon,
  2317. title: title
  2318. });
  2319. }
  2320. //====================== DESKTOP THEME RELATED FUNCTIONS =====================
  2321. //Initiate desktop theme list and user current theme
  2322. function initDesktopTheme() {
  2323. //Update 1 April 2021: Check if the user customize the desktop with the given path
  2324. $.get("system/desktop/theme", function(data) {
  2325. //Return a list of theme stored on the system
  2326. desktopThemeList = data;
  2327. $.get("system/desktop/theme?get=true", function(data) {
  2328. //Get the user theme settings
  2329. changeDesktopTheme(data);
  2330. });
  2331. });
  2332. }
  2333. function setDesktopTheme(themeName) {
  2334. $.get("system/desktop/theme?set=" + themeName, function(data) {
  2335. //Get the user theme settings
  2336. changeDesktopTheme(themeName);
  2337. if (data.includes("Error")) {
  2338. console.log(data);
  2339. }
  2340. });
  2341. }
  2342. //Actiave background cross fade changing animation
  2343. function initBackgroundSwitchingAnimation() {
  2344. if (localStorage.getItem("ao/desktop/backgroundInterval") !== null && !isNaN(parseInt(localStorage.getItem("ao/desktop/backgroundInterval")))){
  2345. //Localstorage has interval setting that is not NaN
  2346. backgroundCrossfadeInterval = parseInt(localStorage.getItem("ao/desktop/backgroundInterval")) * 1000;
  2347. }
  2348. backgroundIntervalCounter = setInterval(function() {
  2349. $("body").css("background-image", "none").css({
  2350. 'background-color': '#000000'
  2351. });
  2352. $(".showBackground").removeClass("showBackground");
  2353. $($(".backgroundFrame")[nextSlideshowIndex]).addClass("showBackground");
  2354. nextSlideshowIndex++;
  2355. if (nextSlideshowIndex > currentBackgroundList.length - 1) {
  2356. nextSlideshowIndex = 0;
  2357. }
  2358. }, backgroundCrossfadeInterval);
  2359. }
  2360. //Function for changing the desktop theme
  2361. function changeDesktopTheme(targetThemeName) {
  2362. currentUserTheme = targetThemeName;
  2363. if (currentUserTheme.includes(":/") == false){
  2364. //This is default theme pack name
  2365. for (var i = 0; i < desktopThemeList.length; i++) {
  2366. var thisTheme = desktopThemeList[i];
  2367. if (thisTheme["Theme"] == targetThemeName) {
  2368. //Use this config as the target theme
  2369. currentBackgroundList = thisTheme["Bglist"];
  2370. break;
  2371. }
  2372. }
  2373. //Initiate the background image.
  2374. $("#bgwrapper").html("");
  2375. for (var i = 0; i < currentBackgroundList.length; i++) {
  2376. var id = "dbg" + i;
  2377. var thisImage = "img/desktop/bg/" + currentUserTheme + "/" + currentBackgroundList[i];
  2378. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" onclick="this.focus();" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2379. }
  2380. setTimeout(function() {
  2381. $("#dbg0").addClass("showBackground");
  2382. }, 300);
  2383. if (currentBackgroundList.length == 1) {
  2384. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2385. nextSlideshowIndex = 0;
  2386. }else if (currentBackgroundList.length == 0){
  2387. //Background no longer exists. Change to default
  2388. changeDesktopTheme("default");
  2389. } else {
  2390. nextSlideshowIndex = 1;
  2391. }
  2392. }else{
  2393. //This is user defined photo file
  2394. $.get("system/desktop/theme?load=" + targetThemeName, function(data){
  2395. if (data.error !== undefined){
  2396. //The folder is gone. Use default instead
  2397. console.log(data.error);
  2398. changeDesktopTheme("default");
  2399. }else{
  2400. //OK! Load it
  2401. currentBackgroundList = data;
  2402. $("#bgwrapper").html("");
  2403. for (var i = 0; i < currentBackgroundList.length; i++) {
  2404. var id = "dbg" + i;
  2405. var thisImage = "media/?file=" + currentBackgroundList[i];
  2406. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2407. }
  2408. setTimeout(function() {
  2409. $("#dbg0").addClass("showBackground");
  2410. }, 300);
  2411. if (currentBackgroundList.length == 1) {
  2412. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2413. nextSlideshowIndex = 0;
  2414. }else if (currentBackgroundList.length == 0){
  2415. //Background no longer exists. Change to default
  2416. changeDesktopTheme("default");
  2417. } else {
  2418. nextSlideshowIndex = 1;
  2419. }
  2420. }
  2421. });
  2422. }
  2423. }
  2424. $("#bgwrapper").on("click", function(evt) {
  2425. evt.preventDefault();
  2426. });
  2427. //================== DESKTOP FILE LOCATION FUNCTIONS ====================
  2428. function initDesktopFiles(optionObject = {}, callback = undefined) {
  2429. $.get("system/desktop/listDesktop", function(data) {
  2430. //Prase optionObject
  2431. var noflash = false;
  2432. if (typeof optionObject.noflash !== "undefined"){
  2433. noflash = optionObject.noflash;
  2434. }
  2435. if (noflash){
  2436. //Only clean out those object that not exists in the new filelist
  2437. var existsingFilepaths = [];
  2438. if (data != null){
  2439. for (var i =0; i < data.length; i++){
  2440. existsingFilepaths.push(data[i].Filepath);
  2441. }
  2442. }else{
  2443. //Nothing on desktop
  2444. }
  2445. //console.log(existsingFilepaths);
  2446. //If the launchIcon path is not in the latest list, remove it from desktop
  2447. $(".launchIcon").each(function(){
  2448. if (existsingFilepaths.includes($(this).attr("filepath")) == false){
  2449. $(this).remove();
  2450. }
  2451. });
  2452. }else{
  2453. //Cleanup all previous icons
  2454. $("#iconwrapper").children().each(function(){
  2455. if ($(this).hasClass("launchIcon") && $(this).attr("type") == "dummy"){
  2456. //Special kind of launchIcon. Skip this
  2457. return;
  2458. }
  2459. $(this).remove();
  2460. });
  2461. }
  2462. //Allocate new items location
  2463. var iheight = 106;
  2464. var iwidth = 70;
  2465. var padding = 16;
  2466. if (desktopIconSize == "small") {
  2467. iheight = 82;
  2468. iwidth = 50;
  2469. } else if (desktopIconSize == "medium") {
  2470. iheight = 106;
  2471. iwidth = 70;
  2472. } else if (desktopIconSize == "big") {
  2473. iheight = 124;
  2474. iwidth = 84;
  2475. }
  2476. iconSize = [iwidth, iheight];
  2477. var screenHeight = window.innerHeight;
  2478. var screenWidth = window.innerWidth;
  2479. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2480. var hc = Math.floor((screenWidth - padding) / iwidth);
  2481. var slots = []; //A 2D array for storing relative to absolute locations
  2482. for (var j = 0; j < hc; j++) {
  2483. var thisLocationList = [];
  2484. for (var i = 0; i < vc; i++) {
  2485. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2486. thisLocationList.push(thisLocation);
  2487. }
  2488. slots.push(thisLocationList);
  2489. }
  2490. //Store the root position (0,0) in rootPosition
  2491. let rootPosition = JSON.parse(JSON.stringify(slots[0][0]));
  2492. desktopGrids = JSON.parse(JSON.stringify(slots));
  2493. //Assign items to desktop
  2494. var unallocatedFiles = [];
  2495. let remainingSlots = JSON.parse(JSON.stringify(slots));
  2496. desktopFileList = [];
  2497. if (data === null){
  2498. //No files on desktop
  2499. return;
  2500. }
  2501. for (var i = 0; i < data.length; i++) {
  2502. var thisFile = data[i];
  2503. desktopFileList.push(JSON.parse(JSON.stringify(thisFile.Filename)));
  2504. //Get icon from the icon list
  2505. var location = [thisFile.IconX, thisFile.IconY];
  2506. if (location[0] == -1 && location[1] == -1) {
  2507. //This file is not located. Push it into unallocatedFileList
  2508. unallocatedFiles.push(thisFile);
  2509. } else if (location[0] >= slots.length || location[1] >= slots[0].length) {
  2510. //This file is outside of the screen area. Set to be be unallocatedFiles as well
  2511. unallocatedFiles.push(thisFile);
  2512. } else {
  2513. //This file is already located. Push it location into occupiedSlots
  2514. //var screenX = location[0] * iwidth + padding/2;
  2515. //var screenY = location[1] * iheight + padding/2;
  2516. var screenLocation = slots[location[0]][location[1]];
  2517. //Remove this object from remaining slots
  2518. remainingSlots[location[0]][location[1]] = undefined;
  2519. //console.log(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth);
  2520. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2521. }
  2522. }
  2523. //Foreach remaining files, assign a location for it.
  2524. var walk = [slots.length, slots[0].length];
  2525. var current = [0, 0];
  2526. for (var i = 0; i < unallocatedFiles.length; i++) {
  2527. var thisFile = unallocatedFiles[i];
  2528. try{
  2529. while (typeof(remainingSlots[current[0]][current[1]]) == "undefined") {
  2530. //This slot is not usabled. Next slot.
  2531. current[1] += 1;
  2532. if (current[1] >= walk[1]) {
  2533. current[1] = 0;
  2534. current[0] += 1;
  2535. }
  2536. if (typeof(remainingSlots[current[0]]) == "undefined"){
  2537. //Not enough space to fit the item. Move it to 0 0 instead
  2538. current = [-1,-1];
  2539. console.log(current);
  2540. break;
  2541. }
  2542. }
  2543. }catch{
  2544. //Something went wrong while assigning positions. Set at root location
  2545. current = [-1,-1];
  2546. }
  2547. //Append the icon to screen
  2548. if (current[0] == -1 && current[1] == -1){
  2549. //Screen overflow. Stack the file at (0,0)
  2550. screenLocation = [rootPosition[0], rootPosition[1]];
  2551. console.log(screenLocation);
  2552. }else{
  2553. screenLocation = remainingSlots[current[0]][current[1]];
  2554. remainingSlots[current[0]][current[1]] = undefined;
  2555. }
  2556. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2557. //Save the icon location to server
  2558. $.ajax({
  2559. url: "system/desktop/files",
  2560. method: "POST",
  2561. data: {"set": thisFile.Filename, "x": current[0], "y": current[1]},
  2562. success: function(data) {
  2563. if (data.error !== undefined) {
  2564. console.log(data.error);
  2565. }
  2566. }
  2567. });
  2568. }
  2569. //Update the desktop hash to prevent the auto refresh by hash
  2570. getDesktopHash(function(hash){
  2571. desktopFileHash = hash;
  2572. });
  2573. if (callback !== undefined) {
  2574. //console.log(callback);
  2575. callback();
  2576. }
  2577. });
  2578. }
  2579. //Handle desktop file multi selection and dragging
  2580. $("#bgwrapper").on("mousedown", function(evt) {
  2581. initMultiSelection(evt);
  2582. });
  2583. $("#bgwrapper").on("touchstart", function(evt) {
  2584. initMultiSelection(evt);
  2585. });
  2586. $("body").on("mouseup", function(evt) {
  2587. mainWindowMouseup(evt);
  2588. });
  2589. $("body").on("touchend", function(evt) {
  2590. mainWindowMouseup(evt);
  2591. });
  2592. $("#selectionPanel").on("mouseup", function(event) {
  2593. });
  2594. function mainWindowMouseup(event) {
  2595. if (event.pageX == multiSelectionStartPoint[0] && event.pageY == multiSelectionStartPoint[1]) {
  2596. //Pressdown and up at the same location
  2597. $(".launchIconWrapper.selected").removeClass("selected");
  2598. endMultiSelection(event);
  2599. } else {
  2600. //Press down and up at different location
  2601. endMultiSelection(event);
  2602. }
  2603. if (resizingWindow){
  2604. //Resizing floatWindow out of the window bound (aka someone don't know how to resize a window correctly)
  2605. resizingWindow = false;
  2606. resizingEdgeID = 0;
  2607. $("#fwdragpanel").hide();
  2608. $("#tfwdragpanel").hide();
  2609. $('.floatWindow.topmost').css("pointer-events", "auto");
  2610. $('.floatWindow.topmost').css("opacity", 1);
  2611. $(resizingWindowTarget).find(".iframecover").hide();
  2612. $(resizingWindowTarget).find(".iframewrapper").css('cursor', '');
  2613. }
  2614. }
  2615. function initMultiSelection(event) {
  2616. event.preventDefault();
  2617. multiSelecting = true;
  2618. hideAllContextMenus();
  2619. $("#selectionPanel").css({
  2620. left: event.pageX,
  2621. top: event.pageY,
  2622. width: 0,
  2623. height: 0
  2624. });
  2625. $("#selectionPanel").show();
  2626. multiSelectionStartPoint = [event.pageX, event.pageY];
  2627. }
  2628. function movingMultiSelectionArea(event) {
  2629. event.preventDefault();
  2630. var sx = multiSelectionStartPoint[0];
  2631. var sy = multiSelectionStartPoint[1];
  2632. var ex = event.pageX;
  2633. var ey = event.pageY;
  2634. var newleft = sx;
  2635. if (ex < sx) {
  2636. newleft = ex;
  2637. }
  2638. var newtop = sy;
  2639. if (ey < sy) {
  2640. newtop = ey;
  2641. }
  2642. var newWidth = Math.abs(sx - ex);
  2643. var newHeight = Math.abs(sy - ey);
  2644. $("#selectionPanel").css({
  2645. left: newleft,
  2646. top: newtop,
  2647. width: newWidth,
  2648. height: newHeight
  2649. });
  2650. //Select all the launch icon selected
  2651. selectAllLaunchIconInRange(newleft, newleft + newWidth, newtop, newtop + newHeight);
  2652. }
  2653. function endMultiSelection(event) {
  2654. event.preventDefault();
  2655. multiSelecting = false;
  2656. multiSelectionStartPoint = [-1, -1];
  2657. $("#selectionPanel").hide();
  2658. }
  2659. function selectAllLaunchIconInRange(minX, maxX, minY, maxY) {
  2660. //Select launch icons from its center point
  2661. var xOffset = iconSize[0] / 2;
  2662. var yOffset = iconSize[1] / 2;
  2663. $(".launchIconWrapper.selected").removeClass("selected");
  2664. $(".launchIcon").each(function() {
  2665. //Calculate center point for this icon
  2666. var thisX = $(this).offset().left + xOffset;
  2667. var thisY = $(this).offset().top + yOffset;
  2668. if (thisX > minX && thisX < maxX) {
  2669. if (thisY > minY && thisY < maxY) {
  2670. $(this).find(".launchIconWrapper").addClass("selected");
  2671. }
  2672. }
  2673. });
  2674. }
  2675. function redrawDesktopGrids() {
  2676. var iheight = 106;
  2677. var iwidth = 70;
  2678. var padding = 16;
  2679. if (desktopIconSize == "small") {
  2680. iheight = 82;
  2681. iwidth = 50;
  2682. } else if (desktopIconSize == "medium") {
  2683. iheight = 106;
  2684. iwidth = 70;
  2685. } else if (desktopIconSize == "big") {
  2686. iheight = 124;
  2687. iwidth = 84;
  2688. }
  2689. iconSize = [iwidth, iheight];
  2690. var screenHeight = window.innerHeight;
  2691. var screenWidth = window.innerWidth;
  2692. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2693. var hc = Math.floor((screenWidth - padding) / iwidth);
  2694. var slots = []; //A 2D array for storing relative to absolute locations
  2695. for (var j = 0; j < hc; j++) {
  2696. var thisLocationList = [];
  2697. for (var i = 0; i < vc; i++) {
  2698. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2699. thisLocationList.push(thisLocation);
  2700. }
  2701. slots.push(thisLocationList);
  2702. }
  2703. desktopGrids = JSON.parse(JSON.stringify(slots));
  2704. }
  2705. function getTextPixelWidth(measureText){
  2706. let canvas = document.getElementById('textWidthCanvas');
  2707. let ctx = canvas.getContext('2d');
  2708. let text = ctx.measureText(measureText);
  2709. let estimatedFilenameSize = text.width;
  2710. if (desktopIconSize == "small"){
  2711. estimatedFilenameSize = estimatedFilenameSize * 0.8679245283018868;
  2712. }else if (desktopIconSize == "big"){
  2713. estimatedFilenameSize = estimatedFilenameSize * 1.509433962264151;
  2714. }else{
  2715. estimatedFilenameSize = estimatedFilenameSize * 1.2452830188679245;
  2716. }
  2717. return estimatedFilenameSize;
  2718. }
  2719. function appendIconAtLocation(filedata, screenX, screenY, iheight, iwidth, updateMode=false) {
  2720. //Get the icon from extension
  2721. var icon = ao_module_utils.getIconFromExt(filedata.Ext.substring(1, filedata.Ext.length));
  2722. var imagePath = "img/desktop/files_icon/" + desktopIconPack + "/" + icon + ".png";
  2723. //Handle special icon types here
  2724. var size = desktopIconSize;
  2725. var filename = JSON.parse(JSON.stringify(filedata.Filename));
  2726. var filepath = JSON.parse(JSON.stringify(filedata.Filepath));
  2727. var isDir = JSON.parse(JSON.stringify(filedata.IsDir));
  2728. var isEmptyDir = JSON.parse(JSON.stringify(filedata.IsEmptyDir));
  2729. var isShared = JSON.parse(JSON.stringify(filedata.IsShared));
  2730. var maxlength = 12;
  2731. var type = "file";
  2732. let shortenedName = filename;
  2733. screenX += iconOffsetXY[0];
  2734. screenY += iconOffsetXY[1];
  2735. if (isDir) {
  2736. //Folder objects
  2737. icon = "folder outline";
  2738. if (isEmptyDir){
  2739. imagePath = "img/desktop/system_icon/folder.png";
  2740. }else{
  2741. imagePath = "img/desktop/system_icon/folder-with-content.png";
  2742. }
  2743. type = "folder";
  2744. } else if (isDir == false && icon == "folder outline") {
  2745. icon = "file outline";
  2746. imagePath = "img/desktop/files_icon/" + desktopIconPack + "/file outline.png";
  2747. type = "file";
  2748. } else if (filedata.Ext == ".exe" || filedata.Ext == ".elf") {
  2749. //Executable objects
  2750. imagePath = "img/desktop/system_icon/script.png";
  2751. type = "executable";
  2752. } else if (filedata.Ext == ".shortcut") {
  2753. //Shortcut
  2754. var shortcutImage = filedata.ShortcutImage;
  2755. shortenedName = JSON.parse(JSON.stringify(filedata.ShortcutName));
  2756. imagePath = shortcutImage;
  2757. type = "shortcut";
  2758. }
  2759. //Check if it is under small text mode
  2760. if (size == "small"){
  2761. maxlength = 46;
  2762. }else if (size == "big"){
  2763. maxlength = 80;
  2764. }else{
  2765. maxlength = 66;
  2766. }
  2767. var estimatedFilenameSize = 0;
  2768. if (type == "shortcut"){
  2769. estimatedFilenameSize = getTextPixelWidth(shortenedName);
  2770. }else{
  2771. estimatedFilenameSize = getTextPixelWidth(filename);
  2772. shortenedName = filename;
  2773. if (estimatedFilenameSize > (maxlength * 2 - 10)) {
  2774. //This name is too long to fit inside two lines
  2775. var newFilenameLength = getTextPixelWidth(shortenedName + "...");
  2776. while (newFilenameLength >= (maxlength * 2 - 10)){
  2777. shortenedName = shortenedName.substr(0, shortenedName.length - 1);
  2778. newFilenameLength = getTextPixelWidth(shortenedName + "...");
  2779. }
  2780. shortenedName = shortenedName + "...";
  2781. }
  2782. }
  2783. if (estimatedFilenameSize < (maxlength * 2 - 10) && estimatedFilenameSize > (maxlength - 5) && shortenedName.indexOf(" ") > 0){
  2784. //This is short enough to fit inside two lines and it contains space
  2785. //Try to see if there is a combination of splitting that fit inside two lines
  2786. var filenameSegments = shortenedName.split(" ");
  2787. var segEnd = 1;
  2788. var currentSegmentText = filenameSegments[0];
  2789. var currentSegmentWidth = getTextPixelWidth(currentSegmentText);
  2790. var spaceWidth = getTextPixelWidth(" ");
  2791. while(segEnd < filenameSegments.length && (currentSegmentWidth + spaceWidth) < (maxlength - 5)){
  2792. //When it is not the last segment && can still fit more segment into current line
  2793. currentSegmentText = currentSegmentText + " " + filenameSegments[segEnd];
  2794. currentSegmentWidth = getTextPixelWidth(currentSegmentText);
  2795. segEnd++;
  2796. }
  2797. //Back trace one segment
  2798. segEnd--;
  2799. //Build the filename segmentation
  2800. var line1 = "";
  2801. var line2 = "";
  2802. for (var i = 0; i < segEnd; i++){
  2803. line1 += filenameSegments[i] + " ";
  2804. }
  2805. for (var i = segEnd; i < filenameSegments.length; i++){
  2806. line2 += filenameSegments[i] + " ";
  2807. }
  2808. line1 = line1.trim();
  2809. line2 = line2.trim();
  2810. if (line1 != "" && line1 != ""){
  2811. shortenedName = line1 + `<br>` + line2;
  2812. }else if (line1 == ""){
  2813. shortenedName = line2;
  2814. }else if (line2 == ""){
  2815. shortenedName = line1;
  2816. }
  2817. }
  2818. var compressedFiledata = ao_module_utils.objectToAttr(filedata);
  2819. if (updateMode){
  2820. //Update the content that already exists for the same filepath object
  2821. var updateObject = undefined;
  2822. $(".launchIcon").each(function(){
  2823. if ($(this).attr("filedata") == compressedFiledata){
  2824. updateObject = $(this);
  2825. }
  2826. });
  2827. if (updateObject !== undefined){
  2828. //Check if content identical. If yes, skip rewrite
  2829. if (updateObject.attr("filedata") == compressedFiledata){
  2830. //Identical. Skipping
  2831. }else{
  2832. //Update its contents
  2833. updateObject.attr("type", type);
  2834. updateObject.attr("filename", filename);
  2835. updateObject.attr("filepath", filepath);
  2836. updateObject.attr("filedata", compressedFiledata);
  2837. updateObject.css("width", iwidth + "px");
  2838. updateObject.css("height", iheight + "px");
  2839. updateObject.css("left", screenX + "px");
  2840. updateObject.css("top", screenY + "px");
  2841. }
  2842. }else{
  2843. //No exists. Append to wrapper
  2844. appendDesktopIcon($("#iconwrapper"),{
  2845. type: type,
  2846. filename: filename,
  2847. filepath: filepath,
  2848. compressedFiledata: compressedFiledata,
  2849. iwidth: iwidth,
  2850. iheight: iheight,
  2851. screenX: screenX,
  2852. screenY: screenY,
  2853. size: size,
  2854. imagePath: imagePath,
  2855. shortenedName: shortenedName,
  2856. isShared: isShared,
  2857. });
  2858. }
  2859. }else{
  2860. //Append into the desktop
  2861. appendDesktopIcon($("#iconwrapper"),{
  2862. type: type,
  2863. filename: filename,
  2864. filepath: filepath,
  2865. compressedFiledata: compressedFiledata,
  2866. iwidth: iwidth,
  2867. iheight: iheight,
  2868. screenX: screenX,
  2869. screenY: screenY,
  2870. size: size,
  2871. imagePath: imagePath,
  2872. shortenedName: shortenedName,
  2873. isShared: isShared,
  2874. });
  2875. }
  2876. }
  2877. /*
  2878. Main function to append desktop icon to desktop
  2879. Usage: Pass in the target (as jquery object, usually $("#iconwrapper")) and properties with the following object
  2880. properties = {
  2881. type: "",
  2882. filename: "",
  2883. filepath: "",
  2884. compressedFiledata: "",
  2885. iwidth: "",
  2886. iheight: "",
  2887. screenX: "",
  2888. screenY: "",
  2889. size: "",
  2890. imagePath: "",
  2891. shortenedName: "",
  2892. }
  2893. Where the enmty string is the value that require filling in
  2894. */
  2895. function appendDesktopIcon(target, properties){
  2896. var htmlType = "div";
  2897. if (properties.type == "file" && isChrome){
  2898. htmlType = "a";
  2899. }
  2900. var imageStyleOverride = "";
  2901. //Special type of override for files
  2902. if (properties.type == "shortcut"){
  2903. var fd = JSON.parse(decodeURIComponent(properties.compressedFiledata));
  2904. if (fd.ShortcutType == "url"){
  2905. imageStyleOverride = `padding: 8px;`;
  2906. }
  2907. }
  2908. var thisIcon = $(`<${htmlType} href="javascript:void(0);" class="launchIcon"
  2909. type="${properties.type}"
  2910. draggable="true"
  2911. ondragover="allowDrop(event)"
  2912. ondrop="drop(event)"
  2913. ondragstart="drag(event)"
  2914. onmousedown="iconClicked(this,event);"
  2915. ondblclick="iconDoubleClicked(this,event);"
  2916. ontouchstart="iconClicked(this,event); doubleTouchHandler(this, event,openViaTouch);"
  2917. filename="${properties.filename}"
  2918. filepath="${properties.filepath}"
  2919. filedata="${properties.compressedFiledata}"
  2920. style="width:${properties.iwidth}px; height:${properties.iheight}px;left:${properties.screenX}px; top:${properties.screenY}px;">
  2921. <span class="launchIconWrapper">
  2922. <img class="launchIconImage ${properties.size}" src="${properties.imagePath}" style="${imageStyleOverride}" draggable="false"></img>
  2923. <p class="launchIconText ${properties.size}">${properties.shortenedName}</p>
  2924. </span>
  2925. </${htmlType}>`);
  2926. $(target).append(thisIcon);
  2927. //Updates 20 May 2021: Check if this file is shared. If yes, append the share icon
  2928. if (typeof(properties.isShared) != "undefined" && properties.isShared == true){
  2929. setFileShareIndicator(properties.filename);
  2930. }
  2931. if (properties.type == "file" && isChrome){
  2932. console.log(isChrome);
  2933. let thisFilepath = properties.filepath;
  2934. $(thisIcon)[0].addEventListener("dragstart",function(evt){
  2935. //var filecontent = toDataUrl("media/?file=" + thisFilepath);
  2936. //var fileBase64 = window.btoa(filecontent);
  2937. var targetMime = "plain/text";
  2938. $.ajax({
  2939. url: "media/getMime/?file=" + encodeURIComponent(properties.filepath),
  2940. success: function(data){
  2941. if (data.error !== undefined){
  2942. targetMime = "text/directory";
  2943. }else{
  2944. targetMime = data;
  2945. }
  2946. },
  2947. async: false
  2948. });
  2949. evt.dataTransfer.setData("DownloadURL",targetMime+":"+ properties.filename +":"+ location.protocol + "//" + location.hostname + ":" + location.port + "/media/?file=" + encodeURIComponent(properties.filepath));
  2950. //evt.dataTransfer.setData("DownloadURL","video/mp4"+":"+"test.mp4"+":"+"data:"+"video/mp4"+";base64,"+fileBase64);
  2951. },false);
  2952. }
  2953. }
  2954. //Folder description box
  2955. var timeoutId;
  2956. function attachDescriptionBoxEvents(){
  2957. $(".launchIcon").off("hover").hover(function(event) {
  2958. let modulePath = $(this).attr("filepath");
  2959. let filename = $(this).attr("filename");
  2960. let filedata = JSON.parse( decodeURIComponent($(this).attr("filedata")));
  2961. if (!timeoutId) {
  2962. if (renameMode == true){
  2963. //Renaming. Do not show hover info tab
  2964. return;
  2965. }
  2966. timeoutId = window.setTimeout(function() {
  2967. let position = [currentMousePosition[0] + 10, currentMousePosition[1] + 10];
  2968. timeoutId = null;
  2969. console.log(filedata, position);
  2970. $('#fileDescriptor').css('left',position[0] + "px");
  2971. $('#fileDescriptor').css('top',position[1] + "px");
  2972. if (filedata.IsShortcut){
  2973. $('#fileDescriptor').html(`<p><i class="linkify icon"></i> ${filedata.ShortcutName}<br><i class="folder icon"></i> ${filedata.ShortcutPath}</p>`);
  2974. $('#fileDescriptor').show();
  2975. }else{
  2976. $.ajax({
  2977. url: "system/file_system/getProperties",
  2978. data: {path: filedata.Filepath},
  2979. success: function(data){
  2980. $('#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>`);
  2981. if (!(data.MimeType == undefined)){
  2982. $('#fileDescriptor').show();
  2983. }
  2984. }
  2985. })
  2986. }
  2987. }, 1500);
  2988. }
  2989. },
  2990. function () {
  2991. if (timeoutId) {
  2992. window.clearTimeout(timeoutId);
  2993. timeoutId = null;
  2994. }else {
  2995. $('#fileDescriptor').hide();
  2996. }
  2997. });
  2998. }
  2999. /*
  3000. Share indicator settings
  3001. This append or remove share from a particular file
  3002. Only require filename as all files here are on desktop
  3003. */
  3004. function getFileObjectByFilename(filename){
  3005. var result = null;
  3006. $(".launchIcon").each(function(){
  3007. var thisFilename = $(this).attr("filename");
  3008. if (thisFilename == filename){
  3009. result = $(this);
  3010. }
  3011. });
  3012. return result;
  3013. }
  3014. function setFileShareIndicator(filename){
  3015. var targetFileObject = getFileObjectByFilename(filename);
  3016. if (targetFileObject == null){
  3017. return;
  3018. }
  3019. var sharedIcon = `<div class="fileShareIndicator ${desktopIconSize}">
  3020. <img src="img/desktop/system_icon/shared.png">
  3021. </div>`;
  3022. $(targetFileObject).find(".launchIconWrapper").append(sharedIcon);
  3023. }
  3024. function removeFileShareIndicator(filename){
  3025. var targetFileObject = getFileObjectByFilename(filename);
  3026. if (targetFileObject == null){
  3027. return;
  3028. }
  3029. var indicator = $(targetFileObject).find(".fileShareIndicator");
  3030. if (indicator.length > 0){
  3031. indicator.remove();
  3032. }
  3033. }
  3034. // ========================== LAUNCH ICON OPERATIONS ================
  3035. //This function start all the launchicon related events
  3036. function drag(ev) {
  3037. //If rename mode, disable drag drop
  3038. if (renameMode){
  3039. return false;
  3040. }
  3041. var target = ev.target;
  3042. if (!($(ev.target).is("div") || $(ev.target).is("a"))) {
  3043. target = $(target).parent();
  3044. }
  3045. //Parse the standard filename / filepath data
  3046. var filename = $(target).attr("filename");
  3047. var filepath = $(target).attr('filepath');
  3048. ev.dataTransfer.setData("filename", filename);
  3049. ev.dataTransfer.setData("filepath", filepath);
  3050. //Parse multifile selection filedata
  3051. var filelist = [];
  3052. if ($(".launchIconWrapper.selected").length > 0){
  3053. if (ctrlHold || $(".launchIconWrapper.selected").length > 1){
  3054. //Include all objects selected
  3055. $(".launchIconWrapper.selected").each(function(){
  3056. var fd = $(this).parent().attr("filedata");
  3057. fd = JSON.parse(decodeURIComponent(fd));
  3058. filelist.push({
  3059. filename: fd.Filename,
  3060. filepath: fd.Filepath,
  3061. hostUUID: hostInfo.DeviceUUID
  3062. });
  3063. });
  3064. }else{
  3065. //Only push the one selected
  3066. filelist.push({
  3067. filename: filename,
  3068. filepath: filepath,
  3069. hostUUID: hostInfo.DeviceUUID
  3070. });
  3071. }
  3072. }else{
  3073. //There is no selected item on desktop. Use the drag drop one
  3074. filelist.push({
  3075. filename: filename,
  3076. filepath: filepath
  3077. });
  3078. }
  3079. //console.log(filelist);
  3080. ev.dataTransfer.setData("filedata", JSON.stringify(filelist));
  3081. console.log(filelist);
  3082. //Set a flag on the drag events that these files are from Desktop GUI
  3083. ev.dataTransfer.setData("desktopflag", "true");
  3084. //Record the start drop relative position of the icon object
  3085. var dx = ev.pageX - $(target).offset().left;
  3086. var dy = ev.pageY - $(target).offset().top;
  3087. startDragRelatuve = [dx, dy];
  3088. ev.stopPropagation();
  3089. }
  3090. function drop(ev) {
  3091. ev.preventDefault();
  3092. ev.stopImmediatePropagation();
  3093. var target = $(ev.target);
  3094. if (!(target.is("div") || target.is("a"))) {
  3095. target = $(target).parent();
  3096. }
  3097. if (target.hasClass("launchIconWrapper")) {
  3098. target = target.parent();
  3099. }
  3100. var thisFilepath = $(target).attr("filepath");
  3101. if (thisFilepath == ev.dataTransfer.getData("filepath")) {
  3102. //Drag and drop on the same item. Ignore it
  3103. return;
  3104. }
  3105. var sourceFilename = ev.dataTransfer.getData("filename");
  3106. var sourceFilepath = ev.dataTransfer.getData("filepath");
  3107. //To handle multiple file transfer from file explorer
  3108. var sourceFilelist = ev.dataTransfer.getData("filedata");
  3109. console.log(target)
  3110. console.log(sourceFilename);
  3111. console.log(sourceFilepath);
  3112. if (sourceFilelist !== ""){
  3113. sourceFilelist = JSON.parse(sourceFilelist);
  3114. }
  3115. //Drop opererations
  3116. if (target.attr("id") == "bgwrapper") {
  3117. if (sourceFilename == "" && sourceFilepath == "" && ev.dataTransfer.files.length > 0){
  3118. //Drag drop from external source. Upload to desktop
  3119. //Assign the locations for the objects
  3120. var files = ev.dataTransfer.files;
  3121. var gridMaxX = desktopGrids.length;
  3122. var gridMaxY = desktopGrids[0].length;
  3123. var targetLocation = findClosestGrid((ev.clientX), (ev.clientY), false);
  3124. var targetGridLocation = targetLocation[1];
  3125. var locations = [];
  3126. //Rewrite of the upload file target location, 2022-02-02
  3127. //Back step the y location of drag point by 1
  3128. targetGridLocation[1] = targetGridLocation[1] - 1;
  3129. var nextLocation = JSON.parse(JSON.stringify(targetGridLocation));
  3130. for (var k =0; k < files.length; k++){
  3131. //Add 1 to the file y position
  3132. nextLocation[1] += 1;
  3133. if (nextLocation[1] >= gridMaxY){
  3134. //If y overflow, move to next x lane
  3135. nextLocation[0] += 1;
  3136. nextLocation[1] = 0;
  3137. }
  3138. if (nextLocation[0] >= desktopGrids.length){
  3139. //Desktop full. Force put to 0 0
  3140. nextLocation[0] = 0;
  3141. nextLocation[1] = 0;
  3142. locations.push(JSON.parse(JSON.stringify(nextLocation)));
  3143. continue;
  3144. }
  3145. //Check if this position is occupied, update next placement location if true
  3146. console.log("Grid Location:", nextLocation[0], nextLocation[1]);
  3147. while (getObjectFromGridLocation(nextLocation[0], nextLocation[1]) !== undefined){
  3148. let gridLocation = getLocationFromGridIndex(nextLocation[0], nextLocation[1]);
  3149. let newAssignmentLocation = findClostestEmptyGridLocation(gridLocation[0],gridLocation[1]);
  3150. nextLocation = newAssignmentLocation[1];
  3151. console.log("Not empty. Updating")
  3152. }
  3153. locations.push(JSON.parse(JSON.stringify(nextLocation)));
  3154. }
  3155. /*
  3156. for (var k =0; k < files.length; k++){
  3157. var thisLocation = JSON.parse(JSON.stringify(targetGridLocation));
  3158. //Add k to y axis of the list.
  3159. thisLocation[1] += k;
  3160. if (thisLocation[1] >= gridMaxY){
  3161. thisLocation[0]++;
  3162. thisLocation[1] = thisLocation[1] % gridMaxY;
  3163. }
  3164. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3165. //Desktop full. Force put to 0 0
  3166. thisLocation[0] = 0;
  3167. thisLocation[1] = 0;
  3168. break;
  3169. }
  3170. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  3171. thisLocation[1] += 1;
  3172. if (thisLocation[1] >= gridMaxY){
  3173. //Over the screen. Shift to the row on the right
  3174. thisLocation[0]++;
  3175. thisLocation[1] = 0;
  3176. }
  3177. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3178. //Desktop full. Force put to 0 0
  3179. thisLocation[0] = 0;
  3180. thisLocation[1] = 0;
  3181. break;
  3182. }
  3183. }
  3184. locations.push(thisLocation)
  3185. }
  3186. */
  3187. console.log(locations, ev.dataTransfer.files);
  3188. //Register file locations
  3189. for (var j =0; j < locations.length; j++){
  3190. let thisFile = files[j];
  3191. let thisFilename = files[j].name;
  3192. let x = parseInt(locations[j][0]);
  3193. let y = parseInt(locations[j][1]);
  3194. let uploadIconUUID = generateUploadingIcon(thisFile.name, [x,y]);
  3195. var refreshTimer;
  3196. uploadFile(thisFile,function(){
  3197. console.log("Uploader callback");
  3198. $.ajax({
  3199. url: "system/desktop/files",
  3200. method: "POST",
  3201. data: {"set": thisFilename, "x": x, "y": y},
  3202. success: function(data) {
  3203. //Refresh the desktop
  3204. clearTimeout(refreshTimer);
  3205. refreshTimer = setTimeout(function(){
  3206. refresh(undefined, false);
  3207. }, 500)
  3208. }
  3209. });
  3210. }, uploadIconUUID);
  3211. }
  3212. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  3213. //Drag drop multiple files from desktop or file explorer to desktop
  3214. var desktopFlag = ev.dataTransfer.getData("desktopflag");
  3215. if (desktopFlag == "" || desktopFlag === undefined || desktopFlag == null){
  3216. //This is a file drag drop from not desktop to desktop
  3217. var filelist = ev.dataTransfer.getData("filedata");
  3218. if (filelist != ""){
  3219. filelist = JSON.parse(filelist);
  3220. if (filelist.length == 0){
  3221. return
  3222. }
  3223. //Get the position for this drop events and arrange grid locations
  3224. var gridPosition = gridPositionAllocate(ev.clientX, ev.clientY, filelist.length);
  3225. console.log(gridPosition)
  3226. //Check if source is also from user:/
  3227. var srcVroot = filelist[0].filepath.split(":/").shift();
  3228. var mode = "copy"
  3229. var title = "Copying "
  3230. if (srcVroot == "user"){
  3231. //Move
  3232. mode = "move"
  3233. title = "Moving "
  3234. }
  3235. var filepathList = [];
  3236. filelist.forEach(file => {
  3237. filepathList.push(file.filepath)
  3238. });
  3239. //Start the file operation dialog
  3240. var oprConfig = {
  3241. opr: mode,
  3242. src: filepathList,
  3243. dest: "user:/Desktop/",
  3244. overwriteMode: "ask"
  3245. }
  3246. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  3247. //Genreate window title
  3248. title = title + filepathList.length;
  3249. if (filepathList.length > 1){
  3250. title += " files";
  3251. }else{
  3252. title += " file";
  3253. }
  3254. newFloatWindow({
  3255. url: "SystemAO/file_system/file_operation.html#" + configHash,
  3256. width: 400,
  3257. height: 220,
  3258. appicon: "SystemAO/file_system/img/selector.png",
  3259. title: title
  3260. });
  3261. }
  3262. }else{
  3263. //This is a file drag event from desktop, but more than one files.
  3264. //Pin the final location for the drag drop object
  3265. var sourceObject = getObjectFromPath(sourceFilepath);
  3266. var dx = startDragRelatuve[0];
  3267. var dy = startDragRelatuve[1];
  3268. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  3269. var closestLocation = targetLocation[0];
  3270. var duplicateObject = getObjectFromLocation(closestLocation[0] + iconOffsetXY[0], closestLocation[1] + iconOffsetXY[1]);
  3271. if (duplicateObject !== undefined) {
  3272. //There are already object there. Do nothing
  3273. console.log("Drop location duplicated!")
  3274. return;
  3275. }
  3276. //Get other objects that is not the one drag dropped
  3277. var iconOffset = {};
  3278. for (var i =0; i < sourceFilelist.length; i++){
  3279. var thisFile = sourceFilelist[i];
  3280. if (thisFile.filepath != sourceFilepath){
  3281. //Calculate the x y offset of this icon to the drag drop one
  3282. var thisIconObject = getObjectFromPath(thisFile.filepath);
  3283. iconOffset[thisFile.filepath] = {
  3284. dx: $(sourceObject).offset().left - $(thisIconObject).offset().left,
  3285. dy: $(sourceObject).offset().top - $(thisIconObject).offset().top
  3286. }
  3287. //console.log(thisFile.filename, iconOffset[thisFile.filepath]);
  3288. }
  3289. }
  3290. //Move the drag drop object to the desiged location
  3291. $(sourceObject).css({
  3292. left: closestLocation[0] + iconOffsetXY[0],
  3293. top: closestLocation[1] + iconOffsetXY[1]
  3294. });
  3295. //Save the drag item location
  3296. $.ajax({
  3297. url: "system/desktop/files",
  3298. method: "POST",
  3299. data: {"set": sourceFilename, "x": targetLocation[1][0], "y": targetLocation[1][1]},
  3300. success: function(data) {
  3301. //console.log(data);
  3302. }
  3303. });
  3304. //Move all the relative files to the main object
  3305. var relocatePendingObjects = [];
  3306. for (const [filepath, offset] of Object.entries(iconOffset)) {
  3307. let thisIconObject = getObjectFromPath(filepath);
  3308. let caluclatedLocation = [$(sourceObject).offset().left - offset.dx, $(sourceObject).offset().top - offset.dy];
  3309. let finalIconLocation = findClosestGrid(caluclatedLocation[0], caluclatedLocation[1]);
  3310. //Move this icon to designed location
  3311. $(thisIconObject).css({
  3312. left: finalIconLocation[0][0] + iconOffsetXY[0],
  3313. top: finalIconLocation[0][1] + iconOffsetXY[1]
  3314. });
  3315. let thisIconFileData = JSON.parse(decodeURIComponent($(thisIconObject).attr("filedata")));
  3316. //Record this in database
  3317. $.ajax({
  3318. url: "system/desktop/files",
  3319. method: "POST",
  3320. data: {"set": thisIconFileData.Filename, "x": finalIconLocation[1][0], "y": finalIconLocation[1][1]},
  3321. success: function(data) {
  3322. //console.log(data);
  3323. }
  3324. });
  3325. }
  3326. //Get duplication objects
  3327. for (const [filepath, offset] of Object.entries(iconOffset)) {
  3328. let thisIconObject = getObjectFromPath(filepath);
  3329. //Check for duplication
  3330. var iconLocation = [$(thisIconObject).offset().left, $(thisIconObject).offset().top];
  3331. $(".launchIcon").each(function(){
  3332. if ($(this).offset().left == iconLocation[0] && $(this).offset().top == iconLocation[1]){
  3333. //This icon is at the target icon location
  3334. if ($(this).attr("filepath") != filepath){
  3335. relocatePendingObjects.push($(this));
  3336. }
  3337. }
  3338. });
  3339. }
  3340. //Relocate objects that is in the way of moving
  3341. for (var i = 0; i < relocatePendingObjects.length; i++){
  3342. var thisObject = relocatePendingObjects[i];
  3343. console.log(thisObject);
  3344. var thisX = $(thisObject).offset().left;
  3345. var thisY = $(thisObject).offset().top;
  3346. var nextEmptyGrid = findClostestEmptyGridLocation(thisX, thisY);
  3347. //Move this file to the next empty grid location
  3348. $(thisObject).css({
  3349. left: nextEmptyGrid[0][0] + iconOffsetXY[0],
  3350. top: nextEmptyGrid[0][1] + iconOffsetXY[1]
  3351. });
  3352. //Save move record to db
  3353. let thisIconFileData = JSON.parse(decodeURIComponent($(thisObject).attr("filedata")));
  3354. $.ajax({
  3355. url: "system/desktop/files",
  3356. method: "POST",
  3357. data: {"set": thisIconFileData.Filename, "x": nextEmptyGrid[1][0], "y": nextEmptyGrid[1][1]},
  3358. success: function(data) {
  3359. //console.log(data);
  3360. }
  3361. });
  3362. }
  3363. }
  3364. }else{
  3365. //Dropping a file onto other place on desktop
  3366. var sourceObject = getObjectFromPath(sourceFilepath);
  3367. var dx = startDragRelatuve[0];
  3368. var dy = startDragRelatuve[1];
  3369. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  3370. var closestLocation = targetLocation[0];
  3371. //Check if there are objects already at that location
  3372. var duplicateObject = getObjectFromLocation(closestLocation[0], closestLocation[1]);
  3373. if (duplicateObject !== undefined) {
  3374. //There are already object there. Do nothing
  3375. console.log("Drop location duplicated!")
  3376. return;
  3377. }
  3378. var closestGridIndex = targetLocation[1];
  3379. $(sourceObject).css({
  3380. left: closestLocation[0] + iconOffsetXY[0],
  3381. top: closestLocation[1] + iconOffsetXY[1]
  3382. });
  3383. $.ajax({
  3384. url: "system/desktop/files",
  3385. method: "POST",
  3386. data: {"set": sourceFilename, "x": closestGridIndex[0], "y": closestGridIndex[1]},
  3387. success: function(data) {
  3388. //console.log(data);
  3389. }
  3390. });
  3391. }
  3392. } else if (target.attr("type") == "folder") {
  3393. //Move this file or folder into the target folder
  3394. var moveSources = [sourceFilepath];
  3395. if ($(".launchIconWrapper.selected").length > 1){
  3396. //Multi move operations
  3397. moveSources = [];
  3398. $(".launchIconWrapper.selected").each(function(){
  3399. var thisFileData = $(this).parent().attr("filedata");
  3400. thisFileData = JSON.parse(decodeURIComponent(thisFileData));
  3401. moveSources.push(thisFileData.Filepath);
  3402. });
  3403. }
  3404. //Get the move target location
  3405. var targetFd = $(target).attr("filedata");
  3406. targetFd = JSON.parse(decodeURIComponent(targetFd));
  3407. //Move it
  3408. moveSourceFilesToTarget(moveSources, targetFd.Filepath)
  3409. } else if (target.attr("type") == "shortcut") {
  3410. //Opening with the shortcut
  3411. //Check shortcut type
  3412. let shortcutData = JSON.parse(decodeURIComponent($(target).attr("filedata")));
  3413. var shortcutType = shortcutData["ShortcutType"];
  3414. if (shortcutType == "module") {
  3415. //Open the source file with this module
  3416. let openFileList = [];
  3417. if ($(".launchiconwrapper.selected").length > 0 && !Array.isArray(sourceFilelist)) {
  3418. $(".launchiconwrapper.selected").each(function() {
  3419. let thisFileData = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3420. openFileList.push({
  3421. filename: thisFileData["Filename"],
  3422. filepath: thisFileData["Filepath"]
  3423. });
  3424. });
  3425. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  3426. //Open file that is transfered from file explorer.
  3427. openFileList = sourceFilelist;
  3428. console.log(openFileList);
  3429. } else {
  3430. //Only pass in the current selected file.
  3431. openFileList.push({
  3432. filename: sourceFilename,
  3433. filepath: sourceFilepath
  3434. });
  3435. }
  3436. var shortcutModule = getModuleFromShortcutInfo(shortcutData);
  3437. //console.log(openFileList);
  3438. if (shortcutModule === undefined){
  3439. //This shortcut module is not found on this server
  3440. return;
  3441. }
  3442. openFileWithModule(shortcutModule, openFileList);
  3443. } else if (shortcutType == "folder") {
  3444. //Move the source file into this folder
  3445. var moveSources = [sourceFilepath];
  3446. if ($(".launchIconWrapper.selected").length > 1){
  3447. //Multi move operations
  3448. moveSources = [];
  3449. $(".launchIconWrapper.selected").each(function(){
  3450. var thisFileData = $(this).parent().attr("filedata");
  3451. thisFileData = JSON.parse(decodeURIComponent(thisFileData));
  3452. moveSources.push(thisFileData.Filepath);
  3453. });
  3454. }
  3455. //Extract shortcut info from the target
  3456. var targetPath = shortcutData.ShortcutPath;
  3457. moveSourceFilesToTarget(moveSources, targetPath);
  3458. }
  3459. } else {
  3460. console.log("Unknown action type: ", target.attr("type"));
  3461. }
  3462. }
  3463. //Use move if it is folder on desktop, use copy if it is a shortcut
  3464. function moveSourceFilesToTarget(sourceList, target, opr="move"){
  3465. var oprConfig = {
  3466. opr: opr,
  3467. src: sourceList,
  3468. dest: target,
  3469. callbackWindowID: "desktop",
  3470. callbackFunction: `refresh(undefined, true)`
  3471. }
  3472. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  3473. var title = "Copying " + sourceList.length;
  3474. if (sourceList.length > 1){
  3475. title += " files";
  3476. }else{
  3477. title += " file";
  3478. }
  3479. //Create FloatWindow to handle the file operations
  3480. newFloatWindow({
  3481. url: "SystemAO/file_system/file_operation.html#" + configHash,
  3482. width: 400,
  3483. height: 220,
  3484. appicon: "SystemAO/file_system/img/selector.png",
  3485. title: title
  3486. });
  3487. //Delete the file location from db
  3488. sourceList.forEach(file => {
  3489. let filename = file.split("/").pop();
  3490. $.ajax({
  3491. url: "system/desktop/files",
  3492. data: {del: filename},
  3493. success: function(data){
  3494. if (data.error !== undefined){
  3495. console.log(data.error);
  3496. }
  3497. }
  3498. });
  3499. });
  3500. }
  3501. function requestCSRFToken(callback){
  3502. $.ajax({
  3503. url: "system/csrf/new",
  3504. success: function(token){
  3505. callback(token);
  3506. }
  3507. });
  3508. }
  3509. function getModuleFromShortcutInfo(shortcutInfo) {
  3510. var ShortcutPath = shortcutInfo["ShortcutPath"];
  3511. if (ShortcutPath.includes("/") == false) {
  3512. //Legacy defination. Append /index.html at the back.
  3513. ShortcutPath = ShortcutPath + "/index.html";
  3514. }
  3515. //Try to match it with the module installed
  3516. for (var i = 0; i < moduleInstalled.length; i++) {
  3517. if (moduleInstalled[i]["StartDir"] == ShortcutPath || moduleInstalled[i]["Name"] == shortcutInfo["ShortcutName"]) {
  3518. //This is the correct module to be loaded
  3519. return moduleInstalled[i];
  3520. }
  3521. }
  3522. }
  3523. //Allocate the given number of grids from desktop
  3524. function gridPositionAllocate(posx, posy, numberOfGridNeeded=1){
  3525. var gridMaxX = desktopGrids.length;
  3526. var gridMaxY = desktopGrids[0].length;
  3527. var targetLocation = findClosestGrid(posx, posy, false);
  3528. var targetGridLocation = targetLocation[1];
  3529. var previousEmptyGridPosition = targetGridLocation;
  3530. var locations = [];
  3531. for (var k =0; k < numberOfGridNeeded; k++){
  3532. var thisLocation = JSON.parse(JSON.stringify(previousEmptyGridPosition));
  3533. //Add k to y axis of the list.
  3534. thisLocation[1] += k;
  3535. if (thisLocation[1] >= gridMaxY){
  3536. thisLocation[0]++;
  3537. thisLocation[1] = 0;
  3538. }
  3539. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3540. //Desktop full. Force put to 0 0
  3541. thisLocation[0] = 0;
  3542. thisLocation[1] = 0;
  3543. break;
  3544. }
  3545. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  3546. thisLocation[1] += 1;
  3547. if (thisLocation[1] >= gridMaxY){
  3548. //Over the screen. Shift to the row on the right
  3549. thisLocation[0]++;
  3550. thisLocation[1] = 0;
  3551. }
  3552. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3553. //Desktop full. Force put to 0 0
  3554. thisLocation[0] = 0;
  3555. thisLocation[1] = 0;
  3556. break;
  3557. }
  3558. }
  3559. previousEmptyGridPosition = JSON.parse(JSON.stringify(thisLocation))
  3560. locations.push(thisLocation)
  3561. }
  3562. return locations
  3563. }
  3564. function setIconDesktopLocation(sourceFilename, gridIndexX, gridIndexY, callback = undefined) {
  3565. $.ajax({
  3566. url: "system/desktop/files",
  3567. method: "POST",
  3568. data: {"set": sourceFilename, "x": gridIndexX, "y": gridIndexY},
  3569. success: function(data) {
  3570. if (data.error !== undefined) {
  3571. console.log(data.error);
  3572. } else {
  3573. if (callback !== undefined) {
  3574. callback();
  3575. }
  3576. }
  3577. }
  3578. });
  3579. }
  3580. //THIS FUNCTION IS NEEDED. DO NOT DELETE ALLOWDROP FUNCTION
  3581. function allowDrop(ev) {
  3582. ev.preventDefault();
  3583. }
  3584. //Pass in the object fullpath and return the icon object onscreen
  3585. function getObjectFromPath(path) {
  3586. var object;
  3587. $(".launchIcon").each(function() {
  3588. if ($(this).attr("filepath") == path) {
  3589. object = $(this);
  3590. }
  3591. });
  3592. return object;
  3593. }
  3594. //Pass in the coordinate and check if there is another object at the same location
  3595. function getObjectFromLocation(x, y) {
  3596. var object;
  3597. $(".launchIcon").each(function() {
  3598. if ($(this).position().left == x && $(this).position().top == y) {
  3599. object = $(this);
  3600. }
  3601. });
  3602. return object;
  3603. }
  3604. //Similar function to getObjectFromLocation but using grid coordinate instead of pixel coordinate
  3605. function getObjectFromGridLocation(gx, gy){
  3606. if (desktopGrids[gx] == undefined){
  3607. //X overflow
  3608. return false;
  3609. }
  3610. var pos = JSON.parse(JSON.stringify(desktopGrids[gx][gy]));
  3611. pos[0] = pos[0] + iconOffsetXY[0];
  3612. pos[1] = pos[1] + iconOffsetXY[1];
  3613. return getObjectFromLocation(pos[0],pos[1]);
  3614. }
  3615. //Find the clostest empty grid, prioirty given to y first then x
  3616. function findClostestEmptyGridLocation(x, y){
  3617. //Reduce icon offset to the x y on screen coordinate
  3618. x = x - iconOffsetXY[0];
  3619. y = y - iconOffsetXY[1];
  3620. //Get the grid index from absolute coordinate
  3621. var currentGridLocation = getGridIndexFromLocation(x,y);
  3622. //console.log(currentGridLocation);
  3623. //Search for the next empty location
  3624. var targetLocation = [[-1,-1],[-1,-1]];
  3625. for (var i = currentGridLocation[0]; i < desktopGrids.length; i++){
  3626. var yStart = 0;
  3627. if (i == currentGridLocation[0]){
  3628. yStart = currentGridLocation[1];
  3629. }
  3630. for (k = yStart; k < desktopGrids[i].length; k++){
  3631. var thisLocation = JSON.parse(JSON.stringify(desktopGrids[i][k]));
  3632. var offsetedLocation = [thisLocation[0], thisLocation[1]];
  3633. var possibleDuplication = getObjectFromGridLocation(i,k);
  3634. //console.log( [i,k], offsetedLocation, possibleDuplication)
  3635. if (possibleDuplication === undefined){
  3636. //This is an empty slot
  3637. targetLocation = [offsetedLocation, [i,k]];
  3638. return targetLocation;
  3639. }
  3640. }
  3641. }
  3642. return targetLocation;
  3643. }
  3644. //Convert location to grid index
  3645. function getGridIndexFromLocation(x,y){
  3646. var gridIndex = [-1,-1];
  3647. for (var i = 0; i < desktopGrids.length; i++){
  3648. var thisXAxis = desktopGrids[i];
  3649. if (thisXAxis[0][0] == x){
  3650. //This x matches. Match y
  3651. gridIndex[0] = i;
  3652. for (var k = 0; k < thisXAxis.length; k++){
  3653. var thisYAxis = thisXAxis[k];
  3654. if (thisYAxis[1] == y){
  3655. gridIndex[1] = k;
  3656. return gridIndex;
  3657. }
  3658. }
  3659. }
  3660. }
  3661. return gridIndex;
  3662. }
  3663. //Convert grid index to location
  3664. function getLocationFromGridIndex(x, y){
  3665. var location = [-1,-1];
  3666. //Calculate the usable grid on screen
  3667. var iheight = 106;
  3668. var iwidth = 70;
  3669. var padding = 16;
  3670. if (desktopIconSize == "small") {
  3671. iheight = 82;
  3672. iwidth = 50;
  3673. } else if (desktopIconSize == "medium") {
  3674. iheight = 106;
  3675. iwidth = 70;
  3676. } else if (desktopIconSize == "big") {
  3677. iheight = 124;
  3678. iwidth = 84;
  3679. }
  3680. var screenHeight = window.innerHeight;
  3681. var screenWidth = window.innerWidth;
  3682. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  3683. var hc = Math.floor((screenWidth - padding) / iwidth);
  3684. //Calculate the position of this icon on the grid
  3685. var resultX = padding + iwidth * x + iconOffsetXY[0];
  3686. var resultY = padding + iheight * y + iconOffsetXY[1];
  3687. return [resultX, resultY];
  3688. }
  3689. //Set allow overshoot to allow drop point to get closest grid with x / y > cursor posx /y
  3690. function findClosestGrid(x, y, allowOvershoot = true) {
  3691. var minDx = window.innerWidth;
  3692. var minDy = window.innerHeight;
  3693. var finalLocation = [-1, -1];
  3694. var gridLocation = [-1, -1];
  3695. for (var i = 0; i < desktopGrids.length; i++) {
  3696. for (var j = 0; j < desktopGrids[0].length; j++) {
  3697. var thisGridLocation = desktopGrids[i][j];
  3698. var dx = x - thisGridLocation[0];
  3699. var dy = y - thisGridLocation[1];
  3700. if (allowOvershoot) {
  3701. if (Math.abs(dx) < minDx) {
  3702. minDx = Math.abs(x - thisGridLocation[0]);
  3703. finalLocation[0] = thisGridLocation[0];
  3704. gridLocation[0] = i;
  3705. }
  3706. if (Math.abs(dy) < minDy) {
  3707. minDy = Math.abs(y - thisGridLocation[1]);
  3708. finalLocation[1] = thisGridLocation[1];
  3709. gridLocation[1] = j;
  3710. }
  3711. } else {
  3712. if (dx < minDx && dx > 0) {
  3713. minDx = Math.abs(x - thisGridLocation[0]);
  3714. finalLocation[0] = thisGridLocation[0];
  3715. gridLocation[0] = i;
  3716. }
  3717. if (dy < minDy && dy > 0) {
  3718. minDy = Math.abs(y - thisGridLocation[1]);
  3719. finalLocation[1] = thisGridLocation[1];
  3720. gridLocation[1] = j;
  3721. }
  3722. }
  3723. }
  3724. }
  3725. return [finalLocation, gridLocation];
  3726. }
  3727. //Ask for confirmation before window close
  3728. //Update 16 Feb 2021: Disabled confirmation and use a new method of implementing this later
  3729. /*
  3730. function myConfirmation() {
  3731. if (!loggingOut){
  3732. return 'Your data might not been saved. Are you sure you want to quit?';
  3733. }
  3734. }
  3735. window.onbeforeunload = myConfirmation;
  3736. */
  3737. function iconClicked(object, evt) {
  3738. if (renameMode){
  3739. //Exit rename mode if icon is clicked during renaming
  3740. if ($(object).find(".renameInput").length == 0){
  3741. exitRenameMode();
  3742. }
  3743. }
  3744. hideAllContextMenus();
  3745. //Clicked on a launch icon.
  3746. var alreadyHighlighted = $(object).find(".launchIconWrapper").hasClass("selected");
  3747. if (alreadyHighlighted){
  3748. //Already selected
  3749. if (ctrlHold) {
  3750. //Selection
  3751. $(object).find(".launchIconWrapper").removeClass("selected");
  3752. }
  3753. }else{
  3754. //Not selected yet
  3755. if (ctrlHold) {
  3756. //Add this into selection
  3757. $(object).find(".launchIconWrapper").addClass("selected");
  3758. }else{
  3759. //Remove all others and select this
  3760. $(".launchIconWrapper.selected").removeClass("selected");
  3761. $(object).find(".launchIconWrapper").addClass("selected");
  3762. }
  3763. }
  3764. }
  3765. function iconDoubleClicked(object, evt=undefined) {
  3766. //Don't allow opening when renaming
  3767. if (renameMode){
  3768. return;
  3769. }
  3770. //Double click on a launch icon, tries to open it
  3771. var filedata = ao_module_utils.attrToObject($(object).attr("filedata"));
  3772. //console.log(filedata);
  3773. if (filedata.IsDir) {
  3774. //This is a directory. Open with file explorer
  3775. newFloatWindow({
  3776. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(filedata.Filepath),
  3777. appicon: "SystemAO/file_system/img/small_icon.png",
  3778. width: 1080,
  3779. height: 580,
  3780. title: "File Manager"
  3781. });
  3782. } else if (filedata.IsShortcut) {
  3783. //This is a shortcut. Open the target endpoint
  3784. var stype = filedata["ShortcutType"];
  3785. if (stype == "module") {
  3786. //Open the target module
  3787. openModule(filedata.ShortcutPath);
  3788. } else if (stype == "folder") {
  3789. //Open the target folder
  3790. openFolder(filedata.ShortcutPath)
  3791. }else if (stype == "url"){
  3792. //Open the target webpage in a new tab
  3793. newFloatWindow({
  3794. url: filedata.ShortcutPath,
  3795. appicon: filedata.ShortcutImage,
  3796. title: filedata.ShortcutName,
  3797. parent: filedata.ShortcutPath
  3798. })
  3799. //window.open(filedata.ShortcutPath);
  3800. }else{
  3801. console.log(filedata);
  3802. }
  3803. } else {
  3804. //This is a file. Open it with default opener
  3805. $.ajax({
  3806. url: "system/modules/getDefault",
  3807. method: "GET",
  3808. data: {
  3809. opr: "launch",
  3810. ext: filedata.Ext,
  3811. mode: "launch"
  3812. },
  3813. success: function(data) {
  3814. if (data.error !== undefined) {
  3815. //No default opener assigned
  3816. var url = "SystemAO/file_system/defaultOpener.html";
  3817. var icon = "SystemAO/file_system/img/opener.png";
  3818. var title = "Select an opener WebApp: "
  3819. var openFileList = [];
  3820. var openFileObject = {
  3821. filepath: filedata.Filepath,
  3822. filename: filedata.Filename
  3823. }
  3824. openFileList.push(openFileObject);
  3825. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  3826. newFloatWindow({
  3827. url: url + "#" + openParamter,
  3828. width: 320,
  3829. height: 510,
  3830. appicon: icon,
  3831. title: title
  3832. });
  3833. } else {
  3834. //Assigned. Launch with given paramter
  3835. var url = data["StartDir"];
  3836. var size = [undefined, undefined];
  3837. var title = data["Name"];
  3838. var icon = "img/system/favicon.png";
  3839. if (data["IconPath"] != "") {
  3840. icon = data["IconPath"];
  3841. }
  3842. //Use floatWindow if exists
  3843. if (data["SupportFW"] == true && data["LaunchFWDir"] != "") {
  3844. url = data["LaunchFWDir"];
  3845. if (data["InitFWSize"] !== null) {
  3846. size = data["InitFWSize"]
  3847. }
  3848. }
  3849. //Use embedded mode if exists
  3850. if (data["SupportEmb"] == true && data["LaunchEmb"] != "") {
  3851. url = data["LaunchEmb"];
  3852. if (data["InitEmbSize"] !== null) {
  3853. size = data["InitEmbSize"]
  3854. }
  3855. }
  3856. //Build open File Hash Data Format
  3857. var openFileList = [];
  3858. var openFileObject = {
  3859. filepath: filedata.Filepath,
  3860. filename: filedata.Filename
  3861. }
  3862. openFileList.push(openFileObject);
  3863. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  3864. //Add launch files info and launch floatWindow
  3865. newFloatWindow({
  3866. url: url + "#" + openParamter,
  3867. width: size[0],
  3868. height: size[1],
  3869. appicon: icon,
  3870. title: title
  3871. });
  3872. }
  3873. }
  3874. })
  3875. }
  3876. }
  3877. $(window).on("resize", function(event) {
  3878. redrawDesktopGrids();
  3879. resizeAllFloatWindowButtons();
  3880. })
  3881. // ======================= DOCUMENT KEY BINDING =====================
  3882. document.addEventListener('keydown', function(event) {
  3883. let keycode = event.which || event.keyCode;
  3884. if (keycode == "17") {
  3885. //Pressdown of Ctrl key
  3886. ctrlHold = true;
  3887. } else if (keycode == "16") {
  3888. //Pressdown of Shift key
  3889. shiftHold = true;
  3890. }else if (keycode == "27"){
  3891. //Cancel all floatwindow events and key events
  3892. $("#fwdragpanel").hide();
  3893. $("#tfwdragpanel").hide();
  3894. $(".floatWindow").find(".iframecover").hide();
  3895. movingWindow = false;
  3896. resizingWindow = false;
  3897. resizingEdgeID = 0;
  3898. multiSelecting = false;
  3899. ctrlHold = false;
  3900. shiftHold = false;
  3901. }else if (keycode == "46"){
  3902. //Delete key
  3903. if (renameMode){
  3904. //Deleting content in textarea. Ignore delte action
  3905. return true
  3906. }
  3907. var deleteFilelist = [];
  3908. var deleteFilenameList = [];
  3909. $(".launchIconWrapper.selected").each(function(){
  3910. var fileObject = $(this).parent();
  3911. var fd = JSON.parse(decodeURIComponent((fileObject).attr("filedata")));
  3912. deleteFilelist.push(fd.Filepath);
  3913. deleteFilenameList.push(fd.Filename)
  3914. });
  3915. //Prase the filelist and pass to trash module
  3916. console.log(deleteFilelist);
  3917. generateCSRFToken(function(csrftoken){
  3918. $.ajax({
  3919. url: "system/file_system/fileOpr",
  3920. method:"POST",
  3921. data: {opr: "recycle", src: JSON.stringify(deleteFilelist), csrft: csrftoken},
  3922. success: function(data){
  3923. if (data.error !== undefined){
  3924. alert(data.error);
  3925. }else{
  3926. //Delete the file's desktop location
  3927. deleteFilenameList.forEach(file => {
  3928. $.ajax({
  3929. url: "system/desktop/files",
  3930. data: {del: file},
  3931. success: function(data){
  3932. if (data.error !== undefined){
  3933. console.log(data.error);
  3934. }
  3935. }
  3936. });
  3937. });
  3938. refresh(undefined, true);
  3939. }
  3940. }
  3941. });
  3942. });
  3943. }else if (keycode == "112"){
  3944. //Enter key
  3945. if (!renameMode){
  3946. //Open selected object by emulating double click
  3947. $(".launchIconWrapper.selected").each(function(){
  3948. var object = $(this).parent();
  3949. iconDoubleClicked(object);
  3950. });
  3951. }else if (renameMode){
  3952. event.preventDefault();
  3953. exitRenameMode();
  3954. }
  3955. }else{
  3956. //console.log(event.which);
  3957. }
  3958. });
  3959. $(document).on("mousemove", function(event){
  3960. currentMousePosition = [event.clientX, event.clientY];
  3961. });
  3962. $(document).keyup(function(event) {
  3963. let keycode = event.which || event.keyCode;
  3964. if (keycode == "17") {
  3965. ctrlHold = false;
  3966. } else if (keycode == "16") {
  3967. shiftHold = false;
  3968. }else if (keycode == "27"){
  3969. //ESC key, stop all floatWindow operations
  3970. console.log("%c[Desktop] Dragging function killed. Restarting all dragging elements.", 'color: #e64747');
  3971. movingWindow = false;
  3972. resizingWindow = false;
  3973. event.preventDefault();
  3974. }
  3975. });
  3976. $("#bgwrapper").on("mouseup", function(event) {
  3977. //Deselect all selected icons
  3978. event.preventDefault();
  3979. event.stopImmediatePropagation();
  3980. mainWindowMouseup(event);
  3981. });
  3982. function openFolder(virtualPath){
  3983. newFloatWindow({
  3984. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(virtualPath),
  3985. appicon: "SystemAO/file_system/img/small_icon.png",
  3986. width:1080,
  3987. height:580,
  3988. title: "File Manager"
  3989. });
  3990. }
  3991. function logout() {
  3992. loggingOut = true;
  3993. if (confirm("Exiting Session. Confirm?")){
  3994. $.get("system/auth/logout", function() {
  3995. window.location.href = "./";
  3996. });
  3997. }
  3998. hideAllContextMenus();
  3999. }
  4000. // ======================= CONTEXT MENU =============================
  4001. window.addEventListener("contextmenu",
  4002. function(e) {
  4003. e.preventDefault();
  4004. e.stopPropagation();
  4005. var clickTarget = $(e.target);
  4006. hideAllContextMenus();
  4007. showMenu = false;
  4008. $("#contextmenu").html("");
  4009. if (clickTarget.hasClass("launchIcon") || clickTarget.hasClass("launchIconImage") || clickTarget.hasClass("launchIconText")) {
  4010. //Click on an object on destkop
  4011. if (clickTarget.hasClass("launchIcon") == false) {
  4012. clickTarget = $(clickTarget).parent().parent();
  4013. }
  4014. if (!ctrlHold && !$(clickTarget).find(".launchIconWrapper").hasClass("selected")){
  4015. $(".launchIconWrapper.selected").removeClass("selected");
  4016. }
  4017. //Select this object
  4018. $(clickTarget).find(".launchIconWrapper").addClass("selected");
  4019. var objectType = $(clickTarget).attr("type");
  4020. operationTargetLaunchIcon = $(clickTarget);
  4021. //Check if selected more than one object
  4022. if ($(".launchIconWrapper.selected").length > 1){
  4023. //When the user selected more than one item on desktop
  4024. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  4025. addContextMenuItem($("#contextmenu"), lcontex('Open With'), "<i class='caret right icon'></i>", "handleOpenWith", true);
  4026. //addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  4027. addContextMenuSeperator($("#contextmenu"));
  4028. addContextMenuItem($("#contextmenu"), lcontex('Download in Zip'), "<i class='download icon'></i>", "downloadFile", false);
  4029. addContextMenuItem($("#contextmenu"), lcontex('Make a Copy'), "<i class='copy icon'></i>", "handleCloning", false);
  4030. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  4031. addContextMenuSeperator($("#contextmenu"));
  4032. addContextMenuItem($("#contextmenu"), lcontex('Properties'), undefined, "openObjectProperty", false);
  4033. }else{
  4034. //When the user only selected one item
  4035. if (objectType == "file") {
  4036. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  4037. addContextMenuItem($("#contextmenu"), lcontex('Open With'), "<i class='caret right icon'></i>", "handleOpenWith", true);
  4038. addContextMenuItem($("#contextmenu"), lcontex('Share'), "<i class='caret right icon'></i>", "handleFileShare", true);
  4039. addContextMenuSeperator($("#contextmenu"));
  4040. addContextMenuItem($("#contextmenu"), lcontex('Download'), "<i class='download icon'></i>", "downloadFile", false);
  4041. addContextMenuItem($("#contextmenu"), lcontex('Make a Copy'), "<i class='copy icon'></i>", "handleCloning", false);
  4042. addContextMenuItem($("#contextmenu"), lcontex('Rename'), undefined, "handleRename", false);
  4043. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  4044. addContextMenuSeperator($("#contextmenu"));
  4045. addContextMenuItem($("#contextmenu"), lcontex('Properties'), undefined, "openObjectProperty", false);
  4046. } else if (objectType == "folder") {
  4047. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  4048. addContextMenuItem($("#contextmenu"), lcontex('Zip here'), "<i class='zip icon'></i>", "handleZipFolder", false);
  4049. addContextMenuItem($("#contextmenu"), lcontex('Share'), "<i class='caret right icon'></i>", "handleFileShare", true);
  4050. addContextMenuSeperator($("#contextmenu"));
  4051. addContextMenuItem($("#contextmenu"), lcontex('Download as Zip'), "<i class='download icon'></i>", "downloadFile", false);
  4052. addContextMenuItem($("#contextmenu"), lcontex('Make a Copy'), "<i class='caret right icon'></i>", "handleCloning", false);
  4053. addContextMenuItem($("#contextmenu"), lcontex('Rename'), undefined, "handleRename", false);
  4054. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  4055. addContextMenuSeperator($("#contextmenu"));
  4056. addContextMenuItem($("#contextmenu"), lcontex('Properties'), undefined, "openObjectProperty", false);
  4057. } else if (objectType == "shortcut") {
  4058. var fd = JSON.parse(decodeURIComponent($(clickTarget).attr("filedata")));
  4059. console.log(fd);
  4060. if (fd.ShortcutType == "module"){
  4061. //Public WebApp
  4062. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  4063. addContextMenuItem($("#contextmenu"), lcontex('Open in New Tab'), "<i class='external icon'></i>", "openWebAppInNewTab", false);
  4064. addContextMenuItem($("#contextmenu"), lcontex('Rename'), undefined, "handleRename", false);
  4065. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  4066. }else if (fd.ShortcutType == "folder"){
  4067. //Folder
  4068. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  4069. addContextMenuItem($("#contextmenu"), lcontex('Open File Location'), "<i class='folder open icon'></i>", "handleShortcutFolderOpen", false);
  4070. addContextMenuItem($("#contextmenu"), lcontex('Rename'), undefined, "handleRename", false);
  4071. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  4072. addContextMenuSeperator($("#contextmenu"));
  4073. addContextMenuItem($("#contextmenu"), lcontex('Properties'), undefined, "openObjectProperty", false);
  4074. }else{
  4075. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  4076. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  4077. }
  4078. }else{
  4079. console.log("Opening context menu on unknown type: ", objectType);
  4080. }
  4081. }
  4082. showMenu = true;
  4083. } else if (clickTarget.hasClass("backgroundFrame") || ((isSafari || (isMacOS && isChrome)) && $(clickTarget).attr("id") == "selectionPanel")) {
  4084. //Click on the background. Load background context menu.
  4085. addContextMenuItem($("#contextmenu"), lcontex('New'), "<i class='caret right icon'></i>", "newitemmenu", true);
  4086. addContextMenuItem($("#contextmenu"), lcontex('Refresh'), "<i class='refresh icon'></i>", "handleMenuRefresh", false);
  4087. addContextMenuItem($("#contextmenu"), lcontex('Open File Manager'), undefined, "openfm", false);
  4088. //addContextMenuItem($("#contextmenu"), 'Get File from URL', "<i class='download icon'></i>", "downloadURL", false);
  4089. addContextMenuItem($("#contextmenu"), lcontex('Personalization'), "<i class='paint brush icon'></i>", "personalization", false);
  4090. addContextMenuItem($("#contextmenu"), lcontex('Background'), "<i class='caret right icon'></i>", "background", true);
  4091. addContextMenuItem($("#contextmenu"), lcontex('Icon Size'), "<i class='caret right icon'></i>", "listIconsize", true);
  4092. addContextMenuItem($("#contextmenu"), lcontex('Toggle FullScreen'), "<i class='maximize icon'></i>", "fullscreen", false);
  4093. addContextMenuItem($("#contextmenu"), lcontex('Exit'), undefined, "logout", false);
  4094. showMenu = true;
  4095. }else if (clickTarget.hasClass("fwdragger") || (clickTarget.hasClass("title") && clickTarget.parent().hasClass("fwdragger"))){
  4096. //Click on the floatWindow object
  4097. addContextMenuItem($("#contextmenu"), lcontex('Open in New Tab'), "<i class='external icon'></i>", "openSelectedFloatWindowInNewTab", false);
  4098. addContextMenuItem($("#contextmenu"), lcontex('Refresh'), "<i class='refresh icon'></i>", "refreshSelectedFloatWindow", false);
  4099. addContextMenuSeperator($("#contextmenu"));
  4100. addContextMenuItem($("#contextmenu"), lcontex('Minimize'), "<i class='window minimize icon'></i>", "minimizeSelectedFloatWindow", false);
  4101. if ($(clickTarget).parent().hasClass("fixedsize") == false && $(clickTarget).parent().parent().hasClass("fixedsize") == false){
  4102. //This FloatWindow is resizable
  4103. console.log($(clickTarget).parent());
  4104. if ($(clickTarget).parent().attr("max") !== undefined && $(clickTarget).parent().attr("max") == "true"){
  4105. addContextMenuItem($("#contextmenu"), lcontex('Restore'), "<i class='window window restore icon'></i>", "maximizeSelectedFloatWindow", false);
  4106. }else{
  4107. addContextMenuItem($("#contextmenu"), lcontex('Maximize'), "<i class='window maximize icon'></i>", "maximizeSelectedFloatWindow", false);
  4108. }
  4109. }
  4110. addContextMenuItem($("#contextmenu"), lcontex('Close'), "<i class='remove icon'></i>", "closeSelectedFloatWindow", false);
  4111. showMenu = true;
  4112. }
  4113. if (showMenu){
  4114. //Toggle context menu
  4115. $("#contextmenu").show();
  4116. var startX = e.pageX;
  4117. var startY = e.pageY;
  4118. if (e.pageX > window.innerWidth / 2){
  4119. startX = e.pageX - $("#contextmenu").width();
  4120. }
  4121. if (e.pageY > window.innerHeight / 2){
  4122. startY = e.pageY - $("#contextmenu").height();
  4123. }
  4124. $("#contextmenu").css({
  4125. left: startX,
  4126. top: startY
  4127. });
  4128. menuStartLocation = [e.pageX, e.pageY];
  4129. }
  4130. }
  4131. , true);
  4132. //Localize context menu items using applocale
  4133. function lcontex(key){
  4134. if (applocale){
  4135. return applocale.getString("contextmenu/" + key, key);
  4136. }else{
  4137. return key;
  4138. }
  4139. }
  4140. function handleMenuRefresh() {
  4141. //This function is here to remove the object and event passed in from menu pressed object
  4142. refresh();
  4143. }
  4144. function newshortcut(){
  4145. //Show the new shortcut creation tool
  4146. newFloatWindow({
  4147. url: "SystemAO/desktop/shortcutCreator.html",
  4148. appicon: "img/desktop/system_icon/shortcut.png",
  4149. width:815,
  4150. height:485,
  4151. title: "New Shortcut"
  4152. });
  4153. hideAllContextMenus();
  4154. }
  4155. function openIconViaMenu(target, event){
  4156. $(".launchIconWrapper.selected").each(function(){
  4157. iconObject = $(this).parent();
  4158. //Emulate a doubleclick on icon
  4159. iconDoubleClicked(iconObject, event);
  4160. });
  4161. hideAllContextMenus();
  4162. }
  4163. //Opening a shortcut module from desktop to new tab
  4164. function openWebAppInNewTab(target, event){
  4165. $(".launchIconWrapper.selected").each(function(){
  4166. var fd = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4167. $.get("system/modules/getLaunchPara?module=" + fd.ShortcutPath, function(data) {
  4168. if (data.error !== undefined) {
  4169. console.log(data.error);
  4170. }else{
  4171. //Open in new tab
  4172. window.open(data.StartDir)
  4173. }
  4174. });
  4175. });
  4176. hideAllContextMenus();
  4177. }
  4178. function downloadFile(target, event){
  4179. if ( $(".launchIconWrapper.selected").length == 1){
  4180. //Download this file directly
  4181. var rawfiledata = $(".launchIconWrapper.selected").parent().attr("filedata");
  4182. var filedata = JSON.parse(decodeURIComponent(rawfiledata));
  4183. var filepath = filedata.Filepath;
  4184. //Resolve the link to media download link
  4185. var downloadLink = "media?file=" + filepath + "&download=true";
  4186. window.open(downloadLink)
  4187. }else if ($(".launchIconWrapper.selected").length > 1){
  4188. //Create a zip file using the fs api
  4189. var filelist = [];
  4190. $(".launchIconWrapper.selected").each(function(){
  4191. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4192. var filepath = filedata.Filepath;
  4193. filelist.push(filepath);
  4194. });
  4195. $.ajax({
  4196. url: "system/file_system/zipHandler",
  4197. data: {opr: "tmpzip", src: JSON.stringify(filelist), dest: ""},
  4198. method: "POST",
  4199. success: function(data){
  4200. if (data.error !== undefined){
  4201. alert(data.error);
  4202. }else{
  4203. //Zip completed.
  4204. window.open("media?file=" + data + "&download=true");
  4205. }
  4206. }
  4207. });
  4208. }
  4209. hideAllContextMenus();
  4210. }
  4211. function handleZipFolder(){
  4212. var filelist = [];
  4213. var filename = "desktop_" + new Date().getTime() + ".zip"
  4214. if ($(".launchIconWrapper.selected").length == 1){
  4215. filename = $(".launchIconWrapper.selected").parent().attr('filename') + ".zip";
  4216. }
  4217. $(".launchIconWrapper.selected").each(function(){
  4218. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4219. var filepath = filedata.Filepath;
  4220. if (filedata.IsDir == true){
  4221. filelist.push(filepath);
  4222. }
  4223. });
  4224. $.ajax({
  4225. url: "system/file_system/zipHandler",
  4226. data: {opr: "zip", src: JSON.stringify(filelist), dest: "user:/Desktop/" + filename},
  4227. method: "POST",
  4228. success: function(data){
  4229. if (data.error !== undefined){
  4230. alert(data.error);
  4231. }else{
  4232. //Zip completed.
  4233. console.log(data);
  4234. }
  4235. }
  4236. });
  4237. //console.log(filelist);
  4238. hideAllContextMenus();
  4239. }
  4240. function handleOpenWith(target, event){
  4241. $("#subcontextmenu").html("");
  4242. //Updates 19 May 2021: Added support for better parsing Open With List
  4243. var exts = [];
  4244. //Get all exts from the selected files
  4245. $(".launchIconWrapper.selected").each(function(){
  4246. var filename = $(this).parent().attr("filename");
  4247. var ext = "." + filename.split(".").pop();
  4248. exts.push(ext);
  4249. });
  4250. $.get("system/modules/list",function(data){
  4251. if (data.error !== undefined){
  4252. alert(data.error);
  4253. }else{
  4254. var supportedModuleCount = 0;
  4255. var openWithTargets = [];
  4256. for (var i =0; i < data.length; i++){
  4257. var thisModule = data[i];
  4258. //If this module support this ext, add it to list
  4259. var thisModuleSupportExt = thisModule.SupportedExt;
  4260. if (thisModule.Name == "File Manager"){
  4261. //Exceptional case
  4262. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  4263. }
  4264. if (thisModuleSupportExt == null || thisModuleSupportExt.length == 0){
  4265. //Not supporting anything
  4266. continue;
  4267. }
  4268. thisModuleSupportExt.forEach(supportedExt => {
  4269. if (exts.includes(supportedExt)){
  4270. //Add this to the menu
  4271. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  4272. }
  4273. })
  4274. //if (thisModule.SupportEmb == true){
  4275. // addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  4276. //}
  4277. }
  4278. //Add select more opener option
  4279. addContextMenuSeperator($("#subcontextmenu"));
  4280. addContextMenuItem($("#subcontextmenu"), lcontex("Select Other WebApps"), ``, "openOpenSelector", false);
  4281. }
  4282. showSubContextMenu(target);
  4283. });
  4284. }
  4285. function handleFileShare(target, object){
  4286. $("#subcontextmenu").html("");
  4287. //Get the selected file
  4288. var targetFile = $(".launchIconWrapper.selected")[0];
  4289. var fileData = $(targetFile).parent().attr("filedata");
  4290. if (fileData != undefined){
  4291. fileData = JSON.parse(decodeURIComponent(fileData));
  4292. //Check if the target file is shared
  4293. $.ajax({
  4294. url: "system/file_system/share/checkShared",
  4295. data: {path: fileData.Filepath},
  4296. success: function(data){
  4297. if (data.IsShared == true){
  4298. addContextMenuItem($("#subcontextmenu"), lcontex("Open Shared Link"), `<i class="external icon"></i>`, "openSharedLink", false, {
  4299. payload: {
  4300. uuid: data.ShareUUID.UUID
  4301. }
  4302. });
  4303. addContextMenuItem($("#subcontextmenu"), lcontex("Copy Link"), `<i class="copy icon"></i>`, "copySharedLink", false, {
  4304. payload: {
  4305. uuid: data.ShareUUID.UUID
  4306. }
  4307. });
  4308. addContextMenuSeperator($("#subcontextmenu"));
  4309. addContextMenuTitle($("#subcontextmenu"), lcontex(`<i class="share alternate icon"></i> ${applocale.getString("contextmenu/Change Share Settings", "Change Share Settings")}]`));
  4310. }else{
  4311. addContextMenuTitle($("#subcontextmenu"), lcontex(`<i class="share alternate icon"></i> ${applocale.getString("contextmenu/Share this File", "Share this File")}`));
  4312. }
  4313. var checkmarkStyle = `style="color: #71ba68;"`;
  4314. var anyoneClass = "";
  4315. if (data.ShareUUID.Permission == "anyone"){
  4316. anyoneClass = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  4317. }
  4318. var signedinClass = "";
  4319. if (data.ShareUUID.Permission == "signedin"){
  4320. signedinClass = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  4321. }
  4322. var sameGroupClass = "";
  4323. if (data.ShareUUID.Permission == "samegroup"){
  4324. samegroup = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  4325. }
  4326. addContextMenuItem($("#subcontextmenu"), `<i class="globe icon"></i> ${applocale.getString("contextmenu/share/link","Anyone with Link")}`, anyoneClass, "shareWithThisPermission", false, {
  4327. payload: {
  4328. type: "anyone"
  4329. }
  4330. });
  4331. addContextMenuItem($("#subcontextmenu"), `<i class="user circle outline icon"></i> ${applocale.getString( "contextmenu/share/signedin","Anyone Signed In")}`, signedinClass, "shareWithThisPermission", false, {
  4332. payload: {
  4333. type: "signedin"
  4334. }
  4335. });
  4336. addContextMenuItem($("#subcontextmenu"), `<i class="users icon"></i> ${applocale.getString("contextmenu/share/samegroup","Same Group Users")}`, sameGroupClass, "shareWithThisPermission", false,{
  4337. payload: {
  4338. type: "samegroup"
  4339. }
  4340. });
  4341. if (data.IsShared == true){
  4342. //This file is shared.
  4343. addContextMenuSeperator($("#subcontextmenu"));
  4344. addContextMenuItem($("#subcontextmenu"), lcontex("Remove Share"), `<i style="color: #d97762;" class="trash icon"></i>`, "shareWithThisPermission", false,{
  4345. payload: {
  4346. type: "remove"
  4347. }
  4348. });
  4349. }
  4350. }
  4351. });
  4352. }
  4353. showSubContextMenu(target);
  4354. }
  4355. //Copy the shared link
  4356. function copySharedLink(target, event){
  4357. var payload = getContextMenuPayload(target);
  4358. if (payload == null){
  4359. //Something wrong
  4360. return;
  4361. }
  4362. //Generate the share link
  4363. let protocol = "https://";
  4364. if (location.protocol !== 'https:') {
  4365. protocol = "http://";
  4366. }
  4367. var shareURL = protocol + window.location.hostname + ":" + window.location.port + "/share/" + payload.uuid;
  4368. //Copy the text to clipboard
  4369. const area = document.createElement('textarea');
  4370. document.body.appendChild(area);
  4371. area.value = shareURL;
  4372. area.select();
  4373. document.execCommand('copy');
  4374. document.body.removeChild(area);
  4375. //Update status so it show the user it has been coped
  4376. $(target).html(`<i style="color: #71ba68;" class="checkmark icon"></i> ${lcontex("Copied")}`);
  4377. setTimeout(function(){
  4378. if ($(target).length > 0){
  4379. $(target).html(`${lcontex("Copy Link")}
  4380. <span class="description">
  4381. <i class="copy icon"></i>
  4382. </span>`);
  4383. }
  4384. }, 3000);
  4385. }
  4386. //Open the shared file link
  4387. function openSharedLink(target, event){
  4388. var payload = getContextMenuPayload(target);
  4389. if (payload == null){
  4390. //Something wrong
  4391. return;
  4392. }
  4393. var targetURL = "share/" + payload.uuid;
  4394. window.open(targetURL);
  4395. hideAllContextMenus();
  4396. }
  4397. function shareWithThisPermission(target, event){
  4398. var payload = getContextMenuPayload(target);
  4399. if (payload == null){
  4400. //Something wrong
  4401. return;
  4402. }
  4403. //Get the selected file
  4404. var selectedFileObjects = $(".launchIconWrapper.selected");
  4405. if (selectedFileObjects.length == 0){
  4406. //Not found
  4407. return
  4408. }else if (selectedFileObjects.length > 1){
  4409. //This should not happens. If it did happens, use the first one
  4410. selectedFileObjects = selectedFileObjects[0];
  4411. }
  4412. //Extract file information
  4413. var fileData = $(selectedFileObjects).parent().attr("filedata");
  4414. fileData = JSON.parse(decodeURIComponent(fileData));
  4415. //Convert the desktop file data to ArozOS generic filedata
  4416. var afd = {
  4417. "filename": fileData.Filename,
  4418. "filepath": fileData.Filepath,
  4419. "shareMode": payload.type
  4420. };
  4421. //Create a new share for this
  4422. var targetURL = "SystemAO/file_system/file_share.html#" + encodeURIComponent(JSON.stringify([afd]));
  4423. //Calculate the window spawn position
  4424. var basePosition = $(selectedFileObjects).offset();
  4425. var left = basePosition.left + 100;
  4426. if (left + 320 > window.innerWidth){
  4427. left = basePosition.left - 350;
  4428. }
  4429. var top = basePosition.top;
  4430. if (top + 480 > window.innerHeight){
  4431. top = window.innerHeight - 480;
  4432. }
  4433. newFloatWindow({
  4434. url: targetURL,
  4435. width: 330,
  4436. height: 480,
  4437. left: left,
  4438. top: top,
  4439. appicon: "SystemAO/file_system/img/share.svg",
  4440. title: "Share File"
  4441. }, function(windowUUID){
  4442. //Set the window to fixed window
  4443. setFloatWindowResizePolicy(windowUUID, false);
  4444. });
  4445. hideAllContextMenus();
  4446. }
  4447. function openObjectProperty(target, object){
  4448. var filelist = [];
  4449. $(".launchIconWrapper.selected").each(function(){
  4450. var filepath = $(this).parent().attr("filepath");
  4451. filelist.push(filepath);
  4452. });
  4453. var hashPassthrough = encodeURIComponent(JSON.stringify(filelist));
  4454. newFloatWindow({
  4455. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  4456. width: 340,
  4457. height: 480,
  4458. appicon: "SystemAO/file_system/img/properties.png",
  4459. title: "File Properties",
  4460. });
  4461. hideAllContextMenus();
  4462. }
  4463. //Open the file extension selector
  4464. function openOpenSelector(target, event){
  4465. var filedata = $($(".launchIconWrapper.selected")[0]).parent().attr("filedata")
  4466. filedata = JSON.parse(decodeURIComponent(filedata));
  4467. var fileDescriptor = {
  4468. filepath: filedata.Filepath,
  4469. filename: filedata.Filename
  4470. }
  4471. newFloatWindow({
  4472. url: "SystemAO/file_system/defaultOpener.html#" + encodeURIComponent(JSON.stringify(fileDescriptor)),
  4473. width: 320,
  4474. height: 510,
  4475. appicon: "SystemAO/file_system/img/opener.png",
  4476. title: "Select WebApp to Open File",
  4477. });
  4478. hideAllContextMenus();
  4479. }
  4480. function openSelectedWith(target, event){
  4481. var targetModulename = $(target).text().trim();
  4482. var openFileList = [];
  4483. $(".selected.launchIconWrapper").each(function(){
  4484. var thisFiledata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4485. openFileList.push({
  4486. filename: thisFiledata.Filename,
  4487. filepath: thisFiledata.Filepath
  4488. });
  4489. });
  4490. //Find the launch info of the module
  4491. var targetModuleInfo = undefined;
  4492. for (var i =0; i < moduleInstalled.length; i++){
  4493. if (moduleInstalled[i].Name == targetModulename){
  4494. targetModuleInfo = JSON.parse(JSON.stringify(moduleInstalled[i]));
  4495. }
  4496. }
  4497. //Open the files with the given module
  4498. openFileWithModule(targetModuleInfo, openFileList);
  4499. hideAllContextMenus();
  4500. }
  4501. function getModuleInfoFromName(moduleName){
  4502. for (var i = 0; i < moduleInstalled.length; i++){
  4503. if (moduleInstalled[i].Name == moduleName){
  4504. return moduleInstalled[i];
  4505. }
  4506. }
  4507. return false
  4508. }
  4509. /*
  4510. This function is used to generate menu items for context menu.
  4511. Options example
  4512. {
  4513. payload: {
  4514. //Some JSON based payload here
  4515. }
  4516. }
  4517. */
  4518. function addContextMenuItem(target, keyword, hotkey = undefined, functionName, containSubMenu = false, options=undefined) {
  4519. var itemClass = "item";
  4520. if (containSubMenu) {
  4521. itemClass = "item submenu";
  4522. }
  4523. var payload = "";
  4524. if (options != undefined && options.payload != undefined){
  4525. payload = encodeURIComponent(JSON.stringify(options.payload));
  4526. }
  4527. if (hotkey !== undefined) {
  4528. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);" payload="${payload}">
  4529. ${keyword}
  4530. <span class="description">${hotkey}</span>
  4531. </div>`);
  4532. } else {
  4533. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);" payload="${payload}">
  4534. ${keyword}
  4535. </div>`);
  4536. }
  4537. }
  4538. function getContextMenuPayload(object){
  4539. var encodedPayload = $(object).attr("payload");
  4540. if (encodedPayload != ""){
  4541. return JSON.parse(decodeURIComponent(encodedPayload));
  4542. }else{
  4543. return null;
  4544. }
  4545. }
  4546. function listIconsize(target, event) {
  4547. $("#subcontextmenu").html("");
  4548. var smallCheckmark = undefined;
  4549. var mediumCheckmark = undefined;
  4550. var bigCheckmark = undefined;
  4551. if (desktopIconSize == "small") {
  4552. smallCheckmark = "<i class='checkmark icon'></i>";
  4553. }
  4554. if (desktopIconSize == "medium") {
  4555. mediumCheckmark = "<i class='checkmark icon'></i>";
  4556. }
  4557. if (desktopIconSize == "big") {
  4558. bigCheckmark = "<i class='checkmark icon'></i>";
  4559. }
  4560. addContextMenuItem($("#subcontextmenu"), lcontex("Small"), smallCheckmark, "setDesktopIconSize", false, {payload: "small"});
  4561. addContextMenuItem($("#subcontextmenu"), lcontex("Medium"), mediumCheckmark, "setDesktopIconSize", false, {payload: "medium"});
  4562. addContextMenuItem($("#subcontextmenu"), lcontex("Big"), bigCheckmark, "setDesktopIconSize", false, {payload: "big"});
  4563. showSubContextMenu(target);
  4564. }
  4565. function setDesktopIconSize(target, evt) {
  4566. var targetSize = $(target).attr("payload");
  4567. targetSize = JSON.parse(decodeURIComponent(targetSize));
  4568. if (["small", "medium", "big"].includes(targetSize)) {
  4569. desktopIconSize = targetSize;
  4570. }
  4571. refresh();
  4572. setStorage("iconsize", desktopIconSize);
  4573. hideAllContextMenus();
  4574. }
  4575. function addContextMenuSeperator(target) {
  4576. $(target).append(`<div class="divider"></div>`);
  4577. }
  4578. function addContextMenuTitle(target, title){
  4579. $(target).append(`<div class="header">
  4580. ${title}
  4581. </div>`);
  4582. }
  4583. function downloadURL() {
  4584. alert("WIP");
  4585. hideAllContextMenus();
  4586. }
  4587. function background(target, evt) {
  4588. $("#subcontextmenu").html('<div class="item"><i class="loading spinning icon"></i> Loading</div>');
  4589. $.get("system/desktop/theme", function(data) {
  4590. $("#subcontextmenu").html("");
  4591. for (var i = 0; i < data.length; i++) {
  4592. if (currentUserTheme == data[i].Theme) {
  4593. addContextMenuItem($("#subcontextmenu"), data[i].Theme, "<i class='checkmark icon'></i>", "setTheme", false);
  4594. } else {
  4595. addContextMenuItem($("#subcontextmenu"), data[i].Theme, undefined, "setTheme", false);
  4596. }
  4597. }
  4598. });
  4599. showSubContextMenu(target);
  4600. }
  4601. //Set theme from button click
  4602. function setTheme(target, evt) {
  4603. var theme = $(target).text().trim();
  4604. setDesktopTheme(theme);
  4605. hideAllContextMenus();
  4606. }
  4607. function personalization() {
  4608. //Show the personalization window
  4609. newFloatWindow({
  4610. url: "SystemAO/desktop/personalization.html",
  4611. appicon: "SystemAO/desktop/img/personalization.png",
  4612. width:640,
  4613. height:480,
  4614. title: "Personalization"
  4615. });
  4616. hideAllContextMenus();
  4617. }
  4618. //New folder on the menu start location
  4619. function newfolder(object, event) {
  4620. var closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4621. let closestPixelLocation = closestLocation[0];
  4622. let closestGridIndexLocation = closestLocation[1];
  4623. //Generate new foldername
  4624. var newFolderName = "New Folder";
  4625. var counter = 1;
  4626. while (desktopFileList.includes(newFolderName)) {
  4627. newFolderName = `New Folder(${counter})`;
  4628. counter++;
  4629. }
  4630. //Check if there are already another object at that locaton
  4631. var duplicateObject = getObjectFromLocation(closestPixelLocation[0], closestPixelLocation[1]);
  4632. var createObjectLocation = true;
  4633. if (duplicateObject !== undefined) {
  4634. //Ignore create position. Let it settle on next new slot.
  4635. createObjectLocation = false;
  4636. }
  4637. //Create the folder
  4638. requestCSRFToken(function(token){
  4639. $.post("system/file_system/newItem", {
  4640. type: "folder",
  4641. src: "user:/Desktop/",
  4642. filename: newFolderName,
  4643. csrft: token
  4644. }).done(function(data) {
  4645. if (data.error !== undefined) {
  4646. alert(data.error);
  4647. } else {
  4648. if (createObjectLocation) {
  4649. setIconDesktopLocation(newFolderName, closestGridIndexLocation[0], closestGridIndexLocation[1], function() {
  4650. //After set Desktop icon, refresh the page
  4651. refresh(function() {
  4652. //After refresh the page, highlight the new folder and set it to rename mode
  4653. var targetFolderObject = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  4654. console.log(targetFolderObject);
  4655. enableRenameOnLaunchIconObject(targetFolderObject);
  4656. });
  4657. });
  4658. }
  4659. }
  4660. });
  4661. });
  4662. /*
  4663. //Open new folder creation window
  4664. var existsingFileList = [];
  4665. for (var i =0; i < desktopFileList.length; i++){
  4666. existsingFileList.push({
  4667. filename: desktopFileList[i],
  4668. filepath: "user:/Desktop/" + desktopFileList[i]
  4669. });
  4670. }
  4671. newFloatWindow({
  4672. url: "SystemAO/file_system/newFolder.html#" + encodeURIComponent(JSON.stringify(existsingFileList)),
  4673. appicon: "SystemAO/file_system/img/new folder.png",
  4674. width:560,
  4675. height:340,
  4676. title: "New Folder"
  4677. });
  4678. */
  4679. hideAllContextMenus();
  4680. }
  4681. function enableRenameOnLaunchIconObject(object) {
  4682. renameMode = true;
  4683. $(".launchIcon").attr("draggable", "false");
  4684. var filedata = JSON.parse(decodeURIComponent($(object).attr("filedata")));
  4685. var originalName = filedata.Filename;
  4686. if (filedata.IsShortcut){
  4687. //Shortcut. Use its display name instead
  4688. originalName = filedata.ShortcutName;
  4689. }
  4690. $(object).find(".launchIconText").hide();
  4691. $(object).append(`<textarea class="renameInput ${desktopIconSize}" type="text" onkeydown="handleRenameKeydown(event);" ondragstart="return false;" dblclick="event.stopImmediatePropagation(); event.stopImmediatePropagation();"maxlength="32">${originalName}</textarea>`);
  4692. $(object).find(".renameInput")[0].select();
  4693. var index = originalName.lastIndexOf(".");
  4694. console.log(index);
  4695. if( index >= 0){
  4696. $(object).find(".renameInput")[0].setSelectionRange(0, index);
  4697. }
  4698. //Updates 4-5-2021: Added IME support on rename input
  4699. $(object).find(".renameInput")[0].addEventListener("keydown", function(event){
  4700. if (window.ime && window.ime.handler != null){
  4701. window.ime.handler(event);
  4702. }else{
  4703. //No IME handler. Just continue the input
  4704. }
  4705. });
  4706. window.ime.focus = $(object).find(".renameInput")[0];
  4707. }
  4708. //Handle enter keypress on the rename textarea
  4709. function handleRenameKeydown(e){
  4710. if (e.keyCode == 13){
  4711. //Enter pressed
  4712. e.preventDefault();
  4713. exitRenameMode();
  4714. }
  4715. }
  4716. function exitRenameMode() {
  4717. if (renameMode) {
  4718. $(".launchIcon").attr("draggable", "true");
  4719. $(".launchIcon").find(".launchIconText").show();
  4720. //Update the folder to textarea content
  4721. $(".renameInput").each(function() {
  4722. if ($(this).text() == "") {
  4723. //Ignore this update
  4724. } else {
  4725. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4726. var filepath = filedata.Filepath;
  4727. var newFilename = $(this).val();
  4728. if (filedata.IsShortcut == true){
  4729. //Shortcut. Edit the shortcut content name
  4730. let currentInputTextArea = $(this);
  4731. $.ajax({
  4732. url: "/system/desktop/opr/renameShortcut",
  4733. data: {src: filepath, new: newFilename},
  4734. success: function(data){
  4735. if (data.error !== undefined){
  4736. //Cancel the operation
  4737. console.log("*ERROR* " + data.error);
  4738. currentInputTextArea.remove();
  4739. }else{
  4740. //No need to update the shortcut position (as its name not changed)
  4741. refresh(function() {
  4742. //Refresh the desktop
  4743. });
  4744. }
  4745. }
  4746. })
  4747. }else{
  4748. //Normal typed files / folder. Rename the object
  4749. let currentInputTextArea = $(this);
  4750. //Check if new filename is identaical to the old filename
  4751. var originalFilename = $(this).parent().attr("filename");
  4752. console.log("Launch Icon object", $(this).parent());
  4753. if (newFilename == originalFilename){
  4754. //Filename has no changes
  4755. currentInputTextArea.remove();
  4756. return;
  4757. }
  4758. generateCSRFToken(function(csrftoken){
  4759. $.ajax({
  4760. url: "./system/file_system/fileOpr",
  4761. method: "POST",
  4762. data: {opr: "rename", src: JSON.stringify([filepath]), new: JSON.stringify([newFilename]), csrft: csrftoken},
  4763. success: function(data){
  4764. if (data.error !== undefined){
  4765. //Cancel the operation
  4766. alert(data.error);
  4767. console.log("*ERROR* " + data.error);
  4768. currentInputTextArea.remove();
  4769. }else{
  4770. //Update the new file position
  4771. let closestLocation = findClosestGrid($(currentInputTextArea).parent().offset().left, $(currentInputTextArea).parent().offset().top);
  4772. let closestGridIndexLocation = closestLocation[1];
  4773. setIconDesktopLocation(newFilename, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4774. //Callback after setting location
  4775. refresh(function() {
  4776. //Refresh the desktop
  4777. });
  4778. });
  4779. }
  4780. }
  4781. });
  4782. });
  4783. }
  4784. }
  4785. });
  4786. renameMode = false;
  4787. }
  4788. }
  4789. //Handle opening shortcut folder location
  4790. function handleShortcutFolderOpen(object, event){
  4791. var openPendingFolders = [];
  4792. $(".launchIconWrapper.selected").each(function(){
  4793. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4794. console.log(filedata);
  4795. if (filedata.IsShortcut == true){
  4796. if (filedata.ShortcutType == "folder"){
  4797. openPendingFolders.push(filedata.ShortcutPath);
  4798. }else if (filedata.ShortcutType == "module"){
  4799. openPendingFolders.push("web:/" + filedata.ShortcutPath);
  4800. }
  4801. }
  4802. });
  4803. //Open all folders
  4804. openPendingFolders.forEach(folder => {
  4805. newFloatWindow({
  4806. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(folder),
  4807. appicon: "SystemAO/file_system/img/small_icon.png",
  4808. width:1080,
  4809. height:580,
  4810. title: "File Manager"
  4811. });
  4812. })
  4813. hideAllContextMenus();
  4814. }
  4815. //Handle basic desktop file operations
  4816. function handleFileDelete(object, event){
  4817. var deleteFileList = [];
  4818. $(".launchIconWrapper.selected").each(function(){
  4819. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4820. deleteFileList.push(filedata.Filepath);
  4821. });
  4822. console.log(deleteFileList);
  4823. generateCSRFToken(function(csrftoken){
  4824. $.ajax({
  4825. url: "system/file_system/fileOpr",
  4826. method:"POST",
  4827. data: {opr: "recycle", src: JSON.stringify(deleteFileList), csrft: csrftoken},
  4828. success: function(data){
  4829. if (data.error !== undefined){
  4830. alert(data.error);
  4831. }else{
  4832. refresh(undefined, true);
  4833. }
  4834. }
  4835. });
  4836. hideAllContextMenus();
  4837. });
  4838. }
  4839. //File Rename
  4840. let renamingItems = [];
  4841. function handleRename(object, event){
  4842. if ($('.launchIconWrapper.selected').length > 0){
  4843. //Enter rename mode
  4844. renamingItems = $('.launchIconWrapper.selected');
  4845. let renameTarget = $('.launchIconWrapper.selected')[0]
  4846. let fileObject = $(renameTarget).parent();
  4847. enableRenameOnLaunchIconObject(fileObject);
  4848. }
  4849. hideAllContextMenus();
  4850. }
  4851. //New item menus.
  4852. function newitemmenu(target, event) {
  4853. $("#subcontextmenu").html("");
  4854. //Append the new folder option first
  4855. addContextMenuItem($("#subcontextmenu"), lcontex('Folder'), "<i class='folder icon'></i>", "newfolder", true);
  4856. addContextMenuItem($("#subcontextmenu"), lcontex('Shortcut'), "<i class='external icon'></i>", "newshortcut", true);
  4857. addContextMenuItem($("#subcontextmenu"), lcontex('Upload'), "<i class='cloud upload icon'></i>", "upload", true);
  4858. addContextMenuSeperator($("#subcontextmenu"));
  4859. requestCSRFToken(function(token){
  4860. $.ajax({
  4861. url: "system/file_system/newItem",
  4862. data: {csrft: token},
  4863. success: function(data){
  4864. for (var i = 0; i < data.length; i++) {
  4865. var thisNewFile = data[i];
  4866. var icon = ao_module_utils.getIconFromExt(thisNewFile.Ext);
  4867. addContextMenuItem($("#subcontextmenu"), `<i class="${icon} icon" ext="${thisNewFile.Ext}"></i> ${thisNewFile.Desc}`, undefined, "newitem");
  4868. }
  4869. //Show sub-context menu
  4870. showSubContextMenu(target);
  4871. }
  4872. })
  4873. });
  4874. }
  4875. function showSubContextMenu(target) {
  4876. $("#subcontextmenu").show();
  4877. var targetLeft = $("#contextmenu").offset().left + $("#contextmenu").width() + 2;
  4878. var targetTop = $(target).offset().top - 1;
  4879. if (targetLeft + $("#subcontextmenu").width() > window.innerWidth){
  4880. //Overflow. Swtich to the left side of the menu
  4881. targetLeft = $("#contextmenu").offset().left - $("#subcontextmenu").width() - 2;
  4882. }
  4883. $("#subcontextmenu").css({
  4884. left: targetLeft,
  4885. top: targetTop
  4886. });
  4887. }
  4888. //Create new file item with that filename
  4889. function newitem(object, event) {
  4890. var extension = $(object).find("i").attr("ext");
  4891. //Generate a newfile name
  4892. var newfn = "NewFile" + "." + extension;
  4893. var counter = 1;
  4894. while (desktopFileList.includes(newfn)){
  4895. newfn = "NewFile (" + counter + ")." + extension;
  4896. counter++;
  4897. }
  4898. //Get the location position
  4899. let closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4900. let closestGridIndexLocation = closestLocation[1];
  4901. //Request backend to generate the new file
  4902. generateCSRFToken(function(token){
  4903. $.ajax({
  4904. url: "system/file_system/newItem",
  4905. data: {type: "file",src: "user:/Desktop/",filename: newfn, csrft: token},
  4906. success: function(data){
  4907. if (data.error !== undefined){
  4908. alert(data.error);
  4909. }else{
  4910. //Set the icon location
  4911. setIconDesktopLocation(newfn, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4912. //Refresh the desktop
  4913. refresh(function(){
  4914. var targetNewFile = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  4915. console.log("Renaming ", targetNewFile);
  4916. enableRenameOnLaunchIconObject(targetNewFile);
  4917. });
  4918. });
  4919. }
  4920. }
  4921. });
  4922. });
  4923. hideAllContextMenus();
  4924. }
  4925. document.getElementById("volumebar").parentNode.addEventListener("touchstart", function(e){
  4926. updateVolume( document.getElementById("volumebar").parentNode, e);
  4927. });
  4928. document.getElementById("brightnessbar").parentNode.addEventListener("touchstart", function(e){
  4929. updateBrightness( document.getElementById("brightnessbar").parentNode, e);
  4930. });
  4931. function getCoordinateFromEvent(e){
  4932. var x = -1;
  4933. var y = -1;
  4934. if (e.originalEvent == undefined){
  4935. e.originalEvent = e;
  4936. }
  4937. if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){
  4938. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  4939. x = touch.pageX;
  4940. y = touch.pageY;
  4941. } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
  4942. x = e.clientX;
  4943. y = e.clientY;
  4944. }else{
  4945. x = e.clientX;
  4946. y = e.clientY;
  4947. }
  4948. return [x,y];
  4949. }
  4950. function updateVolume(object, event){
  4951. var width = $(object).width();
  4952. var left = $(object).offset().left;
  4953. var clickPosition = getCoordinateFromEvent(event)[0];
  4954. var clickRel = clickPosition - left;
  4955. var percentage = clickRel / width * 100;
  4956. if (percentage < 0){
  4957. percentage = 0;
  4958. }else if (percentage > 100){
  4959. percentage = 100;
  4960. }
  4961. //Update the global volume
  4962. $(object).find(".bar").css("width",percentage + "%");
  4963. localStorage.setItem("global_volume", clickRel / width);
  4964. }
  4965. //Update screen brightness, for those who use ArozOS on their TV
  4966. function updateBrightness(object, event){
  4967. var width = $(object).width();
  4968. var left = $(object).offset().left;
  4969. var clickPosition = getCoordinateFromEvent(event)[0];
  4970. var clickRel = clickPosition - left;
  4971. var percentage = clickRel / width * 100;
  4972. if (percentage < 0){
  4973. percentage = 0;
  4974. }else if (percentage > 100){
  4975. percentage = 100;
  4976. }
  4977. //Min is 3%
  4978. if (percentage < 3){
  4979. percentage = 3;
  4980. }
  4981. //Set body brightness filter
  4982. $("body").css("filter", `brightness(${percentage}%)`);
  4983. //Save changes to localStorage
  4984. currentBrightness = percentage;
  4985. $(object).find(".bar").css("width",percentage + "%");
  4986. localStorage.setItem("brightness", clickRel / width);
  4987. }
  4988. function refresh(callback = undefined, noflash=false) {
  4989. //Refresh desktop contents
  4990. let launchOption = {};
  4991. if (noflash){
  4992. launchOption = {
  4993. noflash: true
  4994. };
  4995. }
  4996. if (callback == undefined) {
  4997. initDesktopFiles(launchOption, function(){
  4998. startThumbnailLoader();
  4999. attachDescriptionBoxEvents();
  5000. });
  5001. } else {
  5002. initDesktopFiles(launchOption, function(){
  5003. startThumbnailLoader();
  5004. attachDescriptionBoxEvents();
  5005. callback()
  5006. });
  5007. }
  5008. hideAllContextMenus();
  5009. }
  5010. function startThumbnailLoader(){
  5011. let path = "user:/Desktop";
  5012. let protocol = "wss://";
  5013. if (location.protocol !== 'https:') {
  5014. protocol = "ws://";
  5015. }
  5016. var port = window.location.port;
  5017. if (window.location.port == ""){
  5018. if (location.protocol !== 'https:') {
  5019. port = "80";
  5020. }else{
  5021. port = "443";
  5022. }
  5023. }
  5024. thumbRenderWebSocket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/handleCacheRender?folder=" + path);
  5025. thumbRenderWebSocket.onopen = function(e) {
  5026. };
  5027. thumbRenderWebSocket.onmessage = function(event) {
  5028. //Find the correct file in the current directory and place its image
  5029. let thumbData = JSON.parse(event.data);
  5030. $(".launchIcon").each(function(){
  5031. if (thumbData[1].length > 0){
  5032. if ($(this).attr("filename") == thumbData[0]){
  5033. let imageContainer = $(this).find(".launchIconImage");
  5034. imageContainer.attr("src","data:image/jpg;base64," + thumbData[1]);
  5035. imageContainer.css("padding", "0.6em");
  5036. //Load the application icon on this file
  5037. let filedata = $(this).attr("filedata");
  5038. if (filedata == undefined){
  5039. return;
  5040. }
  5041. filedata = JSON.parse(decodeURIComponent(filedata));
  5042. $.ajax({
  5043. url: "system/modules/getDefault",
  5044. data: {opr: "launch", ext: filedata.Ext},
  5045. method: "GET",
  5046. success: function(data){
  5047. if (data.error == undefined){
  5048. let iconSize = 20;
  5049. let topOffset = $(imageContainer).height() - iconSize/2 + 2;
  5050. $(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>`);
  5051. }
  5052. }
  5053. });
  5054. }
  5055. }
  5056. });
  5057. };
  5058. thumbRenderWebSocket.onclose = function(event) {
  5059. //Transfer ended
  5060. };
  5061. thumbRenderWebSocket.onerror = function(error) {
  5062. console.log("Cannot connect to WebSocket cache renderer. Falling back to AJAX request");
  5063. startFallbackThumbnailLoader();
  5064. };
  5065. }
  5066. function startFallbackThumbnailLoader(){
  5067. $(".launchIcon").each(function(){
  5068. let fd = JSON.parse(decodeURIComponent($(this).attr("filedata")))
  5069. let filepath = fd.Filepath;
  5070. let targetDOM = $(this);
  5071. $.ajax({
  5072. url: "system/file_system/loadThumbnail",
  5073. data: {vpath: filepath},
  5074. success: function(data){
  5075. if (data.error == undefined && data != undefined && data != ""){
  5076. let imageContainer = $(targetDOM).find(".launchIconImage");
  5077. imageContainer.attr("src","data:image/jpg;base64," + data);
  5078. imageContainer.css("padding", "0.6em");
  5079. $.ajax({
  5080. url: "system/modules/getDefault",
  5081. data: {opr: "launch", ext: fd.Ext},
  5082. method: "GET",
  5083. success: function(data){
  5084. if (data.error == undefined){
  5085. let iconSize = 20;
  5086. let topOffset = $(imageContainer).height() - iconSize/2 + 2;
  5087. $(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>`);
  5088. }
  5089. }
  5090. });
  5091. }
  5092. }
  5093. })
  5094. });
  5095. }
  5096. function openfm() {
  5097. //Open file explorer on desktop
  5098. newFloatWindow({
  5099. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent("user:/Desktop"),
  5100. appicon: "SystemAO/file_system/img/small_icon.png",
  5101. width: 1080,
  5102. height: 580,
  5103. title: "File Manager"
  5104. });
  5105. hideAllContextMenus();
  5106. }
  5107. /*
  5108. Notification and Notification bar related functions
  5109. Usage:
  5110. title -> The title of the notification
  5111. content -> The content of the notification
  5112. icon (optional) -> The icon of the notification
  5113. windowOpenOption (optional) -> The window opening option for user onclick redirection
  5114. */
  5115. function sendNotification(title, content, icon="notice circle", windowOpenOption=null){
  5116. if (content.length > 100){
  5117. shortenContent = content.substring(0,100) + "...";
  5118. }else{
  5119. shortenContent = content;
  5120. }
  5121. onClickOpenWindowOption = encodeURIComponent(JSON.parse(windowOpenOption));
  5122. $("#notificationlist").append(` <div class="notification object" originalcontent="${content}" redirect="${onClickOpenWindowOption}" onclick="openNotification(this);">
  5123. <p class="title"><i class="${icon} icon"></i> ${title}</p>
  5124. <p class="notifycontent">${shortenContent}</p>
  5125. <div class="closebtn" onclick="event.stopImmediatePropagation(); closeThisNotification(this);"><i class="remove icon"></i></div>
  5126. <div class="ts divider"></div>
  5127. </div>`);
  5128. $(".nonotification").hide();
  5129. }
  5130. function openNotification(obj){
  5131. newWindowOpeningOption = JSON.parse(decodeURIComponent($(obj).attr("redirect")));
  5132. if (newWindowOpeningOption == null){
  5133. //Ignore
  5134. }else{
  5135. //Start a floatWindow to the given target
  5136. newFloatWindow(newWindowOpeningOption);
  5137. }
  5138. //Clear the notiication
  5139. closeThisNotification($(obj).find(".closebtn"));
  5140. }
  5141. function closeThisNotification(obj){
  5142. $(obj).parent().slideUp("fast",function(data){
  5143. $(this).remove();
  5144. if ($(".notification.object").length == 0){
  5145. $(".nonotification").show();
  5146. }
  5147. });
  5148. }
  5149. function clearAllNotification(){
  5150. $(".notification.object").slideUp('fast',function(data){
  5151. $(this).remove();
  5152. $(".nonotification").show();
  5153. });
  5154. }
  5155. function hideAllContextMenus() {
  5156. $("#subcontextmenu").hide();
  5157. $("#contextmenu").hide()
  5158. $("#quickAccessPanel").slideUp("fast");
  5159. }
  5160. function restart(){
  5161. if (!hardwareman){
  5162. return
  5163. }
  5164. var apiObject = {
  5165. api: "/system/power/restart",
  5166. data: {},
  5167. title: applocale.getString("power/restart/text", "Password Required"),
  5168. desc: applocale.getString("power/restart/instruction", "for restarting the ArozOS Host"),
  5169. thisuser: true, //This username as default, set to false for entering other user
  5170. method: "GET"
  5171. }
  5172. apiObject = encodeURIComponent(JSON.stringify(apiObject));
  5173. newFloatWindow({
  5174. url: "SystemAO/security/authreq.html#" + apiObject,
  5175. width: 480,
  5176. height: 300,
  5177. appicon: "SystemAO/security/img/lock.svg",
  5178. title: applocale.getString("power/restart/title", "Restart - Authentication Required"),
  5179. parent: ao_module_windowID,
  5180. callback: "handleRestartCallback"
  5181. });
  5182. }
  5183. function shutdown(){
  5184. if (!hardwareman){
  5185. return
  5186. }
  5187. var apiObject = {
  5188. api: "system/power/shutdown",
  5189. data: {},
  5190. title: `<i class='red exclamation triangle icon'></i> ${applocale.getString("power/shutdown/text", "Shutdown Host")} <i class='red exclamation triangle icon'></i>`,
  5191. desc: applocale.getString("power/shutdown/instruction", "Please enter your password to confirm operation."),
  5192. thisuser: true, //This username as default, set to false for entering other user
  5193. method: "GET",
  5194. success: "SystemAO/boot/shutdown.html" //Success redirection
  5195. }
  5196. apiObject = encodeURIComponent(JSON.stringify(apiObject));
  5197. newFloatWindow({
  5198. url: "SystemAO/security/authreq.html#" + apiObject,
  5199. width: 480,
  5200. height: 300,
  5201. appicon: "SystemAO/security/img/lock.svg",
  5202. title: applocale.getString("power/shutdown/title", "Shutdown - Authentication Required"),
  5203. parent: ao_module_windowID,
  5204. callback: "handleShutdownCallback"
  5205. });
  5206. }
  5207. //Check if this server is a low memory one
  5208. function initUploadMode(){
  5209. $.ajax({
  5210. url: "system/info/getRAMinfo",
  5211. success: function(data){
  5212. if (data.error !== undefined){
  5213. //Permission denied or other reasons that cannot access harwdare info. Use default mode
  5214. lowMemoryMode = true;
  5215. }else{
  5216. //Check if ramsize > 1.8 GB (2GB). If yes, switch to large memory upload mode
  5217. var memsize = JSON.parse(data);
  5218. if (parseFloat(memsize)/ 1024 / 1024 / 1024 >= 3.8){
  5219. console.log("%c[Desktop] Setting upload mode to large memory mode", 'color: #2ba16e');
  5220. lowMemoryMode = false;
  5221. }
  5222. }
  5223. },
  5224. error: function(){
  5225. //Hardware mode disabled. Always use low memory upload mode instead
  5226. lowMemoryMode = true;
  5227. }
  5228. });
  5229. }
  5230. //Generate a loading icon for this upload task
  5231. function generateUploadingIcon(filename, position){
  5232. //Get position for appending
  5233. var onScreenLocation = getLocationFromGridIndex(position[0], position[1]);
  5234. //Append to UI
  5235. var uploadIconUUID = Date.now();
  5236. $("#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;">
  5237. <span class="launchIconWrapper">
  5238. <img class="launchIconImage medium" src="img/desktop/files_icon/${desktopIconPack}/file upload.png" draggable="false">
  5239. <p class="launchIconText ${desktopIconSize}" >${applocale.getString( "upload/message/uploading", "Uploading")}</p>
  5240. <div class="ts tiny primary progress" style="margin-top: -4px;">
  5241. <div class="bar" style="min-width: 0px !important; width: 0%;"></div>
  5242. </div>
  5243. </span>
  5244. </div>`);
  5245. return uploadIconUUID;
  5246. }
  5247. function upload(){
  5248. var input = document.createElement('input');
  5249. input.type = 'file';
  5250. input.multiple = true;
  5251. input.onchange = e => {
  5252. var files = e.target.files;
  5253. for (var i = 0; i < files.length; i++){
  5254. uploadFile(files[i], function(){
  5255. refresh(undefined, true);
  5256. });
  5257. }
  5258. }
  5259. input.click();
  5260. hideAllContextMenus();
  5261. }
  5262. function uploadFile(file, callback=undefined, uploadingIconUUID = undefined) {
  5263. if (lowMemoryMode){
  5264. /*
  5265. Low Memory Upload Mode
  5266. */
  5267. var filename = encodeURIComponent(file.name);
  5268. var filesize = file.size;
  5269. //Open the websocket
  5270. let path = "user:/Desktop";
  5271. let protocol = "wss://";
  5272. if (location.protocol !== 'https:') {
  5273. protocol = "ws://";
  5274. }
  5275. var port = window.location.port;
  5276. if (window.location.port == ""){
  5277. if (location.protocol !== 'https:') {
  5278. port = "80";
  5279. }else{
  5280. port = "443";
  5281. }
  5282. }
  5283. let uploadDir = "user:/Desktop";
  5284. //Fixing Firefox path issues on or above FF48.0
  5285. if (isFirefox && file.webkitRelativePath != ""){
  5286. //Use the webkitRelativePath instead of the name, this is a folder upload
  5287. let pathinfo = file.webkitRelativePath.split("/");
  5288. pathinfo.pop();
  5289. let subpath = pathinfo.join("/");
  5290. uploadDir = uploadDir + subpath;
  5291. }
  5292. let socket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/lowmemUpload?filename=" + filename + "&path=" + uploadDir);
  5293. let currentSendingIndex = 0;
  5294. let chunks = Math.ceil(file.size/uploadFileChunkSize,uploadFileChunkSize);
  5295. //Define a function for sending a particular chunk
  5296. function sendChunk(id, uploadingIconUUID){
  5297. let offsetStart = id*uploadFileChunkSize;
  5298. let offsetEnd = id*uploadFileChunkSize + uploadFileChunkSize;
  5299. let thisblob = file.slice(offsetStart,offsetEnd);
  5300. socket.send(thisblob);
  5301. //console.log(id + "/" + chunks);
  5302. //Update progress to first percentage
  5303. let progress = id / (chunks-1) * 100.0;
  5304. if (progress > 100){
  5305. progress = 100;
  5306. }
  5307. if (uploadingIconUUID != undefined){
  5308. //Update the progress on the object
  5309. $("." + uploadingIconUUID + ".launchIcon").find(".bar").css("width", progress + "%");
  5310. if (progress == 100){
  5311. $("." + uploadingIconUUID + ".launchIcon").find(".progress").addClass("indeterminate");
  5312. }
  5313. }
  5314. }
  5315. //Start sending
  5316. socket.onopen = function(e) {
  5317. if (filesize < uploadFileChunkSize){
  5318. //This file is smaller than chunk size, set it to somwhere within 10% - 20% so it doesn't look like it is stuck
  5319. $("." + uploadingIconUUID + ".launchIcon").find(".bar").css("width", "15%");
  5320. }
  5321. //Send the first chunk
  5322. sendChunk(0, uploadingIconUUID);
  5323. currentSendingIndex++;
  5324. };
  5325. socket.onmessage = function(event) {
  5326. //Append to the send index
  5327. var incomingValue = event.data;
  5328. if (incomingValue == "next"){
  5329. if (currentSendingIndex == chunks + 1){
  5330. //Already finished
  5331. socket.send("done");
  5332. }else{
  5333. //Send next chunk
  5334. sendChunk(currentSendingIndex, uploadingIconUUID);
  5335. currentSendingIndex++;
  5336. }
  5337. }else if (incomingValue == "OK"){
  5338. //Merge completed
  5339. }else{
  5340. //Try to parse it as JSON
  5341. try{
  5342. var resp = JSON.parse(incomingValue.split('\\' + '"').join("\""));
  5343. console.log(resp);
  5344. if (resp.error !== undefined){
  5345. //This is an error message
  5346. sendNotification("Upload Failed", resp.error, "remove")
  5347. //Update the progress bar to error
  5348. $("." + uploadingIconUUID + ".launchIcon").find(".progress").removeClass("primary").addClass("error");
  5349. $("." + uploadingIconUUID + ".launchIcon").find(".launchIconText").text(applocale.getString("upload/message/failed", "Failed!"));
  5350. setTimeout(function(){
  5351. $("." + uploadingIconUUID + ".launchIcon").fadeOut(3000,function() { $(this).remove(); });
  5352. }, 2000);
  5353. }
  5354. }catch(ex){
  5355. //Something else
  5356. console.log(incomingValue);
  5357. console.log(ex);
  5358. }
  5359. }
  5360. };
  5361. socket.onclose = function(event) {
  5362. $("." + uploadingIconUUID).remove();
  5363. if (callback != undefined){
  5364. callback();
  5365. }
  5366. };
  5367. socket.onerror = function(error) {
  5368. console.log(error.message);
  5369. console.log("[Desktop] Unable to open WebSocket connection. Fall back to FORM POST upload mode. (Check your nginx / reverse proxy settings!!!)")
  5370. //Try to fallback to FORM POST upload mode
  5371. lowMemoryMode = false;
  5372. uploadFile(thisFile, callback)
  5373. return
  5374. };
  5375. }else{
  5376. let url = 'system/file_system/upload'
  5377. let uploadCurrentPath = "user:/Desktop/";
  5378. let formData = new FormData();
  5379. let xhr = new XMLHttpRequest();
  5380. formData.append('file', file);
  5381. formData.append('path', uploadCurrentPath);
  5382. xhr.open('POST', url, true)
  5383. xhr.upload.addEventListener("progress", function(e) {
  5384. console.log((e.loaded * 100.0 / e.total) || 100)
  5385. var progress = (e.loaded * 100.0 / e.total) || 100;
  5386. if (uploadingIconUUID != undefined){
  5387. //Update the progress on the object
  5388. $("." + uploadingIconUUID + ".launchIcon").find(".bar").css("width", progress + "%");
  5389. if (progress == 100){
  5390. $("." + uploadingIconUUID + ".launchIcon").find(".progress").addClass("indeterminate");
  5391. }
  5392. }
  5393. })
  5394. xhr.addEventListener('readystatechange', function(e) {
  5395. if (xhr.readyState == 4 && xhr.status == 200) {
  5396. //Upload Succ
  5397. $("." + uploadingIconUUID).remove();
  5398. if (callback !== undefined){
  5399. callback(e.target.response);
  5400. }
  5401. }
  5402. else if (xhr.readyState == 4 && xhr.status != 200) {
  5403. console.log("Upload failed :" + xhr.status);
  5404. //Set upload progress bar to error
  5405. $("." + uploadingIconUUID + ".launchIcon").find(".progress").removeClass("primary").addClass("error");
  5406. $("." + uploadingIconUUID + ".launchIcon").find(".launchIconText").text(applocale.getString("upload/message/failed", "Failed!"));
  5407. setTimeout(function(){
  5408. $("." + uploadingIconUUID + ".launchIcon").fadeOut(3000,function() { $(this).remove(); });
  5409. }, 2000);
  5410. }
  5411. })
  5412. xhr.send(formData);
  5413. }
  5414. }
  5415. function setStorage(key, value, callback = undefined) {
  5416. $.get("system/desktop/preference?preference=" + key + "&value=" + value, function(data) {
  5417. if (data.error !== undefined) {
  5418. console.log(data.error);
  5419. } else {
  5420. if (callback !== undefined) {
  5421. callback();
  5422. }
  5423. }
  5424. });
  5425. }
  5426. function getStorage(key, callback) {
  5427. $.get("system/desktop/preference?preference=" + key, callback);
  5428. }
  5429. function showSystemSettings(){
  5430. var hasAccessToSetting = false;
  5431. moduleInstalled.forEach(thismod => {
  5432. if (thismod.Name == "System Setting"){
  5433. openModule("System Setting");
  5434. }
  5435. })
  5436. }
  5437. function initTheme(targetTheme=undefined){
  5438. if (targetTheme == undefined){
  5439. $.get("system/file_system/preference?key=file_explorer/theme", function(data){
  5440. if (data == "darkTheme"){
  5441. setDarkTheme();
  5442. }
  5443. });
  5444. }else{
  5445. //Manual override mode
  5446. if (targetTheme == "darkTheme"){
  5447. setDarkTheme();
  5448. }else if (targetTheme == "whiteTheme"){
  5449. setWhiteTheme();
  5450. }
  5451. }
  5452. }
  5453. function setFloatWindowTheme(fwid, theme="dark"){
  5454. var targetFW = getFloatWindowByID(fwid);
  5455. if (theme == "dark"){
  5456. $(targetFW).removeClass("white");
  5457. }else if (theme == "white"){
  5458. $(targetFW).addClass("white");
  5459. }
  5460. }
  5461. function checkFileSystemAccess(){
  5462. var allowReadWrite = false;
  5463. moduleInstalled.forEach(thisModule => {
  5464. if (thisModule.Name == "File Manager"){
  5465. //This user has read write access to file system
  5466. allowReadWrite = true;
  5467. }
  5468. });
  5469. if (!allowReadWrite){
  5470. 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."));
  5471. }
  5472. }
  5473. function setDarkTheme(){
  5474. $("#listMenu").addClass("darkTheme");
  5475. $("#powerIcon").attr("src","img/system/power-white.svg");
  5476. $("#quickAccessPanel").addClass("darkTheme");
  5477. $("#quickAccessPanel").find(".button").addClass("inverted");
  5478. }
  5479. function setWhiteTheme(){
  5480. $("#listMenu").removeClass("darkTheme");
  5481. $("#powerIcon").attr("src","img/system/power.svg");
  5482. $("#quickAccessPanel").removeClass("darkTheme");
  5483. $("#quickAccessPanel").find(".button").removeClass("inverted");
  5484. }
  5485. function hexToRgbA(hex, transparent=1){
  5486. var c;
  5487. if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
  5488. c= hex.substring(1).split('');
  5489. if(c.length== 3){
  5490. c= [c[0], c[0], c[1], c[1], c[2], c[2]];
  5491. }
  5492. c= '0x'+c.join('');
  5493. return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',' + transparent + ')';
  5494. }
  5495. throw new Error('Bad Hex');
  5496. }
  5497. function setThemeColor(newThemeColor){
  5498. //Update the global theme color
  5499. desktopThemeColor = newThemeColor;
  5500. //Update the related elements
  5501. $("#statusbar").css("background-color",newThemeColor);
  5502. $("#navimenu").css("background-color",hexToRgbA(newThemeColor, 0.5));
  5503. $(".floatWindow .controls").css("background-color",hexToRgbA(newThemeColor, 0.85));
  5504. //List menu theme color bar
  5505. $("#listMenu").find(".searchBar").css("border-bottom", "2px solid " + newThemeColor);
  5506. $("#volumebar").css("background-color", newThemeColor);
  5507. $("#brightnessbar").css("background-color", newThemeColor);
  5508. //Connection lost notification css
  5509. $("#connectionLost").find(".ts.card").css("background-color", hexToRgbA(newThemeColor, 0.5));
  5510. }
  5511. //Load the user define theme color to overwrite the default color if exists
  5512. function initUserDefinedThemeColor(){
  5513. $.ajax({
  5514. url: "system/file_system/preference",
  5515. data: {key: "themecolor"},
  5516. success: function(data){
  5517. if (data.error == undefined && data != ""){
  5518. setThemeColor(data);
  5519. }
  5520. }
  5521. });
  5522. }
  5523. //Float Window context menu
  5524. function getFocusedFloatWindowID(){
  5525. var targetFloatWindowId = "";
  5526. $(".floatWindow").each(function() {
  5527. var thisWindowZIndex = $(this).css("z-index");
  5528. if (parseInt(thisWindowZIndex) == 101){
  5529. targetFloatWindowId = $(this).attr("windowid");
  5530. }
  5531. });
  5532. return targetFloatWindowId;
  5533. }
  5534. function getFocusedFloatWindow(){
  5535. var focusedFwId = getFocusedFloatWindowID();
  5536. if (focusedFwId != ""){
  5537. var fw = getFloatWindowByID(focusedFwId);
  5538. return fw;
  5539. }else{
  5540. return undefined;
  5541. }
  5542. }
  5543. function refreshSelectedFloatWindow(target, event){
  5544. var fw = getFocusedFloatWindow();
  5545. if (fw != undefined){
  5546. $(fw).find("iframe")[0].contentWindow.location.reload();
  5547. }
  5548. hideAllContextMenus();
  5549. }
  5550. function maximizeSelectedFloatWindow(target, event){
  5551. var fw = getFocusedFloatWindow();
  5552. if (fw != undefined){
  5553. toggleMax($(fw).find(".buttons.maxtoggle"),event);
  5554. }
  5555. hideAllContextMenus();
  5556. }
  5557. function minimizeSelectedFloatWindow(target, event){
  5558. var fw = getFocusedFloatWindow();
  5559. if (fw != undefined){
  5560. min($(fw).find(".buttons.mintoggle"),event);
  5561. }
  5562. hideAllContextMenus();
  5563. }
  5564. function openSelectedFloatWindowInNewTab(){
  5565. var fw = getFocusedFloatWindow();
  5566. if (fw != undefined){
  5567. try{
  5568. var currentURL = $(fw).find("iframe")[0].contentWindow.location;
  5569. window.open(currentURL);
  5570. }catch(ex){
  5571. //Maybe CORS. Try to get it from window's parent properties
  5572. let parentURL = $(fw).attr("parent");
  5573. if (parentURL != undefined){
  5574. window.open(parentURL);
  5575. }else{
  5576. console.log("Unable to access iframe object")
  5577. }
  5578. }
  5579. }
  5580. hideAllContextMenus();
  5581. }
  5582. function closeSelectedFloatWindow(target, event){
  5583. var fw = getFocusedFloatWindow();
  5584. if (fw != undefined){
  5585. closeFloatWindow($(fw).find(".buttons.closetoggle"),event);
  5586. }
  5587. hideAllContextMenus();
  5588. }
  5589. function fullscreen() {
  5590. //Opening full screen will lead to hidden of all iframe for unknown reasons
  5591. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
  5592. (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
  5593. (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
  5594. (document.msFullscreenElement && document.msFullscreenElement !== null);
  5595. var elem = document.documentElement;
  5596. if (!isInFullScreen) {
  5597. if (elem.requestFullscreen) {
  5598. elem.requestFullscreen();
  5599. } else if (elem.mozRequestFullScreen) { /* Firefox */
  5600. elem.mozRequestFullScreen();
  5601. } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
  5602. elem.webkitRequestFullscreen();
  5603. } else if (elem.msRequestFullscreen) { /* IE/Edge */
  5604. elem.msRequestFullscreen();
  5605. }
  5606. } else {
  5607. if (document.exitFullscreen) {
  5608. document.exitFullscreen();
  5609. } else if (document.webkitExitFullscreen) {
  5610. document.webkitExitFullscreen();
  5611. } else if (document.mozCancelFullScreen) {
  5612. document.mozCancelFullScreen();
  5613. } else if (document.msExitFullscreen) {
  5614. document.msExitFullscreen();
  5615. }
  5616. }
  5617. hideAllContextMenus();
  5618. }
  5619. /*
  5620. var screenshotBuf = [];
  5621. var totalFloatWindowsLeft = 0;
  5622. function screenshot(){
  5623. totalFloatWindowsLeft = $(".floatWindow").length;
  5624. screenshotBuf = [];
  5625. //Get a screenshot from each floatWindow
  5626. $(".floatWindow").each(function(){
  5627. let contentWindow = $(this).find("iframe")[0].contentWindow;
  5628. let offsets = [$(this).find("iframe").offset().left, $(this).find("iframe").offset().top];
  5629. let thisWindowId = $(this).attr("windowid");
  5630. if (contentWindow.ao_module_screenshot){
  5631. contentWindow.ao_module_screenshot(function(capture){
  5632. screenshotBuf.push([thisWindowId,offsets,capture]);
  5633. totalFloatWindowsLeft--;
  5634. if (totalFloatWindowsLeft == 0){
  5635. //Merge the canvas
  5636. mergeScreenshotCanvas();
  5637. }
  5638. })
  5639. }else{
  5640. //Float window do not allow screenshot
  5641. }
  5642. });
  5643. if (totalFloatWindowsLeft == 0){
  5644. setTimeout(function(){
  5645. mergeScreenshotCanvas();
  5646. }, 500);
  5647. }
  5648. }
  5649. function mergeScreenshotCanvas(){
  5650. //Merge the screenshots
  5651. for (var i = 0; i < screenshotBuf.length; i++){
  5652. var thisWindowID = screenshotBuf[i][0];
  5653. var thisOffsets = screenshotBuf[i][1];
  5654. var thisCanvas = screenshotBuf[i][2];
  5655. var imgLink = thisCanvas.toDataURL();
  5656. //Overlay the iframe with image of screenshot
  5657. let targetFw = getFloatWindowByID(thisWindowID);
  5658. $(targetFw).find(".iframecover").append(`<img src="${imgLink}"/>`);
  5659. $(targetFw).find(".iframecover").show();
  5660. }
  5661. html2canvas(document.querySelector("body")).then(basecanvas => {
  5662. downloadCanvas(basecanvas);
  5663. //Clear up the mess
  5664. screenshotBuf.forEach(function(entry){
  5665. let targetFw = getFloatWindowByID(entry[0]);
  5666. $(targetFw).find(".iframecover").html("");
  5667. $(targetFw).find(".iframecover").hide();
  5668. });
  5669. //Reset paramters
  5670. totalFloatWindowsLeft = 0;
  5671. screenshotBuf = [];
  5672. });
  5673. }
  5674. function downloadCanvas(canvas){
  5675. var aDownloadLink = document.createElement('a');
  5676. 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`;
  5677. aDownloadLink.href = canvas.toDataURL();
  5678. aDownloadLink.click();
  5679. }
  5680. */
  5681. //Function for converting bytes to human readable sizes
  5682. 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]}
  5683. /*
  5684. Background services for keeping desktop files updated
  5685. Same mechanism is used as file explorer
  5686. */
  5687. let desktopFileHash = "";
  5688. setInterval(function(){
  5689. getDesktopHash(function(hash){
  5690. if (desktopFileHash == ""){
  5691. //Initialization
  5692. desktopFileHash = hash;
  5693. }else if (desktopFileHash != hash){
  5694. //Changed on desktop files. Refresh
  5695. refresh(undefined, true);
  5696. desktopFileHash = hash;
  5697. }
  5698. //Else, no file change on desktop
  5699. });
  5700. }, 15000);
  5701. function generateCSRFToken(callback){
  5702. $.ajax({
  5703. url: "../../system/csrf/new",
  5704. success: function(token){
  5705. callback(token);
  5706. }
  5707. })
  5708. }
  5709. function getDesktopHash(callback){
  5710. $.ajax({
  5711. url: "system/file_system/listDirHash",
  5712. data: {dir: "user:/Desktop/"},
  5713. success: function(data){
  5714. if (data.error !== undefined){
  5715. }
  5716. callback(data);
  5717. }
  5718. })
  5719. }
  5720. function bindObjectToIMEEvents(object){
  5721. object.addEventListener("keydown", function(event){
  5722. if (window.ime && window.ime.handler != null){
  5723. window.ime.handler(event);
  5724. }else{
  5725. //No IME handler. Just continue the input
  5726. }
  5727. });
  5728. object.addEventListener("focus", function(event){
  5729. if (window.ime){
  5730. //IME exists. Set this field to focused field
  5731. window.ime.focus = event.target;
  5732. }
  5733. });
  5734. }
  5735. </script>
  5736. </body>
  5737. </html>