desktop.system 311 KB

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