desktop.system 254 KB

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