desktop.html 324 KB

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