desktop.system 252 KB

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