desktop.system 246 KB

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