desktop.system 273 KB

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