desktop.system 256 KB

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