desktop.system 257 KB

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