desktop.html 333 KB

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