desktop.system 290 KB

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