desktop.system 277 KB

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