desktop.system 265 KB

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