desktop.system 266 KB

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