desktop.system 238 KB

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