desktop.html 348 KB

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