desktop.system 222 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505
  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.png">
  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. //Others
  889. var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  890. var daysNames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  891. var hostInfo = {};
  892. var userInfo = {};
  893. var hardwareman = false;
  894. var downloadMode = false;
  895. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  896. //Initiation functions
  897. initDesktopTheme();
  898. initDesktopHostInfo();
  899. initDesktopUserInfo();
  900. initBackgroundSwitchingAnimation();
  901. //initDesktopFiles(); //Will be called in initDesktopIconPreference() -> refresh()
  902. initModuleList();
  903. initDesktopIconPreference()
  904. initUserDefinedThemeColor();
  905. hookFloatWindowEvents();
  906. hookLaunchMenuEvents();
  907. initTheme();
  908. //Login cookie expire check
  909. setInterval(function() {
  910. checkConnection();
  911. }, 15000);
  912. function handleManualCheckReconnect(button){
  913. $(button).addClass("loading");
  914. checkConnection(undefined, function(status){
  915. let oldText = $(button).text();
  916. $(button).removeClass("loading");
  917. if (status == false){
  918. //Still unable to connect. Show cross icon
  919. $(button).html(`<i class="remove icon"></i>`);
  920. setTimeout(function(){
  921. //Restore its original text after 5 sec
  922. $(button).text(oldText);
  923. }, 5000);
  924. }
  925. });
  926. }
  927. function checkConnection(timeout=15000, callback=undefined){
  928. $.ajax({
  929. url: 'system/auth/checkLogin',
  930. success: function(data) {
  931. if (data == true) {
  932. //Continue session
  933. } else {
  934. //Session timeout. Redirect to system index
  935. loggingOut = true;
  936. window.location.href = "index.html";
  937. }
  938. $("#connectionLost").hide();
  939. document.title = hostInfo.Hostname;
  940. if (callback != undefined){
  941. callback(true);
  942. }
  943. },
  944. error: function(evt) {
  945. //Server closed or freezed?
  946. $("#connectionLost").show();
  947. document.title = "Reconnecting...";
  948. if (callback != undefined){
  949. callback(false);
  950. }
  951. },
  952. timeout: timeout
  953. });
  954. }
  955. //Keep the clock updated
  956. setInterval(function(){
  957. updateClockTime();
  958. },5000);
  959. updateClockTime();
  960. function updateClockTime(){
  961. var d = new Date();
  962. var display = monthNames[d.getMonth()] + " " + d.getDate() + " " + zeropad(d.getHours(),2) + ":" + zeropad(d.getMinutes(),2);
  963. if ($(".notification.object").length > 0){
  964. display += `<span style="color: #f54242; margin-left: 8px; float: center;"><i class="notice circle icon"></i></span>`;
  965. }
  966. $(".clock").html(display);
  967. var largedate = monthNames[d.getMonth()] + " " + d.getDate() + " " + d.getFullYear()
  968. $("#largedate").text(largedate);
  969. var dow = daysNames[d.getDay()];
  970. $("#dayofweek").text(dow);
  971. }
  972. function zeropad(n, width, z) {
  973. z = z || '0';
  974. n = n + '';
  975. return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
  976. }
  977. function showToolPanel(){
  978. $("#quickAccessPanel").slideToggle("fast");
  979. }
  980. function hideToolPanel(){
  981. $("#quickAccessPanel").slideUp("fast");
  982. }
  983. function initDesktopUserInfo(){
  984. $.get("system/desktop/user", function(data){
  985. if (data.error !== undefined){
  986. alert(data.error);
  987. }else{
  988. userInfo = data;
  989. if (data.IsAdmin == false){
  990. //Hide the power buttons
  991. $(".hardware").hide();
  992. }
  993. //Update the user tag
  994. $("#username").text(userInfo.Username);
  995. $("#usergroups").text("@" + userInfo.UserGroups.join("/"));
  996. $("#usergroups").attr("title",userInfo.UserGroups.join(" / "));
  997. if (data.UserIcon !== ""){
  998. $(".usericon").attr("src",data.UserIcon);
  999. }
  1000. }
  1001. });
  1002. }
  1003. function initDesktopHostInfo(){
  1004. //Load the data into variable
  1005. $.get("system/desktop/host",function(data){
  1006. hostInfo = data;
  1007. //Update the ui element as well
  1008. $(".hostname").text(hostInfo.Hostname);
  1009. document.title = hostInfo.Hostname;
  1010. });
  1011. //Setup volume bar
  1012. var currentGlobalVol = localStorage.getItem("global_volume");
  1013. if (currentGlobalVol != null && currentGlobalVol != undefined && currentGlobalVol != ""){
  1014. $("#volumebar").css("width", currentGlobalVol * 100 + "%");
  1015. }else{
  1016. currentGlobalVol = 0;
  1017. localStorage.setItem("global_volume",currentGlobalVol);
  1018. }
  1019. //Check if hardware management mode is enabled. Hide buttons if needed
  1020. $.get("system/power/accessCheck",function(data){
  1021. if (data == true){
  1022. //Hardware management mode is on
  1023. hardwareman = true;
  1024. }else{
  1025. //Hardware management mode is off
  1026. $(".item.hardware").hide();
  1027. hardwareman = false;
  1028. }
  1029. });
  1030. }
  1031. function toggleNotification(action=undefined){
  1032. var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  1033. if (typeof action == "undefined"){
  1034. $(".notificationbar").stop().finish().fadeToggle("fast", function(){
  1035. if ($(this).is(":visible")){
  1036. if (isFirefox){
  1037. $("#bgwrapper").addClass("blured");
  1038. $("#iconwrapper").addClass("blured");
  1039. $("#navimenu").addClass("blured");
  1040. $(".floatWindow").addClass("blured");
  1041. $("#listMenu").addClass("blured");
  1042. }
  1043. }else{
  1044. if (isFirefox){
  1045. $("#bgwrapper").removeClass("blured");
  1046. $("#iconwrapper").removeClass("blured");
  1047. $("#navimenu").removeClass("blured");
  1048. $(".floatWindow").removeClass("blured");
  1049. $("#listMenu").removeClass("blured");
  1050. }
  1051. }
  1052. });
  1053. }else{
  1054. if (action == "hide"){
  1055. $(".notificationbar").stop().finish().fadeOut("fast");
  1056. if (isFirefox){
  1057. $("#bgwrapper").removeClass("blured");
  1058. $("#iconwrapper").removeClass("blured");
  1059. $("#navimenu").removeClass("blured");
  1060. $(".floatWindow").removeClass("blured");
  1061. $("#listMenu").removeClass("blured");
  1062. }
  1063. }else if (action == "show"){
  1064. $(".notificationbar").stop().finish().fadeIn("fast");
  1065. if (isFirefox){
  1066. $("#bgwrapper").addClass("blured");
  1067. $("#iconwrapper").addClass("blured");
  1068. $("#navimenu").addClass("blured");
  1069. $(".floatWindow").addClass("blured");
  1070. $("#listMenu").addClass("blured");
  1071. }
  1072. }
  1073. }
  1074. }
  1075. // ===================== LIST MENU EVENTS FUNCTIONS ===============
  1076. function toggleListMenu() {
  1077. $("#listMenu").stop().finish().animate({
  1078. height: "toggle"
  1079. }, 300, function() {
  1080. if ($("#listMenu").offset().top == 0) {
  1081. listMenuShown = false;
  1082. } else {
  1083. listMenuShown = true;
  1084. }
  1085. });
  1086. }
  1087. function initDesktopIconPreference() {
  1088. getStorage("iconsize", function(catergory) {
  1089. if (["small", "medium", "big"].includes(catergory)) {
  1090. desktopIconSize = catergory;
  1091. }
  1092. refresh();
  1093. hideAllContextMenus();
  1094. });
  1095. }
  1096. function hideListMenu() {
  1097. if (listMenuShown) {
  1098. $("#listMenu").animate({
  1099. height: "hide"
  1100. }, 300);
  1101. listMenuShown = false;
  1102. }
  1103. }
  1104. function initModuleList() {
  1105. $.ajax({
  1106. url: "system/modules/list",
  1107. success: function(data) {
  1108. moduleInstalled = data;
  1109. listModulesType("All");
  1110. checkFileSystemAccess();
  1111. //Hide the system setting button if access is denied
  1112. var allowSettingAccess = false;
  1113. moduleInstalled.forEach(thismod => {
  1114. if (thismod.Name == "System Setting"){
  1115. allowSettingAccess = true;
  1116. }
  1117. });
  1118. if (!allowSettingAccess){
  1119. $("#settingButton").hide();
  1120. }
  1121. }
  1122. });
  1123. }
  1124. function hookLaunchMenuEvents(){
  1125. $(".groupType").on("click touchstart",function(){
  1126. moduleTypeButtonClicked(this);
  1127. });
  1128. $(".poweroption").on("click touchstart",function(){
  1129. logout();
  1130. });
  1131. }
  1132. function moduleTypeButtonClicked(object) {
  1133. var groupType = $(object).attr("group");
  1134. listModulesType(groupType);
  1135. $(".groupType.selected").removeClass("selected");
  1136. $(object).addClass("selected");
  1137. $("#searchResults").slideUp('fast');
  1138. $("#searchBar").val("");
  1139. }
  1140. function listModulesType(groupType) {
  1141. var listingItems = [];
  1142. if (groupType == "All") {
  1143. //List all of the items
  1144. for (var i = 0; i < moduleInstalled.length; i++) {
  1145. if (moduleInstalled[i]["StartDir"] != "") {
  1146. listingItems.push(moduleInstalled[i]);
  1147. }
  1148. }
  1149. } else if (groupType == "Other") {
  1150. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilities"];
  1151. //List the Other groups
  1152. for (var i = 0; i < moduleInstalled.length; i++) {
  1153. if (excludeList.includes(moduleInstalled[i]["Group"]) == false && moduleInstalled[i]["StartDir"] != "") {
  1154. console.log(moduleInstalled[i]["Group"]);
  1155. listingItems.push(moduleInstalled[i]);
  1156. }
  1157. }
  1158. } else {
  1159. //List the given group
  1160. for (var i = 0; i < moduleInstalled.length; i++) {
  1161. if (moduleInstalled[i]["Group"] == groupType && moduleInstalled[i]["StartDir"] != "") {
  1162. listingItems.push(moduleInstalled[i]);
  1163. }
  1164. }
  1165. }
  1166. //List the item to the listmenu
  1167. $("#listMenuItem").html("");
  1168. for (var i = 0; i < listingItems.length; i++) {
  1169. var thisModule = listingItems[i];
  1170. generateListMenuItem(thisModule);
  1171. }
  1172. if (listingItems.length == 0) {
  1173. $("#listMenuItem").html(`<div class="item module"><span><img src="img/system/not found.png">No WebApp found</span></div>`)
  1174. }
  1175. }
  1176. //Given a module information and generate a selectable item in the list menu
  1177. function generateListMenuItem(thisModule) {
  1178. var icon = thisModule["IconPath"];
  1179. if (icon == "") {
  1180. //Use default system icon
  1181. icon = "img/system/service.png";
  1182. }
  1183. var name = thisModule["Name"];
  1184. var startdir = thisModule["StartDir"];
  1185. var fwsupport = "false";
  1186. if (thisModule["SupportFW"]) {
  1187. fwsupport = "true";
  1188. }
  1189. $("#listMenuItem").append(`<div class="item module" module="${name}" startdir="${startdir}" fw="${fwsupport}" onclick="openModuleFromMenu(this);" ontouchstart="openModuleFromMenu(this);">
  1190. <span>
  1191. <img src="${icon}"></img>
  1192. ${name}
  1193. </span>
  1194. </div>`);
  1195. }
  1196. function searchModule(event) {
  1197. if (event.which == 13) {
  1198. var keyword = $("#searchBar").val().toLowerCase();
  1199. var results = [];
  1200. var lessAccurateResults = [];
  1201. $(".groupType.selected").removeClass("selected");
  1202. $("#searchResults").addClass("selected").slideDown('fast');
  1203. //Load all search results
  1204. for (var i = 0; i < moduleInstalled.length; i++) {
  1205. var thisModule = moduleInstalled[i];
  1206. if (thisModule["StartDir"] == ""){
  1207. continue;
  1208. }
  1209. var pathInfo = thisModule["StartDir"].split("/");
  1210. for (var j = 0; j < pathInfo.length; j++) {
  1211. pathInfo[j] = pathInfo[j].toLowerCase();
  1212. }
  1213. if (thisModule["Name"].toLowerCase().includes(keyword)) {
  1214. results.push(thisModule);
  1215. } else if (pathInfo.includes(keyword.toLowerCase()) || pathInfo.includes(keyword.split(" ").join("_").toLowerCase())) {
  1216. lessAccurateResults.push(thisModule);
  1217. }
  1218. }
  1219. results = results.concat(lessAccurateResults);
  1220. //Append the results to list
  1221. $("#listMenuItem").html("");
  1222. for (var i = 0; i < results.length; i++) {
  1223. generateListMenuItem(results[i]);
  1224. }
  1225. if (results.length == 0) {
  1226. //Append a custom no results div to the content
  1227. $("#listMenuItem").append(` <div class="item">
  1228. <span>
  1229. <img src="img/system/not found.png"></img>
  1230. No Result
  1231. </span>
  1232. </div>`);
  1233. }
  1234. }
  1235. }
  1236. function openModuleFromMenu(object) {
  1237. var moduleName = $(object).attr("module");
  1238. openModule(moduleName);
  1239. }
  1240. function openModule(moduleName, callback=undefined) {
  1241. $.get("system/modules/getLaunchPara?module=" + moduleName, function(data) {
  1242. if (data.error !== undefined) {
  1243. //Something went wrong.
  1244. console.log("Unable to open module " + moduleName);
  1245. if (data.error == "Not logged in."){
  1246. //Session expired
  1247. window.location.href = "login.system";
  1248. }
  1249. } else {
  1250. //Launch the given module
  1251. var url = data["StartDir"];
  1252. var size = [undefined, undefined];
  1253. var icon = "img/system/favicon.png";
  1254. if (data["IconPath"] != "") {
  1255. icon = data["IconPath"];
  1256. }
  1257. var title = data["Name"];
  1258. //Check if the module support fw mode. If yes, launch with fwmode url. IF not, launch to index
  1259. if (data["SupportFW"] == true) {
  1260. if (data["LaunchFWDir"] != null) {
  1261. url = data["LaunchFWDir"];
  1262. }
  1263. if (data["InitFWSize"] != null) {
  1264. size = data["InitFWSize"];
  1265. }
  1266. }
  1267. //Launch the given module
  1268. var uuid = newFloatWindow({
  1269. url: url,
  1270. width: size[0],
  1271. height: size[1],
  1272. appicon: icon,
  1273. title: title
  1274. });
  1275. if (callback !== undefined){
  1276. callback();
  1277. }
  1278. hideListMenu();
  1279. }
  1280. });
  1281. }
  1282. // ===================== FLOAT WINDOWS EVENTS =====================
  1283. function hookFloatWindowEvents() {
  1284. //Handle floatWindow mouse drag events
  1285. $(".fwdragger").off("mousedown").on("mousedown", function(evt) {
  1286. evt.preventDefault();
  1287. evt.stopImmediatePropagation();
  1288. fwdown($(this).parent(), evt);
  1289. });
  1290. $(".fwdragger").off("mousemove").on("mousemove", function(evt) {
  1291. evt.preventDefault();
  1292. evt.stopImmediatePropagation();
  1293. fwmove($(this).parent(), evt);
  1294. });
  1295. $(".fwdragger").off("mouseup").on("mouseup", function(evt) {
  1296. evt.preventDefault();
  1297. evt.stopImmediatePropagation();
  1298. fwup($(this).parent(), evt);
  1299. });
  1300. $(".fwdragger").off("touchstart").on("touchstart", function(evt) {
  1301. evt.preventDefault();
  1302. evt.stopImmediatePropagation();
  1303. fwdown($(this).parent(), evt);
  1304. });
  1305. $(".fwdragger").off("touchmove").on("touchmove", function(evt) {
  1306. evt.preventDefault();
  1307. evt.stopImmediatePropagation();
  1308. fwmove($(this).parent(), evt);
  1309. });
  1310. $(".fwdragger").off("touchend").on("touchend", function(evt) {
  1311. evt.preventDefault();
  1312. evt.stopImmediatePropagation();
  1313. fwup($(this).parent(), evt);
  1314. });
  1315. $(".fwdragger").off("dblclick").on("dblclick", function(evt) {
  1316. //Activate full screen
  1317. evt.preventDefault();
  1318. evt.stopImmediatePropagation();
  1319. //Emulate keypress on maximize btn
  1320. toggleMax($(this).parent().find(".maxToogleButton").parent()[0], evt);
  1321. });
  1322. //Floatwindow operations for touch devices
  1323. $(".maxtoggle").off("touchstart").on("touchstart",function(evt){
  1324. evt.preventDefault();
  1325. evt.stopImmediatePropagation();
  1326. toggleMax(this, evt);
  1327. });
  1328. $(".mintoggle").off("touchstart").on("touchstart",function(evt){
  1329. evt.preventDefault();
  1330. evt.stopImmediatePropagation();
  1331. min(this, evt);
  1332. });
  1333. $(".closetoggle").off("touchstart").on("touchstart",function(evt){
  1334. evt.preventDefault();
  1335. evt.stopImmediatePropagation();
  1336. closeFloatWindow(this,evt);
  1337. });
  1338. //floatWindow events for mouse
  1339. $(".maxtoggle").off("mousedown").on("mousedown",function(evt){
  1340. evt.preventDefault();
  1341. evt.stopImmediatePropagation();
  1342. toggleMax(this, evt);
  1343. });
  1344. $(".mintoggle").off("mousedown").on("mousedown",function(evt){
  1345. evt.preventDefault();
  1346. evt.stopImmediatePropagation();
  1347. min(this, evt);
  1348. });
  1349. $(".closetoggle").off("mousedown").on("mousedown",function(evt){
  1350. evt.preventDefault();
  1351. evt.stopImmediatePropagation();
  1352. closeFloatWindow(this,evt);
  1353. });
  1354. //Float Window events for resizing
  1355. $(".iframewrapper").off("mousedown").on("mousedown", function(evt) {
  1356. evt.preventDefault();
  1357. evt.stopImmediatePropagation();
  1358. if ($(this).parent().hasClass("fixedsize")) {
  1359. return false;
  1360. }
  1361. resizeDown($(this).parent(), evt);
  1362. });
  1363. $(".iframewrapper").off("mousemove").on("mousemove", function(evt) {
  1364. evt.preventDefault();
  1365. evt.stopImmediatePropagation();
  1366. if (resizingWindow == true) {
  1367. //Resizeing Move
  1368. resizeMove($(this).parent(), evt);
  1369. } else {
  1370. //Dragdropping move
  1371. fwmove($(this).parent(), evt);
  1372. }
  1373. });
  1374. $(".iframewrapper").off("mouseup").on("mouseup", function(evt) {
  1375. evt.preventDefault();
  1376. evt.stopImmediatePropagation();
  1377. resizeUp($(this).parent(), evt);
  1378. });
  1379. $(".iframewrapper").off("mouseover").on("mouseover", function(evt) {
  1380. var object = $(this).parent();
  1381. if ($(object).hasClass("fixedsize")) {
  1382. return false;
  1383. }
  1384. var dx = event.pageX - $(object).find(".iframewrapper").offset().left;
  1385. var dy = event.pageY - $(object).offset().top;
  1386. if (dx < 10 && dy > $(object).height() - 10) {
  1387. //Left Bottom Corner
  1388. $(".iframewrapper").attr("class", "iframewrapper leftCorner");
  1389. } else if (dx > $(object).width() - 10 && dy > $(object).height() - 10) {
  1390. //Right Bottom Corner
  1391. $(".iframewrapper").attr("class", "iframewrapper rightCorner");
  1392. } else if (dx < 10) {
  1393. //Dragging left edge
  1394. $(".iframewrapper").attr("class", "iframewrapper widthHover");
  1395. } else if (dx > $(object).width() - 10) {
  1396. //Dragging right edge
  1397. $(".iframewrapper").attr("class", "iframewrapper widthHover");
  1398. } else if (dy > $(object).height() - 10) {
  1399. //Bottom Edge
  1400. $(".iframewrapper").attr("class", "iframewrapper heighHover");
  1401. } else {
  1402. //???
  1403. $(".iframewrapper").attr("class", "iframewrapper");
  1404. }
  1405. });
  1406. //Hook events on the floatWindow button
  1407. $(".floatWindowButton").off("click touchstart").on("click touchstart", function(event) {
  1408. event.preventDefault();
  1409. event.stopImmediatePropagation();
  1410. $("#stackedWindowList").css("left", $(this).offset().left);
  1411. //Generate the stackedWindowList
  1412. var windowIdList = JSON.parse(decodeURIComponent($(this).attr("windowidgroup")));
  1413. if (windowIdList.length == 1) {
  1414. //There are only one window in this group. Show it anyway
  1415. var targetFW = getFloatWindowByID(windowIdList[0]);
  1416. $(targetFW).fadeIn(100);
  1417. MoveFloatWindowToTop(targetFW);
  1418. stackedFloatWindowListShwon = false;
  1419. $("#stackedWindowList").hide();
  1420. } else {
  1421. //Get icon for each windows and build the list objects
  1422. $("#stackedWindowList").html("");
  1423. for (var i = 0; i < windowIdList.length; i++) {
  1424. var iconURL = getFloatWindowIconByID(windowIdList[i]);
  1425. var title = getFloatWindowTitleByID(windowIdList[i]);
  1426. $("#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>`);
  1427. }
  1428. $("#stackedWindowList").show();
  1429. stackedFloatWindowListShwon = true;
  1430. }
  1431. });
  1432. }
  1433. var tapedTwiceTouch = false;
  1434. var timeoutObject;
  1435. var tappingTarget = undefined;
  1436. function doubleTouchHandler(object, event, callback) {
  1437. if(!tapedTwiceTouch) {
  1438. tapedTwiceTouch = true;
  1439. tappingTarget = object;
  1440. timeoutObject = setTimeout( function() { tapedTwiceTouch = false; }, 300 );
  1441. return false;
  1442. }
  1443. if (tappingTarget == object){
  1444. //Double click on the same icon
  1445. event.preventDefault();
  1446. callback(object, event);
  1447. tappingTarget = undefined;
  1448. }else{
  1449. //Although it touch twice within 300ms, but it is on different target
  1450. //Update the tab target instead.
  1451. tappingTarget = object;
  1452. tapedTwiceTouch = true;
  1453. clearTimeout(timeoutObject);
  1454. timeoutObject = setTimeout( function() { tapedTwiceTouch = false; }, 300 );
  1455. }
  1456. }
  1457. function openViaTouch(object, event){
  1458. iconDoubleClicked(object,event);
  1459. }
  1460. //Handle focus through floatWindow taskbar button
  1461. function bringFloatWindowToFrontByFWB(object, event) {
  1462. event.preventDefault();
  1463. event.stopImmediatePropagation();
  1464. var targetWFID = $(object).attr("windowId");
  1465. var targetFW = getFloatWindowByID(targetWFID);
  1466. $(targetFW).fadeIn(100);
  1467. MoveFloatWindowToTop(targetFW);
  1468. stackedFloatWindowListShwon = false;
  1469. $("#stackedWindowList").hide();
  1470. }
  1471. function closeFWviaFWB(object, event) {
  1472. event.preventDefault();
  1473. event.stopImmediatePropagation();
  1474. var targetWFID = $(object).parent().attr("windowId");
  1475. var targetFW = getFloatWindowByID(targetWFID);
  1476. closeFloatWindow(targetFW.find(".close"), event);
  1477. $(object).parent().remove();
  1478. if ($("#stackedWindowList").find(".item").length == 0) {
  1479. //There are no more things in this tab. Close this list as well.
  1480. stackedFloatWindowListShwon = false;
  1481. $("#stackedWindowList").hide();
  1482. }
  1483. }
  1484. //Handle floatWindow resize events
  1485. let resizingWindowTarget;
  1486. let resizingMinX = 0;
  1487. let minxWidth = 120;
  1488. let minHeight = 100;
  1489. function resizeDown(object, event) {
  1490. //Mouse down, start resizing
  1491. resizingWindow = true;
  1492. resizingWindowTarget = object;
  1493. resizingMinX = $(object).offset().left + $(object).width() - minxWidth;
  1494. MoveFloatWindowToTop(object);
  1495. if ($(object).hasClass("topmost")){
  1496. //Top most windows
  1497. $("#tfwdragpanel").show();
  1498. }else{
  1499. //Normal Windows
  1500. $('.floatWindow.topmost').css("pointer-events", "none");
  1501. $('.floatWindow.topmost').css("opacity", 0.7);
  1502. $("#fwdragpanel").show();
  1503. }
  1504. $(object).find(".iframecover").show();
  1505. //Check which edge is the user dragging
  1506. var dx = event.pageX - $(object).find(".iframewrapper").offset().left;
  1507. var dy = event.pageY - $(object).offset().top;
  1508. if (dx < 10 && dy > $(object).height() - 10) {
  1509. //Left Bottom Corner
  1510. resizingEdgeID = 4;
  1511. $(object).find(".iframewrapper").css('cursor', 'sw-resize');
  1512. } else if (dx > $(object).width() - 10 && dy > $(object).height() - 10) {
  1513. //Right Bottom Corner
  1514. resizingEdgeID = 2;
  1515. $(object).find(".iframewrapper").css('cursor', 'se-resize');
  1516. } else if (dx < 10) {
  1517. //Dragging left edge
  1518. resizingEdgeID = 5;
  1519. $(object).find(".iframewrapper").css('cursor', 'w-resize');
  1520. } else if (dx > $(object).width() - 10) {
  1521. //Dragging right edge
  1522. resizingEdgeID = 1;
  1523. $(object).find(".iframewrapper").css('cursor', 'w-resize');
  1524. } else if (dy > $(object).height() - 10) {
  1525. //Bottom Edge
  1526. resizingEdgeID = 3;
  1527. $(object).find(".iframewrapper").css('cursor', 's-resize');
  1528. }
  1529. }
  1530. function resizeMove(object, event) {
  1531. var posX = event.pageX;
  1532. var posY = event.pageY;
  1533. if (resizingWindow == true && resizingEdgeID != 0) {
  1534. if (resizingEdgeID == 1) {
  1535. //Width = posX - floatWindow width + 2 (for border width)
  1536. var newWidth = posX - $(object).offset().left + 2;
  1537. $(object).css("width", Math.max(newWidth, minxWidth));
  1538. } else if (resizingEdgeID == 2) {
  1539. var newWidth = posX - $(object).offset().left + 2;
  1540. var newHeight = posY - $(object).offset().top + 2;
  1541. $(object).css({
  1542. width: Math.max(newWidth, minxWidth),
  1543. height: Math.max(newHeight, minHeight)
  1544. });
  1545. } else if (resizingEdgeID == 3) {
  1546. var newHeight = posY - $(object).offset().top + 2;
  1547. $(object).css("height", Math.max(newHeight,minHeight));
  1548. } else if (resizingEdgeID == 4) {
  1549. var newWidth = $(object).offset().left - posX + $(object).width();
  1550. var newHeight = posY - $(object).offset().top + 2;
  1551. if (newWidth < minxWidth){
  1552. posX = resizingMinX;
  1553. }
  1554. $(object).css({
  1555. width: Math.max(newWidth, minxWidth),
  1556. height: Math.max(newHeight, minHeight),
  1557. left: posX
  1558. });
  1559. } else if (resizingEdgeID == 5) {
  1560. var newWidth = $(object).offset().left - posX + $(object).width();
  1561. if (newWidth < minxWidth){
  1562. posX = resizingMinX;
  1563. }
  1564. $(object).css({
  1565. width: Math.max(newWidth, minxWidth),
  1566. left: posX
  1567. });
  1568. }
  1569. }
  1570. }
  1571. function resizeUp(object, event) {
  1572. resizingWindow = false;
  1573. resizingEdgeID = 0;
  1574. $("#fwdragpanel").hide();
  1575. $("#tfwdragpanel").hide();
  1576. $('.floatWindow.topmost').css("pointer-events", "auto");
  1577. $('.floatWindow.topmost').css("opacity", 1);
  1578. $(object).find(".iframecover").hide();
  1579. $(object).find(".iframewrapper").css('cursor', '');
  1580. //Force minmium width and height on any floatWindow objects
  1581. if ($(object).width() < 120) {
  1582. $(object).css("width", "120px");
  1583. }
  1584. if ($(object).height() < 120) {
  1585. $(object).css("height", "120px");
  1586. }
  1587. resizingWindowTarget = undefined;
  1588. $(".topmost").show();
  1589. }
  1590. //Hook body mousemove assistant events
  1591. $("body").on("mousemove", function(evt) {
  1592. if (focusedWindow !== undefined && movingWindow == true) {
  1593. fwmove(focusedWindow, evt);
  1594. } else if (focusedWindow !== undefined && resizingWindow == true) {
  1595. resizeMove(focusedWindow, evt);
  1596. } else if (multiSelecting == true) {
  1597. movingMultiSelectionArea(evt);
  1598. }
  1599. });
  1600. //Hook body clicke vents
  1601. $("body").on("click", function(evt) {
  1602. if (stackedFloatWindowListShwon == true) {
  1603. //Hide the stacked Float Window list if it is shown
  1604. $("#stackedWindowList").hide();
  1605. stackedFloatWindowListShwon = false;
  1606. }
  1607. if (renameMode == true){
  1608. //Exit rename mode if the target is not on the editing launchIcon
  1609. console.log(evt.target);
  1610. if ($(evt.target).is("body")){
  1611. //End rename mode
  1612. exitRenameMode();
  1613. }
  1614. }
  1615. });
  1616. //Convert touch events to click events
  1617. function mapEventFromTouch(event){
  1618. if (typeof event.originalEvent == "undefined"){
  1619. //Mouse click / down / up events
  1620. return event;
  1621. }
  1622. try{
  1623. //Touch events
  1624. if (typeof event.pageX == "undefined"){
  1625. event.pageX = event.originalEvent.touches[0].pageX;
  1626. }
  1627. if (typeof event.pageY == "undefined"){
  1628. event.pageY = event.originalEvent.touches[0].pageY;
  1629. }
  1630. return event;
  1631. }catch{
  1632. return event;
  1633. }
  1634. }
  1635. //Please pass in the floatWindow object instead of the dragger
  1636. function fwdown(object, event) {
  1637. event = mapEventFromTouch(event);
  1638. //Hide all contenxt menus
  1639. hideAllContextMenus();
  1640. //Move the window to the top layer
  1641. MoveFloatWindowToTop(object);
  1642. //Show the background drag panel
  1643. if ($(object).hasClass("topmost")){
  1644. $("#tfwdragpanel").show();
  1645. }else{
  1646. $('.floatWindow.topmost').css("pointer-events", "none");
  1647. $('.floatWindow.topmost').css("opacity", 0.7);
  1648. $("#fwdragpanel").show();
  1649. }
  1650. //Get the relative click offset of the down event
  1651. clickDownOffset = [event.pageX - $(object).offset().left, event.pageY - $(object).offset().top];
  1652. movingWindow = true;
  1653. $(object).find(".iframecover").show();
  1654. }
  1655. function fwmove(object, event) {
  1656. event = mapEventFromTouch(event);
  1657. if (movingWindow == true) {
  1658. //Check if the object is maximized. If yes, minimized it
  1659. if ($(object).attr("max") == "true") {
  1660. var originalSize = JSON.parse(decodeURIComponent($(object).attr("orgsize")));
  1661. $(object).attr("max", "false");
  1662. $(object).attr("orgsize", "");
  1663. //Calculate new left right offsets
  1664. var clickRatio = event.pageX / window.innerWidth;
  1665. var newLeft = event.pageX - (clickRatio * originalSize[0]);
  1666. originalSize
  1667. $(object).css({
  1668. width: originalSize[0],
  1669. height: originalSize[1],
  1670. left: newLeft,
  1671. top: event.Y - 2
  1672. });
  1673. clickDownOffset[0] = clickRatio * originalSize[0];
  1674. clickDownOffset[1] = 2;
  1675. //Restore the maximize icon
  1676. $(object).find(".maxToogleButton").attr('src', "img/system/max.png")
  1677. }
  1678. $(object).css("left", event.pageX - clickDownOffset[0]);
  1679. $(object).css("top", event.pageY - clickDownOffset[1]);
  1680. }
  1681. }
  1682. function fwup(object, event) {
  1683. event = mapEventFromTouch(event);
  1684. if (movingWindow) {
  1685. $("#fwdragpanel").hide();
  1686. $("#tfwdragpanel").hide();
  1687. $('.floatWindow.topmost').css("pointer-events", "auto");
  1688. $('.floatWindow.topmost').css("opacity", 1);
  1689. $(object).find(".iframecover").hide();
  1690. movingWindow = false;
  1691. //Check if the window location is drag to the edge of the screen. If yes, toggle half screen fullscreen
  1692. //Not need to check for if max because it must be minimized during drag move
  1693. var dockMode = false;
  1694. if (event.pageX < 10) {
  1695. //Dock to left
  1696. var originalSize = [$(object).width(), $(object).height(), $(object).offset().left, $(object).offset().top];
  1697. $(object).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1698. $(object).css({
  1699. width: "50%",
  1700. height: "calc(100% - 36px)",
  1701. left: "0px",
  1702. top: "0px"
  1703. });
  1704. $(object).attr("max", "true");
  1705. $(object).find(".maxToogleButton").attr('src', "img/system/restore.png");
  1706. } else if (event.pageX > window.innerWidth - 10) {
  1707. //Dock to right
  1708. var originalSize = [$(object).width(), $(object).height(), $(object).offset().left, $(object).offset().top];
  1709. $(object).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1710. $(object).css({
  1711. width: "50%",
  1712. height: "calc(100% - 36px)",
  1713. left: (window.innerWidth / 2) + "px",
  1714. top: "0px"
  1715. });
  1716. $(object).attr("max", "true");
  1717. $(object).find(".maxToogleButton").attr('src', "img/system/restore.png");
  1718. }
  1719. }
  1720. }
  1721. //Handle floatWindow min, max and close
  1722. function min(object, event) {
  1723. event.preventDefault();
  1724. event.stopImmediatePropagation();
  1725. if (event.type == "mousedown" && event.which != 1) {
  1726. //Ignore right mouse down
  1727. return;
  1728. }
  1729. var fw = $(object).parent().parent().parent();
  1730. $(fw).fadeOut(100);
  1731. }
  1732. function toggleMax(object, event) {
  1733. event.preventDefault();
  1734. event.stopImmediatePropagation();
  1735. event = mapEventFromTouch(event);
  1736. if (event.type == "mousedown" && event.which != 1) {
  1737. //Ignore right mouse down
  1738. return;
  1739. }
  1740. if ($(object).css('display') == 'none'){
  1741. //This windows do not allow resizing.
  1742. return;
  1743. }
  1744. var fw = $(object).parent().parent().parent();
  1745. var maxedAlready = $(fw).attr('max');
  1746. MoveFloatWindowToTop(fw);
  1747. //Add transition animation
  1748. $(fw).css({
  1749. "transition": "width 0.3s ease-out, height 0.3s ease-out, top 0.3s ease-out, left 0.3s ease-out"
  1750. });
  1751. //Remove transition animation after complete wth 50ms buffer
  1752. setTimeout(function(){
  1753. $(fw).css({
  1754. "transition": ""
  1755. });
  1756. }, 350);
  1757. if (maxedAlready == "true") {
  1758. //Resize to original
  1759. console.log($(fw));
  1760. var originalSize = JSON.parse(decodeURIComponent($(fw).attr("orgsize")));
  1761. $(fw).attr("max", "false");
  1762. $(fw).attr("orgsize", "");
  1763. $(fw).css({
  1764. width: originalSize[0],
  1765. height: originalSize[1],
  1766. left: originalSize[2],
  1767. top: originalSize[3]
  1768. });
  1769. $(fw).find(".maxToogleButton").attr('src', "img/system/max.png");
  1770. } else {
  1771. //Maxmize
  1772. var originalSize = [$(fw).width(), $(fw).height(), $(fw).offset().left, $(fw).offset().top];
  1773. $(fw).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1774. $(fw).css({
  1775. width: "100%",
  1776. height: "calc(100% - 36px)",
  1777. left: "0px",
  1778. top: "0px"
  1779. });
  1780. $(fw).attr("max", "true");
  1781. $(fw).find(".maxToogleButton").attr('src', "img/system/restore.png")
  1782. }
  1783. }
  1784. function closeFloatWindow(object, event) {
  1785. if (event.type == "mousedown" && event.which != 1) {
  1786. //Ignore right mouse down on close buttons
  1787. return;
  1788. }
  1789. event.preventDefault();
  1790. event.stopImmediatePropagation();
  1791. if ($(object).is("img")) {
  1792. object = $(object).panret();
  1793. }
  1794. var fw = $(object).parent().parent().parent();
  1795. var contentWindow = $(fw).find("iframe")[0].contentWindow;
  1796. try {
  1797. if (contentWindow.ao_module_close === undefined) {
  1798. //This module do not use ao_module wrapper. Close it directly.
  1799. closeFwProcess($(fw).attr("windowId"));
  1800. } else {
  1801. //Pass the closing events to the window itself
  1802. contentWindow.ao_module_close();
  1803. }
  1804. } catch (ex) {
  1805. //Problems of closing floatWindow. Force closing.
  1806. closeFwProcess($(fw).attr("windowId"));
  1807. }
  1808. //Find the btn object that contains the windowID
  1809. var closingWindowID = $(fw).attr("windowId");
  1810. resizeAllFloatWindowButtons();
  1811. hideAllContextMenus();
  1812. }
  1813. function findFloatWindowButtonWithID(windowID) {
  1814. var targetButtonObject;
  1815. $(".floatWindowButton").each(function() {
  1816. var originalIDlist = JSON.parse(decodeURIComponent($(this).attr('windowIDGroup')));
  1817. originalIDlist = originalIDlist.map(String);
  1818. if (originalIDlist.includes(windowID)) {
  1819. targetButtonObject = $(this);
  1820. }
  1821. });
  1822. return targetButtonObject;
  1823. }
  1824. function closeFwProcess(windowID) {
  1825. //Close the floatwindow process
  1826. $(".floatWindow").each(function() {
  1827. if ($(this).attr("windowId") == windowID) {
  1828. $(this).remove();
  1829. }
  1830. });
  1831. //Remove the button from menu as well
  1832. var targetTab = findFloatWindowButtonWithID(windowID);
  1833. var originalIDlist = JSON.parse(decodeURIComponent($(targetTab).attr('windowIDGroup')));
  1834. originalIDlist = originalIDlist.map(String);
  1835. if (originalIDlist.length > 1) {
  1836. //There are more than 1 floatWindow in this tab.
  1837. var newIDList = [];
  1838. for (var i = 0; i < originalIDlist.length; i++) {
  1839. if (originalIDlist[i] != windowID) {
  1840. newIDList.push(originalIDlist[i]);
  1841. }
  1842. }
  1843. newIDListAttr = encodeURIComponent(JSON.stringify(newIDList));
  1844. //console.log("Newlist",newIDList);
  1845. $(targetTab).attr("windowIDGroup", newIDListAttr);
  1846. } else {
  1847. //This is the only floatWindow in this tab. Remove the tab itself.
  1848. $(targetTab).remove();
  1849. }
  1850. }
  1851. function PinFloatWindowToTopMostMode(object){
  1852. if ($(".floatwindow.topmost").length >= 100){
  1853. //Cannot add more topmost fw
  1854. console.log("Max number of top most floatWindow reached")
  1855. return
  1856. }
  1857. //Move the current fw to top, its z index is now 101
  1858. MoveFloatWindowToTop(object);
  1859. var windowID = $(object).attr("windowId");
  1860. console.log("[Desktop] Pinning window ID: " + windowID)
  1861. //Move this to fixed layer position
  1862. $(object).addClass("topmost");
  1863. $(object).css("z-index", 501);
  1864. }
  1865. function UnpinFloatWindowFromTopMostMode(object){
  1866. $(object).removeClass("topmost");
  1867. if (focusedWindow == object){
  1868. focusedWindow = undefined;
  1869. $(object).css("z-index", 1);
  1870. }
  1871. MoveFloatWindowToTop(object);
  1872. }
  1873. function MoveFloatWindowToTop(object) {
  1874. var windowID = $(object).attr("windowId");
  1875. var windowZindex = $(object).css("z-index");
  1876. //Shift down all floatWindows that has z-index higher than this window by 2
  1877. if (windowID == $(focusedWindow).attr("windowId")) {
  1878. //This window already at the top
  1879. return;
  1880. }
  1881. if ($(focusedWindow).hasClass("topmost")){
  1882. //The previous focused windows is topmost. Move it to layer 109
  1883. $(focusedWindow).css("z-index", 500);
  1884. $(".floatWindow.topmost").each(function(){
  1885. var thisWindowZIndex = $(this).css("z-index");
  1886. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1887. if ($(this).attr("windowId") != windowID) {
  1888. $(this).css("z-index", thisWindowZIndex - 1);
  1889. }
  1890. }
  1891. });
  1892. }else{
  1893. //The previous focused windows is normal windows. Move it to 100
  1894. $(focusedWindow).css("z-index", 100);
  1895. //Shift all the other windows down
  1896. $(".floatWindow").each(function() {
  1897. if ($(this).hasClass("topmost")){
  1898. return;
  1899. }
  1900. var thisWindowZIndex = $(this).css("z-index");
  1901. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1902. if ($(this).attr("windowId") != windowID) {
  1903. $(this).css("z-index", thisWindowZIndex - 1);
  1904. //console.log($(this).attr("windowId"), $(this).css("z-index"));
  1905. }
  1906. }
  1907. });
  1908. }
  1909. if ($(object).hasClass("topmost")){
  1910. //The new windows is a topmost window
  1911. $(object).css("z-index", 501);
  1912. }else{
  1913. $(object).css("z-index", 101);
  1914. }
  1915. focusedWindow = $(object);
  1916. //Check if this div is hidden. If not, fade it in.
  1917. if ($(object).is(":hidden")) {
  1918. $(object).fadeIn(100);
  1919. }
  1920. }
  1921. function newFloatWindow(config, callback=undefined) {
  1922. //Check if the number of floatWindow already reaching its maxmium
  1923. if ($(".floatWindow").length > maxWindowCount){
  1924. console.log("Max number of floatWindow reached.")
  1925. return;
  1926. }
  1927. //Generate new floatwindow startup config from object
  1928. var url = defaultOrKey(config, "about:blank", "url");
  1929. var uuid = defaultOrKey(config, (new Date()).getTime(), "uid");
  1930. var width = defaultOrKey(config, 854, "width");
  1931. var height = defaultOrKey(config, 480, "height");
  1932. var moduleIcon = defaultOrKey(config, "img/system/favicon.png", "appicon");
  1933. var title = defaultOrKey(config, "New floatWindow", "title");
  1934. var left = defaultOrKey(config, 100, "left");
  1935. var top = defaultOrKey(config, 100, "top");
  1936. var parentWindowID = defaultOrKey(config, "", "parent");
  1937. var callbackFunctionName = defaultOrKey(config, "", "callback");
  1938. var bgcolor = defaultOrKey(config, "", "background-color");
  1939. //Encode function name
  1940. callbackFunctionName = encodeURIComponent(callbackFunctionName);
  1941. //Validate paramters
  1942. if (width > window.innerWidth) {
  1943. width = window.innerWidth;
  1944. }
  1945. if (height > window.innerHeight) {
  1946. height = window.innerHeight;
  1947. }
  1948. if (left + width > window.innerWidth) {
  1949. left = 0;
  1950. }
  1951. if (top + height > window.innerHeight) {
  1952. top = 0;
  1953. }
  1954. //Check if the location already cotain any window
  1955. while (floatWindowLocationDuplicated(left, top)) {
  1956. left += 30;
  1957. top += 30;
  1958. }
  1959. //Check if the opening require a overwrite on background color
  1960. var backgroundStyle = "";
  1961. if (bgcolor !== ""){
  1962. backgroundStyle = `background-color: ${bgcolor};`;
  1963. }
  1964. //Check if the theme color is applied. If yes, generate the floatWindow with overwritten theem color
  1965. var overWriteThemeColor = "";
  1966. if (desktopThemeColor != ""){
  1967. overWriteThemeColor = `background-color: ${hexToRgbA(desktopThemeColor, 0.85)}`;
  1968. }
  1969. //Append the floatWindow into the body
  1970. $("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}">
  1971. <div class="controls fwdragger themeColorSolid" style="${overWriteThemeColor}">
  1972. <img class="moduleicon" src="${moduleIcon}"></img>
  1973. <div class="title">${title}</div>
  1974. <div class="fwcontrol">
  1975. <div class="buttons mintoggle">
  1976. <img src="img/system/min.png"></img>
  1977. </div>
  1978. <div class="buttons maxtoggle">
  1979. <img class="maxToogleButton" src="img/system/max.png"></img>
  1980. </div>
  1981. <div class="buttons closetoggle close">
  1982. <img src="img/system/close.png"></img>
  1983. </div>
  1984. </div>
  1985. </div>
  1986. <div class="iframewrapper">
  1987. <iframe src="${url}" allowfullscreen="true"></iframe>
  1988. <div class="iframecover"></div>
  1989. </div>
  1990. </div>`);
  1991. var newWindowObject = getFloatWindowByID(uuid);
  1992. //console.log(newWindowObject);
  1993. MoveFloatWindowToTop(newWindowObject);
  1994. //Append window to taskbar
  1995. var groupInfo = url.split("/");
  1996. var group = "";
  1997. if (groupInfo.length == 1) {
  1998. group = groupInfo[0];
  1999. } else {
  2000. groupInfo.pop();
  2001. group = groupInfo.join("/");
  2002. }
  2003. //File system windows require special grouping based on their filename
  2004. if (url.includes("SystemAO/file_system/")){
  2005. group = url.split("/").pop().split(".").join("_");
  2006. }else if (url.includes("SystemAO/utilities/")){
  2007. group = url.split("/").pop().split(".").join("_");
  2008. if (group.includes("#")){
  2009. group = group.split("#")[0];
  2010. }
  2011. }
  2012. //Check if the group already exists.
  2013. var groupExists = false;
  2014. var targetGroupingTab;
  2015. $(".floatWindowButton").each(function() {
  2016. if ($(this).attr("group") == group) {
  2017. groupExists = true;
  2018. targetGroupingTab = $(this);
  2019. }
  2020. });
  2021. //Check if the group is System Explorer and held special treatment if yes
  2022. if (group.split("/").shift() == "SystemAO") {
  2023. if (url.includes("file_explorer.html") && groupExists) {
  2024. //File Manager. Group them
  2025. group = "file_explorer";
  2026. }else if (url.includes("utilities") && groupExists){
  2027. //Allow grouping
  2028. } else {
  2029. //Do not group anything from SystemAO other than file explorer
  2030. groupExists = false;
  2031. }
  2032. }
  2033. if (groupExists == false) {
  2034. //Append the item to taskbar
  2035. var windowIDGroup = encodeURIComponent(JSON.stringify([uuid]));
  2036. var floatWindowButtonObject = ` <div class="item clickable floatWindowButton onscreen" group="${group}" windowIDGroup="${windowIDGroup}">
  2037. <img class="floatWindowAppIcon" src="${moduleIcon}"></img>
  2038. <p class="floatWindowTitle">${title}</p>
  2039. </div>`;
  2040. $(".navimenu").append(floatWindowButtonObject);
  2041. } else {
  2042. //Group already exists. Add tab into that group.
  2043. var originalIDlist = JSON.parse(decodeURIComponent($(targetGroupingTab).attr('windowIDGroup')));
  2044. originalIDlist.push(uuid);
  2045. //Encode and put the group list back to the object
  2046. var newIDList = encodeURIComponent(JSON.stringify(originalIDlist));
  2047. $(targetGroupingTab).attr("windowIDGroup", newIDList);
  2048. }
  2049. hookFloatWindowEvents();
  2050. resizeAllFloatWindowButtons();
  2051. if (callback !== undefined){
  2052. callback(uuid);
  2053. }
  2054. }
  2055. function resizeAllFloatWindowButtons() {
  2056. var fwbTotalWidth = $(".floatWindowButton").length * 200;
  2057. if (fwbTotalWidth > window.innerWidth * 0.7) {
  2058. $(".floatWindowButton").addClass("hideText");
  2059. } else {
  2060. $(".floatWindowButton").removeClass("hideText");
  2061. }
  2062. }
  2063. function floatWindowLocationDuplicated(left, top) {
  2064. var duplicated = false;
  2065. $(".floatWindow").each(function() {
  2066. if ($(this).offset().left == left && $(this).offset().top == top) {
  2067. duplicated = true;
  2068. }
  2069. });
  2070. return duplicated;
  2071. }
  2072. function defaultOrKey(object, defaultvalue, key) {
  2073. if (object[key] !== undefined) {
  2074. return object[key];
  2075. }
  2076. return defaultvalue;
  2077. }
  2078. function getFloatWindowByID(id) {
  2079. var targetWindow = undefined;
  2080. $(".floatWindow").each(function() {
  2081. if ($(this).attr("windowId") == id) {
  2082. targetWindow = $(this);
  2083. }
  2084. });
  2085. return targetWindow;
  2086. }
  2087. function getFloatWindowIconByID(id) {
  2088. var targetIconURL = "img/system/favicon.png";
  2089. $(".floatWindow").each(function() {
  2090. if ($(this).attr("windowId") == id) {
  2091. //This window ID matched the target fw
  2092. targetIconURL = $(this).find(".moduleicon").attr('src');
  2093. }
  2094. });
  2095. return targetIconURL;
  2096. }
  2097. function getFloatWindowTitleByID(id) {
  2098. var title = "";
  2099. $(".floatWindow").each(function() {
  2100. if ($(this).attr("windowId") == id) {
  2101. //This window ID matched the target fw
  2102. title = $(this).find(".title").text();
  2103. }
  2104. });
  2105. return title;
  2106. }
  2107. function setFloatWindowResizePolicy(targetFWId, resizble = true) {
  2108. var targetfw = getFloatWindowByID(targetFWId);
  2109. if (resizble) {
  2110. $(targetfw).find(".maxtoggle").show();
  2111. $(targetfw).removeClass("fixedsize");
  2112. } else {
  2113. $(targetfw).find(".maxtoggle").hide();
  2114. $(targetfw).addClass("fixedsize");
  2115. }
  2116. }
  2117. function setFloatWindowSize(targetFWId, newWidth, newHeight) {
  2118. var targetfw = getFloatWindowByID(targetFWId);
  2119. $(targetfw).css({
  2120. height: newHeight,
  2121. width: newWidth
  2122. });
  2123. }
  2124. function setFloatWindowTitle(targetFWId, newTitle) {
  2125. var targetfw = getFloatWindowByID(targetFWId);
  2126. $(targetfw).find(".title").text(newTitle);
  2127. }
  2128. function openFileWithModule(moduleLaunchInfo, openFileList) {
  2129. var url = moduleLaunchInfo["StartDir"];
  2130. var size = [undefined, undefined];
  2131. var title = moduleLaunchInfo["Name"];
  2132. var icon = "img/system/favicon.png";
  2133. if (moduleLaunchInfo["IconPath"] != "") {
  2134. icon = moduleLaunchInfo["IconPath"];
  2135. }
  2136. //Use floatWindow if exists
  2137. if (moduleLaunchInfo["SupportFW"] == true && moduleLaunchInfo["LaunchFWDir"] != "") {
  2138. url = moduleLaunchInfo["LaunchFWDir"];
  2139. if (moduleLaunchInfo["InitFWSize"] !== null) {
  2140. size = moduleLaunchInfo["InitFWSize"]
  2141. }
  2142. }
  2143. //Use embedded mode if exists
  2144. if (moduleLaunchInfo["SupportEmb"] == true && moduleLaunchInfo["LaunchEmb"] != "") {
  2145. url = moduleLaunchInfo["LaunchEmb"];
  2146. if (moduleLaunchInfo["InitEmbSize"] !== null) {
  2147. size = moduleLaunchInfo["InitEmbSize"]
  2148. }
  2149. }
  2150. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  2151. //Add launch files info and launch floatWindow
  2152. parent.newFloatWindow({
  2153. url: url + "#" + openParamter,
  2154. width: size[0],
  2155. height: size[1],
  2156. appicon: icon,
  2157. title: title
  2158. });
  2159. }
  2160. //====================== DESKTOP THEME RELATED FUNCTIONS =====================
  2161. //Initiate desktop theme list and user current theme
  2162. function initDesktopTheme() {
  2163. //Update 1 April 2021: Check if the user customize the desktop with the given path
  2164. $.get("system/desktop/theme", function(data) {
  2165. //Return a list of theme stored on the system
  2166. desktopThemeList = data;
  2167. $.get("system/desktop/theme?get=true", function(data) {
  2168. //Get the user theme settings
  2169. changeDesktopTheme(data);
  2170. });
  2171. });
  2172. }
  2173. function setDesktopTheme(themeName) {
  2174. $.get("system/desktop/theme?set=" + themeName, function(data) {
  2175. //Get the user theme settings
  2176. changeDesktopTheme(themeName);
  2177. if (data.includes("Error")) {
  2178. console.log(data);
  2179. }
  2180. });
  2181. }
  2182. //Actiave background cross fade changing animation
  2183. function initBackgroundSwitchingAnimation() {
  2184. if (localStorage.getItem("ao/desktop/backgroundInterval") !== null && !isNaN(parseInt(localStorage.getItem("ao/desktop/backgroundInterval")))){
  2185. //Localstorage has interval setting that is not NaN
  2186. backgroundCrossfadeInterval = parseInt(localStorage.getItem("ao/desktop/backgroundInterval")) * 1000;
  2187. }
  2188. backgroundIntervalCounter = setInterval(function() {
  2189. $("body").css("background-image", "none").css({
  2190. 'background-color': '#000000'
  2191. });
  2192. $(".showBackground").removeClass("showBackground");
  2193. $($(".backgroundFrame")[nextSlideshowIndex]).addClass("showBackground");
  2194. nextSlideshowIndex++;
  2195. if (nextSlideshowIndex > currentBackgroundList.length - 1) {
  2196. nextSlideshowIndex = 0;
  2197. }
  2198. }, backgroundCrossfadeInterval);
  2199. }
  2200. //Function for changing the desktop theme
  2201. function changeDesktopTheme(targetThemeName) {
  2202. currentUserTheme = targetThemeName;
  2203. if (currentUserTheme.includes(":/") == false){
  2204. //This is default theme pack name
  2205. for (var i = 0; i < desktopThemeList.length; i++) {
  2206. var thisTheme = desktopThemeList[i];
  2207. if (thisTheme["Theme"] == targetThemeName) {
  2208. //Use this config as the target theme
  2209. currentBackgroundList = thisTheme["Bglist"];
  2210. break;
  2211. }
  2212. }
  2213. //Initiate the background image.
  2214. $("#bgwrapper").html("");
  2215. for (var i = 0; i < currentBackgroundList.length; i++) {
  2216. var id = "dbg" + i;
  2217. var thisImage = "img/desktop/bg/" + currentUserTheme + "/" + currentBackgroundList[i];
  2218. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2219. }
  2220. setTimeout(function() {
  2221. $("#dbg0").addClass("showBackground");
  2222. }, 300);
  2223. if (currentBackgroundList.length == 1) {
  2224. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2225. nextSlideshowIndex = 0;
  2226. }else if (currentBackgroundList.length == 0){
  2227. //Background no longer exists. Change to default
  2228. changeDesktopTheme("default");
  2229. } else {
  2230. nextSlideshowIndex = 1;
  2231. }
  2232. }else{
  2233. //This is user defined photo file
  2234. $.get("system/desktop/theme?load=" + targetThemeName, function(data){
  2235. if (data.error !== undefined){
  2236. //The folder is gone. Use default instead
  2237. console.log(data.error);
  2238. changeDesktopTheme("default");
  2239. }else{
  2240. //OK! Load it
  2241. currentBackgroundList = data;
  2242. $("#bgwrapper").html("");
  2243. for (var i = 0; i < currentBackgroundList.length; i++) {
  2244. var id = "dbg" + i;
  2245. var thisImage = "media/?file=" + currentBackgroundList[i];
  2246. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2247. }
  2248. setTimeout(function() {
  2249. $("#dbg0").addClass("showBackground");
  2250. }, 300);
  2251. if (currentBackgroundList.length == 1) {
  2252. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2253. nextSlideshowIndex = 0;
  2254. }else if (currentBackgroundList.length == 0){
  2255. //Background no longer exists. Change to default
  2256. changeDesktopTheme("default");
  2257. } else {
  2258. nextSlideshowIndex = 1;
  2259. }
  2260. }
  2261. });
  2262. }
  2263. }
  2264. $("#bgwrapper").on("click", function(evt) {
  2265. evt.preventDefault();
  2266. });
  2267. //================== DESKTOP FILE LOCATION FUNCTIONS ====================
  2268. function initDesktopFiles(optionObject = {}, callback = undefined) {
  2269. $.get("system/desktop/listDesktop", function(data) {
  2270. //Prase optionObject
  2271. var noflash = false;
  2272. if (typeof optionObject.noflash !== "undefined"){
  2273. noflash = optionObject.noflash;
  2274. }
  2275. if (noflash){
  2276. //Only clean out those object that not exists in the new filelist
  2277. var existsingFilepaths = [];
  2278. if (data != null){
  2279. for (var i =0; i < data.length; i++){
  2280. existsingFilepaths.push(data[i].Filepath);
  2281. }
  2282. }else{
  2283. //Nothing on desktop
  2284. }
  2285. //console.log(existsingFilepaths);
  2286. //If the launchIcon path is not in the latest list, remove it from desktop
  2287. $(".launchIcon").each(function(){
  2288. if (existsingFilepaths.includes($(this).attr("filepath")) == false){
  2289. $(this).remove();
  2290. }
  2291. });
  2292. }else{
  2293. //Cleanup all previous icons
  2294. $("#iconwrapper").html("");
  2295. }
  2296. //Allocate new items location
  2297. var iheight = 106;
  2298. var iwidth = 70;
  2299. var padding = 16;
  2300. if (desktopIconSize == "small") {
  2301. iheight = 82;
  2302. iwidth = 50;
  2303. } else if (desktopIconSize == "medium") {
  2304. iheight = 106;
  2305. iwidth = 70;
  2306. } else if (desktopIconSize == "big") {
  2307. iheight = 124;
  2308. iwidth = 84;
  2309. }
  2310. iconSize = [iwidth, iheight];
  2311. var screenHeight = window.innerHeight;
  2312. var screenWidth = window.innerWidth;
  2313. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2314. var hc = Math.floor((screenWidth - padding) / iwidth);
  2315. var slots = []; //A 2D array for storing relative to absolute locations
  2316. for (var j = 0; j < hc; j++) {
  2317. var thisLocationList = [];
  2318. for (var i = 0; i < vc; i++) {
  2319. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2320. thisLocationList.push(thisLocation);
  2321. }
  2322. slots.push(thisLocationList);
  2323. }
  2324. //Store the root position (0,0) in rootPosition
  2325. let rootPosition = JSON.parse(JSON.stringify(slots[0][0]));
  2326. desktopGrids = JSON.parse(JSON.stringify(slots));
  2327. //Assign items to desktop
  2328. var unallocatedFiles = [];
  2329. let remainingSlots = JSON.parse(JSON.stringify(slots));
  2330. desktopFileList = [];
  2331. if (data === null){
  2332. //No files on desktop
  2333. return;
  2334. }
  2335. for (var i = 0; i < data.length; i++) {
  2336. var thisFile = data[i];
  2337. desktopFileList.push(JSON.parse(JSON.stringify(thisFile.Filename)));
  2338. //Get icon from the icon list
  2339. var location = [thisFile.IconX, thisFile.IconY];
  2340. if (location[0] == -1 && location[1] == -1) {
  2341. //This file is not located. Push it into unallocatedFileList
  2342. unallocatedFiles.push(thisFile);
  2343. } else if (location[0] >= slots.length || location[1] >= slots[0].length) {
  2344. //This file is outside of the screen area. Set to be be unallocatedFiles as well
  2345. unallocatedFiles.push(thisFile);
  2346. } else {
  2347. //This file is already located. Push it location into occupiedSlots
  2348. //var screenX = location[0] * iwidth + padding/2;
  2349. //var screenY = location[1] * iheight + padding/2;
  2350. var screenLocation = slots[location[0]][location[1]];
  2351. //Remove this object from remaining slots
  2352. remainingSlots[location[0]][location[1]] = undefined;
  2353. //console.log(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth);
  2354. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2355. }
  2356. }
  2357. //Foreach remaining files, assign a location for it.
  2358. var walk = [slots.length, slots[0].length];
  2359. var current = [0, 0];
  2360. for (var i = 0; i < unallocatedFiles.length; i++) {
  2361. var thisFile = unallocatedFiles[i];
  2362. try{
  2363. while (typeof(remainingSlots[current[0]][current[1]]) == "undefined") {
  2364. //This slot is not usabled. Next slot.
  2365. current[1] += 1;
  2366. if (current[1] >= walk[1]) {
  2367. current[1] = 0;
  2368. current[0] += 1;
  2369. }
  2370. if (typeof(remainingSlots[current[0]]) == "undefined"){
  2371. //Not enough space to fit the item. Move it to 0 0 instead
  2372. current = [-1,-1];
  2373. console.log(current);
  2374. break;
  2375. }
  2376. }
  2377. }catch{
  2378. //Something went wrong while assigning positions. Set at root location
  2379. current = [-1,-1];
  2380. }
  2381. //Append the icon to screen
  2382. if (current[0] == -1 && current[1] == -1){
  2383. //Screen overflow. Stack the file at (0,0)
  2384. screenLocation = [rootPosition[0], rootPosition[1]];
  2385. console.log(screenLocation);
  2386. }else{
  2387. screenLocation = remainingSlots[current[0]][current[1]];
  2388. remainingSlots[current[0]][current[1]] = undefined;
  2389. }
  2390. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2391. //Save the icon location to server
  2392. $.ajax({
  2393. url: "system/desktop/files",
  2394. method: "POST",
  2395. data: {"set": thisFile.Filename, "x": current[0], "y": current[1]},
  2396. success: function(data) {
  2397. if (data.error !== undefined) {
  2398. console.log(data.error);
  2399. }
  2400. }
  2401. });
  2402. }
  2403. if (callback !== undefined) {
  2404. //console.log(callback);
  2405. callback();
  2406. }
  2407. });
  2408. }
  2409. //Handle desktop file multi selection and dragging
  2410. $("#bgwrapper").on("mousedown", function(evt) {
  2411. initMultiSelection(evt);
  2412. });
  2413. $("#bgwrapper").on("touchstart", function(evt) {
  2414. initMultiSelection(evt);
  2415. });
  2416. $("body").on("mouseup", function(evt) {
  2417. mainWindowMouseup(evt);
  2418. });
  2419. $("body").on("touchend", function(evt) {
  2420. mainWindowMouseup(evt);
  2421. });
  2422. $("#selectionPanel").on("mouseup", function(event) {
  2423. });
  2424. function mainWindowMouseup(event) {
  2425. if (event.pageX == multiSelectionStartPoint[0] && event.pageY == multiSelectionStartPoint[1]) {
  2426. //Pressdown and up at the same location
  2427. $(".launchIconWrapper.selected").removeClass("selected");
  2428. endMultiSelection(event);
  2429. } else {
  2430. //Press down and up at different location
  2431. endMultiSelection(event);
  2432. }
  2433. if (resizingWindow){
  2434. //Resizing floatWindow out of the window bound (aka someone don't know how to resize a window correctly)
  2435. resizingWindow = false;
  2436. resizingEdgeID = 0;
  2437. $("#fwdragpanel").hide();
  2438. $("#tfwdragpanel").hide();
  2439. $('.floatWindow.topmost').css("pointer-events", "auto");
  2440. $('.floatWindow.topmost').css("opacity", 1);
  2441. $(resizingWindowTarget).find(".iframecover").hide();
  2442. $(resizingWindowTarget).find(".iframewrapper").css('cursor', '');
  2443. }
  2444. }
  2445. function initMultiSelection(event) {
  2446. event.preventDefault();
  2447. multiSelecting = true;
  2448. hideAllContextMenus();
  2449. $("#selectionPanel").css({
  2450. left: event.pageX,
  2451. top: event.pageY,
  2452. width: 0,
  2453. height: 0
  2454. });
  2455. $("#selectionPanel").show();
  2456. multiSelectionStartPoint = [event.pageX, event.pageY];
  2457. }
  2458. function movingMultiSelectionArea(event) {
  2459. event.preventDefault();
  2460. var sx = multiSelectionStartPoint[0];
  2461. var sy = multiSelectionStartPoint[1];
  2462. var ex = event.pageX;
  2463. var ey = event.pageY;
  2464. var newleft = sx;
  2465. if (ex < sx) {
  2466. newleft = ex;
  2467. }
  2468. var newtop = sy;
  2469. if (ey < sy) {
  2470. newtop = ey;
  2471. }
  2472. var newWidth = Math.abs(sx - ex);
  2473. var newHeight = Math.abs(sy - ey);
  2474. $("#selectionPanel").css({
  2475. left: newleft,
  2476. top: newtop,
  2477. width: newWidth,
  2478. height: newHeight
  2479. });
  2480. //Select all the launch icon selected
  2481. selectAllLaunchIconInRange(newleft, newleft + newWidth, newtop, newtop + newHeight);
  2482. }
  2483. function endMultiSelection(event) {
  2484. event.preventDefault();
  2485. multiSelecting = false;
  2486. multiSelectionStartPoint = [-1, -1];
  2487. $("#selectionPanel").hide();
  2488. }
  2489. function selectAllLaunchIconInRange(minX, maxX, minY, maxY) {
  2490. //Select launch icons from its center point
  2491. var xOffset = iconSize[0] / 2;
  2492. var yOffset = iconSize[1] / 2;
  2493. $(".launchIconWrapper.selected").removeClass("selected");
  2494. $(".launchIcon").each(function() {
  2495. //Calculate center point for this icon
  2496. var thisX = $(this).offset().left + xOffset;
  2497. var thisY = $(this).offset().top + yOffset;
  2498. if (thisX > minX && thisX < maxX) {
  2499. if (thisY > minY && thisY < maxY) {
  2500. $(this).find(".launchIconWrapper").addClass("selected");
  2501. }
  2502. }
  2503. });
  2504. }
  2505. function redrawDesktopGrids() {
  2506. var iheight = 106;
  2507. var iwidth = 70;
  2508. var padding = 16;
  2509. if (desktopIconSize == "small") {
  2510. iheight = 82;
  2511. iwidth = 50;
  2512. } else if (desktopIconSize == "medium") {
  2513. iheight = 106;
  2514. iwidth = 70;
  2515. } else if (desktopIconSize == "big") {
  2516. iheight = 124;
  2517. iwidth = 84;
  2518. }
  2519. iconSize = [iwidth, iheight];
  2520. var screenHeight = window.innerHeight;
  2521. var screenWidth = window.innerWidth;
  2522. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2523. var hc = Math.floor((screenWidth - padding) / iwidth);
  2524. var slots = []; //A 2D array for storing relative to absolute locations
  2525. for (var j = 0; j < hc; j++) {
  2526. var thisLocationList = [];
  2527. for (var i = 0; i < vc; i++) {
  2528. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2529. thisLocationList.push(thisLocation);
  2530. }
  2531. slots.push(thisLocationList);
  2532. }
  2533. desktopGrids = JSON.parse(JSON.stringify(slots));
  2534. }
  2535. function appendIconAtLocation(filedata, screenX, screenY, iheight, iwidth, updateMode=false) {
  2536. //Get the icon from extension
  2537. var icon = ao_module_utils.getIconFromExt(filedata.Ext.substring(1, filedata.Ext.length));
  2538. var imagePath = "img/desktop/files_icon/" + desktopIconPack + "/" + icon + ".png";
  2539. //Handle special icon types here
  2540. var size = desktopIconSize;
  2541. var filename = JSON.parse(JSON.stringify(filedata.Filename));
  2542. var filepath = JSON.parse(JSON.stringify(filedata.Filepath));
  2543. var isDir = JSON.parse(JSON.stringify(filedata.IsDir));
  2544. var isEmptyDir = JSON.parse(JSON.stringify(filedata.IsEmptyDir));
  2545. var isShared = JSON.parse(JSON.stringify(filedata.IsShared));
  2546. var maxlength = 12;
  2547. var type = "file";
  2548. let shortenedName = filename;
  2549. screenX += iconOffsetXY[0];
  2550. screenY += iconOffsetXY[1];
  2551. if (isDir) {
  2552. //Folder objects
  2553. icon = "folder outline";
  2554. if (isEmptyDir){
  2555. imagePath = "img/desktop/system_icon/folder.png";
  2556. }else{
  2557. imagePath = "img/desktop/system_icon/folder-with-content.png";
  2558. }
  2559. type = "folder";
  2560. } else if (isDir == false && icon == "folder outline") {
  2561. icon = "file outline";
  2562. imagePath = "img/desktop/files_icon/" + desktopIconPack + "/file outline.png";
  2563. type = "file";
  2564. } else if (filedata.Ext == ".exe" || filedata.Ext == ".elf") {
  2565. //Executable objects
  2566. imagePath = "img/desktop/system_icon/script.png";
  2567. type = "executable";
  2568. } else if (filedata.Ext == ".shortcut") {
  2569. //Shortcut
  2570. var shortcutImage = filedata.ShortcutImage;
  2571. shortenedName = JSON.parse(JSON.stringify(filedata.ShortcutName));
  2572. imagePath = shortcutImage;
  2573. type = "shortcut";
  2574. }
  2575. //Check if filename is english only.
  2576. if (/^[a-zA-Z\d .-=+]+$/.test(filename)) {
  2577. maxlength = 20;
  2578. }else{
  2579. //Check if it is under small text mode
  2580. if (size == "small"){
  2581. maxlength = 10;
  2582. }
  2583. }
  2584. if (type != "shortcut" && filename.length > maxlength) {
  2585. shortenedName = filename.substring(0, maxlength) + "...";
  2586. }
  2587. var compressedFiledata = ao_module_utils.objectToAttr(filedata);
  2588. if (updateMode){
  2589. //Update the content that already exists for the same filepath object
  2590. var updateObject = undefined;
  2591. $(".launchIcon").each(function(){
  2592. if ($(this).attr("filedata") == compressedFiledata){
  2593. updateObject = $(this);
  2594. }
  2595. });
  2596. if (updateObject !== undefined){
  2597. //Check if content identical. If yes, skip rewrite
  2598. if (updateObject.attr("filedata") == compressedFiledata){
  2599. //Identical. Skipping
  2600. }else{
  2601. //Update its contents
  2602. updateObject.attr("type", type);
  2603. updateObject.attr("filename", filename);
  2604. updateObject.attr("filepath", filepath);
  2605. updateObject.attr("filedata", compressedFiledata);
  2606. updateObject.css("width", iwidth + "px");
  2607. updateObject.css("height", iheight + "px");
  2608. updateObject.css("left", screenX + "px");
  2609. updateObject.css("top", screenY + "px");
  2610. }
  2611. }else{
  2612. //No exists. Append to wrapper
  2613. appendDesktopIcon($("#iconwrapper"),{
  2614. type: type,
  2615. filename: filename,
  2616. filepath: filepath,
  2617. compressedFiledata: compressedFiledata,
  2618. iwidth: iwidth,
  2619. iheight: iheight,
  2620. screenX: screenX,
  2621. screenY: screenY,
  2622. size: size,
  2623. imagePath: imagePath,
  2624. shortenedName: shortenedName,
  2625. isShared: isShared,
  2626. });
  2627. }
  2628. }else{
  2629. //Append into the desktop
  2630. appendDesktopIcon($("#iconwrapper"),{
  2631. type: type,
  2632. filename: filename,
  2633. filepath: filepath,
  2634. compressedFiledata: compressedFiledata,
  2635. iwidth: iwidth,
  2636. iheight: iheight,
  2637. screenX: screenX,
  2638. screenY: screenY,
  2639. size: size,
  2640. imagePath: imagePath,
  2641. shortenedName: shortenedName,
  2642. isShared: isShared,
  2643. });
  2644. }
  2645. }
  2646. /*
  2647. Main function to append desktop icon to desktop
  2648. Usage: Pass in the target (as jquery object, usually $("#iconwrapper")) and properties with the following object
  2649. properties = {
  2650. type: "",
  2651. filename: "",
  2652. filepath: "",
  2653. compressedFiledata: "",
  2654. iwidth: "",
  2655. iheight: "",
  2656. screenX: "",
  2657. screenY: "",
  2658. size: "",
  2659. imagePath: "",
  2660. shortenedName: "",
  2661. }
  2662. Where the enmty string is the value that require filling in
  2663. */
  2664. function appendDesktopIcon(target, properties){
  2665. var htmlType = "div";
  2666. var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  2667. if (properties.type == "file" && isChrome){
  2668. htmlType = "a";
  2669. }
  2670. var thisIcon = $(`<${htmlType} href="javascript:void(0);" class="launchIcon"
  2671. type="${properties.type}"
  2672. draggable="true"
  2673. ondragover="allowDrop(event)"
  2674. ondrop="drop(event)"
  2675. ondragstart="drag(event)"
  2676. onmousedown="iconClicked(this,event);"
  2677. ondblclick="iconDoubleClicked(this,event);"
  2678. ontouchstart="iconClicked(this,event); doubleTouchHandler(this, event,openViaTouch);"
  2679. filename="${properties.filename}"
  2680. filepath="${properties.filepath}"
  2681. filedata="${properties.compressedFiledata}"
  2682. style="width:${properties.iwidth}px; height:${properties.iheight}px;left:${properties.screenX}px; top:${properties.screenY}px;">
  2683. <span class="launchIconWrapper">
  2684. <img class="launchIconImage ${properties.size}" src="${properties.imagePath}" draggable="false"></img>
  2685. <p class="launchIconText ${properties.size} ">${properties.shortenedName}</p>
  2686. </span>
  2687. </${htmlType}>`);
  2688. $(target).append(thisIcon);
  2689. //Updates 20 May 2021: Check if this file is shared. If yes, append the share icon
  2690. if (typeof(properties.isShared) != "undefined" && properties.isShared == true){
  2691. setFileShareIndicator(properties.filename);
  2692. }
  2693. if (properties.type == "file" && isChrome){
  2694. console.log(isChrome);
  2695. let thisFilepath = properties.filepath;
  2696. $(thisIcon)[0].addEventListener("dragstart",function(evt){
  2697. //var filecontent = toDataUrl("media/?file=" + thisFilepath);
  2698. //var fileBase64 = window.btoa(filecontent);
  2699. var targetMime = "plain/text";
  2700. $.ajax({
  2701. url: "media/getMime/?file=" + encodeURIComponent(properties.filepath),
  2702. success: function(data){
  2703. if (data.error !== undefined){
  2704. targetMime = "text/directory";
  2705. }else{
  2706. targetMime = data;
  2707. }
  2708. },
  2709. async: false
  2710. });
  2711. evt.dataTransfer.setData("DownloadURL",targetMime+":"+ properties.filename +":"+ location.protocol + "//" + location.hostname + ":" + location.port + "/media/?file=" + encodeURIComponent(properties.filepath));
  2712. //evt.dataTransfer.setData("DownloadURL","video/mp4"+":"+"test.mp4"+":"+"data:"+"video/mp4"+";base64,"+fileBase64);
  2713. },false);
  2714. }
  2715. }
  2716. /*
  2717. Share indicator settings
  2718. This append or remove share from a particular file
  2719. Only require filename as all files here are on desktop
  2720. */
  2721. function getFileObjectByFilename(filename){
  2722. var result = null;
  2723. $(".launchIcon").each(function(){
  2724. var thisFilename = $(this).attr("filename");
  2725. if (thisFilename == filename){
  2726. result = $(this);
  2727. }
  2728. });
  2729. return result;
  2730. }
  2731. function setFileShareIndicator(filename){
  2732. var targetFileObject = getFileObjectByFilename(filename);
  2733. if (targetFileObject == null){
  2734. return;
  2735. }
  2736. var sharedIcon = `<div class="fileShareIndicator ${desktopIconSize}">
  2737. <img src="img/desktop/system_icon/shared.png">
  2738. </div>`;
  2739. $(targetFileObject).find(".launchIconWrapper").append(sharedIcon);
  2740. }
  2741. function removeFileShareIndicator(filename){
  2742. var targetFileObject = getFileObjectByFilename(filename);
  2743. if (targetFileObject == null){
  2744. return;
  2745. }
  2746. var indicator = $(targetFileObject).find(".fileShareIndicator");
  2747. if (indicator.length > 0){
  2748. indicator.remove();
  2749. }
  2750. }
  2751. // ========================== LAUNCH ICON OPERATIONS ================
  2752. //This function start all the launchicon related events
  2753. function drag(ev) {
  2754. //If rename mode, disable drag drop
  2755. if (renameMode){
  2756. return false;
  2757. }
  2758. var target = ev.target;
  2759. if (!($(ev.target).is("div") || $(ev.target).is("a"))) {
  2760. target = $(target).parent();
  2761. }
  2762. //Parse the standard filename / filepath data
  2763. var filename = $(target).attr("filename");
  2764. var filepath = $(target).attr('filepath');
  2765. ev.dataTransfer.setData("filename", filename);
  2766. ev.dataTransfer.setData("filepath", filepath);
  2767. //Parse multifile selection filedata
  2768. var filelist = [];
  2769. if ($(".launchIconWrapper.selected").length > 0){
  2770. if (ctrlHold || $(".launchIconWrapper.selected").length > 1){
  2771. //Include all objects selected
  2772. $(".launchIconWrapper.selected").each(function(){
  2773. var fd = $(this).parent().attr("filedata");
  2774. fd = JSON.parse(decodeURIComponent(fd));
  2775. filelist.push({
  2776. filename: fd.Filename,
  2777. filepath: fd.Filepath,
  2778. hostUUID: hostInfo.DeviceUUID
  2779. });
  2780. });
  2781. }else{
  2782. //Only push the one selected
  2783. filelist.push({
  2784. filename: filename,
  2785. filepath: filepath,
  2786. hostUUID: hostInfo.DeviceUUID
  2787. });
  2788. }
  2789. }else{
  2790. //There is no selected item on desktop. Use the drag drop one
  2791. filelist.push({
  2792. filename: filename,
  2793. filepath: filepath
  2794. });
  2795. }
  2796. //console.log(filelist);
  2797. ev.dataTransfer.setData("filedata", JSON.stringify(filelist));
  2798. console.log(filelist);
  2799. //Set a flag on the drag events that these files are from Desktop GUI
  2800. ev.dataTransfer.setData("desktopflag", "true");
  2801. //Record the start drop relative position of the icon object
  2802. var dx = ev.pageX - $(target).offset().left;
  2803. var dy = ev.pageY - $(target).offset().top;
  2804. startDragRelatuve = [dx, dy];
  2805. ev.stopPropagation();
  2806. }
  2807. function drop(ev) {
  2808. ev.preventDefault();
  2809. ev.stopImmediatePropagation();
  2810. var target = $(ev.target);
  2811. if (!(target.is("div") || target.is("a"))) {
  2812. target = $(target).parent();
  2813. }
  2814. if (target.hasClass("launchIconWrapper")) {
  2815. target = target.parent();
  2816. }
  2817. var thisFilepath = $(target).attr("filepath");
  2818. if (thisFilepath == ev.dataTransfer.getData("filepath")) {
  2819. //Drag and drop on the same item. Ignore it
  2820. return;
  2821. }
  2822. var sourceFilename = ev.dataTransfer.getData("filename");
  2823. var sourceFilepath = ev.dataTransfer.getData("filepath");
  2824. //To handle multiple file transfer from file explorer
  2825. var sourceFilelist = ev.dataTransfer.getData("filedata");
  2826. console.log(target)
  2827. console.log(sourceFilename);
  2828. console.log(sourceFilepath);
  2829. if (sourceFilelist !== ""){
  2830. sourceFilelist = JSON.parse(sourceFilelist);
  2831. }
  2832. console.log(sourceFilelist);
  2833. //Drop opererations
  2834. if (target.attr("id") == "bgwrapper") {
  2835. if (sourceFilename == "" && sourceFilepath == "" && ev.dataTransfer.files.length > 0){
  2836. //Drag drop from external source. Upload to desktop
  2837. //Assign the locations for the objects
  2838. var files = ev.dataTransfer.files;
  2839. var gridMaxX = desktopGrids.length;
  2840. var gridMaxY = desktopGrids[0].length;
  2841. var targetLocation = findClosestGrid((ev.clientX), (ev.clientY), false);
  2842. var targetGridLocation = targetLocation[1];
  2843. var locations = [];
  2844. for (var k =0; k < files.length; k++){
  2845. var thisLocation = JSON.parse(JSON.stringify(targetGridLocation));
  2846. //Add k to y axis of the list.
  2847. thisLocation[1] += k;
  2848. if (thisLocation[1] >= gridMaxY){
  2849. thisLocation[0]++;
  2850. thisLocation[1] = 0;
  2851. }
  2852. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2853. //Desktop full. Force put to 0 0
  2854. thisLocation[0] = 0;
  2855. thisLocation[1] = 0;
  2856. break;
  2857. }
  2858. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  2859. thisLocation[1] += 1;
  2860. if (thisLocation[1] >= gridMaxY){
  2861. //Over the screen. Shift to the row on the right
  2862. thisLocation[0]++;
  2863. thisLocation[1] = 0;
  2864. }
  2865. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2866. //Desktop full. Force put to 0 0
  2867. thisLocation[0] = 0;
  2868. thisLocation[1] = 0;
  2869. break;
  2870. }
  2871. }
  2872. locations.push(thisLocation)
  2873. }
  2874. console.log(locations, ev.dataTransfer.files);
  2875. //Register file locations
  2876. for (var j =0; j < locations.length; j++){
  2877. let thisFile = files[j];
  2878. let thisFilename = files[j].name;
  2879. let x = parseInt(locations[j][0]);
  2880. let y = parseInt(locations[j][1]);
  2881. uploadFile(thisFile,function(){
  2882. console.log("Uploader callback");
  2883. $.ajax({
  2884. url: "system/desktop/files",
  2885. method: "POST",
  2886. data: {"set": thisFilename, "x": x, "y": y},
  2887. success: function(data) {
  2888. //Refresh the desktop
  2889. refresh(undefined, true);
  2890. }
  2891. });
  2892. });
  2893. }
  2894. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  2895. //Drag drop multiple files from desktop or file explorer to desktop
  2896. var desktopFlag = ev.dataTransfer.getData("desktopflag");
  2897. if (desktopFlag == "" || desktopFlag === undefined || desktopFlag == null){
  2898. //This is a file drag drop from not desktop to desktop
  2899. var filelist = ev.dataTransfer.getData("filedata");
  2900. if (filelist != ""){
  2901. filelist = JSON.parse(filelist);
  2902. if (filelist.length == 0){
  2903. return
  2904. }
  2905. //Get the position for this drop events and arrange grid locations
  2906. var gridPosition = gridPositionAllocate(ev.clientX, ev.clientY, filelist.length);
  2907. console.log(gridPosition)
  2908. //Check if source is also from user:/
  2909. var srcVroot = filelist[0].filepath.split(":/").shift();
  2910. var mode = "copy"
  2911. var title = "Copying "
  2912. if (srcVroot == "user"){
  2913. //Move
  2914. mode = "move"
  2915. title = "Moving "
  2916. }
  2917. //Check if any of the files already exists on desktop
  2918. /*
  2919. var duplicateFound = false;
  2920. filelist.forEach(file => {
  2921. var thisFilename = file.filename;
  2922. desktopFileList.forEach(desktopFile => {
  2923. if (desktopFile == thisFilename){
  2924. //Diplicate
  2925. duplicateFound = true;
  2926. }
  2927. });
  2928. });
  2929. */
  2930. var filepathList = [];
  2931. filelist.forEach(file => {
  2932. filepathList.push(file.filepath)
  2933. });
  2934. //Start the file operation dialog
  2935. var oprConfig = {
  2936. opr: mode,
  2937. src: filepathList,
  2938. dest: "user:/Desktop/",
  2939. overwriteMode: "ask"
  2940. }
  2941. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2942. //Genreate window title
  2943. title = title + filepathList.length;
  2944. if (filepathList.length > 1){
  2945. title += " files";
  2946. }else{
  2947. title += " file";
  2948. }
  2949. newFloatWindow({
  2950. url: "SystemAO/file_system/file_operation.html#" + configHash,
  2951. width: 400,
  2952. height: 220,
  2953. appicon: "SystemAO/file_system/img/selector.png",
  2954. title: title
  2955. });
  2956. }
  2957. }else{
  2958. //This is a file drag event from desktop, but more than one files.
  2959. //Pin the final location for the drag drop object
  2960. var sourceObject = getObjectFromPath(sourceFilepath);
  2961. var dx = startDragRelatuve[0];
  2962. var dy = startDragRelatuve[1];
  2963. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  2964. var closestLocation = targetLocation[0];
  2965. var duplicateObject = getObjectFromLocation(closestLocation[0] + iconOffsetXY[0], closestLocation[1] + iconOffsetXY[1]);
  2966. if (duplicateObject !== undefined) {
  2967. //There are already object there. Do nothing
  2968. console.log("Drop location duplicated!")
  2969. return;
  2970. }
  2971. //Get other objects that is not the one drag dropped
  2972. var iconOffset = {};
  2973. for (var i =0; i < sourceFilelist.length; i++){
  2974. var thisFile = sourceFilelist[i];
  2975. if (thisFile.filepath != sourceFilepath){
  2976. //Calculate the x y offset of this icon to the drag drop one
  2977. var thisIconObject = getObjectFromPath(thisFile.filepath);
  2978. iconOffset[thisFile.filepath] = {
  2979. dx: $(sourceObject).offset().left - $(thisIconObject).offset().left,
  2980. dy: $(sourceObject).offset().top - $(thisIconObject).offset().top
  2981. }
  2982. //console.log(thisFile.filename, iconOffset[thisFile.filepath]);
  2983. }
  2984. }
  2985. //Move the drag drop object to the desiged location
  2986. $(sourceObject).css({
  2987. left: closestLocation[0] + iconOffsetXY[0],
  2988. top: closestLocation[1] + iconOffsetXY[1]
  2989. });
  2990. //Save the drag item location
  2991. $.ajax({
  2992. url: "system/desktop/files",
  2993. method: "POST",
  2994. data: {"set": sourceFilename, "x": targetLocation[1][0], "y": targetLocation[1][1]},
  2995. success: function(data) {
  2996. //console.log(data);
  2997. }
  2998. });
  2999. //Move all the relative files to the main object
  3000. var relocatePendingObjects = [];
  3001. for (const [filepath, offset] of Object.entries(iconOffset)) {
  3002. let thisIconObject = getObjectFromPath(filepath);
  3003. let caluclatedLocation = [$(sourceObject).offset().left - offset.dx, $(sourceObject).offset().top - offset.dy];
  3004. let finalIconLocation = findClosestGrid(caluclatedLocation[0], caluclatedLocation[1]);
  3005. //Check for duplication
  3006. /*
  3007. var duplicateObject = getObjectFromLocation(finalIconLocation[0][0] + iconOffsetXY[0], finalIconLocation[0][1] + iconOffsetXY[1]);
  3008. if (duplicateObject !== undefined) {
  3009. //There are already object there. Relocate this object later
  3010. relocatePendingObjects.push(duplicateObject)
  3011. }
  3012. */
  3013. //Move this icon to designed location
  3014. $(thisIconObject).css({
  3015. left: finalIconLocation[0][0] + iconOffsetXY[0],
  3016. top: finalIconLocation[0][1] + iconOffsetXY[1]
  3017. });
  3018. let thisIconFileData = JSON.parse(decodeURIComponent($(thisIconObject).attr("filedata")));
  3019. //Record this in database
  3020. $.ajax({
  3021. url: "system/desktop/files",
  3022. method: "POST",
  3023. data: {"set": thisIconFileData.Filename, "x": finalIconLocation[1][0], "y": finalIconLocation[1][1]},
  3024. success: function(data) {
  3025. //console.log(data);
  3026. }
  3027. });
  3028. }
  3029. //Get duplication objects
  3030. for (const [filepath, offset] of Object.entries(iconOffset)) {
  3031. let thisIconObject = getObjectFromPath(filepath);
  3032. //Check for duplication
  3033. var iconLocation = [$(thisIconObject).offset().left, $(thisIconObject).offset().top];
  3034. $(".launchIcon").each(function(){
  3035. if ($(this).offset().left == iconLocation[0] && $(this).offset().top == iconLocation[1]){
  3036. //This icon is at the target icon location
  3037. if ($(this).attr("filepath") != filepath){
  3038. relocatePendingObjects.push($(this));
  3039. }
  3040. }
  3041. });
  3042. }
  3043. //Relocate objects that is in the way of moving
  3044. for (var i = 0; i < relocatePendingObjects.length; i++){
  3045. var thisObject = relocatePendingObjects[i];
  3046. console.log(thisObject);
  3047. var thisX = $(thisObject).offset().left;
  3048. var thisY = $(thisObject).offset().top;
  3049. var nextEmptyGrid = findClostestEmptyGridLocation(thisX, thisY);
  3050. //Move this file to the next empty grid location
  3051. $(thisObject).css({
  3052. left: nextEmptyGrid[0][0] + iconOffsetXY[0],
  3053. top: nextEmptyGrid[0][1] + iconOffsetXY[1]
  3054. });
  3055. //Save move record to db
  3056. let thisIconFileData = JSON.parse(decodeURIComponent($(thisObject).attr("filedata")));
  3057. $.ajax({
  3058. url: "system/desktop/files",
  3059. method: "POST",
  3060. data: {"set": thisIconFileData.Filename, "x": nextEmptyGrid[1][0], "y": nextEmptyGrid[1][1]},
  3061. success: function(data) {
  3062. //console.log(data);
  3063. }
  3064. });
  3065. }
  3066. }
  3067. }else{
  3068. //Dropping a file onto other place on desktop
  3069. var sourceObject = getObjectFromPath(sourceFilepath);
  3070. var dx = startDragRelatuve[0];
  3071. var dy = startDragRelatuve[1];
  3072. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  3073. var closestLocation = targetLocation[0];
  3074. //Check if there are objects already at that location
  3075. var duplicateObject = getObjectFromLocation(closestLocation[0], closestLocation[1]);
  3076. if (duplicateObject !== undefined) {
  3077. //There are already object there. Do nothing
  3078. console.log("Drop location duplicated!")
  3079. return;
  3080. }
  3081. var closestGridIndex = targetLocation[1];
  3082. $(sourceObject).css({
  3083. left: closestLocation[0] + iconOffsetXY[0],
  3084. top: closestLocation[1] + iconOffsetXY[1]
  3085. });
  3086. $.ajax({
  3087. url: "system/desktop/files",
  3088. method: "POST",
  3089. data: {"set": sourceFilename, "x": closestGridIndex[0], "y": closestGridIndex[1]},
  3090. success: function(data) {
  3091. //console.log(data);
  3092. }
  3093. });
  3094. }
  3095. } else if (target.attr("type") == "folder") {
  3096. //Move this file or folder into the target folder
  3097. //WIP
  3098. } else if (target.attr("type") == "shortcut") {
  3099. //Opening with the shortcut
  3100. //Check shortcut type
  3101. let shortcutData = JSON.parse(decodeURIComponent($(target).attr("filedata")));
  3102. var shortcutType = shortcutData["ShortcutType"];
  3103. if (shortcutType == "module") {
  3104. //Open the source file with this module
  3105. let openFileList = [];
  3106. if ($(".launchiconwrapper.selected").length > 0 && !Array.isArray(sourceFilelist)) {
  3107. $(".launchiconwrapper.selected").each(function() {
  3108. let thisFileData = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3109. openFileList.push({
  3110. filename: thisFileData["Filename"],
  3111. filepath: thisFileData["Filepath"]
  3112. });
  3113. });
  3114. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  3115. //Open file that is transfered from file explorer.
  3116. openFileList = sourceFilelist;
  3117. console.log(openFileList);
  3118. } else {
  3119. //Only pass in the current selected file.
  3120. openFileList.push({
  3121. filename: sourceFilename,
  3122. filepath: sourceFilepath
  3123. });
  3124. }
  3125. var shortcutModule = getModuleFromShortcutInfo(shortcutData);
  3126. //console.log(openFileList);
  3127. if (shortcutModule === undefined){
  3128. //This shortcut module is not found on this server
  3129. return;
  3130. }
  3131. openFileWithModule(shortcutModule, openFileList);
  3132. } else if (shortcutType == "folder") {
  3133. //Move the source file into this folder
  3134. }
  3135. } else {
  3136. console.log("Unknown reaction type: ", target.attr("type"));
  3137. }
  3138. }
  3139. function getModuleFromShortcutInfo(shortcutInfo) {
  3140. var ShortcutPath = shortcutInfo["ShortcutPath"];
  3141. if (ShortcutPath.includes("/") == false) {
  3142. //Legacy defination. Append /index.html at the back.
  3143. ShortcutPath = ShortcutPath + "/index.html";
  3144. }
  3145. //Try to match it with the module installed
  3146. for (var i = 0; i < moduleInstalled.length; i++) {
  3147. if (moduleInstalled[i]["StartDir"] == ShortcutPath || moduleInstalled[i]["Name"] == shortcutInfo["ShortcutName"]) {
  3148. //This is the correct module to be loaded
  3149. return moduleInstalled[i];
  3150. }
  3151. }
  3152. }
  3153. //Allocate the given number of grids from desktop
  3154. function gridPositionAllocate(posx, posy, numberOfGridNeeded=1){
  3155. var gridMaxX = desktopGrids.length;
  3156. var gridMaxY = desktopGrids[0].length;
  3157. var targetLocation = findClosestGrid(posx, posy, false);
  3158. var targetGridLocation = targetLocation[1];
  3159. var previousEmptyGridPosition = targetGridLocation;
  3160. var locations = [];
  3161. for (var k =0; k < numberOfGridNeeded; k++){
  3162. var thisLocation = JSON.parse(JSON.stringify(previousEmptyGridPosition));
  3163. //Add k to y axis of the list.
  3164. thisLocation[1] += k;
  3165. if (thisLocation[1] >= gridMaxY){
  3166. thisLocation[0]++;
  3167. thisLocation[1] = 0;
  3168. }
  3169. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3170. //Desktop full. Force put to 0 0
  3171. thisLocation[0] = 0;
  3172. thisLocation[1] = 0;
  3173. break;
  3174. }
  3175. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  3176. thisLocation[1] += 1;
  3177. if (thisLocation[1] >= gridMaxY){
  3178. //Over the screen. Shift to the row on the right
  3179. thisLocation[0]++;
  3180. thisLocation[1] = 0;
  3181. }
  3182. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3183. //Desktop full. Force put to 0 0
  3184. thisLocation[0] = 0;
  3185. thisLocation[1] = 0;
  3186. break;
  3187. }
  3188. }
  3189. previousEmptyGridPosition = JSON.parse(JSON.stringify(thisLocation))
  3190. locations.push(thisLocation)
  3191. }
  3192. return locations
  3193. }
  3194. function setIconDesktopLocation(sourceFilename, gridIndexX, gridIndexY, callback = undefined) {
  3195. $.ajax({
  3196. url: "system/desktop/files",
  3197. method: "POST",
  3198. data: {"set": sourceFilename, "x": gridIndexX, "y": gridIndexY},
  3199. success: function(data) {
  3200. if (data.error !== undefined) {
  3201. console.log(data.error);
  3202. } else {
  3203. if (callback !== undefined) {
  3204. callback();
  3205. }
  3206. }
  3207. }
  3208. });
  3209. }
  3210. //THIS FUNCTION IS NEEDED. DO NOT DELETE ALLOWDROP FUNCTION
  3211. function allowDrop(ev) {
  3212. ev.preventDefault();
  3213. }
  3214. //Pass in the object fullpath and return the icon object onscreen
  3215. function getObjectFromPath(path) {
  3216. var object;
  3217. $(".launchIcon").each(function() {
  3218. if ($(this).attr("filepath") == path) {
  3219. object = $(this);
  3220. }
  3221. });
  3222. return object;
  3223. }
  3224. //Pass in the coordinate and check if there is another object at the same location
  3225. function getObjectFromLocation(x, y) {
  3226. var object;
  3227. $(".launchIcon").each(function() {
  3228. if ($(this).position().left == x && $(this).position().top == y) {
  3229. object = $(this);
  3230. }
  3231. });
  3232. return object;
  3233. }
  3234. //Similar function to getObjectFromLocation but using grid coordinate instead of pixel coordinate
  3235. function getObjectFromGridLocation(gx, gy){
  3236. var pos = JSON.parse(JSON.stringify(desktopGrids[gx][gy]));
  3237. pos[0] = pos[0] + iconOffsetXY[0];
  3238. pos[1] = pos[1] + iconOffsetXY[1];
  3239. return getObjectFromLocation(pos[0],pos[1]);
  3240. }
  3241. //Find the clostest empty grid, prioirty given to y first then x
  3242. function findClostestEmptyGridLocation(x, y){
  3243. //Reduce icon offset to the x y on screen coordinate
  3244. x = x - iconOffsetXY[0];
  3245. y = y - iconOffsetXY[1];
  3246. //Get the grid index from absolute coordinate
  3247. var currentGridLocation = getGridIndexFromLocation(x,y);
  3248. console.log(currentGridLocation);
  3249. //Search for the next empty location
  3250. var targetLocation = [[-1,-1],[-1,-1]];
  3251. for (var i = currentGridLocation[0]; i < desktopGrids.length; i++){
  3252. var yStart = 0;
  3253. if (i == currentGridLocation[0]){
  3254. yStart = currentGridLocation[1];
  3255. }
  3256. for (k = yStart; k < desktopGrids[i].length; k++){
  3257. var thisLocation = JSON.parse(JSON.stringify(desktopGrids[i][k]));
  3258. var offsetedLocation = [thisLocation[0], thisLocation[1]];
  3259. var possibleDuplication = getObjectFromGridLocation(i,k);
  3260. //console.log( [i,k], offsetedLocation, possibleDuplication)
  3261. if (possibleDuplication === undefined){
  3262. //This is an empty slot
  3263. targetLocation = [offsetedLocation, [i,k]];
  3264. return targetLocation;
  3265. }
  3266. }
  3267. }
  3268. return targetLocation;
  3269. }
  3270. function getGridIndexFromLocation(x,y){
  3271. var gridIndex = [-1,-1];
  3272. for (var i = 0; i < desktopGrids.length; i++){
  3273. var thisXAxis = desktopGrids[i];
  3274. if (thisXAxis[0][0] == x){
  3275. //This x matches. Match y
  3276. gridIndex[0] = i;
  3277. for (var k = 0; k < thisXAxis.length; k++){
  3278. var thisYAxis = thisXAxis[k];
  3279. if (thisYAxis[1] == y){
  3280. gridIndex[1] = k;
  3281. return gridIndex;
  3282. }
  3283. }
  3284. }
  3285. }
  3286. return gridIndex;
  3287. }
  3288. //Set allow overshoot to allow drop point to get closest grid with x / y > cursor posx /y
  3289. function findClosestGrid(x, y, allowOvershoot = true) {
  3290. var minDx = window.innerWidth;
  3291. var minDy = window.innerHeight;
  3292. var finalLocation = [-1, -1];
  3293. var gridLocation = [-1, -1];
  3294. for (var i = 0; i < desktopGrids.length; i++) {
  3295. for (var j = 0; j < desktopGrids[0].length; j++) {
  3296. var thisGridLocation = desktopGrids[i][j];
  3297. var dx = x - thisGridLocation[0];
  3298. var dy = y - thisGridLocation[1];
  3299. if (allowOvershoot) {
  3300. if (Math.abs(dx) < minDx) {
  3301. minDx = Math.abs(x - thisGridLocation[0]);
  3302. finalLocation[0] = thisGridLocation[0];
  3303. gridLocation[0] = i;
  3304. }
  3305. if (Math.abs(dy) < minDy) {
  3306. minDy = Math.abs(y - thisGridLocation[1]);
  3307. finalLocation[1] = thisGridLocation[1];
  3308. gridLocation[1] = j;
  3309. }
  3310. } else {
  3311. if (dx < minDx && dx > 0) {
  3312. minDx = Math.abs(x - thisGridLocation[0]);
  3313. finalLocation[0] = thisGridLocation[0];
  3314. gridLocation[0] = i;
  3315. }
  3316. if (dy < minDy && dy > 0) {
  3317. minDy = Math.abs(y - thisGridLocation[1]);
  3318. finalLocation[1] = thisGridLocation[1];
  3319. gridLocation[1] = j;
  3320. }
  3321. }
  3322. }
  3323. }
  3324. return [finalLocation, gridLocation];
  3325. }
  3326. //Ask for confirmation before window close
  3327. //Update 16 Feb 2021: Disabled confirmation and use a new method of implementing this later
  3328. /*
  3329. function myConfirmation() {
  3330. if (!loggingOut){
  3331. return 'Your data might not been saved. Are you sure you want to quit?';
  3332. }
  3333. }
  3334. window.onbeforeunload = myConfirmation;
  3335. */
  3336. function iconClicked(object, evt) {
  3337. if (renameMode){
  3338. //Exit rename mode if icon is clicked during renaming
  3339. if ($(object).find(".renameInput").length == 0){
  3340. exitRenameMode();
  3341. }
  3342. }
  3343. //Clicked on a launch icon.
  3344. var alreadyHighlighted = $(object).find(".launchIconWrapper").hasClass("selected");
  3345. if (alreadyHighlighted){
  3346. //Already selected
  3347. if (ctrlHold) {
  3348. //Selection
  3349. $(object).find(".launchIconWrapper").removeClass("selected");
  3350. }
  3351. }else{
  3352. //Not selected yet
  3353. if (ctrlHold) {
  3354. //Add this into selection
  3355. $(object).find(".launchIconWrapper").addClass("selected");
  3356. }else{
  3357. //Remove all others and select this
  3358. $(".launchIconWrapper.selected").removeClass("selected");
  3359. $(object).find(".launchIconWrapper").addClass("selected");
  3360. }
  3361. }
  3362. }
  3363. function iconDoubleClicked(object, evt=undefined) {
  3364. //Don't allow opening when renaming
  3365. if (renameMode){
  3366. return;
  3367. }
  3368. //Double click on a launch icon, tries to open it
  3369. var filedata = ao_module_utils.attrToObject($(object).attr("filedata"));
  3370. //console.log(filedata);
  3371. if (filedata.IsDir) {
  3372. //This is a directory. Open with file explorer
  3373. newFloatWindow({
  3374. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(filedata.Filepath),
  3375. appicon: "SystemAO/file_system/img/small_icon.png",
  3376. width: 1080,
  3377. height: 580,
  3378. title: "File Manager"
  3379. });
  3380. } else if (filedata.IsShortcut) {
  3381. //This is a shortcut. Open the target endpoint
  3382. var stype = filedata["ShortcutType"];
  3383. if (stype == "module") {
  3384. //Open the target module
  3385. openModule(filedata.ShortcutPath);
  3386. } else if (stype == "folder") {
  3387. //Open the target folder
  3388. openFolder(filedata.ShortcutPath)
  3389. }else if (stype == "url"){
  3390. //Open the target webpage in a new tab
  3391. window.open(filedata.ShortcutPath);
  3392. }else{
  3393. console.log(filedata);
  3394. }
  3395. } else {
  3396. //This is a file. Open it with default opener
  3397. $.ajax({
  3398. url: "system/modules/getDefault",
  3399. method: "GET",
  3400. data: {
  3401. opr: "launch",
  3402. ext: filedata.Ext,
  3403. mode: "launch"
  3404. },
  3405. success: function(data) {
  3406. if (data.error !== undefined) {
  3407. //No default opener assigned
  3408. var url = "SystemAO/file_system/defaultOpener.html";
  3409. var icon = "SystemAO/file_system/img/opener.png";
  3410. var title = "Select an opener WebApp: "
  3411. var openFileList = [];
  3412. var openFileObject = {
  3413. filepath: filedata.Filepath,
  3414. filename: filedata.Filename
  3415. }
  3416. openFileList.push(openFileObject);
  3417. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  3418. newFloatWindow({
  3419. url: url + "#" + openParamter,
  3420. width: 320,
  3421. height: 510,
  3422. appicon: icon,
  3423. title: title
  3424. });
  3425. } else {
  3426. //Assigned. Launch with given paramter
  3427. var url = data["StartDir"];
  3428. var size = [undefined, undefined];
  3429. var title = data["Name"];
  3430. var icon = "img/system/favicon.png";
  3431. if (data["IconPath"] != "") {
  3432. icon = data["IconPath"];
  3433. }
  3434. //Use floatWindow if exists
  3435. if (data["SupportFW"] == true && data["LaunchFWDir"] != "") {
  3436. url = data["LaunchFWDir"];
  3437. if (data["InitFWSize"] !== null) {
  3438. size = data["InitFWSize"]
  3439. }
  3440. }
  3441. //Use embedded mode if exists
  3442. if (data["SupportEmb"] == true && data["LaunchEmb"] != "") {
  3443. url = data["LaunchEmb"];
  3444. if (data["InitEmbSize"] !== null) {
  3445. size = data["InitEmbSize"]
  3446. }
  3447. }
  3448. //Build open File Hash Data Format
  3449. var openFileList = [];
  3450. var openFileObject = {
  3451. filepath: filedata.Filepath,
  3452. filename: filedata.Filename
  3453. }
  3454. openFileList.push(openFileObject);
  3455. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  3456. //Add launch files info and launch floatWindow
  3457. newFloatWindow({
  3458. url: url + "#" + openParamter,
  3459. width: size[0],
  3460. height: size[1],
  3461. appicon: icon,
  3462. title: title
  3463. });
  3464. }
  3465. }
  3466. })
  3467. }
  3468. }
  3469. $(window).on("resize", function(event) {
  3470. redrawDesktopGrids();
  3471. resizeAllFloatWindowButtons();
  3472. })
  3473. // ======================= DOCUMENT KEY BINDING =====================
  3474. $(document).keydown(function(event) {
  3475. if (event.which == "17") {
  3476. //Pressdown of Ctrl key
  3477. ctrlHold = true;
  3478. } else if (event.which == "16") {
  3479. //Pressdown of Shift key
  3480. shiftHold = true;
  3481. }else if (event.which == "27"){
  3482. //Cancel all floatwindow events and key events
  3483. $("#fwdragpanel").hide();
  3484. $("#tfwdragpanel").hide();
  3485. $(".floatWindow").find(".iframecover").hide();
  3486. movingWindow = false;
  3487. resizingWindow = false;
  3488. resizingEdgeID = 0;
  3489. multiSelecting = false;
  3490. ctrlHold = false;
  3491. shiftHold = false;
  3492. }else if (event.which == "46"){
  3493. //Delete key
  3494. if (renameMode){
  3495. //Deleting content in textarea. Ignore delte action
  3496. return true
  3497. }
  3498. var deleteFilelist = [];
  3499. var deleteFilenameList = [];
  3500. $(".launchIconWrapper.selected").each(function(){
  3501. var fileObject = $(this).parent();
  3502. var fd = JSON.parse(decodeURIComponent((fileObject).attr("filedata")));
  3503. deleteFilelist.push(fd.Filepath);
  3504. deleteFilenameList.push(fd.Filename)
  3505. });
  3506. //Prase the filelist and pass to trash module
  3507. console.log(deleteFilelist);
  3508. generateCSRFToken(function(csrftoken){
  3509. $.ajax({
  3510. url: "system/file_system/fileOpr",
  3511. method:"POST",
  3512. data: {opr: "recycle", src: JSON.stringify(deleteFilelist), csrft: csrftoken},
  3513. success: function(data){
  3514. if (data.error !== undefined){
  3515. alert(data.error);
  3516. }else{
  3517. refresh(undefined, true);
  3518. }
  3519. }
  3520. });
  3521. });
  3522. //Delete the file's desktop location
  3523. deleteFilenameList.forEach(file => {
  3524. $.ajax({
  3525. url: "system/desktop/files",
  3526. data: {del: file},
  3527. success: function(data){
  3528. if (data.error !== undefined){
  3529. console.log(data.error);
  3530. }
  3531. }
  3532. });
  3533. })
  3534. }else if (event.which == "13"){
  3535. //Enter key
  3536. if (!renameMode){
  3537. //Open selected object by emulating double click
  3538. $(".launchIconWrapper.selected").each(function(){
  3539. var object = $(this).parent();
  3540. iconDoubleClicked(object);
  3541. });
  3542. }else if (renameMode){
  3543. event.preventDefault();
  3544. exitRenameMode();
  3545. }
  3546. }else{
  3547. //console.log(event.which);
  3548. }
  3549. });
  3550. $(document).keyup(function(event) {
  3551. if (event.which == "17") {
  3552. ctrlHold = false;
  3553. } else if (event.which == "16") {
  3554. shiftHold = false;
  3555. }
  3556. });
  3557. $("#bgwrapper").on("mouseup", function(event) {
  3558. //Deselect all selected icons
  3559. event.preventDefault();
  3560. event.stopImmediatePropagation();
  3561. mainWindowMouseup(event);
  3562. });
  3563. function openFolder(virtualPath){
  3564. newFloatWindow({
  3565. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(virtualPath),
  3566. appicon: "SystemAO/file_system/img/small_icon.png",
  3567. width:1080,
  3568. height:580,
  3569. title: "File Manager"
  3570. });
  3571. }
  3572. function logout() {
  3573. loggingOut = true;
  3574. if (confirm("Exiting Session. Confirm?")){
  3575. $.get("system/auth/logout", function() {
  3576. window.location.href = "/";
  3577. });
  3578. }
  3579. hideAllContextMenus();
  3580. }
  3581. // ======================= CONTEXT MENU =============================
  3582. window.addEventListener("contextmenu",
  3583. function(e) {
  3584. e.preventDefault();
  3585. e.stopPropagation();
  3586. var clickTarget = $(e.target);
  3587. hideAllContextMenus();
  3588. showMenu = false;
  3589. $("#contextmenu").html("");
  3590. if (clickTarget.hasClass("launchIcon") || clickTarget.hasClass("launchIconImage") || clickTarget.hasClass("launchIconText")) {
  3591. //Click on an object on destkop
  3592. if (clickTarget.hasClass("launchIcon") == false) {
  3593. clickTarget = $(clickTarget).parent().parent();
  3594. }
  3595. if (!ctrlHold && !$(clickTarget).find(".launchIconWrapper").hasClass("selected")){
  3596. $(".launchIconWrapper.selected").removeClass("selected");
  3597. }
  3598. //Select this object
  3599. $(clickTarget).find(".launchIconWrapper").addClass("selected");
  3600. var objectType = $(clickTarget).attr("type");
  3601. operationTargetLaunchIcon = $(clickTarget);
  3602. //Check if selected more than one object
  3603. if ($(".launchIconWrapper.selected").length > 1){
  3604. //When the user selected more than one item on desktop
  3605. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3606. addContextMenuItem($("#contextmenu"), 'Open With', "<i class='caret right icon'></i>", "handleOpenWith", true);
  3607. //addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3608. addContextMenuSeperator($("#contextmenu"));
  3609. addContextMenuItem($("#contextmenu"), 'Download in Zip', "<i class='download icon'></i>", "downloadFile", false);
  3610. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='copy icon'></i>", "handleCloning", false);
  3611. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3612. addContextMenuSeperator($("#contextmenu"));
  3613. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3614. }else{
  3615. //When the user only selected one item
  3616. if (objectType == "file") {
  3617. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3618. addContextMenuItem($("#contextmenu"), 'Open With', "<i class='caret right icon'></i>", "handleOpenWith", true);
  3619. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3620. addContextMenuSeperator($("#contextmenu"));
  3621. addContextMenuItem($("#contextmenu"), 'Download', "<i class='download icon'></i>", "downloadFile", false);
  3622. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='copy icon'></i>", "handleCloning", false);
  3623. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3624. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3625. addContextMenuSeperator($("#contextmenu"));
  3626. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3627. } else if (objectType == "folder") {
  3628. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3629. addContextMenuItem($("#contextmenu"), 'Zip here', "<i class='zip icon'></i>", "handleZipFolder", false);
  3630. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3631. addContextMenuSeperator($("#contextmenu"));
  3632. addContextMenuItem($("#contextmenu"), 'Download as Zip', "<i class='download icon'></i>", "downloadFile", false);
  3633. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='caret right icon'></i>", "handleCloning", false);
  3634. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3635. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3636. addContextMenuSeperator($("#contextmenu"));
  3637. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3638. } else if (objectType == "shortcut") {
  3639. var fd = JSON.parse(decodeURIComponent($(clickTarget).attr("filedata")));
  3640. console.log(fd);
  3641. if (fd.ShortcutType == "module"){
  3642. //Public WebApp
  3643. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3644. addContextMenuItem($("#contextmenu"), 'Open in New Tab', "<i class='external icon'></i>", "openWebAppInNewTab", false);
  3645. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3646. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3647. }else if (fd.ShortcutType == "folder"){
  3648. //Folder
  3649. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3650. addContextMenuItem($("#contextmenu"), 'Open File Location', "<i class='folder open icon'></i>", "handleShortcutFolderOpen", false);
  3651. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3652. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3653. addContextMenuSeperator($("#contextmenu"));
  3654. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3655. }else{
  3656. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3657. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3658. }
  3659. }else{
  3660. console.log("Opening context menu on unknown type: ", objectType);
  3661. }
  3662. }
  3663. showMenu = true;
  3664. } else if (clickTarget.hasClass("backgroundFrame") || (isSafari && $(clickTarget).attr("id") == "selectionPanel")) {
  3665. //Click on the background. Load background context menu.
  3666. addContextMenuItem($("#contextmenu"), 'New', "<i class='caret right icon'></i>", "newitemmenu", true);
  3667. addContextMenuItem($("#contextmenu"), 'Refresh', "<i class='refresh icon'></i>", "handleMenuRefresh", false);
  3668. addContextMenuItem($("#contextmenu"), 'Open File Manager', undefined, "openfm", false);
  3669. //addContextMenuItem($("#contextmenu"), 'Get File from URL', "<i class='download icon'></i>", "downloadURL", false);
  3670. addContextMenuItem($("#contextmenu"), 'Personalization', "<i class='paint brush icon'></i>", "personalization", false);
  3671. addContextMenuItem($("#contextmenu"), 'Background', "<i class='caret right icon'></i>", "background", true);
  3672. addContextMenuItem($("#contextmenu"), 'Icon Size', "<i class='caret right icon'></i>", "listIconsize", true);
  3673. addContextMenuItem($("#contextmenu"), 'Toggle FullScreen', "<i class='maximize icon'></i>", "fullscreen", false);
  3674. addContextMenuItem($("#contextmenu"), 'Exit', undefined, "logout", false);
  3675. showMenu = true;
  3676. }else if (clickTarget.hasClass("fwdragger") || (clickTarget.hasClass("title") && clickTarget.parent().hasClass("fwdragger"))){
  3677. //Click on the floatWindow object
  3678. addContextMenuItem($("#contextmenu"), 'Open in New Tab', "<i class='external icon'></i>", "openSelectedFloatWindowInNewTab", false);
  3679. addContextMenuItem($("#contextmenu"), 'Refresh', "<i class='refresh icon'></i>", "refreshSelectedFloatWindow", false);
  3680. addContextMenuSeperator($("#contextmenu"));
  3681. addContextMenuItem($("#contextmenu"), 'Minimize', "<i class='window minimize icon'></i>", "minimizeSelectedFloatWindow", false);
  3682. if ($(clickTarget).parent().hasClass("fixedsize") == false && $(clickTarget).parent().parent().hasClass("fixedsize") == false){
  3683. //This FloatWindow is resizable
  3684. console.log($(clickTarget).parent());
  3685. if ($(clickTarget).parent().attr("max") !== undefined && $(clickTarget).parent().attr("max") == "true"){
  3686. addContextMenuItem($("#contextmenu"), 'Restore', "<i class='window window restore icon'></i>", "maximizeSelectedFloatWindow", false);
  3687. }else{
  3688. addContextMenuItem($("#contextmenu"), 'Maximize', "<i class='window maximize icon'></i>", "maximizeSelectedFloatWindow", false);
  3689. }
  3690. }
  3691. addContextMenuItem($("#contextmenu"), 'Close', "<i class='remove icon'></i>", "closeSelectedFloatWindow", false);
  3692. showMenu = true;
  3693. }
  3694. if (showMenu){
  3695. //Toggle context menu
  3696. $("#contextmenu").show();
  3697. var startX = e.pageX;
  3698. var startY = e.pageY;
  3699. if (e.pageX > window.innerWidth / 2){
  3700. startX = e.pageX - $("#contextmenu").width();
  3701. }
  3702. if (e.pageY > window.innerHeight / 2){
  3703. startY = e.pageY - $("#contextmenu").height();
  3704. }
  3705. $("#contextmenu").css({
  3706. left: startX,
  3707. top: startY
  3708. });
  3709. menuStartLocation = [e.pageX, e.pageY];
  3710. }
  3711. }, true);
  3712. function handleMenuRefresh() {
  3713. //This function is here to remove the object and event passed in from menu pressed object
  3714. refresh();
  3715. }
  3716. function newshortcut(){
  3717. //Show the new shortcut creation tool
  3718. newFloatWindow({
  3719. url: "SystemAO/desktop/shortcutCreator.html",
  3720. appicon: "img/desktop/system_icon/shortcut.png",
  3721. width:815,
  3722. height:485,
  3723. title: "New Shortcut"
  3724. });
  3725. hideAllContextMenus();
  3726. }
  3727. function openIconViaMenu(target, event){
  3728. $(".launchIconWrapper.selected").each(function(){
  3729. iconObject = $(this).parent();
  3730. //Emulate a doubleclick on icon
  3731. iconDoubleClicked(iconObject, event);
  3732. });
  3733. hideAllContextMenus();
  3734. }
  3735. //Opening a shortcut module from desktop to new tab
  3736. function openWebAppInNewTab(target, event){
  3737. $(".launchIconWrapper.selected").each(function(){
  3738. var fd = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3739. $.get("system/modules/getLaunchPara?module=" + fd.ShortcutPath, function(data) {
  3740. if (data.error !== undefined) {
  3741. console.log(data.error);
  3742. }else{
  3743. //Open in new tab
  3744. window.open(data.StartDir)
  3745. }
  3746. });
  3747. });
  3748. }
  3749. function downloadFile(target, event){
  3750. if ( $(".launchIconWrapper.selected").length == 1){
  3751. //Download this file directly
  3752. var rawfiledata = $(".launchIconWrapper.selected").parent().attr("filedata");
  3753. var filedata = JSON.parse(decodeURIComponent(rawfiledata));
  3754. var filepath = filedata.Filepath;
  3755. //Resolve the link to media download link
  3756. var downloadLink = "media?file=" + filepath + "&download=true";
  3757. window.open(downloadLink)
  3758. }else if ($(".launchIconWrapper.selected").length > 1){
  3759. //Create a zip file using the fs api
  3760. var filelist = [];
  3761. $(".launchIconWrapper.selected").each(function(){
  3762. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3763. var filepath = filedata.Filepath;
  3764. filelist.push(filepath);
  3765. });
  3766. $.ajax({
  3767. url: "system/file_system/zipHandler",
  3768. data: {opr: "tmpzip", src: JSON.stringify(filelist), dest: ""},
  3769. method: "POST",
  3770. success: function(data){
  3771. if (data.error !== undefined){
  3772. alert(data.error);
  3773. }else{
  3774. //Zip completed.
  3775. window.open("media?file=" + data + "&download=true");
  3776. }
  3777. }
  3778. });
  3779. }
  3780. hideAllContextMenus();
  3781. }
  3782. function handleZipFolder(){
  3783. var filelist = [];
  3784. var filename = "desktop_" + new Date().getTime() + ".zip"
  3785. if ($(".launchIconWrapper.selected").length == 1){
  3786. filename = $(".launchIconWrapper.selected").parent().attr('filename') + ".zip";
  3787. }
  3788. $(".launchIconWrapper.selected").each(function(){
  3789. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3790. var filepath = filedata.Filepath;
  3791. if (filedata.IsDir == true){
  3792. filelist.push(filepath);
  3793. }
  3794. });
  3795. $.ajax({
  3796. url: "system/file_system/zipHandler",
  3797. data: {opr: "zip", src: JSON.stringify(filelist), dest: "user:/Desktop/" + filename},
  3798. method: "POST",
  3799. success: function(data){
  3800. if (data.error !== undefined){
  3801. alert(data.error);
  3802. }else{
  3803. //Zip completed.
  3804. console.log(data);
  3805. }
  3806. }
  3807. });
  3808. //console.log(filelist);
  3809. hideAllContextMenus();
  3810. }
  3811. function handleOpenWith(target, event){
  3812. $("#subcontextmenu").html("");
  3813. //Updates 19 May 2021: Added support for better parsing Open With List
  3814. var exts = [];
  3815. //Get all exts from the selected files
  3816. $(".launchIconWrapper.selected").each(function(){
  3817. var filename = $(this).parent().attr("filename");
  3818. var ext = "." + filename.split(".").pop();
  3819. exts.push(ext);
  3820. });
  3821. $.get("system/modules/list",function(data){
  3822. if (data.error !== undefined){
  3823. alert(data.error);
  3824. }else{
  3825. var supportedModuleCount = 0;
  3826. var openWithTargets = [];
  3827. for (var i =0; i < data.length; i++){
  3828. var thisModule = data[i];
  3829. //If this module support this ext, add it to list
  3830. var thisModuleSupportExt = thisModule.SupportedExt;
  3831. if (thisModule.Name == "File Manager"){
  3832. //Exceptional case
  3833. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  3834. }
  3835. if (thisModuleSupportExt == null || thisModuleSupportExt.length == 0){
  3836. //Not supporting anything
  3837. continue;
  3838. }
  3839. thisModuleSupportExt.forEach(supportedExt => {
  3840. if (exts.includes(supportedExt)){
  3841. //Add this to the menu
  3842. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  3843. }
  3844. })
  3845. //if (thisModule.SupportEmb == true){
  3846. // addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  3847. //}
  3848. }
  3849. //Add select more opener option
  3850. addContextMenuSeperator($("#subcontextmenu"));
  3851. addContextMenuItem($("#subcontextmenu"), "Select Other WebApps", ``, "openOpenSelector", false);
  3852. }
  3853. showSubContextMenu(target);
  3854. });
  3855. }
  3856. function handleFileShare(target, object){
  3857. $("#subcontextmenu").html("");
  3858. //Get the selected file
  3859. var targetFile = $(".launchIconWrapper.selected")[0];
  3860. var fileData = $(targetFile).parent().attr("filedata");
  3861. if (fileData != undefined){
  3862. fileData = JSON.parse(decodeURIComponent(fileData));
  3863. //Check if the target file is shared
  3864. $.ajax({
  3865. url: "system/file_system/share/checkShared",
  3866. data: {path: fileData.Filepath},
  3867. success: function(data){
  3868. if (data.IsShared == true){
  3869. addContextMenuItem($("#subcontextmenu"), "Open Shared Link", `<i class="external icon"></i>`, "openSharedLink", false, {
  3870. payload: {
  3871. uuid: data.ShareUUID.UUID
  3872. }
  3873. });
  3874. addContextMenuItem($("#subcontextmenu"), "Copy Link", `<i class="copy icon"></i>`, "copySharedLink", false, {
  3875. payload: {
  3876. uuid: data.ShareUUID.UUID
  3877. }
  3878. });
  3879. addContextMenuSeperator($("#subcontextmenu"));
  3880. addContextMenuTitle($("#subcontextmenu"), `<i class="share alternate icon"></i> Change Share Settings`);
  3881. }else{
  3882. addContextMenuTitle($("#subcontextmenu"), `<i class="share alternate icon"></i> Share this File`);
  3883. }
  3884. var checkmarkStyle = `style="color: #71ba68;"`;
  3885. var anyoneClass = "";
  3886. if (data.ShareUUID.Permission == "anyone"){
  3887. anyoneClass = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  3888. }
  3889. var signedinClass = "";
  3890. if (data.ShareUUID.Permission == "signedin"){
  3891. signedinClass = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  3892. }
  3893. var sameGroupClass = "";
  3894. if (data.ShareUUID.Permission == "samegroup"){
  3895. samegroup = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  3896. }
  3897. addContextMenuItem($("#subcontextmenu"), `<i class="globe icon"></i> Anyone with Link`, anyoneClass, "shareWithThisPermission", false, {
  3898. payload: {
  3899. type: "anyone"
  3900. }
  3901. });
  3902. addContextMenuItem($("#subcontextmenu"), `<i class="user circle outline icon"></i> Anyone Signed In`, signedinClass, "shareWithThisPermission", false, {
  3903. payload: {
  3904. type: "signedin"
  3905. }
  3906. });
  3907. addContextMenuItem($("#subcontextmenu"), `<i class="users icon"></i> Same Group Users`, sameGroupClass, "shareWithThisPermission", false,{
  3908. payload: {
  3909. type: "samegroup"
  3910. }
  3911. });
  3912. if (data.IsShared == true){
  3913. //This file is shared.
  3914. addContextMenuSeperator($("#subcontextmenu"));
  3915. addContextMenuItem($("#subcontextmenu"), "Remove Share", `<i style="color: #d97762;" class="trash icon"></i>`, "shareWithThisPermission", false,{
  3916. payload: {
  3917. type: "remove"
  3918. }
  3919. });
  3920. }
  3921. }
  3922. });
  3923. }
  3924. showSubContextMenu(target);
  3925. }
  3926. //Copy the shared link
  3927. function copySharedLink(target, event){
  3928. var payload = getContextMenuPayload(target);
  3929. if (payload == null){
  3930. //Something wrong
  3931. return;
  3932. }
  3933. //Generate the share link
  3934. let protocol = "https://";
  3935. if (location.protocol !== 'https:') {
  3936. protocol = "http://";
  3937. }
  3938. var shareURL = protocol + window.location.hostname + ":" + window.location.port + "/share?id=" + payload.uuid;
  3939. //Copy the text to clipboard
  3940. const area = document.createElement('textarea');
  3941. document.body.appendChild(area);
  3942. area.value = shareURL;
  3943. area.select();
  3944. document.execCommand('copy');
  3945. document.body.removeChild(area);
  3946. //Update status so it show the user it has been coped
  3947. $(target).html(`<i style="color: #71ba68;" class="checkmark icon"></i> Copied!`);
  3948. setTimeout(function(){
  3949. if ($(target).length > 0){
  3950. $(target).html(`Copy Link
  3951. <span class="description">
  3952. <i class="copy icon"></i>
  3953. </span>`);
  3954. }
  3955. }, 3000);
  3956. }
  3957. //Open the shared file link
  3958. function openSharedLink(target, event){
  3959. var payload = getContextMenuPayload(target);
  3960. if (payload == null){
  3961. //Something wrong
  3962. return;
  3963. }
  3964. var targetURL = "share?id=" + payload.uuid;
  3965. window.open(targetURL);
  3966. hideAllContextMenus();
  3967. }
  3968. function shareWithThisPermission(target, event){
  3969. var payload = getContextMenuPayload(target);
  3970. if (payload == null){
  3971. //Something wrong
  3972. return;
  3973. }
  3974. //Get the selected file
  3975. var selectedFileObjects = $(".launchIconWrapper.selected");
  3976. if (selectedFileObjects.length == 0){
  3977. //Not found
  3978. return
  3979. }else if (selectedFileObjects.length > 1){
  3980. //This should not happens. If it did happens, use the first one
  3981. selectedFileObjects = selectedFileObjects[0];
  3982. }
  3983. //Extract file information
  3984. var fileData = $(selectedFileObjects).parent().attr("filedata");
  3985. fileData = JSON.parse(decodeURIComponent(fileData));
  3986. //Convert the desktop file data to ArozOS generic filedata
  3987. var afd = {
  3988. "filename": fileData.Filename,
  3989. "filepath": fileData.Filepath,
  3990. "shareMode": payload.type
  3991. };
  3992. //Create a new share for this
  3993. var targetURL = "SystemAO/file_system/file_share.html#" + encodeURIComponent(JSON.stringify([afd]));
  3994. //Calculate the window spawn position
  3995. var basePosition = $(selectedFileObjects).offset();
  3996. var left = basePosition.left + 100;
  3997. if (left + 320 > window.innerWidth){
  3998. left = basePosition.left - 350;
  3999. }
  4000. var top = basePosition.top;
  4001. if (top + 480 > window.innerHeight){
  4002. top = window.innerHeight - 480;
  4003. }
  4004. newFloatWindow({
  4005. url: targetURL,
  4006. width: 330,
  4007. height: 480,
  4008. left: left,
  4009. top: top,
  4010. appicon: "SystemAO/file_system/img/share.svg",
  4011. title: "Share File"
  4012. }, function(windowUUID){
  4013. //Set the window to fixed window
  4014. setFloatWindowResizePolicy(windowUUID, false);
  4015. });
  4016. hideAllContextMenus();
  4017. }
  4018. function openObjectProperty(target, object){
  4019. var filelist = [];
  4020. $(".launchIconWrapper.selected").each(function(){
  4021. var filepath = $(this).parent().attr("filepath");
  4022. filelist.push(filepath);
  4023. });
  4024. var hashPassthrough = encodeURIComponent(JSON.stringify(filelist));
  4025. newFloatWindow({
  4026. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  4027. width: 340,
  4028. height: 480,
  4029. appicon: "SystemAO/file_system/img/properties.png",
  4030. title: "File Properties",
  4031. });
  4032. hideAllContextMenus();
  4033. }
  4034. //Open the file extension selector
  4035. function openOpenSelector(target, event){
  4036. var filedata = $($(".launchIconWrapper.selected")[0]).parent().attr("filedata")
  4037. filedata = JSON.parse(decodeURIComponent(filedata));
  4038. var fileDescriptor = {
  4039. filepath: filedata.Filepath,
  4040. filename: filedata.Filename
  4041. }
  4042. newFloatWindow({
  4043. url: "SystemAO/file_system/defaultOpener.html#" + encodeURIComponent(JSON.stringify(fileDescriptor)),
  4044. width: 320,
  4045. height: 510,
  4046. appicon: "SystemAO/file_system/img/opener.png",
  4047. title: "Select WebApp to Open File",
  4048. });
  4049. hideAllContextMenus();
  4050. }
  4051. function openSelectedWith(target, event){
  4052. var targetModulename = $(target).text().trim();
  4053. var openFileList = [];
  4054. $(".selected.launchIconWrapper").each(function(){
  4055. var thisFiledata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4056. openFileList.push({
  4057. filename: thisFiledata.Filename,
  4058. filepath: thisFiledata.Filepath
  4059. });
  4060. });
  4061. //Find the launch info of the module
  4062. var targetModuleInfo = undefined;
  4063. for (var i =0; i < moduleInstalled.length; i++){
  4064. if (moduleInstalled[i].Name == targetModulename){
  4065. targetModuleInfo = JSON.parse(JSON.stringify(moduleInstalled[i]));
  4066. }
  4067. }
  4068. //Open the files with the given module
  4069. openFileWithModule(targetModuleInfo, openFileList);
  4070. hideAllContextMenus();
  4071. }
  4072. function getModuleInfoFromName(moduleName){
  4073. for (var i = 0; i < moduleInstalled.length; i++){
  4074. if (moduleInstalled[i].Name == moduleName){
  4075. return moduleInstalled[i];
  4076. }
  4077. }
  4078. return false
  4079. }
  4080. /*
  4081. This function is used to generate menu items for context menu.
  4082. Options example
  4083. {
  4084. payload: {
  4085. //Some JSON based payload here
  4086. }
  4087. }
  4088. */
  4089. function addContextMenuItem(target, keyword, hotkey = undefined, functionName, containSubMenu = false, options=undefined) {
  4090. var itemClass = "item";
  4091. if (containSubMenu) {
  4092. itemClass = "item submenu";
  4093. }
  4094. var payload = "";
  4095. if (options != undefined && options.payload != undefined){
  4096. payload = encodeURIComponent(JSON.stringify(options.payload));
  4097. }
  4098. if (hotkey !== undefined) {
  4099. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);" payload="${payload}">
  4100. ${keyword}
  4101. <span class="description">${hotkey}</span>
  4102. </div>`);
  4103. } else {
  4104. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);" payload="${payload}">
  4105. ${keyword}
  4106. </div>`);
  4107. }
  4108. }
  4109. function getContextMenuPayload(object){
  4110. var encodedPayload = $(object).attr("payload");
  4111. if (encodedPayload != ""){
  4112. return JSON.parse(decodeURIComponent(encodedPayload));
  4113. }else{
  4114. return null;
  4115. }
  4116. }
  4117. function listIconsize(target, event) {
  4118. $("#subcontextmenu").html("");
  4119. var smallCheckmark = undefined;
  4120. var mediumCheckmark = undefined;
  4121. var bigCheckmark = undefined;
  4122. if (desktopIconSize == "small") {
  4123. smallCheckmark = "<i class='checkmark icon'></i>";
  4124. }
  4125. if (desktopIconSize == "medium") {
  4126. mediumCheckmark = "<i class='checkmark icon'></i>";
  4127. }
  4128. if (desktopIconSize == "big") {
  4129. bigCheckmark = "<i class='checkmark icon'></i>";
  4130. }
  4131. addContextMenuItem($("#subcontextmenu"), "Small", smallCheckmark, "setDesktopIconSize", false);
  4132. addContextMenuItem($("#subcontextmenu"), "Medium", mediumCheckmark, "setDesktopIconSize", false);
  4133. addContextMenuItem($("#subcontextmenu"), "Big", bigCheckmark, "setDesktopIconSize", false);
  4134. showSubContextMenu(target);
  4135. }
  4136. function setDesktopIconSize(target, evt) {
  4137. var targetSize = $(target).text().trim().toLowerCase();
  4138. if (["small", "medium", "big"].includes(targetSize)) {
  4139. desktopIconSize = targetSize;
  4140. }
  4141. refresh();
  4142. setStorage("iconsize", desktopIconSize);
  4143. hideAllContextMenus();
  4144. }
  4145. function addContextMenuSeperator(target) {
  4146. $(target).append(`<div class="divider"></div>`);
  4147. }
  4148. function addContextMenuTitle(target, title){
  4149. $(target).append(`<div class="header">
  4150. ${title}
  4151. </div>`);
  4152. }
  4153. function downloadURL() {
  4154. alert("WIP");
  4155. hideAllContextMenus();
  4156. }
  4157. function background(target, evt) {
  4158. $("#subcontextmenu").html('<div class="item"><i class="loading spinning icon"></i> Loading</div>');
  4159. $.get("system/desktop/theme", function(data) {
  4160. $("#subcontextmenu").html("");
  4161. for (var i = 0; i < data.length; i++) {
  4162. if (currentUserTheme == data[i].Theme) {
  4163. addContextMenuItem($("#subcontextmenu"), data[i].Theme, "<i class='checkmark icon'></i>", "setTheme", false);
  4164. } else {
  4165. addContextMenuItem($("#subcontextmenu"), data[i].Theme, undefined, "setTheme", false);
  4166. }
  4167. }
  4168. });
  4169. showSubContextMenu(target);
  4170. }
  4171. //Set theme from button click
  4172. function setTheme(target, evt) {
  4173. var theme = $(target).text().trim();
  4174. setDesktopTheme(theme);
  4175. hideAllContextMenus();
  4176. }
  4177. function personalization() {
  4178. //Show the personalization window
  4179. newFloatWindow({
  4180. url: "SystemAO/desktop/personalization.html",
  4181. appicon: "SystemAO/desktop/img/personalization.png",
  4182. width:640,
  4183. height:480,
  4184. title: "Personalization"
  4185. });
  4186. hideAllContextMenus();
  4187. }
  4188. //New folder on the menu start location
  4189. function newfolder(object, event) {
  4190. var closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4191. let closestPixelLocation = closestLocation[0];
  4192. let closestGridIndexLocation = closestLocation[1];
  4193. //Generate new foldername
  4194. var newFolderName = "New Folder";
  4195. var counter = 1;
  4196. while (desktopFileList.includes(newFolderName)) {
  4197. newFolderName = `New Folder(${counter})`;
  4198. counter++;
  4199. }
  4200. //Check if there are already another object at that locaton
  4201. var duplicateObject = getObjectFromLocation(closestPixelLocation[0], closestPixelLocation[1]);
  4202. var createObjectLocation = true;
  4203. if (duplicateObject !== undefined) {
  4204. //Ignore create position. Let it settle on next new slot.
  4205. createObjectLocation = false;
  4206. }
  4207. //Create the folder
  4208. $.post("system/file_system/newItem", {
  4209. type: "folder",
  4210. src: "user:/Desktop/",
  4211. filename: newFolderName
  4212. }).done(function(data) {
  4213. if (data.error !== undefined) {
  4214. console.log(data.error);
  4215. } else {
  4216. if (createObjectLocation) {
  4217. setIconDesktopLocation(newFolderName, closestGridIndexLocation[0], closestGridIndexLocation[1], function() {
  4218. //After set Desktop icon, refresh the page
  4219. refresh(function() {
  4220. //After refresh the page, highlight the new folder and set it to rename mode
  4221. var targetFolderObject = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  4222. console.log(targetFolderObject);
  4223. enableRenameOnLaunchIconObject(targetFolderObject);
  4224. });
  4225. });
  4226. }
  4227. }
  4228. });
  4229. /*
  4230. //Open new folder creation window
  4231. var existsingFileList = [];
  4232. for (var i =0; i < desktopFileList.length; i++){
  4233. existsingFileList.push({
  4234. filename: desktopFileList[i],
  4235. filepath: "user:/Desktop/" + desktopFileList[i]
  4236. });
  4237. }
  4238. newFloatWindow({
  4239. url: "SystemAO/file_system/newFolder.html#" + encodeURIComponent(JSON.stringify(existsingFileList)),
  4240. appicon: "SystemAO/file_system/img/new folder.png",
  4241. width:560,
  4242. height:340,
  4243. title: "New Folder"
  4244. });
  4245. */
  4246. hideAllContextMenus();
  4247. }
  4248. function enableRenameOnLaunchIconObject(object) {
  4249. renameMode = true;
  4250. $(".launchIcon").attr("draggable", "false");
  4251. var filedata = JSON.parse(decodeURIComponent($(object).attr("filedata")));
  4252. var originalName = filedata.Filename;
  4253. if (filedata.IsShortcut){
  4254. //Shortcut. Use its display name instead
  4255. originalName = filedata.ShortcutName;
  4256. }
  4257. $(object).find(".launchIconText").hide();
  4258. $(object).append(`<textarea class="renameInput ${desktopIconSize}" type="text" ondragstart="return false;" dblclick="event.stopImmediatePropagation(); event.stopImmediatePropagation();"maxlength="32">${originalName}</textarea>`);
  4259. $(object).find(".renameInput")[0].select();
  4260. var index = originalName.lastIndexOf(".");
  4261. console.log(index);
  4262. if( index >= 0){
  4263. $(object).find(".renameInput")[0].setSelectionRange(0, index);
  4264. }
  4265. //Updates 4-5-2021: Added IME support on rename input
  4266. $(object).find(".renameInput")[0].addEventListener("keydown", function(event){
  4267. if (window.ime && window.ime.handler != null){
  4268. window.ime.handler(event);
  4269. }else{
  4270. //No IME handler. Just continue the input
  4271. }
  4272. });
  4273. window.ime.focus = $(object).find(".renameInput")[0];
  4274. }
  4275. function exitRenameMode() {
  4276. if (renameMode) {
  4277. $(".launchIcon").attr("draggable", "true");
  4278. $(".launchIcon").find(".launchIconText").show();
  4279. //Update the folder to textarea content
  4280. $(".renameInput").each(function() {
  4281. if ($(this).text() == "") {
  4282. //Ignore this update
  4283. } else {
  4284. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4285. var filepath = filedata.Filepath;
  4286. var newFilename = $(this).val();
  4287. if (filedata.IsShortcut == true){
  4288. //Shortcut. Edit the shortcut content name
  4289. let currentInputTextArea = $(this);
  4290. $.ajax({
  4291. url: "/system/desktop/opr/renameShortcut",
  4292. data: {src: filepath, new: newFilename},
  4293. success: function(data){
  4294. if (data.error !== undefined){
  4295. //Cancel the operation
  4296. console.log("*ERROR* " + data.error);
  4297. currentInputTextArea.remove();
  4298. }else{
  4299. //No need to update the shortcut position (as its name not changed)
  4300. refresh(function() {
  4301. //Refresh the desktop
  4302. });
  4303. }
  4304. }
  4305. })
  4306. }else{
  4307. //Normal typed files / folder. Rename the object
  4308. let currentInputTextArea = $(this);
  4309. generateCSRFToken(function(csrftoken){
  4310. $.ajax({
  4311. url: "./system/file_system/fileOpr",
  4312. method: "POST",
  4313. data: {opr: "rename", src: JSON.stringify([filepath]), new: JSON.stringify([newFilename]), token: csrftoken},
  4314. success: function(data){
  4315. if (data.error !== undefined){
  4316. //Cancel the operation
  4317. console.log("*ERROR* " + data.error);
  4318. currentInputTextArea.remove();
  4319. }else{
  4320. //Update the new file position
  4321. let closestLocation = findClosestGrid($(currentInputTextArea).parent().offset().left, $(currentInputTextArea).parent().offset().top);
  4322. let closestGridIndexLocation = closestLocation[1];
  4323. setIconDesktopLocation(newFilename, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4324. //Callback after setting location
  4325. refresh(function() {
  4326. //Refresh the desktop
  4327. });
  4328. });
  4329. }
  4330. }
  4331. });
  4332. });
  4333. }
  4334. }
  4335. });
  4336. renameMode = false;
  4337. }
  4338. }
  4339. //Handle opening shortcut folder location
  4340. function handleShortcutFolderOpen(object, event){
  4341. var openPendingFolders = [];
  4342. $(".launchIconWrapper.selected").each(function(){
  4343. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4344. console.log(filedata);
  4345. if (filedata.IsShortcut == true){
  4346. if (filedata.ShortcutType == "folder"){
  4347. openPendingFolders.push(filedata.ShortcutPath);
  4348. }else if (filedata.ShortcutType == "module"){
  4349. openPendingFolders.push("web:/" + filedata.ShortcutPath);
  4350. }
  4351. }
  4352. });
  4353. //Open all folders
  4354. openPendingFolders.forEach(folder => {
  4355. newFloatWindow({
  4356. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(folder),
  4357. appicon: "SystemAO/file_system/img/small_icon.png",
  4358. width:1080,
  4359. height:580,
  4360. title: "File Manager"
  4361. });
  4362. })
  4363. hideAllContextMenus();
  4364. }
  4365. //Handle basic desktop file operations
  4366. function handleFileDelete(object, event){
  4367. var deleteFileList = [];
  4368. $(".launchIconWrapper.selected").each(function(){
  4369. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4370. deleteFileList.push(filedata.Filepath);
  4371. });
  4372. console.log(deleteFileList);
  4373. generateCSRFToken(function(csrftoken){
  4374. $.ajax({
  4375. url: "system/file_system/fileOpr",
  4376. method:"POST",
  4377. data: {opr: "recycle", src: JSON.stringify(deleteFileList), csrft: csrftoken},
  4378. success: function(data){
  4379. if (data.error !== undefined){
  4380. alert(data.error);
  4381. }else{
  4382. refresh(undefined, true);
  4383. }
  4384. }
  4385. });
  4386. hideAllContextMenus();
  4387. });
  4388. }
  4389. //File Rename
  4390. let renamingItems = [];
  4391. function handleRename(object, event){
  4392. if ($('.launchIconWrapper.selected').length > 0){
  4393. //Enter rename mode
  4394. renamingItems = $('.launchIconWrapper.selected');
  4395. let renameTarget = $('.launchIconWrapper.selected')[0]
  4396. let fileObject = $(renameTarget).parent();
  4397. enableRenameOnLaunchIconObject(fileObject);
  4398. }
  4399. hideAllContextMenus();
  4400. }
  4401. //New item menus.
  4402. function newitemmenu(target, event) {
  4403. $("#subcontextmenu").html("");
  4404. //Append the new folder option first
  4405. addContextMenuItem($("#subcontextmenu"), 'Folder', "<i class='folder icon'></i>", "newfolder", true);
  4406. addContextMenuItem($("#subcontextmenu"), 'Shortcut', "<i class='external icon'></i>", "newshortcut", true);
  4407. addContextMenuSeperator($("#subcontextmenu"));
  4408. $.get("system/file_system/newItem", function(data) {
  4409. for (var i = 0; i < data.length; i++) {
  4410. var thisNewFile = data[i];
  4411. var icon = ao_module_utils.getIconFromExt(thisNewFile.Ext);
  4412. addContextMenuItem($("#subcontextmenu"), `<i class="${icon} icon" ext="${thisNewFile.Ext}"></i> ${thisNewFile.Desc}`, undefined, "newitem");
  4413. }
  4414. //Show sub-context menu
  4415. showSubContextMenu(target);
  4416. });
  4417. }
  4418. function showSubContextMenu(target) {
  4419. $("#subcontextmenu").show();
  4420. var targetLeft = $("#contextmenu").offset().left + $("#contextmenu").width() + 2;
  4421. var targetTop = $(target).offset().top - 1;
  4422. if (targetLeft + $("#subcontextmenu").width() > window.innerWidth){
  4423. //Overflow. Swtich to the left side of the menu
  4424. targetLeft = $("#contextmenu").offset().left - $("#subcontextmenu").width() - 2;
  4425. }
  4426. $("#subcontextmenu").css({
  4427. left: targetLeft,
  4428. top: targetTop
  4429. });
  4430. }
  4431. //Create new file item with that filename
  4432. function newitem(object, event) {
  4433. var extension = $(object).find("i").attr("ext");
  4434. //Generate a newfile name
  4435. var newfn = "NewFile" + "." + extension;
  4436. var counter = 1;
  4437. while (desktopFileList.includes(newfn)){
  4438. newfn = "NewFile (" + counter + ")." + extension;
  4439. counter++;
  4440. }
  4441. //Get the location position
  4442. let closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4443. let closestGridIndexLocation = closestLocation[1];
  4444. //Request backend to generate the new file
  4445. $.ajax({
  4446. url: "system/file_system/newItem",
  4447. data: {type: "file",src: "user:/Desktop/",filename: newfn},
  4448. success: function(data){
  4449. if (data.error !== undefined){
  4450. alert(data.error);
  4451. }else{
  4452. //Set the icon location
  4453. setIconDesktopLocation(newfn, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4454. //Refresh the desktop
  4455. refresh(function(){
  4456. var targetNewFile = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  4457. console.log("Renaming ", targetNewFile);
  4458. enableRenameOnLaunchIconObject(targetNewFile);
  4459. });
  4460. });
  4461. }
  4462. }
  4463. });
  4464. hideAllContextMenus();
  4465. }
  4466. document.getElementById("volumebar").parentNode.addEventListener("touchstart", function(e){
  4467. updateVolume( document.getElementById("volumebar").parentNode, e);
  4468. });
  4469. function getCoordinateFromEvent(e){
  4470. var x = -1;
  4471. var y = -1;
  4472. if (e.originalEvent == undefined){
  4473. e.originalEvent = e;
  4474. }
  4475. if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){
  4476. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  4477. x = touch.pageX;
  4478. y = touch.pageY;
  4479. } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
  4480. x = e.clientX;
  4481. y = e.clientY;
  4482. }else{
  4483. x = e.clientX;
  4484. y = e.clientY;
  4485. }
  4486. return [x,y];
  4487. }
  4488. function updateVolume(object, event){
  4489. var width = $(object).width();
  4490. var left = $(object).offset().left;
  4491. var clickPosition = getCoordinateFromEvent(event)[0];
  4492. var clickRel = clickPosition - left;
  4493. var percentage = clickRel / width * 100;
  4494. if (percentage < 0){
  4495. percentage = 0;
  4496. }else if (percentage > 100){
  4497. percentage = 100;
  4498. }
  4499. //Update the global volume
  4500. $(object).find(".bar").css("width",percentage + "%");
  4501. localStorage.setItem("global_volume", clickRel / width);
  4502. }
  4503. function refresh(callback = undefined, noflash=false) {
  4504. //Refresh desktop contents
  4505. let launchOption = {};
  4506. if (noflash){
  4507. launchOption = {
  4508. noflash: true
  4509. };
  4510. }else{
  4511. $(".launchIcon").remove();
  4512. }
  4513. if (callback == undefined) {
  4514. initDesktopFiles(launchOption);
  4515. } else {
  4516. initDesktopFiles(launchOption, callback);
  4517. }
  4518. hideAllContextMenus();
  4519. }
  4520. function openfm() {
  4521. //Open file explorer on desktop
  4522. newFloatWindow({
  4523. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent("user:/Desktop"),
  4524. appicon: "SystemAO/file_system/img/small_icon.png",
  4525. width: 1080,
  4526. height: 580,
  4527. title: "File Manager"
  4528. });
  4529. hideAllContextMenus();
  4530. }
  4531. /*
  4532. Notification and Notification bar related functions
  4533. Usage:
  4534. title -> The title of the notification
  4535. content -> The content of the notification
  4536. icon (optional) -> The icon of the notification
  4537. windowOpenOption (optional) -> The window opening option for user onclick redirection
  4538. */
  4539. function sendNotification(title, content, icon="notice circle", windowOpenOption=null){
  4540. if (content.length > 100){
  4541. shortenContent = content.substring(0,100) + "...";
  4542. }else{
  4543. shortenContent = content;
  4544. }
  4545. onClickOpenWindowOption = encodeURIComponent(JSON.parse(windowOpenOption));
  4546. $("#notificationlist").append(` <div class="notification object" originalcontent="${content}" redirect="${onClickOpenWindowOption}" onclick="openNotification(this);">
  4547. <p class="title"><i class="${icon} icon"></i> ${title}</p>
  4548. <p class="notifycontent">${shortenContent}</p>
  4549. <div class="closebtn" onclick="event.stopImmediatePropagation(); closeThisNotification(this);"><i class="remove icon"></i></div>
  4550. <div class="ts divider"></div>
  4551. </div>`);
  4552. $(".nonotification").hide();
  4553. }
  4554. function openNotification(obj){
  4555. newWindowOpeningOption = JSON.parse(decodeURIComponent($(obj).attr("redirect")));
  4556. if (newWindowOpeningOption == null){
  4557. //Ignore
  4558. }else{
  4559. //Start a floatWindow to the given target
  4560. newFloatWindow(newWindowOpeningOption);
  4561. }
  4562. //Clear the notiication
  4563. closeThisNotification($(obj).find(".closebtn"));
  4564. }
  4565. function closeThisNotification(obj){
  4566. $(obj).parent().slideUp("fast",function(data){
  4567. $(this).remove();
  4568. if ($(".notification.object").length == 0){
  4569. $(".nonotification").show();
  4570. }
  4571. });
  4572. }
  4573. function clearAllNotification(){
  4574. $(".notification.object").slideUp('fast',function(data){
  4575. $(this).remove();
  4576. $(".nonotification").show();
  4577. });
  4578. }
  4579. function hideAllContextMenus() {
  4580. $("#subcontextmenu").hide();
  4581. $("#contextmenu").hide()
  4582. $("#quickAccessPanel").slideUp("fast");
  4583. }
  4584. function restart(){
  4585. if (!hardwareman){
  4586. return
  4587. }
  4588. if (confirm("Confirm Restart?")){
  4589. $.ajax({
  4590. url: "system/power/restart",
  4591. success: function(data){
  4592. if (data.error !== undefined){
  4593. alert(data.error);
  4594. }
  4595. },
  4596. error: function(){
  4597. }
  4598. });
  4599. }
  4600. }
  4601. function shutdown(){
  4602. if (!hardwareman){
  4603. return
  4604. }
  4605. if (confirm("Confirm Poweroff?")){
  4606. $.ajax({
  4607. url: "system/power/shutdown",
  4608. success: function(data){
  4609. if (data.error !== undefined){
  4610. alert(data.error);
  4611. }else{
  4612. //Shutdown suceed
  4613. }
  4614. },
  4615. error: function(){
  4616. //Shutdown suceed
  4617. }
  4618. });
  4619. }
  4620. }
  4621. function uploadFile(file, callback=undefined) {
  4622. let url = 'system/file_system/upload'
  4623. let uploadCurrentPath = "user:/Desktop/";
  4624. let formData = new FormData()
  4625. let xhr = new XMLHttpRequest()
  4626. formData.append('file', file);
  4627. formData.append('path', uploadCurrentPath);
  4628. xhr.open('POST', url, true)
  4629. xhr.upload.addEventListener("progress", function(e) {
  4630. console.log((e.loaded * 100.0 / e.total) || 100)
  4631. })
  4632. xhr.addEventListener('readystatechange', function(e) {
  4633. if (xhr.readyState == 4 && xhr.status == 200) {
  4634. if (callback !== undefined){
  4635. callback(e.target.response);
  4636. }
  4637. }
  4638. else if (xhr.readyState == 4 && xhr.status != 200) {
  4639. console.log("Upload failed :" + xhr.status);
  4640. }
  4641. })
  4642. xhr.send(formData);
  4643. }
  4644. function setStorage(key, value, callback = undefined) {
  4645. $.get("system/desktop/preference?preference=" + key + "&value=" + value, function(data) {
  4646. if (data.error !== undefined) {
  4647. console.log(data.error);
  4648. } else {
  4649. if (callback !== undefined) {
  4650. callback();
  4651. }
  4652. }
  4653. });
  4654. }
  4655. function getStorage(key, callback) {
  4656. $.get("system/desktop/preference?preference=" + key, callback);
  4657. }
  4658. function showSystemSettings(){
  4659. var hasAccessToSetting = false;
  4660. moduleInstalled.forEach(thismod => {
  4661. if (thismod.Name == "System Setting"){
  4662. openModule("System Setting");
  4663. }
  4664. })
  4665. }
  4666. function initTheme(targetTheme=undefined){
  4667. if (targetTheme == undefined){
  4668. $.get("../../system/file_system/preference?key=file_explorer/theme", function(data){
  4669. if (data == "darkTheme"){
  4670. setDarkTheme();
  4671. }
  4672. });
  4673. }else{
  4674. //Manual override mode
  4675. if (targetTheme == "darkTheme"){
  4676. setDarkTheme();
  4677. }else if (targetTheme == "whiteTheme"){
  4678. setWhiteTheme();
  4679. }
  4680. }
  4681. }
  4682. function setFloatWindowTheme(fwid, theme="dark"){
  4683. var targetFW = getFloatWindowByID(fwid);
  4684. if (theme == "dark"){
  4685. $(targetFW).removeClass("white");
  4686. }else if (theme == "white"){
  4687. $(targetFW).addClass("white");
  4688. }
  4689. }
  4690. function checkFileSystemAccess(){
  4691. var allowReadWrite = false;
  4692. moduleInstalled.forEach(thisModule => {
  4693. if (thisModule.Name == "File Manager"){
  4694. //This user has read write access to file system
  4695. allowReadWrite = true;
  4696. }
  4697. });
  4698. if (!allowReadWrite){
  4699. sendNotification("READ ONLY Account", "This account is read only. You cannot perform any file operations on this desktop.");
  4700. }
  4701. }
  4702. function setDarkTheme(){
  4703. $("#listMenu").addClass("darkTheme");
  4704. $("#powerIcon").attr("src","img/system/power-white.svg");
  4705. $("#quickAccessPanel").addClass("darkTheme");
  4706. $("#quickAccessPanel").find(".button").addClass("inverted");
  4707. }
  4708. function setWhiteTheme(){
  4709. $("#listMenu").removeClass("darkTheme");
  4710. $("#powerIcon").attr("src","img/system/power.svg");
  4711. $("#quickAccessPanel").removeClass("darkTheme");
  4712. $("#quickAccessPanel").find(".button").removeClass("inverted");
  4713. }
  4714. function hexToRgbA(hex, transparent=1){
  4715. var c;
  4716. if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
  4717. c= hex.substring(1).split('');
  4718. if(c.length== 3){
  4719. c= [c[0], c[0], c[1], c[1], c[2], c[2]];
  4720. }
  4721. c= '0x'+c.join('');
  4722. return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',' + transparent + ')';
  4723. }
  4724. throw new Error('Bad Hex');
  4725. }
  4726. function setThemeColor(newThemeColor){
  4727. //Update the global theme color
  4728. desktopThemeColor = newThemeColor;
  4729. //Update the related elements
  4730. $("#statusbar").css("background-color",newThemeColor);
  4731. $("#navimenu").css("background-color",hexToRgbA(newThemeColor, 0.5));
  4732. $(".floatWindow .controls").css("background-color",hexToRgbA(newThemeColor, 0.85));
  4733. //List menu theme color bar
  4734. $("#listMenu").find(".searchBar").css("border-bottom", "2px solid " + newThemeColor);
  4735. $("#volumebar").css("background-color", newThemeColor);
  4736. //Connection lost notification css
  4737. $("#connectionLost").find(".ts.card").css("background-color", hexToRgbA(newThemeColor, 0.5));
  4738. }
  4739. //Load the user define theme color to overwrite the default color if exists
  4740. function initUserDefinedThemeColor(){
  4741. $.ajax({
  4742. url: "../../system/file_system/preference",
  4743. data: {key: "themecolor"},
  4744. success: function(data){
  4745. if (data.error == undefined && data != ""){
  4746. setThemeColor(data);
  4747. }
  4748. }
  4749. });
  4750. }
  4751. //Float Window context menu
  4752. function getFocusedFloatWindowID(){
  4753. var targetFloatWindowId = "";
  4754. $(".floatWindow").each(function() {
  4755. var thisWindowZIndex = $(this).css("z-index");
  4756. if (parseInt(thisWindowZIndex) == 101){
  4757. targetFloatWindowId = $(this).attr("windowid");
  4758. }
  4759. });
  4760. return targetFloatWindowId;
  4761. }
  4762. function getFocusedFloatWindow(){
  4763. var focusedFwId = getFocusedFloatWindowID();
  4764. if (focusedFwId != ""){
  4765. var fw = getFloatWindowByID(focusedFwId);
  4766. return fw;
  4767. }else{
  4768. return undefined;
  4769. }
  4770. }
  4771. function refreshSelectedFloatWindow(target, event){
  4772. var fw = getFocusedFloatWindow();
  4773. if (fw != undefined){
  4774. $(fw).find("iframe")[0].contentWindow.location.reload();
  4775. }
  4776. hideAllContextMenus();
  4777. }
  4778. function maximizeSelectedFloatWindow(target, event){
  4779. var fw = getFocusedFloatWindow();
  4780. if (fw != undefined){
  4781. toggleMax($(fw).find(".buttons.maxtoggle"),event);
  4782. }
  4783. hideAllContextMenus();
  4784. }
  4785. function minimizeSelectedFloatWindow(target, event){
  4786. var fw = getFocusedFloatWindow();
  4787. if (fw != undefined){
  4788. min($(fw).find(".buttons.mintoggle"),event);
  4789. }
  4790. hideAllContextMenus();
  4791. }
  4792. function openSelectedFloatWindowInNewTab(){
  4793. var fw = getFocusedFloatWindow();
  4794. if (fw != undefined){
  4795. var currentURL = $(fw).find("iframe")[0].contentWindow.location;
  4796. window.open(currentURL);
  4797. }
  4798. hideAllContextMenus();
  4799. }
  4800. function closeSelectedFloatWindow(target, event){
  4801. var fw = getFocusedFloatWindow();
  4802. if (fw != undefined){
  4803. closeFloatWindow($(fw).find(".buttons.closetoggle"),event);
  4804. }
  4805. hideAllContextMenus();
  4806. }
  4807. function fullscreen() {
  4808. //Opening full screen will lead to hidden of all iframe for unknown reasons
  4809. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
  4810. (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
  4811. (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
  4812. (document.msFullscreenElement && document.msFullscreenElement !== null);
  4813. var elem = document.documentElement;
  4814. if (!isInFullScreen) {
  4815. if (elem.requestFullscreen) {
  4816. elem.requestFullscreen();
  4817. } else if (elem.mozRequestFullScreen) { /* Firefox */
  4818. elem.mozRequestFullScreen();
  4819. } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
  4820. elem.webkitRequestFullscreen();
  4821. } else if (elem.msRequestFullscreen) { /* IE/Edge */
  4822. elem.msRequestFullscreen();
  4823. }
  4824. } else {
  4825. if (document.exitFullscreen) {
  4826. document.exitFullscreen();
  4827. } else if (document.webkitExitFullscreen) {
  4828. document.webkitExitFullscreen();
  4829. } else if (document.mozCancelFullScreen) {
  4830. document.mozCancelFullScreen();
  4831. } else if (document.msExitFullscreen) {
  4832. document.msExitFullscreen();
  4833. }
  4834. }
  4835. hideAllContextMenus();
  4836. }
  4837. /*
  4838. Background services for keeping desktop files updated
  4839. Same mechanism is used as file explorer
  4840. */
  4841. let desktopFileHash = "";
  4842. setInterval(function(){
  4843. getDesktopHash(function(hash){
  4844. if (desktopFileHash == ""){
  4845. //Initialization
  4846. desktopFileHash = hash;
  4847. }else if (desktopFileHash != hash){
  4848. //Changed on desktop files. Refresh
  4849. refresh();
  4850. desktopFileHash = hash;
  4851. }
  4852. //Else, no file change on desktop
  4853. });
  4854. }, 15000);
  4855. function generateCSRFToken(callback){
  4856. $.ajax({
  4857. url: "../../system/csrf/new",
  4858. success: function(token){
  4859. callback(token);
  4860. }
  4861. })
  4862. }
  4863. function getDesktopHash(callback){
  4864. $.ajax({
  4865. url: "system/file_system/listDirHash",
  4866. data: {dir: "user:/Desktop/"},
  4867. success: function(data){
  4868. if (data.error !== undefined){
  4869. }
  4870. callback(data);
  4871. }
  4872. })
  4873. }
  4874. function bindObjectToIMEEvents(object){
  4875. object.addEventListener("keydown", function(event){
  4876. if (window.ime && window.ime.handler != null){
  4877. window.ime.handler(event);
  4878. }else{
  4879. //No IME handler. Just continue the input
  4880. }
  4881. });
  4882. object.addEventListener("focus", function(event){
  4883. if (window.ime){
  4884. //IME exists. Set this field to focused field
  4885. window.ime.focus = event.target;
  4886. }
  4887. });
  4888. }
  4889. </script>
  4890. </body>
  4891. </html>