desktop.html 349 KB

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