desktop.system 246 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005
  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 stackedFloatWindowListShown = 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. console.log(data["LaunchFWDir"]);
  1309. if (data["LaunchFWDir"] != null && data["LaunchFWDir"] != "") {
  1310. url = data["LaunchFWDir"];
  1311. }
  1312. if (data["InitFWSize"] != null) {
  1313. size = data["InitFWSize"];
  1314. }
  1315. }
  1316. //Launch the given module
  1317. var uuid = newFloatWindow({
  1318. url: url,
  1319. width: size[0],
  1320. height: size[1],
  1321. appicon: icon,
  1322. title: title
  1323. });
  1324. if (callback !== undefined){
  1325. callback();
  1326. }
  1327. hideListMenu();
  1328. }
  1329. });
  1330. }
  1331. // ===================== FLOAT WINDOWS EVENTS =====================
  1332. function hookFloatWindowEvents() {
  1333. //Handle floatWindow mouse drag events
  1334. $(".fwdragger").off("mousedown").on("mousedown", function(evt) {
  1335. evt.preventDefault();
  1336. evt.stopImmediatePropagation();
  1337. fwdown($(this).parent(), evt);
  1338. });
  1339. $(".fwdragger").off("mousemove").on("mousemove", function(evt) {
  1340. evt.preventDefault();
  1341. evt.stopImmediatePropagation();
  1342. fwmove($(this).parent(), evt);
  1343. });
  1344. $(".fwdragger").off("mouseup").on("mouseup", function(evt) {
  1345. evt.preventDefault();
  1346. evt.stopImmediatePropagation();
  1347. fwup($(this).parent(), evt);
  1348. });
  1349. $(".fwdragger").off("touchstart").on("touchstart", function(evt) {
  1350. evt.preventDefault();
  1351. evt.stopImmediatePropagation();
  1352. fwdown($(this).parent(), evt);
  1353. });
  1354. $(".fwdragger").off("touchmove").on("touchmove", function(evt) {
  1355. evt.preventDefault();
  1356. evt.stopImmediatePropagation();
  1357. fwmove($(this).parent(), evt);
  1358. });
  1359. $(".fwdragger").off("touchend").on("touchend", function(evt) {
  1360. evt.preventDefault();
  1361. evt.stopImmediatePropagation();
  1362. fwup($(this).parent(), evt);
  1363. });
  1364. $(".fwdragger").off("dblclick").on("dblclick", function(evt) {
  1365. //Activate full screen
  1366. evt.preventDefault();
  1367. evt.stopImmediatePropagation();
  1368. //Emulate keypress on maximize btn
  1369. toggleMax($(this).parent().find(".maxToogleButton").parent()[0], evt);
  1370. });
  1371. //Floatwindow operations for touch devices
  1372. $(".maxtoggle").off("touchstart").on("touchstart",function(evt){
  1373. evt.preventDefault();
  1374. evt.stopImmediatePropagation();
  1375. toggleMax(this, evt);
  1376. });
  1377. $(".mintoggle").off("touchstart").on("touchstart",function(evt){
  1378. evt.preventDefault();
  1379. evt.stopImmediatePropagation();
  1380. min(this, evt);
  1381. });
  1382. $(".closetoggle").off("touchstart").on("touchstart",function(evt){
  1383. evt.preventDefault();
  1384. evt.stopImmediatePropagation();
  1385. closeFloatWindow(this,evt);
  1386. });
  1387. //floatWindow events for mouse
  1388. $(".maxtoggle").off("mousedown").on("mousedown",function(evt){
  1389. evt.preventDefault();
  1390. evt.stopImmediatePropagation();
  1391. toggleMax(this, evt);
  1392. });
  1393. $(".mintoggle").off("mousedown").on("mousedown",function(evt){
  1394. evt.preventDefault();
  1395. evt.stopImmediatePropagation();
  1396. min(this, evt);
  1397. });
  1398. $(".closetoggle").off("mousedown").on("mousedown",function(evt){
  1399. evt.preventDefault();
  1400. evt.stopImmediatePropagation();
  1401. closeFloatWindow(this,evt);
  1402. });
  1403. //Float Window events for resizing
  1404. $(".iframewrapper").off("mousedown").on("mousedown", function(evt) {
  1405. evt.preventDefault();
  1406. evt.stopImmediatePropagation();
  1407. if ($(this).parent().hasClass("fixedsize")) {
  1408. return false;
  1409. }
  1410. resizeDown($(this).parent(), evt);
  1411. });
  1412. $(".iframewrapper").off("mousemove").on("mousemove", function(evt) {
  1413. evt.preventDefault();
  1414. evt.stopImmediatePropagation();
  1415. if (resizingWindow == true) {
  1416. //Resizeing Move
  1417. resizeMove($(this).parent(), evt);
  1418. } else {
  1419. //Dragdropping move
  1420. fwmove($(this).parent(), evt);
  1421. }
  1422. });
  1423. $(".iframewrapper").off("mouseup").on("mouseup", function(evt) {
  1424. evt.preventDefault();
  1425. evt.stopImmediatePropagation();
  1426. resizeUp($(this).parent(), evt);
  1427. });
  1428. $(".iframewrapper").off("mouseover").on("mouseover", function(evt) {
  1429. var object = $(this).parent();
  1430. if ($(object).hasClass("fixedsize")) {
  1431. return false;
  1432. }
  1433. var dx = event.pageX - $(object).find(".iframewrapper").offset().left;
  1434. var dy = event.pageY - $(object).offset().top;
  1435. if (dx < 10 && dy > $(object).height() - 10) {
  1436. //Left Bottom Corner
  1437. $(".iframewrapper").attr("class", "iframewrapper leftCorner");
  1438. } else if (dx > $(object).width() - 10 && dy > $(object).height() - 10) {
  1439. //Right Bottom Corner
  1440. $(".iframewrapper").attr("class", "iframewrapper rightCorner");
  1441. } else if (dx < 10) {
  1442. //Dragging left edge
  1443. $(".iframewrapper").attr("class", "iframewrapper widthHover");
  1444. } else if (dx > $(object).width() - 10) {
  1445. //Dragging right edge
  1446. $(".iframewrapper").attr("class", "iframewrapper widthHover");
  1447. } else if (dy > $(object).height() - 10) {
  1448. //Bottom Edge
  1449. $(".iframewrapper").attr("class", "iframewrapper heighHover");
  1450. } else {
  1451. //???
  1452. $(".iframewrapper").attr("class", "iframewrapper");
  1453. }
  1454. });
  1455. //Hook events on the floatWindow button
  1456. $(".floatWindowButton").off("click touchstart").on("click touchstart", function(event) {
  1457. event.preventDefault();
  1458. event.stopImmediatePropagation();
  1459. $("#stackedWindowList").css("left", $(this).offset().left);
  1460. //Generate the stackedWindowList
  1461. var windowIdList = JSON.parse(decodeURIComponent($(this).attr("windowidgroup")));
  1462. if (windowIdList.length == 1) {
  1463. //There are only one window in this group. Show it anyway
  1464. var targetFW = getFloatWindowByID(windowIdList[0]);
  1465. $(targetFW).fadeIn(100);
  1466. MoveFloatWindowToTop(targetFW);
  1467. stackedFloatWindowListShown = false;
  1468. $("#stackedWindowList").hide();
  1469. } else {
  1470. //Get icon for each windows and build the list objects
  1471. $("#stackedWindowList").html("");
  1472. for (var i = 0; i < windowIdList.length; i++) {
  1473. var iconURL = getFloatWindowIconByID(windowIdList[i]);
  1474. var title = getFloatWindowTitleByID(windowIdList[i]);
  1475. $("#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>`);
  1476. }
  1477. $("#stackedWindowList").show();
  1478. stackedFloatWindowListShown = true;
  1479. }
  1480. });
  1481. }
  1482. var tapedTwiceTouch = false;
  1483. var timeoutObject;
  1484. var tappingTarget = undefined;
  1485. function doubleTouchHandler(object, event, callback) {
  1486. if(!tapedTwiceTouch) {
  1487. tapedTwiceTouch = true;
  1488. tappingTarget = object;
  1489. timeoutObject = setTimeout( function() { tapedTwiceTouch = false; }, 300 );
  1490. return false;
  1491. }
  1492. if (tappingTarget == object){
  1493. //Double click on the same icon
  1494. event.preventDefault();
  1495. callback(object, event);
  1496. tappingTarget = undefined;
  1497. }else{
  1498. //Although it touch twice within 300ms, but it is on different target
  1499. //Update the tab target instead.
  1500. tappingTarget = object;
  1501. tapedTwiceTouch = true;
  1502. clearTimeout(timeoutObject);
  1503. timeoutObject = setTimeout( function() { tapedTwiceTouch = false; }, 300 );
  1504. }
  1505. }
  1506. function openViaTouch(object, event){
  1507. iconDoubleClicked(object,event);
  1508. }
  1509. //Handle focus through floatWindow taskbar button
  1510. function bringFloatWindowToFrontByFWB(object, event) {
  1511. event.preventDefault();
  1512. event.stopImmediatePropagation();
  1513. var targetWFID = $(object).attr("windowId");
  1514. var targetFW = getFloatWindowByID(targetWFID);
  1515. if (targetFW == undefined){
  1516. //fw not found
  1517. return;
  1518. }
  1519. $(targetFW).fadeIn(100);
  1520. MoveFloatWindowToTop(targetFW);
  1521. stackedFloatWindowListShown = false;
  1522. $("#stackedWindowList").hide();
  1523. }
  1524. function closeFWviaFWB(object, event) {
  1525. event.preventDefault();
  1526. event.stopImmediatePropagation();
  1527. var targetWFID = $(object).parent().attr("windowId");
  1528. var targetFW = getFloatWindowByID(targetWFID);
  1529. if (targetFW == undefined){
  1530. //fw not found
  1531. return;
  1532. }
  1533. closeFloatWindow(targetFW.find(".close"), event);
  1534. $(object).parent().remove();
  1535. if ($("#stackedWindowList").find(".item").length == 0) {
  1536. //There are no more things in this tab. Close this list as well.
  1537. stackedFloatWindowListShown = false;
  1538. $("#stackedWindowList").hide();
  1539. }
  1540. }
  1541. //Handle floatWindow resize events
  1542. let resizingWindowTarget;
  1543. let resizingMinX = 0;
  1544. let minxWidth = 120;
  1545. let minHeight = 100;
  1546. function resizeDown(object, event) {
  1547. //Mouse down, start resizing
  1548. resizingWindow = true;
  1549. resizingWindowTarget = object;
  1550. resizingMinX = $(object).offset().left + $(object).width() - minxWidth;
  1551. MoveFloatWindowToTop(object);
  1552. if ($(object).hasClass("topmost")){
  1553. //Top most windows
  1554. $("#tfwdragpanel").show();
  1555. }else{
  1556. //Normal Windows
  1557. $('.floatWindow.topmost').css("pointer-events", "none");
  1558. $('.floatWindow.topmost').css("opacity", 0.7);
  1559. $("#fwdragpanel").show();
  1560. }
  1561. $(object).find(".iframecover").show();
  1562. //Check which edge is the user dragging
  1563. var dx = event.pageX - $(object).find(".iframewrapper").offset().left;
  1564. var dy = event.pageY - $(object).offset().top;
  1565. if (dx < 10 && dy > $(object).height() - 10) {
  1566. //Left Bottom Corner
  1567. resizingEdgeID = 4;
  1568. $(object).find(".iframewrapper").css('cursor', 'sw-resize');
  1569. } else if (dx > $(object).width() - 10 && dy > $(object).height() - 10) {
  1570. //Right Bottom Corner
  1571. resizingEdgeID = 2;
  1572. $(object).find(".iframewrapper").css('cursor', 'se-resize');
  1573. } else if (dx < 10) {
  1574. //Dragging left edge
  1575. resizingEdgeID = 5;
  1576. $(object).find(".iframewrapper").css('cursor', 'w-resize');
  1577. } else if (dx > $(object).width() - 10) {
  1578. //Dragging right edge
  1579. resizingEdgeID = 1;
  1580. $(object).find(".iframewrapper").css('cursor', 'w-resize');
  1581. } else if (dy > $(object).height() - 10) {
  1582. //Bottom Edge
  1583. resizingEdgeID = 3;
  1584. $(object).find(".iframewrapper").css('cursor', 's-resize');
  1585. }
  1586. }
  1587. function resizeMove(object, event) {
  1588. var posX = event.pageX;
  1589. var posY = event.pageY;
  1590. if (resizingWindow == true && resizingEdgeID != 0) {
  1591. if (resizingEdgeID == 1) {
  1592. //Width = posX - floatWindow width + 2 (for border width)
  1593. var newWidth = posX - $(object).offset().left + 2;
  1594. $(object).css("width", Math.max(newWidth, minxWidth));
  1595. } else if (resizingEdgeID == 2) {
  1596. var newWidth = posX - $(object).offset().left + 2;
  1597. var newHeight = posY - $(object).offset().top + 2;
  1598. $(object).css({
  1599. width: Math.max(newWidth, minxWidth),
  1600. height: Math.max(newHeight, minHeight)
  1601. });
  1602. } else if (resizingEdgeID == 3) {
  1603. var newHeight = posY - $(object).offset().top + 2;
  1604. $(object).css("height", Math.max(newHeight,minHeight));
  1605. } else if (resizingEdgeID == 4) {
  1606. var newWidth = $(object).offset().left - posX + $(object).width();
  1607. var newHeight = posY - $(object).offset().top + 2;
  1608. if (newWidth < minxWidth){
  1609. posX = resizingMinX;
  1610. }
  1611. $(object).css({
  1612. width: Math.max(newWidth, minxWidth),
  1613. height: Math.max(newHeight, minHeight),
  1614. left: posX
  1615. });
  1616. } else if (resizingEdgeID == 5) {
  1617. var newWidth = $(object).offset().left - posX + $(object).width();
  1618. if (newWidth < minxWidth){
  1619. posX = resizingMinX;
  1620. }
  1621. $(object).css({
  1622. width: Math.max(newWidth, minxWidth),
  1623. left: posX
  1624. });
  1625. }
  1626. }
  1627. }
  1628. function resizeUp(object, event) {
  1629. resizingWindow = false;
  1630. resizingEdgeID = 0;
  1631. $("#fwdragpanel").hide();
  1632. $("#tfwdragpanel").hide();
  1633. $('.floatWindow.topmost').css("pointer-events", "auto");
  1634. $('.floatWindow.topmost').css("opacity", 1);
  1635. $(object).find(".iframecover").hide();
  1636. $(object).find(".iframewrapper").css('cursor', '');
  1637. //Force minmium width and height on any floatWindow objects
  1638. if ($(object).width() < 120) {
  1639. $(object).css("width", "120px");
  1640. }
  1641. if ($(object).height() < 120) {
  1642. $(object).css("height", "120px");
  1643. }
  1644. resizingWindowTarget = undefined;
  1645. $(".topmost").show();
  1646. }
  1647. //Hook body mousemove assistant events
  1648. $("body").on("mousemove", function(evt) {
  1649. if (focusedWindow !== undefined && movingWindow == true) {
  1650. fwmove(focusedWindow, evt);
  1651. } else if (focusedWindow !== undefined && resizingWindow == true) {
  1652. resizeMove(focusedWindow, evt);
  1653. } else if (multiSelecting == true) {
  1654. movingMultiSelectionArea(evt);
  1655. }
  1656. });
  1657. //Hook body clicke vents
  1658. $("body").on("click", function(evt) {
  1659. if (stackedFloatWindowListShown == true) {
  1660. //Hide the stacked Float Window list if it is shown
  1661. $("#stackedWindowList").hide();
  1662. stackedFloatWindowListShown = false;
  1663. }
  1664. if (renameMode == true){
  1665. //Exit rename mode if the target is not on the editing launchIcon
  1666. console.log(evt.target);
  1667. if ($(evt.target).is("body")){
  1668. //End rename mode
  1669. exitRenameMode();
  1670. }
  1671. }
  1672. });
  1673. //Convert touch events to click events
  1674. function mapEventFromTouch(event){
  1675. if (typeof event.originalEvent == "undefined"){
  1676. //Mouse click / down / up events
  1677. return event;
  1678. }
  1679. try{
  1680. //Touch events
  1681. if (typeof event.pageX == "undefined"){
  1682. event.pageX = event.originalEvent.touches[0].pageX;
  1683. }
  1684. if (typeof event.pageY == "undefined"){
  1685. event.pageY = event.originalEvent.touches[0].pageY;
  1686. }
  1687. return event;
  1688. }catch{
  1689. return event;
  1690. }
  1691. }
  1692. //Please pass in the floatWindow object instead of the dragger
  1693. function fwdown(object, event) {
  1694. event = mapEventFromTouch(event);
  1695. //Hide all contenxt menus
  1696. hideAllContextMenus();
  1697. //Move the window to the top layer
  1698. MoveFloatWindowToTop(object);
  1699. //Show the background drag panel
  1700. if ($(object).hasClass("topmost")){
  1701. $("#tfwdragpanel").show();
  1702. }else{
  1703. $('.floatWindow.topmost').css("pointer-events", "none");
  1704. $('.floatWindow.topmost').css("opacity", 0.7);
  1705. $("#fwdragpanel").show();
  1706. }
  1707. //Get the relative click offset of the down event
  1708. clickDownOffset = [event.pageX - $(object).offset().left, event.pageY - $(object).offset().top];
  1709. movingWindow = true;
  1710. $(object).find(".iframecover").show();
  1711. }
  1712. function fwmove(object, event) {
  1713. event = mapEventFromTouch(event);
  1714. if (movingWindow == true) {
  1715. //Check if the object is maximized. If yes, minimized it
  1716. if ($(object).attr("max") == "true") {
  1717. var originalSize = JSON.parse(decodeURIComponent($(object).attr("orgsize")));
  1718. $(object).attr("max", "false");
  1719. $(object).attr("orgsize", "");
  1720. //Calculate new left right offsets
  1721. var clickRatio = event.pageX / window.innerWidth;
  1722. var newLeft = event.pageX - (clickRatio * originalSize[0]);
  1723. originalSize
  1724. $(object).css({
  1725. width: originalSize[0],
  1726. height: originalSize[1],
  1727. left: newLeft,
  1728. top: event.Y - 2
  1729. });
  1730. clickDownOffset[0] = clickRatio * originalSize[0];
  1731. clickDownOffset[1] = 2;
  1732. //Restore the maximize icon
  1733. $(object).find(".maxToogleButton").attr('src', "img/system/max.png")
  1734. }
  1735. $(object).css("left", event.pageX - clickDownOffset[0]);
  1736. $(object).css("top", event.pageY - clickDownOffset[1]);
  1737. }
  1738. }
  1739. function fwup(object, event) {
  1740. event = mapEventFromTouch(event);
  1741. if (movingWindow) {
  1742. $("#fwdragpanel").hide();
  1743. $("#tfwdragpanel").hide();
  1744. $('.floatWindow.topmost').css("pointer-events", "auto");
  1745. $('.floatWindow.topmost').css("opacity", 1);
  1746. $(object).find(".iframecover").hide();
  1747. movingWindow = false;
  1748. //Check if the window location is drag to the edge of the screen. If yes, toggle half screen fullscreen
  1749. //Not need to check for if max because it must be minimized during drag move
  1750. var dockMode = false;
  1751. if (event.pageX < 10) {
  1752. //Dock to left
  1753. var originalSize = [$(object).width(), $(object).height(), $(object).offset().left, $(object).offset().top];
  1754. $(object).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1755. $(object).css({
  1756. width: "50%",
  1757. height: "calc(100% - 36px)",
  1758. left: "0px",
  1759. top: "0px"
  1760. });
  1761. $(object).attr("max", "true");
  1762. $(object).find(".maxToogleButton").attr('src', "img/system/restore.png");
  1763. } else if (event.pageX > window.innerWidth - 10) {
  1764. //Dock to right
  1765. var originalSize = [$(object).width(), $(object).height(), $(object).offset().left, $(object).offset().top];
  1766. $(object).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1767. $(object).css({
  1768. width: "50%",
  1769. height: "calc(100% - 36px)",
  1770. left: (window.innerWidth / 2) + "px",
  1771. top: "0px"
  1772. });
  1773. $(object).attr("max", "true");
  1774. $(object).find(".maxToogleButton").attr('src', "img/system/restore.png");
  1775. }
  1776. }
  1777. }
  1778. //Handle floatWindow min, max and close
  1779. function min(object, event) {
  1780. event.preventDefault();
  1781. event.stopImmediatePropagation();
  1782. if (event.type == "mousedown" && event.which != 1) {
  1783. //Ignore right mouse down
  1784. return;
  1785. }
  1786. var fw = $(object).parent().parent().parent();
  1787. $(fw).fadeOut(100);
  1788. }
  1789. function toggleMax(object, event) {
  1790. event.preventDefault();
  1791. event.stopImmediatePropagation();
  1792. event = mapEventFromTouch(event);
  1793. if (event.type == "mousedown" && event.which != 1) {
  1794. //Ignore right mouse down
  1795. return;
  1796. }
  1797. if ($(object).css('display') == 'none'){
  1798. //This windows do not allow resizing.
  1799. return;
  1800. }
  1801. var fw = $(object).parent().parent().parent();
  1802. var maxedAlready = $(fw).attr('max');
  1803. MoveFloatWindowToTop(fw);
  1804. //Add transition animation
  1805. $(fw).css({
  1806. "transition": "width 0.3s ease-out, height 0.3s ease-out, top 0.3s ease-out, left 0.3s ease-out"
  1807. });
  1808. //Remove transition animation after complete wth 50ms buffer
  1809. setTimeout(function(){
  1810. $(fw).css({
  1811. "transition": ""
  1812. });
  1813. }, 350);
  1814. if (maxedAlready == "true") {
  1815. //Resize to original
  1816. console.log($(fw));
  1817. var originalSize = JSON.parse(decodeURIComponent($(fw).attr("orgsize")));
  1818. $(fw).attr("max", "false");
  1819. $(fw).attr("orgsize", "");
  1820. $(fw).css({
  1821. width: originalSize[0],
  1822. height: originalSize[1],
  1823. left: originalSize[2],
  1824. top: originalSize[3]
  1825. });
  1826. $(fw).find(".maxToogleButton").attr('src', "img/system/max.png");
  1827. } else {
  1828. //Maxmize
  1829. var originalSize = [$(fw).width(), $(fw).height(), $(fw).offset().left, $(fw).offset().top];
  1830. $(fw).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1831. $(fw).css({
  1832. width: "100%",
  1833. height: "calc(100% - 36px)",
  1834. left: "0px",
  1835. top: "0px"
  1836. });
  1837. $(fw).attr("max", "true");
  1838. $(fw).find(".maxToogleButton").attr('src', "img/system/restore.png")
  1839. }
  1840. }
  1841. function closeFloatWindow(object, event) {
  1842. if (event.type == "mousedown" && event.which != 1) {
  1843. //Ignore right mouse down on close buttons
  1844. return;
  1845. }
  1846. event.preventDefault();
  1847. event.stopImmediatePropagation();
  1848. if ($(object).is("img")) {
  1849. object = $(object).panret();
  1850. }
  1851. var fw = $(object).parent().parent().parent();
  1852. var contentWindow = $(fw).find("iframe")[0].contentWindow;
  1853. try {
  1854. if (contentWindow.ao_module_close === undefined) {
  1855. //This module do not use ao_module wrapper. Close it directly.
  1856. closeFwProcess($(fw).attr("windowId"));
  1857. } else {
  1858. //Pass the closing events to the window itself
  1859. contentWindow.ao_module_close();
  1860. }
  1861. } catch (ex) {
  1862. //Problems of closing floatWindow. Force closing.
  1863. closeFwProcess($(fw).attr("windowId"));
  1864. }
  1865. //Find the btn object that contains the windowID
  1866. var closingWindowID = $(fw).attr("windowId");
  1867. $("#stackedWindowList").hide();
  1868. resizeAllFloatWindowButtons();
  1869. hideAllContextMenus();
  1870. }
  1871. function findFloatWindowButtonWithID(windowID) {
  1872. var targetButtonObject;
  1873. $(".floatWindowButton").each(function() {
  1874. var originalIDlist = JSON.parse(decodeURIComponent($(this).attr('windowIDGroup')));
  1875. originalIDlist = originalIDlist.map(String);
  1876. if (originalIDlist.includes(windowID)) {
  1877. targetButtonObject = $(this);
  1878. }
  1879. });
  1880. return targetButtonObject;
  1881. }
  1882. function closeFwProcess(windowID) {
  1883. //Close the floatwindow process
  1884. $(".floatWindow").each(function() {
  1885. if ($(this).attr("windowId") == windowID) {
  1886. $(this).remove();
  1887. }
  1888. });
  1889. //Remove the button from menu as well
  1890. var targetTab = findFloatWindowButtonWithID(windowID);
  1891. var originalIDlist = JSON.parse(decodeURIComponent($(targetTab).attr('windowIDGroup')));
  1892. originalIDlist = originalIDlist.map(String);
  1893. if (originalIDlist.length > 1) {
  1894. //There are more than 1 floatWindow in this tab.
  1895. var newIDList = [];
  1896. for (var i = 0; i < originalIDlist.length; i++) {
  1897. if (originalIDlist[i] != windowID) {
  1898. newIDList.push(originalIDlist[i]);
  1899. }
  1900. }
  1901. newIDListAttr = encodeURIComponent(JSON.stringify(newIDList));
  1902. //console.log("Newlist",newIDList);
  1903. $(targetTab).attr("windowIDGroup", newIDListAttr);
  1904. } else {
  1905. //This is the only floatWindow in this tab. Remove the tab itself.
  1906. $(targetTab).remove();
  1907. }
  1908. }
  1909. function PinFloatWindowToTopMostMode(object){
  1910. if ($(".floatwindow.topmost").length >= 100){
  1911. //Cannot add more topmost fw
  1912. console.log("Max number of top most floatWindow reached")
  1913. return
  1914. }
  1915. //Move the current fw to top, its z index is now 101
  1916. MoveFloatWindowToTop(object);
  1917. var windowID = $(object).attr("windowId");
  1918. console.log("[Desktop] Pinning window ID: " + windowID)
  1919. //Move this to fixed layer position
  1920. $(object).addClass("topmost");
  1921. $(object).css("z-index", 501);
  1922. }
  1923. function UnpinFloatWindowFromTopMostMode(object){
  1924. $(object).removeClass("topmost");
  1925. if (focusedWindow == object){
  1926. focusedWindow = undefined;
  1927. $(object).css("z-index", 1);
  1928. }
  1929. MoveFloatWindowToTop(object);
  1930. }
  1931. function MoveFloatWindowToTop(object) {
  1932. var windowID = $(object).attr("windowId");
  1933. var windowZindex = $(object).css("z-index");
  1934. //Shift down all floatWindows that has z-index higher than this window by 2
  1935. if (windowID == $(focusedWindow).attr("windowId")) {
  1936. //This window already at the top
  1937. return;
  1938. }
  1939. if ($(focusedWindow).hasClass("topmost")){
  1940. //The previous focused windows is topmost. Move it to layer 109
  1941. $(focusedWindow).css("z-index", 500);
  1942. $(".floatWindow.topmost").each(function(){
  1943. var thisWindowZIndex = $(this).css("z-index");
  1944. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1945. if ($(this).attr("windowId") != windowID) {
  1946. $(this).css("z-index", thisWindowZIndex - 1);
  1947. }
  1948. }
  1949. });
  1950. }else{
  1951. //The previous focused windows is normal windows. Move it to 100
  1952. $(focusedWindow).css("z-index", 100);
  1953. //Shift all the other windows down
  1954. $(".floatWindow").each(function() {
  1955. if ($(this).hasClass("topmost")){
  1956. return;
  1957. }
  1958. var thisWindowZIndex = $(this).css("z-index");
  1959. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1960. if ($(this).attr("windowId") != windowID) {
  1961. $(this).css("z-index", thisWindowZIndex - 1);
  1962. //console.log($(this).attr("windowId"), $(this).css("z-index"));
  1963. }
  1964. }
  1965. });
  1966. }
  1967. if ($(object).hasClass("topmost")){
  1968. //The new windows is a topmost window
  1969. $(object).css("z-index", 501);
  1970. }else{
  1971. $(object).css("z-index", 101);
  1972. }
  1973. focusedWindow = $(object);
  1974. //Check if this div is hidden. If yes, fade it in.
  1975. if ($(object).is(":hidden")) {
  1976. $(object).fadeIn(100);
  1977. }
  1978. //Focus on the top most floatWindow
  1979. var iframe = focusedWindow.find("iframe")[0];
  1980. iframe.contentWindow.focus();
  1981. }
  1982. function newFloatWindow(config, callback=undefined) {
  1983. //Check if the number of floatWindow already reaching its maxmium
  1984. if ($(".floatWindow").length > maxWindowCount){
  1985. console.log("Max number of floatWindow reached.");
  1986. return;
  1987. }
  1988. //Generate new floatwindow startup config from object
  1989. var url = defaultOrKey(config, "about:blank", "url");
  1990. var uuid = defaultOrKey(config, (new Date()).getTime(), "uid");
  1991. var width = defaultOrKey(config, 854, "width");
  1992. var height = defaultOrKey(config, 480, "height");
  1993. var moduleIcon = defaultOrKey(config, "img/system/favicon.png", "appicon");
  1994. var title = defaultOrKey(config, "New floatWindow", "title");
  1995. var left = defaultOrKey(config, 100, "left");
  1996. var top = defaultOrKey(config, 100, "top");
  1997. var parentWindowID = defaultOrKey(config, "", "parent");
  1998. var callbackFunctionName = defaultOrKey(config, "", "callback");
  1999. var bgcolor = defaultOrKey(config, "", "background-color");
  2000. //Encode function name
  2001. callbackFunctionName = encodeURIComponent(callbackFunctionName);
  2002. //Validate paramters
  2003. if (width > window.innerWidth) {
  2004. width = window.innerWidth;
  2005. }
  2006. if (height > window.innerHeight) {
  2007. height = window.innerHeight;
  2008. }
  2009. if (left + width > window.innerWidth) {
  2010. left = 0;
  2011. }
  2012. if (top + height > window.innerHeight) {
  2013. top = 0;
  2014. }
  2015. //Check if the location already cotain any window
  2016. while (floatWindowLocationDuplicated(left, top)) {
  2017. left += 30;
  2018. top += 30;
  2019. }
  2020. //Check if the opening require a overwrite on background color
  2021. var backgroundStyle = "";
  2022. if (bgcolor !== ""){
  2023. backgroundStyle = `background-color: ${bgcolor};`;
  2024. }
  2025. //Check if the theme color is applied. If yes, generate the floatWindow with overwritten theem color
  2026. var overWriteThemeColor = "";
  2027. if (desktopThemeColor != ""){
  2028. overWriteThemeColor = `background-color: ${hexToRgbA(desktopThemeColor, 0.85)}`;
  2029. }
  2030. //Append the floatWindow into the body
  2031. $("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}">
  2032. <div class="controls fwdragger themeColorSolid" style="${overWriteThemeColor}">
  2033. <img class="moduleicon" src="${moduleIcon}"></img>
  2034. <div class="title">${title}</div>
  2035. <div class="fwcontrol">
  2036. <div class="buttons mintoggle">
  2037. <img src="img/system/min.png"></img>
  2038. </div>
  2039. <div class="buttons maxtoggle">
  2040. <img class="maxToogleButton" src="img/system/max.png"></img>
  2041. </div>
  2042. <div class="buttons closetoggle close">
  2043. <img src="img/system/close.png"></img>
  2044. </div>
  2045. </div>
  2046. </div>
  2047. <div class="iframewrapper">
  2048. <iframe src="${url}" allowfullscreen="true"></iframe>
  2049. <div class="iframecover"></div>
  2050. </div>
  2051. </div>`);
  2052. var newWindowObject = getFloatWindowByID(uuid);
  2053. //console.log(newWindowObject);
  2054. MoveFloatWindowToTop(newWindowObject);
  2055. //Append window to taskbar
  2056. var groupInfo = url.split("/");
  2057. var group = "";
  2058. if (groupInfo.length == 1) {
  2059. group = groupInfo[0];
  2060. } else {
  2061. groupInfo.pop();
  2062. group = groupInfo.join("/");
  2063. }
  2064. //File system windows require special grouping based on their filename
  2065. if (url.includes("SystemAO/file_system/")){
  2066. group = url.split("/").pop().split(".").join("_");
  2067. }else if (url.includes("SystemAO/utilities/")){
  2068. group = url.split("/").pop().split(".").join("_");
  2069. if (group.includes("#")){
  2070. group = group.split("#")[0];
  2071. }
  2072. }
  2073. //Check if the group already exists.
  2074. var groupExists = false;
  2075. var targetGroupingTab;
  2076. $(".floatWindowButton").each(function() {
  2077. if ($(this).attr("group") == group) {
  2078. groupExists = true;
  2079. targetGroupingTab = $(this);
  2080. }
  2081. });
  2082. //Check if the group is System Explorer and held special treatment if yes
  2083. if (group.split("/").shift() == "SystemAO") {
  2084. if (url.includes("file_explorer.html") && groupExists) {
  2085. //File Manager. Group them
  2086. group = "file_explorer";
  2087. }else if (url.includes("utilities") && groupExists){
  2088. //Allow grouping
  2089. } else {
  2090. //Do not group anything from SystemAO other than file explorer
  2091. groupExists = false;
  2092. }
  2093. }
  2094. if (groupExists == false) {
  2095. //Append the item to taskbar
  2096. var windowIDGroup = encodeURIComponent(JSON.stringify([uuid]));
  2097. var floatWindowButtonObject = ` <div class="item clickable floatWindowButton onscreen" group="${group}" windowIDGroup="${windowIDGroup}">
  2098. <img class="floatWindowAppIcon" src="${moduleIcon}"></img>
  2099. <p class="floatWindowTitle">${title}</p>
  2100. </div>`;
  2101. $(".navimenu").append(floatWindowButtonObject);
  2102. } else {
  2103. //Group already exists. Add tab into that group.
  2104. var originalIDlist = JSON.parse(decodeURIComponent($(targetGroupingTab).attr('windowIDGroup')));
  2105. originalIDlist.push(uuid);
  2106. //Encode and put the group list back to the object
  2107. var newIDList = encodeURIComponent(JSON.stringify(originalIDlist));
  2108. $(targetGroupingTab).attr("windowIDGroup", newIDList);
  2109. }
  2110. hookFloatWindowEvents();
  2111. resizeAllFloatWindowButtons();
  2112. if (callback !== undefined){
  2113. callback(uuid);
  2114. }
  2115. }
  2116. function resizeAllFloatWindowButtons() {
  2117. var fwbTotalWidth = $(".floatWindowButton").length * 200;
  2118. if (fwbTotalWidth > window.innerWidth * 0.7) {
  2119. $(".floatWindowButton").addClass("hideText");
  2120. } else {
  2121. $(".floatWindowButton").removeClass("hideText");
  2122. }
  2123. }
  2124. function floatWindowLocationDuplicated(left, top) {
  2125. var duplicated = false;
  2126. $(".floatWindow").each(function() {
  2127. if ($(this).offset().left == left && $(this).offset().top == top) {
  2128. duplicated = true;
  2129. }
  2130. });
  2131. return duplicated;
  2132. }
  2133. function defaultOrKey(object, defaultvalue, key) {
  2134. if (object[key] !== undefined) {
  2135. return object[key];
  2136. }
  2137. return defaultvalue;
  2138. }
  2139. function getFloatWindowByID(id) {
  2140. var targetWindow = undefined;
  2141. $(".floatWindow").each(function() {
  2142. if ($(this).attr("windowId") == id) {
  2143. targetWindow = $(this);
  2144. }
  2145. });
  2146. return targetWindow;
  2147. }
  2148. function getFloatWindowIconByID(id) {
  2149. var targetIconURL = "img/system/favicon.png";
  2150. $(".floatWindow").each(function() {
  2151. if ($(this).attr("windowId") == id) {
  2152. //This window ID matched the target fw
  2153. targetIconURL = $(this).find(".moduleicon").attr('src');
  2154. }
  2155. });
  2156. return targetIconURL;
  2157. }
  2158. function getFloatWindowTitleByID(id) {
  2159. var title = "";
  2160. $(".floatWindow").each(function() {
  2161. if ($(this).attr("windowId") == id) {
  2162. //This window ID matched the target fw
  2163. title = $(this).find(".title").text();
  2164. }
  2165. });
  2166. return title;
  2167. }
  2168. function setFloatWindowResizePolicy(targetFWId, resizble = true) {
  2169. var targetfw = getFloatWindowByID(targetFWId);
  2170. if (resizble) {
  2171. $(targetfw).find(".maxtoggle").show();
  2172. $(targetfw).removeClass("fixedsize");
  2173. } else {
  2174. $(targetfw).find(".maxtoggle").hide();
  2175. $(targetfw).addClass("fixedsize");
  2176. }
  2177. }
  2178. function setFloatWindowSize(targetFWId, newWidth, newHeight) {
  2179. var targetfw = getFloatWindowByID(targetFWId);
  2180. $(targetfw).css({
  2181. height: newHeight,
  2182. width: newWidth
  2183. });
  2184. }
  2185. function setFloatWindowTitle(targetFWId, newTitle) {
  2186. var targetfw = getFloatWindowByID(targetFWId);
  2187. $(targetfw).find(".title").text(newTitle);
  2188. }
  2189. function openFileWithModule(moduleLaunchInfo, openFileList) {
  2190. var url = moduleLaunchInfo["StartDir"];
  2191. var size = [undefined, undefined];
  2192. var title = moduleLaunchInfo["Name"];
  2193. var icon = "img/system/favicon.png";
  2194. if (moduleLaunchInfo["IconPath"] != "") {
  2195. icon = moduleLaunchInfo["IconPath"];
  2196. }
  2197. //Use floatWindow if exists
  2198. if (moduleLaunchInfo["SupportFW"] == true && moduleLaunchInfo["LaunchFWDir"] != "") {
  2199. url = moduleLaunchInfo["LaunchFWDir"];
  2200. if (moduleLaunchInfo["InitFWSize"] !== null) {
  2201. size = moduleLaunchInfo["InitFWSize"]
  2202. }
  2203. }
  2204. //Use embedded mode if exists
  2205. if (moduleLaunchInfo["SupportEmb"] == true && moduleLaunchInfo["LaunchEmb"] != "") {
  2206. url = moduleLaunchInfo["LaunchEmb"];
  2207. if (moduleLaunchInfo["InitEmbSize"] !== null) {
  2208. size = moduleLaunchInfo["InitEmbSize"]
  2209. }
  2210. }
  2211. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  2212. //Add launch files info and launch floatWindow
  2213. parent.newFloatWindow({
  2214. url: url + "#" + openParamter,
  2215. width: size[0],
  2216. height: size[1],
  2217. appicon: icon,
  2218. title: title
  2219. });
  2220. }
  2221. //====================== DESKTOP THEME RELATED FUNCTIONS =====================
  2222. //Initiate desktop theme list and user current theme
  2223. function initDesktopTheme() {
  2224. //Update 1 April 2021: Check if the user customize the desktop with the given path
  2225. $.get("system/desktop/theme", function(data) {
  2226. //Return a list of theme stored on the system
  2227. desktopThemeList = data;
  2228. $.get("system/desktop/theme?get=true", function(data) {
  2229. //Get the user theme settings
  2230. changeDesktopTheme(data);
  2231. });
  2232. });
  2233. }
  2234. function setDesktopTheme(themeName) {
  2235. $.get("system/desktop/theme?set=" + themeName, function(data) {
  2236. //Get the user theme settings
  2237. changeDesktopTheme(themeName);
  2238. if (data.includes("Error")) {
  2239. console.log(data);
  2240. }
  2241. });
  2242. }
  2243. //Actiave background cross fade changing animation
  2244. function initBackgroundSwitchingAnimation() {
  2245. if (localStorage.getItem("ao/desktop/backgroundInterval") !== null && !isNaN(parseInt(localStorage.getItem("ao/desktop/backgroundInterval")))){
  2246. //Localstorage has interval setting that is not NaN
  2247. backgroundCrossfadeInterval = parseInt(localStorage.getItem("ao/desktop/backgroundInterval")) * 1000;
  2248. }
  2249. backgroundIntervalCounter = setInterval(function() {
  2250. $("body").css("background-image", "none").css({
  2251. 'background-color': '#000000'
  2252. });
  2253. $(".showBackground").removeClass("showBackground");
  2254. $($(".backgroundFrame")[nextSlideshowIndex]).addClass("showBackground");
  2255. nextSlideshowIndex++;
  2256. if (nextSlideshowIndex > currentBackgroundList.length - 1) {
  2257. nextSlideshowIndex = 0;
  2258. }
  2259. }, backgroundCrossfadeInterval);
  2260. }
  2261. //Function for changing the desktop theme
  2262. function changeDesktopTheme(targetThemeName) {
  2263. currentUserTheme = targetThemeName;
  2264. if (currentUserTheme.includes(":/") == false){
  2265. //This is default theme pack name
  2266. for (var i = 0; i < desktopThemeList.length; i++) {
  2267. var thisTheme = desktopThemeList[i];
  2268. if (thisTheme["Theme"] == targetThemeName) {
  2269. //Use this config as the target theme
  2270. currentBackgroundList = thisTheme["Bglist"];
  2271. break;
  2272. }
  2273. }
  2274. //Initiate the background image.
  2275. $("#bgwrapper").html("");
  2276. for (var i = 0; i < currentBackgroundList.length; i++) {
  2277. var id = "dbg" + i;
  2278. var thisImage = "img/desktop/bg/" + currentUserTheme + "/" + currentBackgroundList[i];
  2279. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2280. }
  2281. setTimeout(function() {
  2282. $("#dbg0").addClass("showBackground");
  2283. }, 300);
  2284. if (currentBackgroundList.length == 1) {
  2285. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2286. nextSlideshowIndex = 0;
  2287. }else if (currentBackgroundList.length == 0){
  2288. //Background no longer exists. Change to default
  2289. changeDesktopTheme("default");
  2290. } else {
  2291. nextSlideshowIndex = 1;
  2292. }
  2293. }else{
  2294. //This is user defined photo file
  2295. $.get("system/desktop/theme?load=" + targetThemeName, function(data){
  2296. if (data.error !== undefined){
  2297. //The folder is gone. Use default instead
  2298. console.log(data.error);
  2299. changeDesktopTheme("default");
  2300. }else{
  2301. //OK! Load it
  2302. currentBackgroundList = data;
  2303. $("#bgwrapper").html("");
  2304. for (var i = 0; i < currentBackgroundList.length; i++) {
  2305. var id = "dbg" + i;
  2306. var thisImage = "media/?file=" + currentBackgroundList[i];
  2307. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2308. }
  2309. setTimeout(function() {
  2310. $("#dbg0").addClass("showBackground");
  2311. }, 300);
  2312. if (currentBackgroundList.length == 1) {
  2313. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2314. nextSlideshowIndex = 0;
  2315. }else if (currentBackgroundList.length == 0){
  2316. //Background no longer exists. Change to default
  2317. changeDesktopTheme("default");
  2318. } else {
  2319. nextSlideshowIndex = 1;
  2320. }
  2321. }
  2322. });
  2323. }
  2324. }
  2325. $("#bgwrapper").on("click", function(evt) {
  2326. evt.preventDefault();
  2327. });
  2328. //================== DESKTOP FILE LOCATION FUNCTIONS ====================
  2329. function initDesktopFiles(optionObject = {}, callback = undefined) {
  2330. $.get("system/desktop/listDesktop", function(data) {
  2331. //Prase optionObject
  2332. var noflash = false;
  2333. if (typeof optionObject.noflash !== "undefined"){
  2334. noflash = optionObject.noflash;
  2335. }
  2336. if (noflash){
  2337. //Only clean out those object that not exists in the new filelist
  2338. var existsingFilepaths = [];
  2339. if (data != null){
  2340. for (var i =0; i < data.length; i++){
  2341. existsingFilepaths.push(data[i].Filepath);
  2342. }
  2343. }else{
  2344. //Nothing on desktop
  2345. }
  2346. //console.log(existsingFilepaths);
  2347. //If the launchIcon path is not in the latest list, remove it from desktop
  2348. $(".launchIcon").each(function(){
  2349. if (existsingFilepaths.includes($(this).attr("filepath")) == false){
  2350. $(this).remove();
  2351. }
  2352. });
  2353. }else{
  2354. //Cleanup all previous icons
  2355. $("#iconwrapper").children().each(function(){
  2356. if ($(this).hasClass("launchIcon") && $(this).attr("type") == "dummy"){
  2357. //Special kind of launchIcon. Skip this
  2358. return;
  2359. }
  2360. $(this).remove();
  2361. });
  2362. }
  2363. //Allocate new items location
  2364. var iheight = 106;
  2365. var iwidth = 70;
  2366. var padding = 16;
  2367. if (desktopIconSize == "small") {
  2368. iheight = 82;
  2369. iwidth = 50;
  2370. } else if (desktopIconSize == "medium") {
  2371. iheight = 106;
  2372. iwidth = 70;
  2373. } else if (desktopIconSize == "big") {
  2374. iheight = 124;
  2375. iwidth = 84;
  2376. }
  2377. iconSize = [iwidth, iheight];
  2378. var screenHeight = window.innerHeight;
  2379. var screenWidth = window.innerWidth;
  2380. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2381. var hc = Math.floor((screenWidth - padding) / iwidth);
  2382. var slots = []; //A 2D array for storing relative to absolute locations
  2383. for (var j = 0; j < hc; j++) {
  2384. var thisLocationList = [];
  2385. for (var i = 0; i < vc; i++) {
  2386. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2387. thisLocationList.push(thisLocation);
  2388. }
  2389. slots.push(thisLocationList);
  2390. }
  2391. //Store the root position (0,0) in rootPosition
  2392. let rootPosition = JSON.parse(JSON.stringify(slots[0][0]));
  2393. desktopGrids = JSON.parse(JSON.stringify(slots));
  2394. //Assign items to desktop
  2395. var unallocatedFiles = [];
  2396. let remainingSlots = JSON.parse(JSON.stringify(slots));
  2397. desktopFileList = [];
  2398. if (data === null){
  2399. //No files on desktop
  2400. return;
  2401. }
  2402. for (var i = 0; i < data.length; i++) {
  2403. var thisFile = data[i];
  2404. desktopFileList.push(JSON.parse(JSON.stringify(thisFile.Filename)));
  2405. //Get icon from the icon list
  2406. var location = [thisFile.IconX, thisFile.IconY];
  2407. if (location[0] == -1 && location[1] == -1) {
  2408. //This file is not located. Push it into unallocatedFileList
  2409. unallocatedFiles.push(thisFile);
  2410. } else if (location[0] >= slots.length || location[1] >= slots[0].length) {
  2411. //This file is outside of the screen area. Set to be be unallocatedFiles as well
  2412. unallocatedFiles.push(thisFile);
  2413. } else {
  2414. //This file is already located. Push it location into occupiedSlots
  2415. //var screenX = location[0] * iwidth + padding/2;
  2416. //var screenY = location[1] * iheight + padding/2;
  2417. var screenLocation = slots[location[0]][location[1]];
  2418. //Remove this object from remaining slots
  2419. remainingSlots[location[0]][location[1]] = undefined;
  2420. //console.log(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth);
  2421. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2422. }
  2423. }
  2424. //Foreach remaining files, assign a location for it.
  2425. var walk = [slots.length, slots[0].length];
  2426. var current = [0, 0];
  2427. for (var i = 0; i < unallocatedFiles.length; i++) {
  2428. var thisFile = unallocatedFiles[i];
  2429. try{
  2430. while (typeof(remainingSlots[current[0]][current[1]]) == "undefined") {
  2431. //This slot is not usabled. Next slot.
  2432. current[1] += 1;
  2433. if (current[1] >= walk[1]) {
  2434. current[1] = 0;
  2435. current[0] += 1;
  2436. }
  2437. if (typeof(remainingSlots[current[0]]) == "undefined"){
  2438. //Not enough space to fit the item. Move it to 0 0 instead
  2439. current = [-1,-1];
  2440. console.log(current);
  2441. break;
  2442. }
  2443. }
  2444. }catch{
  2445. //Something went wrong while assigning positions. Set at root location
  2446. current = [-1,-1];
  2447. }
  2448. //Append the icon to screen
  2449. if (current[0] == -1 && current[1] == -1){
  2450. //Screen overflow. Stack the file at (0,0)
  2451. screenLocation = [rootPosition[0], rootPosition[1]];
  2452. console.log(screenLocation);
  2453. }else{
  2454. screenLocation = remainingSlots[current[0]][current[1]];
  2455. remainingSlots[current[0]][current[1]] = undefined;
  2456. }
  2457. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2458. //Save the icon location to server
  2459. $.ajax({
  2460. url: "system/desktop/files",
  2461. method: "POST",
  2462. data: {"set": thisFile.Filename, "x": current[0], "y": current[1]},
  2463. success: function(data) {
  2464. if (data.error !== undefined) {
  2465. console.log(data.error);
  2466. }
  2467. }
  2468. });
  2469. }
  2470. //Update the desktop hash to prevent the auto refresh by hash
  2471. getDesktopHash(function(hash){
  2472. desktopFileHash = hash;
  2473. });
  2474. if (callback !== undefined) {
  2475. //console.log(callback);
  2476. callback();
  2477. }
  2478. });
  2479. }
  2480. //Handle desktop file multi selection and dragging
  2481. $("#bgwrapper").on("mousedown", function(evt) {
  2482. initMultiSelection(evt);
  2483. });
  2484. $("#bgwrapper").on("touchstart", function(evt) {
  2485. initMultiSelection(evt);
  2486. });
  2487. $("body").on("mouseup", function(evt) {
  2488. mainWindowMouseup(evt);
  2489. });
  2490. $("body").on("touchend", function(evt) {
  2491. mainWindowMouseup(evt);
  2492. });
  2493. $("#selectionPanel").on("mouseup", function(event) {
  2494. });
  2495. function mainWindowMouseup(event) {
  2496. if (event.pageX == multiSelectionStartPoint[0] && event.pageY == multiSelectionStartPoint[1]) {
  2497. //Pressdown and up at the same location
  2498. $(".launchIconWrapper.selected").removeClass("selected");
  2499. endMultiSelection(event);
  2500. } else {
  2501. //Press down and up at different location
  2502. endMultiSelection(event);
  2503. }
  2504. if (resizingWindow){
  2505. //Resizing floatWindow out of the window bound (aka someone don't know how to resize a window correctly)
  2506. resizingWindow = false;
  2507. resizingEdgeID = 0;
  2508. $("#fwdragpanel").hide();
  2509. $("#tfwdragpanel").hide();
  2510. $('.floatWindow.topmost').css("pointer-events", "auto");
  2511. $('.floatWindow.topmost').css("opacity", 1);
  2512. $(resizingWindowTarget).find(".iframecover").hide();
  2513. $(resizingWindowTarget).find(".iframewrapper").css('cursor', '');
  2514. }
  2515. }
  2516. function initMultiSelection(event) {
  2517. event.preventDefault();
  2518. multiSelecting = true;
  2519. hideAllContextMenus();
  2520. $("#selectionPanel").css({
  2521. left: event.pageX,
  2522. top: event.pageY,
  2523. width: 0,
  2524. height: 0
  2525. });
  2526. $("#selectionPanel").show();
  2527. multiSelectionStartPoint = [event.pageX, event.pageY];
  2528. }
  2529. function movingMultiSelectionArea(event) {
  2530. event.preventDefault();
  2531. var sx = multiSelectionStartPoint[0];
  2532. var sy = multiSelectionStartPoint[1];
  2533. var ex = event.pageX;
  2534. var ey = event.pageY;
  2535. var newleft = sx;
  2536. if (ex < sx) {
  2537. newleft = ex;
  2538. }
  2539. var newtop = sy;
  2540. if (ey < sy) {
  2541. newtop = ey;
  2542. }
  2543. var newWidth = Math.abs(sx - ex);
  2544. var newHeight = Math.abs(sy - ey);
  2545. $("#selectionPanel").css({
  2546. left: newleft,
  2547. top: newtop,
  2548. width: newWidth,
  2549. height: newHeight
  2550. });
  2551. //Select all the launch icon selected
  2552. selectAllLaunchIconInRange(newleft, newleft + newWidth, newtop, newtop + newHeight);
  2553. }
  2554. function endMultiSelection(event) {
  2555. event.preventDefault();
  2556. multiSelecting = false;
  2557. multiSelectionStartPoint = [-1, -1];
  2558. $("#selectionPanel").hide();
  2559. }
  2560. function selectAllLaunchIconInRange(minX, maxX, minY, maxY) {
  2561. //Select launch icons from its center point
  2562. var xOffset = iconSize[0] / 2;
  2563. var yOffset = iconSize[1] / 2;
  2564. $(".launchIconWrapper.selected").removeClass("selected");
  2565. $(".launchIcon").each(function() {
  2566. //Calculate center point for this icon
  2567. var thisX = $(this).offset().left + xOffset;
  2568. var thisY = $(this).offset().top + yOffset;
  2569. if (thisX > minX && thisX < maxX) {
  2570. if (thisY > minY && thisY < maxY) {
  2571. $(this).find(".launchIconWrapper").addClass("selected");
  2572. }
  2573. }
  2574. });
  2575. }
  2576. function redrawDesktopGrids() {
  2577. var iheight = 106;
  2578. var iwidth = 70;
  2579. var padding = 16;
  2580. if (desktopIconSize == "small") {
  2581. iheight = 82;
  2582. iwidth = 50;
  2583. } else if (desktopIconSize == "medium") {
  2584. iheight = 106;
  2585. iwidth = 70;
  2586. } else if (desktopIconSize == "big") {
  2587. iheight = 124;
  2588. iwidth = 84;
  2589. }
  2590. iconSize = [iwidth, iheight];
  2591. var screenHeight = window.innerHeight;
  2592. var screenWidth = window.innerWidth;
  2593. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2594. var hc = Math.floor((screenWidth - padding) / iwidth);
  2595. var slots = []; //A 2D array for storing relative to absolute locations
  2596. for (var j = 0; j < hc; j++) {
  2597. var thisLocationList = [];
  2598. for (var i = 0; i < vc; i++) {
  2599. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2600. thisLocationList.push(thisLocation);
  2601. }
  2602. slots.push(thisLocationList);
  2603. }
  2604. desktopGrids = JSON.parse(JSON.stringify(slots));
  2605. }
  2606. function appendIconAtLocation(filedata, screenX, screenY, iheight, iwidth, updateMode=false) {
  2607. //Get the icon from extension
  2608. var icon = ao_module_utils.getIconFromExt(filedata.Ext.substring(1, filedata.Ext.length));
  2609. var imagePath = "img/desktop/files_icon/" + desktopIconPack + "/" + icon + ".png";
  2610. //Handle special icon types here
  2611. var size = desktopIconSize;
  2612. var filename = JSON.parse(JSON.stringify(filedata.Filename));
  2613. var filepath = JSON.parse(JSON.stringify(filedata.Filepath));
  2614. var isDir = JSON.parse(JSON.stringify(filedata.IsDir));
  2615. var isEmptyDir = JSON.parse(JSON.stringify(filedata.IsEmptyDir));
  2616. var isShared = JSON.parse(JSON.stringify(filedata.IsShared));
  2617. var maxlength = 12;
  2618. var type = "file";
  2619. let shortenedName = filename;
  2620. screenX += iconOffsetXY[0];
  2621. screenY += iconOffsetXY[1];
  2622. if (isDir) {
  2623. //Folder objects
  2624. icon = "folder outline";
  2625. if (isEmptyDir){
  2626. imagePath = "img/desktop/system_icon/folder.png";
  2627. }else{
  2628. imagePath = "img/desktop/system_icon/folder-with-content.png";
  2629. }
  2630. type = "folder";
  2631. } else if (isDir == false && icon == "folder outline") {
  2632. icon = "file outline";
  2633. imagePath = "img/desktop/files_icon/" + desktopIconPack + "/file outline.png";
  2634. type = "file";
  2635. } else if (filedata.Ext == ".exe" || filedata.Ext == ".elf") {
  2636. //Executable objects
  2637. imagePath = "img/desktop/system_icon/script.png";
  2638. type = "executable";
  2639. } else if (filedata.Ext == ".shortcut") {
  2640. //Shortcut
  2641. var shortcutImage = filedata.ShortcutImage;
  2642. shortenedName = JSON.parse(JSON.stringify(filedata.ShortcutName));
  2643. imagePath = shortcutImage;
  2644. type = "shortcut";
  2645. }
  2646. //Check if filename is english only.
  2647. if (/^[a-zA-Z\d .-=+]+$/.test(filename)) {
  2648. maxlength = 20;
  2649. }else{
  2650. //Check if it is under small text mode
  2651. if (size == "small"){
  2652. maxlength = 10;
  2653. }
  2654. }
  2655. if (type != "shortcut" && filename.length > maxlength) {
  2656. shortenedName = filename.substring(0, maxlength) + "...";
  2657. }
  2658. var compressedFiledata = ao_module_utils.objectToAttr(filedata);
  2659. if (updateMode){
  2660. //Update the content that already exists for the same filepath object
  2661. var updateObject = undefined;
  2662. $(".launchIcon").each(function(){
  2663. if ($(this).attr("filedata") == compressedFiledata){
  2664. updateObject = $(this);
  2665. }
  2666. });
  2667. if (updateObject !== undefined){
  2668. //Check if content identical. If yes, skip rewrite
  2669. if (updateObject.attr("filedata") == compressedFiledata){
  2670. //Identical. Skipping
  2671. }else{
  2672. //Update its contents
  2673. updateObject.attr("type", type);
  2674. updateObject.attr("filename", filename);
  2675. updateObject.attr("filepath", filepath);
  2676. updateObject.attr("filedata", compressedFiledata);
  2677. updateObject.css("width", iwidth + "px");
  2678. updateObject.css("height", iheight + "px");
  2679. updateObject.css("left", screenX + "px");
  2680. updateObject.css("top", screenY + "px");
  2681. }
  2682. }else{
  2683. //No exists. Append to wrapper
  2684. appendDesktopIcon($("#iconwrapper"),{
  2685. type: type,
  2686. filename: filename,
  2687. filepath: filepath,
  2688. compressedFiledata: compressedFiledata,
  2689. iwidth: iwidth,
  2690. iheight: iheight,
  2691. screenX: screenX,
  2692. screenY: screenY,
  2693. size: size,
  2694. imagePath: imagePath,
  2695. shortenedName: shortenedName,
  2696. isShared: isShared,
  2697. });
  2698. }
  2699. }else{
  2700. //Append into the desktop
  2701. appendDesktopIcon($("#iconwrapper"),{
  2702. type: type,
  2703. filename: filename,
  2704. filepath: filepath,
  2705. compressedFiledata: compressedFiledata,
  2706. iwidth: iwidth,
  2707. iheight: iheight,
  2708. screenX: screenX,
  2709. screenY: screenY,
  2710. size: size,
  2711. imagePath: imagePath,
  2712. shortenedName: shortenedName,
  2713. isShared: isShared,
  2714. });
  2715. }
  2716. }
  2717. /*
  2718. Main function to append desktop icon to desktop
  2719. Usage: Pass in the target (as jquery object, usually $("#iconwrapper")) and properties with the following object
  2720. properties = {
  2721. type: "",
  2722. filename: "",
  2723. filepath: "",
  2724. compressedFiledata: "",
  2725. iwidth: "",
  2726. iheight: "",
  2727. screenX: "",
  2728. screenY: "",
  2729. size: "",
  2730. imagePath: "",
  2731. shortenedName: "",
  2732. }
  2733. Where the enmty string is the value that require filling in
  2734. */
  2735. function appendDesktopIcon(target, properties){
  2736. var htmlType = "div";
  2737. if (properties.type == "file" && isChrome){
  2738. htmlType = "a";
  2739. }
  2740. var thisIcon = $(`<${htmlType} href="javascript:void(0);" class="launchIcon"
  2741. type="${properties.type}"
  2742. draggable="true"
  2743. ondragover="allowDrop(event)"
  2744. ondrop="drop(event)"
  2745. ondragstart="drag(event)"
  2746. onmousedown="iconClicked(this,event);"
  2747. ondblclick="iconDoubleClicked(this,event);"
  2748. ontouchstart="iconClicked(this,event); doubleTouchHandler(this, event,openViaTouch);"
  2749. filename="${properties.filename}"
  2750. filepath="${properties.filepath}"
  2751. filedata="${properties.compressedFiledata}"
  2752. style="width:${properties.iwidth}px; height:${properties.iheight}px;left:${properties.screenX}px; top:${properties.screenY}px;">
  2753. <span class="launchIconWrapper">
  2754. <img class="launchIconImage ${properties.size}" src="${properties.imagePath}" draggable="false"></img>
  2755. <p class="launchIconText ${properties.size} ">${properties.shortenedName}</p>
  2756. </span>
  2757. </${htmlType}>`);
  2758. $(target).append(thisIcon);
  2759. //Updates 20 May 2021: Check if this file is shared. If yes, append the share icon
  2760. if (typeof(properties.isShared) != "undefined" && properties.isShared == true){
  2761. setFileShareIndicator(properties.filename);
  2762. }
  2763. if (properties.type == "file" && isChrome){
  2764. console.log(isChrome);
  2765. let thisFilepath = properties.filepath;
  2766. $(thisIcon)[0].addEventListener("dragstart",function(evt){
  2767. //var filecontent = toDataUrl("media/?file=" + thisFilepath);
  2768. //var fileBase64 = window.btoa(filecontent);
  2769. var targetMime = "plain/text";
  2770. $.ajax({
  2771. url: "media/getMime/?file=" + encodeURIComponent(properties.filepath),
  2772. success: function(data){
  2773. if (data.error !== undefined){
  2774. targetMime = "text/directory";
  2775. }else{
  2776. targetMime = data;
  2777. }
  2778. },
  2779. async: false
  2780. });
  2781. evt.dataTransfer.setData("DownloadURL",targetMime+":"+ properties.filename +":"+ location.protocol + "//" + location.hostname + ":" + location.port + "/media/?file=" + encodeURIComponent(properties.filepath));
  2782. //evt.dataTransfer.setData("DownloadURL","video/mp4"+":"+"test.mp4"+":"+"data:"+"video/mp4"+";base64,"+fileBase64);
  2783. },false);
  2784. }
  2785. }
  2786. /*
  2787. Share indicator settings
  2788. This append or remove share from a particular file
  2789. Only require filename as all files here are on desktop
  2790. */
  2791. function getFileObjectByFilename(filename){
  2792. var result = null;
  2793. $(".launchIcon").each(function(){
  2794. var thisFilename = $(this).attr("filename");
  2795. if (thisFilename == filename){
  2796. result = $(this);
  2797. }
  2798. });
  2799. return result;
  2800. }
  2801. function setFileShareIndicator(filename){
  2802. var targetFileObject = getFileObjectByFilename(filename);
  2803. if (targetFileObject == null){
  2804. return;
  2805. }
  2806. var sharedIcon = `<div class="fileShareIndicator ${desktopIconSize}">
  2807. <img src="img/desktop/system_icon/shared.png">
  2808. </div>`;
  2809. $(targetFileObject).find(".launchIconWrapper").append(sharedIcon);
  2810. }
  2811. function removeFileShareIndicator(filename){
  2812. var targetFileObject = getFileObjectByFilename(filename);
  2813. if (targetFileObject == null){
  2814. return;
  2815. }
  2816. var indicator = $(targetFileObject).find(".fileShareIndicator");
  2817. if (indicator.length > 0){
  2818. indicator.remove();
  2819. }
  2820. }
  2821. // ========================== LAUNCH ICON OPERATIONS ================
  2822. //This function start all the launchicon related events
  2823. function drag(ev) {
  2824. //If rename mode, disable drag drop
  2825. if (renameMode){
  2826. return false;
  2827. }
  2828. var target = ev.target;
  2829. if (!($(ev.target).is("div") || $(ev.target).is("a"))) {
  2830. target = $(target).parent();
  2831. }
  2832. //Parse the standard filename / filepath data
  2833. var filename = $(target).attr("filename");
  2834. var filepath = $(target).attr('filepath');
  2835. ev.dataTransfer.setData("filename", filename);
  2836. ev.dataTransfer.setData("filepath", filepath);
  2837. //Parse multifile selection filedata
  2838. var filelist = [];
  2839. if ($(".launchIconWrapper.selected").length > 0){
  2840. if (ctrlHold || $(".launchIconWrapper.selected").length > 1){
  2841. //Include all objects selected
  2842. $(".launchIconWrapper.selected").each(function(){
  2843. var fd = $(this).parent().attr("filedata");
  2844. fd = JSON.parse(decodeURIComponent(fd));
  2845. filelist.push({
  2846. filename: fd.Filename,
  2847. filepath: fd.Filepath,
  2848. hostUUID: hostInfo.DeviceUUID
  2849. });
  2850. });
  2851. }else{
  2852. //Only push the one selected
  2853. filelist.push({
  2854. filename: filename,
  2855. filepath: filepath,
  2856. hostUUID: hostInfo.DeviceUUID
  2857. });
  2858. }
  2859. }else{
  2860. //There is no selected item on desktop. Use the drag drop one
  2861. filelist.push({
  2862. filename: filename,
  2863. filepath: filepath
  2864. });
  2865. }
  2866. //console.log(filelist);
  2867. ev.dataTransfer.setData("filedata", JSON.stringify(filelist));
  2868. console.log(filelist);
  2869. //Set a flag on the drag events that these files are from Desktop GUI
  2870. ev.dataTransfer.setData("desktopflag", "true");
  2871. //Record the start drop relative position of the icon object
  2872. var dx = ev.pageX - $(target).offset().left;
  2873. var dy = ev.pageY - $(target).offset().top;
  2874. startDragRelatuve = [dx, dy];
  2875. ev.stopPropagation();
  2876. }
  2877. function drop(ev) {
  2878. ev.preventDefault();
  2879. ev.stopImmediatePropagation();
  2880. var target = $(ev.target);
  2881. if (!(target.is("div") || target.is("a"))) {
  2882. target = $(target).parent();
  2883. }
  2884. if (target.hasClass("launchIconWrapper")) {
  2885. target = target.parent();
  2886. }
  2887. var thisFilepath = $(target).attr("filepath");
  2888. if (thisFilepath == ev.dataTransfer.getData("filepath")) {
  2889. //Drag and drop on the same item. Ignore it
  2890. return;
  2891. }
  2892. var sourceFilename = ev.dataTransfer.getData("filename");
  2893. var sourceFilepath = ev.dataTransfer.getData("filepath");
  2894. //To handle multiple file transfer from file explorer
  2895. var sourceFilelist = ev.dataTransfer.getData("filedata");
  2896. console.log(target)
  2897. console.log(sourceFilename);
  2898. console.log(sourceFilepath);
  2899. if (sourceFilelist !== ""){
  2900. sourceFilelist = JSON.parse(sourceFilelist);
  2901. }
  2902. //Drop opererations
  2903. if (target.attr("id") == "bgwrapper") {
  2904. if (sourceFilename == "" && sourceFilepath == "" && ev.dataTransfer.files.length > 0){
  2905. //Drag drop from external source. Upload to desktop
  2906. //Assign the locations for the objects
  2907. var files = ev.dataTransfer.files;
  2908. var gridMaxX = desktopGrids.length;
  2909. var gridMaxY = desktopGrids[0].length;
  2910. var targetLocation = findClosestGrid((ev.clientX), (ev.clientY), false);
  2911. var targetGridLocation = targetLocation[1];
  2912. var locations = [];
  2913. for (var k =0; k < files.length; k++){
  2914. var thisLocation = JSON.parse(JSON.stringify(targetGridLocation));
  2915. //Add k to y axis of the list.
  2916. thisLocation[1] += k;
  2917. if (thisLocation[1] >= gridMaxY){
  2918. thisLocation[0]++;
  2919. thisLocation[1] = 0;
  2920. }
  2921. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2922. //Desktop full. Force put to 0 0
  2923. thisLocation[0] = 0;
  2924. thisLocation[1] = 0;
  2925. break;
  2926. }
  2927. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  2928. thisLocation[1] += 1;
  2929. if (thisLocation[1] >= gridMaxY){
  2930. //Over the screen. Shift to the row on the right
  2931. thisLocation[0]++;
  2932. thisLocation[1] = 0;
  2933. }
  2934. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2935. //Desktop full. Force put to 0 0
  2936. thisLocation[0] = 0;
  2937. thisLocation[1] = 0;
  2938. break;
  2939. }
  2940. }
  2941. locations.push(thisLocation)
  2942. }
  2943. console.log(locations, ev.dataTransfer.files);
  2944. //Register file locations
  2945. for (var j =0; j < locations.length; j++){
  2946. let thisFile = files[j];
  2947. let thisFilename = files[j].name;
  2948. let x = parseInt(locations[j][0]);
  2949. let y = parseInt(locations[j][1]);
  2950. let uploadIconUUID = generateUploadingIcon(thisFile.name, [x,y]);
  2951. uploadFile(thisFile,function(){
  2952. console.log("Uploader callback");
  2953. $.ajax({
  2954. url: "system/desktop/files",
  2955. method: "POST",
  2956. data: {"set": thisFilename, "x": x, "y": y},
  2957. success: function(data) {
  2958. //Refresh the desktop
  2959. refresh(undefined, false);
  2960. }
  2961. });
  2962. }, uploadIconUUID);
  2963. }
  2964. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  2965. //Drag drop multiple files from desktop or file explorer to desktop
  2966. var desktopFlag = ev.dataTransfer.getData("desktopflag");
  2967. if (desktopFlag == "" || desktopFlag === undefined || desktopFlag == null){
  2968. //This is a file drag drop from not desktop to desktop
  2969. var filelist = ev.dataTransfer.getData("filedata");
  2970. if (filelist != ""){
  2971. filelist = JSON.parse(filelist);
  2972. if (filelist.length == 0){
  2973. return
  2974. }
  2975. //Get the position for this drop events and arrange grid locations
  2976. var gridPosition = gridPositionAllocate(ev.clientX, ev.clientY, filelist.length);
  2977. console.log(gridPosition)
  2978. //Check if source is also from user:/
  2979. var srcVroot = filelist[0].filepath.split(":/").shift();
  2980. var mode = "copy"
  2981. var title = "Copying "
  2982. if (srcVroot == "user"){
  2983. //Move
  2984. mode = "move"
  2985. title = "Moving "
  2986. }
  2987. var filepathList = [];
  2988. filelist.forEach(file => {
  2989. filepathList.push(file.filepath)
  2990. });
  2991. //Start the file operation dialog
  2992. var oprConfig = {
  2993. opr: mode,
  2994. src: filepathList,
  2995. dest: "user:/Desktop/",
  2996. overwriteMode: "ask"
  2997. }
  2998. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2999. //Genreate window title
  3000. title = title + filepathList.length;
  3001. if (filepathList.length > 1){
  3002. title += " files";
  3003. }else{
  3004. title += " file";
  3005. }
  3006. newFloatWindow({
  3007. url: "SystemAO/file_system/file_operation.html#" + configHash,
  3008. width: 400,
  3009. height: 220,
  3010. appicon: "SystemAO/file_system/img/selector.png",
  3011. title: title
  3012. });
  3013. }
  3014. }else{
  3015. //This is a file drag event from desktop, but more than one files.
  3016. //Pin the final location for the drag drop object
  3017. var sourceObject = getObjectFromPath(sourceFilepath);
  3018. var dx = startDragRelatuve[0];
  3019. var dy = startDragRelatuve[1];
  3020. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  3021. var closestLocation = targetLocation[0];
  3022. var duplicateObject = getObjectFromLocation(closestLocation[0] + iconOffsetXY[0], closestLocation[1] + iconOffsetXY[1]);
  3023. if (duplicateObject !== undefined) {
  3024. //There are already object there. Do nothing
  3025. console.log("Drop location duplicated!")
  3026. return;
  3027. }
  3028. //Get other objects that is not the one drag dropped
  3029. var iconOffset = {};
  3030. for (var i =0; i < sourceFilelist.length; i++){
  3031. var thisFile = sourceFilelist[i];
  3032. if (thisFile.filepath != sourceFilepath){
  3033. //Calculate the x y offset of this icon to the drag drop one
  3034. var thisIconObject = getObjectFromPath(thisFile.filepath);
  3035. iconOffset[thisFile.filepath] = {
  3036. dx: $(sourceObject).offset().left - $(thisIconObject).offset().left,
  3037. dy: $(sourceObject).offset().top - $(thisIconObject).offset().top
  3038. }
  3039. //console.log(thisFile.filename, iconOffset[thisFile.filepath]);
  3040. }
  3041. }
  3042. //Move the drag drop object to the desiged location
  3043. $(sourceObject).css({
  3044. left: closestLocation[0] + iconOffsetXY[0],
  3045. top: closestLocation[1] + iconOffsetXY[1]
  3046. });
  3047. //Save the drag item location
  3048. $.ajax({
  3049. url: "system/desktop/files",
  3050. method: "POST",
  3051. data: {"set": sourceFilename, "x": targetLocation[1][0], "y": targetLocation[1][1]},
  3052. success: function(data) {
  3053. //console.log(data);
  3054. }
  3055. });
  3056. //Move all the relative files to the main object
  3057. var relocatePendingObjects = [];
  3058. for (const [filepath, offset] of Object.entries(iconOffset)) {
  3059. let thisIconObject = getObjectFromPath(filepath);
  3060. let caluclatedLocation = [$(sourceObject).offset().left - offset.dx, $(sourceObject).offset().top - offset.dy];
  3061. let finalIconLocation = findClosestGrid(caluclatedLocation[0], caluclatedLocation[1]);
  3062. //Move this icon to designed location
  3063. $(thisIconObject).css({
  3064. left: finalIconLocation[0][0] + iconOffsetXY[0],
  3065. top: finalIconLocation[0][1] + iconOffsetXY[1]
  3066. });
  3067. let thisIconFileData = JSON.parse(decodeURIComponent($(thisIconObject).attr("filedata")));
  3068. //Record this in database
  3069. $.ajax({
  3070. url: "system/desktop/files",
  3071. method: "POST",
  3072. data: {"set": thisIconFileData.Filename, "x": finalIconLocation[1][0], "y": finalIconLocation[1][1]},
  3073. success: function(data) {
  3074. //console.log(data);
  3075. }
  3076. });
  3077. }
  3078. //Get duplication objects
  3079. for (const [filepath, offset] of Object.entries(iconOffset)) {
  3080. let thisIconObject = getObjectFromPath(filepath);
  3081. //Check for duplication
  3082. var iconLocation = [$(thisIconObject).offset().left, $(thisIconObject).offset().top];
  3083. $(".launchIcon").each(function(){
  3084. if ($(this).offset().left == iconLocation[0] && $(this).offset().top == iconLocation[1]){
  3085. //This icon is at the target icon location
  3086. if ($(this).attr("filepath") != filepath){
  3087. relocatePendingObjects.push($(this));
  3088. }
  3089. }
  3090. });
  3091. }
  3092. //Relocate objects that is in the way of moving
  3093. for (var i = 0; i < relocatePendingObjects.length; i++){
  3094. var thisObject = relocatePendingObjects[i];
  3095. console.log(thisObject);
  3096. var thisX = $(thisObject).offset().left;
  3097. var thisY = $(thisObject).offset().top;
  3098. var nextEmptyGrid = findClostestEmptyGridLocation(thisX, thisY);
  3099. //Move this file to the next empty grid location
  3100. $(thisObject).css({
  3101. left: nextEmptyGrid[0][0] + iconOffsetXY[0],
  3102. top: nextEmptyGrid[0][1] + iconOffsetXY[1]
  3103. });
  3104. //Save move record to db
  3105. let thisIconFileData = JSON.parse(decodeURIComponent($(thisObject).attr("filedata")));
  3106. $.ajax({
  3107. url: "system/desktop/files",
  3108. method: "POST",
  3109. data: {"set": thisIconFileData.Filename, "x": nextEmptyGrid[1][0], "y": nextEmptyGrid[1][1]},
  3110. success: function(data) {
  3111. //console.log(data);
  3112. }
  3113. });
  3114. }
  3115. }
  3116. }else{
  3117. //Dropping a file onto other place on desktop
  3118. var sourceObject = getObjectFromPath(sourceFilepath);
  3119. var dx = startDragRelatuve[0];
  3120. var dy = startDragRelatuve[1];
  3121. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  3122. var closestLocation = targetLocation[0];
  3123. //Check if there are objects already at that location
  3124. var duplicateObject = getObjectFromLocation(closestLocation[0], closestLocation[1]);
  3125. if (duplicateObject !== undefined) {
  3126. //There are already object there. Do nothing
  3127. console.log("Drop location duplicated!")
  3128. return;
  3129. }
  3130. var closestGridIndex = targetLocation[1];
  3131. $(sourceObject).css({
  3132. left: closestLocation[0] + iconOffsetXY[0],
  3133. top: closestLocation[1] + iconOffsetXY[1]
  3134. });
  3135. $.ajax({
  3136. url: "system/desktop/files",
  3137. method: "POST",
  3138. data: {"set": sourceFilename, "x": closestGridIndex[0], "y": closestGridIndex[1]},
  3139. success: function(data) {
  3140. //console.log(data);
  3141. }
  3142. });
  3143. }
  3144. } else if (target.attr("type") == "folder") {
  3145. //Move this file or folder into the target folder
  3146. var moveSources = [sourceFilepath];
  3147. if ($(".launchIconWrapper.selected").length > 1){
  3148. //Multi move operations
  3149. moveSources = [];
  3150. $(".launchIconWrapper.selected").each(function(){
  3151. var thisFileData = $(this).parent().attr("filedata");
  3152. thisFileData = JSON.parse(decodeURIComponent(thisFileData));
  3153. moveSources.push(thisFileData.Filepath);
  3154. });
  3155. }
  3156. //Get the move target location
  3157. var targetFd = $(target).attr("filedata");
  3158. targetFd = JSON.parse(decodeURIComponent(targetFd));
  3159. //Move it
  3160. moveSourceFilesToTarget(moveSources, targetFd.Filepath)
  3161. } else if (target.attr("type") == "shortcut") {
  3162. //Opening with the shortcut
  3163. //Check shortcut type
  3164. let shortcutData = JSON.parse(decodeURIComponent($(target).attr("filedata")));
  3165. var shortcutType = shortcutData["ShortcutType"];
  3166. if (shortcutType == "module") {
  3167. //Open the source file with this module
  3168. let openFileList = [];
  3169. if ($(".launchiconwrapper.selected").length > 0 && !Array.isArray(sourceFilelist)) {
  3170. $(".launchiconwrapper.selected").each(function() {
  3171. let thisFileData = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3172. openFileList.push({
  3173. filename: thisFileData["Filename"],
  3174. filepath: thisFileData["Filepath"]
  3175. });
  3176. });
  3177. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  3178. //Open file that is transfered from file explorer.
  3179. openFileList = sourceFilelist;
  3180. console.log(openFileList);
  3181. } else {
  3182. //Only pass in the current selected file.
  3183. openFileList.push({
  3184. filename: sourceFilename,
  3185. filepath: sourceFilepath
  3186. });
  3187. }
  3188. var shortcutModule = getModuleFromShortcutInfo(shortcutData);
  3189. //console.log(openFileList);
  3190. if (shortcutModule === undefined){
  3191. //This shortcut module is not found on this server
  3192. return;
  3193. }
  3194. openFileWithModule(shortcutModule, openFileList);
  3195. } else if (shortcutType == "folder") {
  3196. //Move the source file into this folder
  3197. var moveSources = [sourceFilepath];
  3198. if ($(".launchIconWrapper.selected").length > 1){
  3199. //Multi move operations
  3200. moveSources = [];
  3201. $(".launchIconWrapper.selected").each(function(){
  3202. var thisFileData = $(this).parent().attr("filedata");
  3203. thisFileData = JSON.parse(decodeURIComponent(thisFileData));
  3204. moveSources.push(thisFileData.Filepath);
  3205. });
  3206. }
  3207. //Extract shortcut info from the target
  3208. var targetPath = shortcutData.ShortcutPath;
  3209. moveSourceFilesToTarget(moveSources, targetPath);
  3210. }
  3211. } else {
  3212. console.log("Unknown action type: ", target.attr("type"));
  3213. }
  3214. }
  3215. //Use move if it is folder on desktop, use copy if it is a shortcut
  3216. function moveSourceFilesToTarget(sourceList, target, opr="move"){
  3217. var oprConfig = {
  3218. opr: opr,
  3219. src: sourceList,
  3220. dest: target,
  3221. callbackWindowID: "desktop",
  3222. callbackFunction: `refresh(undefined, true)`
  3223. }
  3224. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  3225. var title = "Copying " + sourceList.length;
  3226. if (sourceList.length > 1){
  3227. title += " files";
  3228. }else{
  3229. title += " file";
  3230. }
  3231. //Create FloatWindow to handle the file operations
  3232. newFloatWindow({
  3233. url: "SystemAO/file_system/file_operation.html#" + configHash,
  3234. width: 400,
  3235. height: 220,
  3236. appicon: "SystemAO/file_system/img/selector.png",
  3237. title: title
  3238. });
  3239. //Delete the file location from db
  3240. sourceList.forEach(file => {
  3241. let filename = file.split("/").pop();
  3242. $.ajax({
  3243. url: "system/desktop/files",
  3244. data: {del: filename},
  3245. success: function(data){
  3246. if (data.error !== undefined){
  3247. console.log(data.error);
  3248. }
  3249. }
  3250. });
  3251. });
  3252. }
  3253. function requestCSRFToken(callback){
  3254. $.ajax({
  3255. url: "system/csrf/new",
  3256. success: function(token){
  3257. callback(token);
  3258. }
  3259. });
  3260. }
  3261. function getModuleFromShortcutInfo(shortcutInfo) {
  3262. var ShortcutPath = shortcutInfo["ShortcutPath"];
  3263. if (ShortcutPath.includes("/") == false) {
  3264. //Legacy defination. Append /index.html at the back.
  3265. ShortcutPath = ShortcutPath + "/index.html";
  3266. }
  3267. //Try to match it with the module installed
  3268. for (var i = 0; i < moduleInstalled.length; i++) {
  3269. if (moduleInstalled[i]["StartDir"] == ShortcutPath || moduleInstalled[i]["Name"] == shortcutInfo["ShortcutName"]) {
  3270. //This is the correct module to be loaded
  3271. return moduleInstalled[i];
  3272. }
  3273. }
  3274. }
  3275. //Allocate the given number of grids from desktop
  3276. function gridPositionAllocate(posx, posy, numberOfGridNeeded=1){
  3277. var gridMaxX = desktopGrids.length;
  3278. var gridMaxY = desktopGrids[0].length;
  3279. var targetLocation = findClosestGrid(posx, posy, false);
  3280. var targetGridLocation = targetLocation[1];
  3281. var previousEmptyGridPosition = targetGridLocation;
  3282. var locations = [];
  3283. for (var k =0; k < numberOfGridNeeded; k++){
  3284. var thisLocation = JSON.parse(JSON.stringify(previousEmptyGridPosition));
  3285. //Add k to y axis of the list.
  3286. thisLocation[1] += k;
  3287. if (thisLocation[1] >= gridMaxY){
  3288. thisLocation[0]++;
  3289. thisLocation[1] = 0;
  3290. }
  3291. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3292. //Desktop full. Force put to 0 0
  3293. thisLocation[0] = 0;
  3294. thisLocation[1] = 0;
  3295. break;
  3296. }
  3297. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  3298. thisLocation[1] += 1;
  3299. if (thisLocation[1] >= gridMaxY){
  3300. //Over the screen. Shift to the row on the right
  3301. thisLocation[0]++;
  3302. thisLocation[1] = 0;
  3303. }
  3304. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3305. //Desktop full. Force put to 0 0
  3306. thisLocation[0] = 0;
  3307. thisLocation[1] = 0;
  3308. break;
  3309. }
  3310. }
  3311. previousEmptyGridPosition = JSON.parse(JSON.stringify(thisLocation))
  3312. locations.push(thisLocation)
  3313. }
  3314. return locations
  3315. }
  3316. function setIconDesktopLocation(sourceFilename, gridIndexX, gridIndexY, callback = undefined) {
  3317. $.ajax({
  3318. url: "system/desktop/files",
  3319. method: "POST",
  3320. data: {"set": sourceFilename, "x": gridIndexX, "y": gridIndexY},
  3321. success: function(data) {
  3322. if (data.error !== undefined) {
  3323. console.log(data.error);
  3324. } else {
  3325. if (callback !== undefined) {
  3326. callback();
  3327. }
  3328. }
  3329. }
  3330. });
  3331. }
  3332. //THIS FUNCTION IS NEEDED. DO NOT DELETE ALLOWDROP FUNCTION
  3333. function allowDrop(ev) {
  3334. ev.preventDefault();
  3335. }
  3336. //Pass in the object fullpath and return the icon object onscreen
  3337. function getObjectFromPath(path) {
  3338. var object;
  3339. $(".launchIcon").each(function() {
  3340. if ($(this).attr("filepath") == path) {
  3341. object = $(this);
  3342. }
  3343. });
  3344. return object;
  3345. }
  3346. //Pass in the coordinate and check if there is another object at the same location
  3347. function getObjectFromLocation(x, y) {
  3348. var object;
  3349. $(".launchIcon").each(function() {
  3350. if ($(this).position().left == x && $(this).position().top == y) {
  3351. object = $(this);
  3352. }
  3353. });
  3354. return object;
  3355. }
  3356. //Similar function to getObjectFromLocation but using grid coordinate instead of pixel coordinate
  3357. function getObjectFromGridLocation(gx, gy){
  3358. var pos = JSON.parse(JSON.stringify(desktopGrids[gx][gy]));
  3359. pos[0] = pos[0] + iconOffsetXY[0];
  3360. pos[1] = pos[1] + iconOffsetXY[1];
  3361. return getObjectFromLocation(pos[0],pos[1]);
  3362. }
  3363. //Find the clostest empty grid, prioirty given to y first then x
  3364. function findClostestEmptyGridLocation(x, y){
  3365. //Reduce icon offset to the x y on screen coordinate
  3366. x = x - iconOffsetXY[0];
  3367. y = y - iconOffsetXY[1];
  3368. //Get the grid index from absolute coordinate
  3369. var currentGridLocation = getGridIndexFromLocation(x,y);
  3370. console.log(currentGridLocation);
  3371. //Search for the next empty location
  3372. var targetLocation = [[-1,-1],[-1,-1]];
  3373. for (var i = currentGridLocation[0]; i < desktopGrids.length; i++){
  3374. var yStart = 0;
  3375. if (i == currentGridLocation[0]){
  3376. yStart = currentGridLocation[1];
  3377. }
  3378. for (k = yStart; k < desktopGrids[i].length; k++){
  3379. var thisLocation = JSON.parse(JSON.stringify(desktopGrids[i][k]));
  3380. var offsetedLocation = [thisLocation[0], thisLocation[1]];
  3381. var possibleDuplication = getObjectFromGridLocation(i,k);
  3382. //console.log( [i,k], offsetedLocation, possibleDuplication)
  3383. if (possibleDuplication === undefined){
  3384. //This is an empty slot
  3385. targetLocation = [offsetedLocation, [i,k]];
  3386. return targetLocation;
  3387. }
  3388. }
  3389. }
  3390. return targetLocation;
  3391. }
  3392. //Convert location to grid index
  3393. function getGridIndexFromLocation(x,y){
  3394. var gridIndex = [-1,-1];
  3395. for (var i = 0; i < desktopGrids.length; i++){
  3396. var thisXAxis = desktopGrids[i];
  3397. if (thisXAxis[0][0] == x){
  3398. //This x matches. Match y
  3399. gridIndex[0] = i;
  3400. for (var k = 0; k < thisXAxis.length; k++){
  3401. var thisYAxis = thisXAxis[k];
  3402. if (thisYAxis[1] == y){
  3403. gridIndex[1] = k;
  3404. return gridIndex;
  3405. }
  3406. }
  3407. }
  3408. }
  3409. return gridIndex;
  3410. }
  3411. //Convert grid index to location
  3412. function getLocationFromGridIndex(x, y){
  3413. var location = [-1,-1];
  3414. //Calculate the usable grid on screen
  3415. var iheight = 106;
  3416. var iwidth = 70;
  3417. var padding = 16;
  3418. if (desktopIconSize == "small") {
  3419. iheight = 82;
  3420. iwidth = 50;
  3421. } else if (desktopIconSize == "medium") {
  3422. iheight = 106;
  3423. iwidth = 70;
  3424. } else if (desktopIconSize == "big") {
  3425. iheight = 124;
  3426. iwidth = 84;
  3427. }
  3428. var screenHeight = window.innerHeight;
  3429. var screenWidth = window.innerWidth;
  3430. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  3431. var hc = Math.floor((screenWidth - padding) / iwidth);
  3432. //Calculate the position of this icon on the grid
  3433. var resultX = padding + iwidth * x + iconOffsetXY[0];
  3434. var resultY = padding + iheight * y + iconOffsetXY[1];
  3435. return [resultX, resultY];
  3436. }
  3437. //Set allow overshoot to allow drop point to get closest grid with x / y > cursor posx /y
  3438. function findClosestGrid(x, y, allowOvershoot = true) {
  3439. var minDx = window.innerWidth;
  3440. var minDy = window.innerHeight;
  3441. var finalLocation = [-1, -1];
  3442. var gridLocation = [-1, -1];
  3443. for (var i = 0; i < desktopGrids.length; i++) {
  3444. for (var j = 0; j < desktopGrids[0].length; j++) {
  3445. var thisGridLocation = desktopGrids[i][j];
  3446. var dx = x - thisGridLocation[0];
  3447. var dy = y - thisGridLocation[1];
  3448. if (allowOvershoot) {
  3449. if (Math.abs(dx) < minDx) {
  3450. minDx = Math.abs(x - thisGridLocation[0]);
  3451. finalLocation[0] = thisGridLocation[0];
  3452. gridLocation[0] = i;
  3453. }
  3454. if (Math.abs(dy) < minDy) {
  3455. minDy = Math.abs(y - thisGridLocation[1]);
  3456. finalLocation[1] = thisGridLocation[1];
  3457. gridLocation[1] = j;
  3458. }
  3459. } else {
  3460. if (dx < minDx && dx > 0) {
  3461. minDx = Math.abs(x - thisGridLocation[0]);
  3462. finalLocation[0] = thisGridLocation[0];
  3463. gridLocation[0] = i;
  3464. }
  3465. if (dy < minDy && dy > 0) {
  3466. minDy = Math.abs(y - thisGridLocation[1]);
  3467. finalLocation[1] = thisGridLocation[1];
  3468. gridLocation[1] = j;
  3469. }
  3470. }
  3471. }
  3472. }
  3473. return [finalLocation, gridLocation];
  3474. }
  3475. //Ask for confirmation before window close
  3476. //Update 16 Feb 2021: Disabled confirmation and use a new method of implementing this later
  3477. /*
  3478. function myConfirmation() {
  3479. if (!loggingOut){
  3480. return 'Your data might not been saved. Are you sure you want to quit?';
  3481. }
  3482. }
  3483. window.onbeforeunload = myConfirmation;
  3484. */
  3485. function iconClicked(object, evt) {
  3486. if (renameMode){
  3487. //Exit rename mode if icon is clicked during renaming
  3488. if ($(object).find(".renameInput").length == 0){
  3489. exitRenameMode();
  3490. }
  3491. }
  3492. //Clicked on a launch icon.
  3493. var alreadyHighlighted = $(object).find(".launchIconWrapper").hasClass("selected");
  3494. if (alreadyHighlighted){
  3495. //Already selected
  3496. if (ctrlHold) {
  3497. //Selection
  3498. $(object).find(".launchIconWrapper").removeClass("selected");
  3499. }
  3500. }else{
  3501. //Not selected yet
  3502. if (ctrlHold) {
  3503. //Add this into selection
  3504. $(object).find(".launchIconWrapper").addClass("selected");
  3505. }else{
  3506. //Remove all others and select this
  3507. $(".launchIconWrapper.selected").removeClass("selected");
  3508. $(object).find(".launchIconWrapper").addClass("selected");
  3509. }
  3510. }
  3511. }
  3512. function iconDoubleClicked(object, evt=undefined) {
  3513. //Don't allow opening when renaming
  3514. if (renameMode){
  3515. return;
  3516. }
  3517. //Double click on a launch icon, tries to open it
  3518. var filedata = ao_module_utils.attrToObject($(object).attr("filedata"));
  3519. //console.log(filedata);
  3520. if (filedata.IsDir) {
  3521. //This is a directory. Open with file explorer
  3522. newFloatWindow({
  3523. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(filedata.Filepath),
  3524. appicon: "SystemAO/file_system/img/small_icon.png",
  3525. width: 1080,
  3526. height: 580,
  3527. title: "File Manager"
  3528. });
  3529. } else if (filedata.IsShortcut) {
  3530. //This is a shortcut. Open the target endpoint
  3531. var stype = filedata["ShortcutType"];
  3532. if (stype == "module") {
  3533. //Open the target module
  3534. openModule(filedata.ShortcutPath);
  3535. } else if (stype == "folder") {
  3536. //Open the target folder
  3537. openFolder(filedata.ShortcutPath)
  3538. }else if (stype == "url"){
  3539. //Open the target webpage in a new tab
  3540. window.open(filedata.ShortcutPath);
  3541. }else{
  3542. console.log(filedata);
  3543. }
  3544. } else {
  3545. //This is a file. Open it with default opener
  3546. $.ajax({
  3547. url: "system/modules/getDefault",
  3548. method: "GET",
  3549. data: {
  3550. opr: "launch",
  3551. ext: filedata.Ext,
  3552. mode: "launch"
  3553. },
  3554. success: function(data) {
  3555. if (data.error !== undefined) {
  3556. //No default opener assigned
  3557. var url = "SystemAO/file_system/defaultOpener.html";
  3558. var icon = "SystemAO/file_system/img/opener.png";
  3559. var title = "Select an opener WebApp: "
  3560. var openFileList = [];
  3561. var openFileObject = {
  3562. filepath: filedata.Filepath,
  3563. filename: filedata.Filename
  3564. }
  3565. openFileList.push(openFileObject);
  3566. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  3567. newFloatWindow({
  3568. url: url + "#" + openParamter,
  3569. width: 320,
  3570. height: 510,
  3571. appicon: icon,
  3572. title: title
  3573. });
  3574. } else {
  3575. //Assigned. Launch with given paramter
  3576. var url = data["StartDir"];
  3577. var size = [undefined, undefined];
  3578. var title = data["Name"];
  3579. var icon = "img/system/favicon.png";
  3580. if (data["IconPath"] != "") {
  3581. icon = data["IconPath"];
  3582. }
  3583. //Use floatWindow if exists
  3584. if (data["SupportFW"] == true && data["LaunchFWDir"] != "") {
  3585. url = data["LaunchFWDir"];
  3586. if (data["InitFWSize"] !== null) {
  3587. size = data["InitFWSize"]
  3588. }
  3589. }
  3590. //Use embedded mode if exists
  3591. if (data["SupportEmb"] == true && data["LaunchEmb"] != "") {
  3592. url = data["LaunchEmb"];
  3593. if (data["InitEmbSize"] !== null) {
  3594. size = data["InitEmbSize"]
  3595. }
  3596. }
  3597. //Build open File Hash Data Format
  3598. var openFileList = [];
  3599. var openFileObject = {
  3600. filepath: filedata.Filepath,
  3601. filename: filedata.Filename
  3602. }
  3603. openFileList.push(openFileObject);
  3604. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  3605. //Add launch files info and launch floatWindow
  3606. newFloatWindow({
  3607. url: url + "#" + openParamter,
  3608. width: size[0],
  3609. height: size[1],
  3610. appicon: icon,
  3611. title: title
  3612. });
  3613. }
  3614. }
  3615. })
  3616. }
  3617. }
  3618. $(window).on("resize", function(event) {
  3619. redrawDesktopGrids();
  3620. resizeAllFloatWindowButtons();
  3621. })
  3622. // ======================= DOCUMENT KEY BINDING =====================
  3623. document.addEventListener('keydown', function(event) {
  3624. let keycode = event.which || event.keyCode;
  3625. if (keycode == "17") {
  3626. //Pressdown of Ctrl key
  3627. ctrlHold = true;
  3628. } else if (keycode == "16") {
  3629. //Pressdown of Shift key
  3630. shiftHold = true;
  3631. }else if (keycode == "27"){
  3632. //Cancel all floatwindow events and key events
  3633. $("#fwdragpanel").hide();
  3634. $("#tfwdragpanel").hide();
  3635. $(".floatWindow").find(".iframecover").hide();
  3636. movingWindow = false;
  3637. resizingWindow = false;
  3638. resizingEdgeID = 0;
  3639. multiSelecting = false;
  3640. ctrlHold = false;
  3641. shiftHold = false;
  3642. }else if (keycode == "46"){
  3643. //Delete key
  3644. if (renameMode){
  3645. //Deleting content in textarea. Ignore delte action
  3646. return true
  3647. }
  3648. var deleteFilelist = [];
  3649. var deleteFilenameList = [];
  3650. $(".launchIconWrapper.selected").each(function(){
  3651. var fileObject = $(this).parent();
  3652. var fd = JSON.parse(decodeURIComponent((fileObject).attr("filedata")));
  3653. deleteFilelist.push(fd.Filepath);
  3654. deleteFilenameList.push(fd.Filename)
  3655. });
  3656. //Prase the filelist and pass to trash module
  3657. console.log(deleteFilelist);
  3658. generateCSRFToken(function(csrftoken){
  3659. $.ajax({
  3660. url: "system/file_system/fileOpr",
  3661. method:"POST",
  3662. data: {opr: "recycle", src: JSON.stringify(deleteFilelist), csrft: csrftoken},
  3663. success: function(data){
  3664. if (data.error !== undefined){
  3665. alert(data.error);
  3666. }else{
  3667. refresh(undefined, true);
  3668. }
  3669. }
  3670. });
  3671. });
  3672. //Delete the file's desktop location
  3673. deleteFilenameList.forEach(file => {
  3674. $.ajax({
  3675. url: "system/desktop/files",
  3676. data: {del: file},
  3677. success: function(data){
  3678. if (data.error !== undefined){
  3679. console.log(data.error);
  3680. }
  3681. }
  3682. });
  3683. })
  3684. }else if (keycode == "112"){
  3685. //Enter key
  3686. if (!renameMode){
  3687. //Open selected object by emulating double click
  3688. $(".launchIconWrapper.selected").each(function(){
  3689. var object = $(this).parent();
  3690. iconDoubleClicked(object);
  3691. });
  3692. }else if (renameMode){
  3693. event.preventDefault();
  3694. exitRenameMode();
  3695. }
  3696. }else{
  3697. //console.log(event.which);
  3698. }
  3699. });
  3700. $(document).keyup(function(event) {
  3701. let keycode = event.which || event.keyCode;
  3702. if (keycode == "17") {
  3703. ctrlHold = false;
  3704. } else if (keycode == "16") {
  3705. shiftHold = false;
  3706. }else if (keycode == "27"){
  3707. //ESC key, stop all floatWindow operations
  3708. console.log("%c[Desktop] Dragging function killed. Restarting all dragging elements.", 'color: #e64747');
  3709. movingWindow = false;
  3710. resizingWindow = false;
  3711. event.preventDefault();
  3712. }
  3713. });
  3714. $("#bgwrapper").on("mouseup", function(event) {
  3715. //Deselect all selected icons
  3716. event.preventDefault();
  3717. event.stopImmediatePropagation();
  3718. mainWindowMouseup(event);
  3719. });
  3720. function openFolder(virtualPath){
  3721. newFloatWindow({
  3722. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(virtualPath),
  3723. appicon: "SystemAO/file_system/img/small_icon.png",
  3724. width:1080,
  3725. height:580,
  3726. title: "File Manager"
  3727. });
  3728. }
  3729. function logout() {
  3730. loggingOut = true;
  3731. if (confirm("Exiting Session. Confirm?")){
  3732. $.get("system/auth/logout", function() {
  3733. window.location.href = "./";
  3734. });
  3735. }
  3736. hideAllContextMenus();
  3737. }
  3738. // ======================= CONTEXT MENU =============================
  3739. window.addEventListener("contextmenu",
  3740. function(e) {
  3741. e.preventDefault();
  3742. e.stopPropagation();
  3743. var clickTarget = $(e.target);
  3744. hideAllContextMenus();
  3745. showMenu = false;
  3746. $("#contextmenu").html("");
  3747. if (clickTarget.hasClass("launchIcon") || clickTarget.hasClass("launchIconImage") || clickTarget.hasClass("launchIconText")) {
  3748. //Click on an object on destkop
  3749. if (clickTarget.hasClass("launchIcon") == false) {
  3750. clickTarget = $(clickTarget).parent().parent();
  3751. }
  3752. if (!ctrlHold && !$(clickTarget).find(".launchIconWrapper").hasClass("selected")){
  3753. $(".launchIconWrapper.selected").removeClass("selected");
  3754. }
  3755. //Select this object
  3756. $(clickTarget).find(".launchIconWrapper").addClass("selected");
  3757. var objectType = $(clickTarget).attr("type");
  3758. operationTargetLaunchIcon = $(clickTarget);
  3759. //Check if selected more than one object
  3760. if ($(".launchIconWrapper.selected").length > 1){
  3761. //When the user selected more than one item on desktop
  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"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3765. addContextMenuSeperator($("#contextmenu"));
  3766. addContextMenuItem($("#contextmenu"), lcontex('Download in Zip'), "<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('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  3769. addContextMenuSeperator($("#contextmenu"));
  3770. addContextMenuItem($("#contextmenu"), lcontex('Properties'), undefined, "openObjectProperty", false);
  3771. }else{
  3772. //When the user only selected one item
  3773. if (objectType == "file") {
  3774. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  3775. addContextMenuItem($("#contextmenu"), lcontex('Open With'), "<i class='caret right icon'></i>", "handleOpenWith", true);
  3776. addContextMenuItem($("#contextmenu"), lcontex('Share'), "<i class='caret right icon'></i>", "handleFileShare", true);
  3777. addContextMenuSeperator($("#contextmenu"));
  3778. addContextMenuItem($("#contextmenu"), lcontex('Download'), "<i class='download icon'></i>", "downloadFile", false);
  3779. addContextMenuItem($("#contextmenu"), lcontex('Make a Copy'), "<i class='copy icon'></i>", "handleCloning", false);
  3780. addContextMenuItem($("#contextmenu"), lcontex('Rename'), undefined, "handleRename", false);
  3781. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  3782. addContextMenuSeperator($("#contextmenu"));
  3783. addContextMenuItem($("#contextmenu"), lcontex('Properties'), undefined, "openObjectProperty", false);
  3784. } else if (objectType == "folder") {
  3785. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  3786. addContextMenuItem($("#contextmenu"), lcontex('Zip here'), "<i class='zip icon'></i>", "handleZipFolder", false);
  3787. addContextMenuItem($("#contextmenu"), lcontex('Share'), "<i class='caret right icon'></i>", "handleFileShare", true);
  3788. addContextMenuSeperator($("#contextmenu"));
  3789. addContextMenuItem($("#contextmenu"), lcontex('Download as Zip'), "<i class='download icon'></i>", "downloadFile", false);
  3790. addContextMenuItem($("#contextmenu"), lcontex('Make a Copy'), "<i class='caret right icon'></i>", "handleCloning", false);
  3791. addContextMenuItem($("#contextmenu"), lcontex('Rename'), undefined, "handleRename", false);
  3792. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  3793. addContextMenuSeperator($("#contextmenu"));
  3794. addContextMenuItem($("#contextmenu"), lcontex('Properties'), undefined, "openObjectProperty", false);
  3795. } else if (objectType == "shortcut") {
  3796. var fd = JSON.parse(decodeURIComponent($(clickTarget).attr("filedata")));
  3797. console.log(fd);
  3798. if (fd.ShortcutType == "module"){
  3799. //Public WebApp
  3800. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  3801. addContextMenuItem($("#contextmenu"), lcontex('Open in New Tab'), "<i class='external icon'></i>", "openWebAppInNewTab", false);
  3802. addContextMenuItem($("#contextmenu"), lcontex('Rename'), undefined, "handleRename", false);
  3803. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  3804. }else if (fd.ShortcutType == "folder"){
  3805. //Folder
  3806. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  3807. addContextMenuItem($("#contextmenu"), lcontex('Open File Location'), "<i class='folder open icon'></i>", "handleShortcutFolderOpen", false);
  3808. addContextMenuItem($("#contextmenu"), lcontex('Rename'), undefined, "handleRename", false);
  3809. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  3810. addContextMenuSeperator($("#contextmenu"));
  3811. addContextMenuItem($("#contextmenu"), lcontex('Properties'), undefined, "openObjectProperty", false);
  3812. }else{
  3813. addContextMenuItem($("#contextmenu"), lcontex('Open'), undefined, "openIconViaMenu", false);
  3814. addContextMenuItem($("#contextmenu"), lcontex('Delete'), "<i class='trash icon'></i>", "handleFileDelete", false);
  3815. }
  3816. }else{
  3817. console.log("Opening context menu on unknown type: ", objectType);
  3818. }
  3819. }
  3820. showMenu = true;
  3821. } else if (clickTarget.hasClass("backgroundFrame") || ((isSafari || (isMacOS && isChrome)) && $(clickTarget).attr("id") == "selectionPanel")) {
  3822. //Click on the background. Load background context menu.
  3823. addContextMenuItem($("#contextmenu"), lcontex('New'), "<i class='caret right icon'></i>", "newitemmenu", true);
  3824. addContextMenuItem($("#contextmenu"), lcontex('Refresh'), "<i class='refresh icon'></i>", "handleMenuRefresh", false);
  3825. addContextMenuItem($("#contextmenu"), lcontex('Open File Manager'), undefined, "openfm", false);
  3826. //addContextMenuItem($("#contextmenu"), 'Get File from URL', "<i class='download icon'></i>", "downloadURL", false);
  3827. addContextMenuItem($("#contextmenu"), lcontex('Personalization'), "<i class='paint brush icon'></i>", "personalization", false);
  3828. addContextMenuItem($("#contextmenu"), lcontex('Background'), "<i class='caret right icon'></i>", "background", true);
  3829. addContextMenuItem($("#contextmenu"), lcontex('Icon Size'), "<i class='caret right icon'></i>", "listIconsize", true);
  3830. addContextMenuItem($("#contextmenu"), lcontex('Toggle FullScreen'), "<i class='maximize icon'></i>", "fullscreen", false);
  3831. addContextMenuItem($("#contextmenu"), lcontex('Exit'), undefined, "logout", false);
  3832. showMenu = true;
  3833. }else if (clickTarget.hasClass("fwdragger") || (clickTarget.hasClass("title") && clickTarget.parent().hasClass("fwdragger"))){
  3834. //Click on the floatWindow object
  3835. addContextMenuItem($("#contextmenu"), lcontex('Open in New Tab'), "<i class='external icon'></i>", "openSelectedFloatWindowInNewTab", false);
  3836. addContextMenuItem($("#contextmenu"), lcontex('Refresh'), "<i class='refresh icon'></i>", "refreshSelectedFloatWindow", false);
  3837. addContextMenuSeperator($("#contextmenu"));
  3838. addContextMenuItem($("#contextmenu"), lcontex('Minimize'), "<i class='window minimize icon'></i>", "minimizeSelectedFloatWindow", false);
  3839. if ($(clickTarget).parent().hasClass("fixedsize") == false && $(clickTarget).parent().parent().hasClass("fixedsize") == false){
  3840. //This FloatWindow is resizable
  3841. console.log($(clickTarget).parent());
  3842. if ($(clickTarget).parent().attr("max") !== undefined && $(clickTarget).parent().attr("max") == "true"){
  3843. addContextMenuItem($("#contextmenu"), lcontex('Restore'), "<i class='window window restore icon'></i>", "maximizeSelectedFloatWindow", false);
  3844. }else{
  3845. addContextMenuItem($("#contextmenu"), lcontex('Maximize'), "<i class='window maximize icon'></i>", "maximizeSelectedFloatWindow", false);
  3846. }
  3847. }
  3848. addContextMenuItem($("#contextmenu"), lcontex('Close'), "<i class='remove icon'></i>", "closeSelectedFloatWindow", false);
  3849. showMenu = true;
  3850. }
  3851. if (showMenu){
  3852. //Toggle context menu
  3853. $("#contextmenu").show();
  3854. var startX = e.pageX;
  3855. var startY = e.pageY;
  3856. if (e.pageX > window.innerWidth / 2){
  3857. startX = e.pageX - $("#contextmenu").width();
  3858. }
  3859. if (e.pageY > window.innerHeight / 2){
  3860. startY = e.pageY - $("#contextmenu").height();
  3861. }
  3862. $("#contextmenu").css({
  3863. left: startX,
  3864. top: startY
  3865. });
  3866. menuStartLocation = [e.pageX, e.pageY];
  3867. }
  3868. }
  3869. , true);
  3870. //Localize context menu items using applocale
  3871. function lcontex(key){
  3872. if (applocale){
  3873. return applocale.getString("contextmenu/" + key, key);
  3874. }else{
  3875. return key;
  3876. }
  3877. }
  3878. function handleMenuRefresh() {
  3879. //This function is here to remove the object and event passed in from menu pressed object
  3880. refresh();
  3881. }
  3882. function newshortcut(){
  3883. //Show the new shortcut creation tool
  3884. newFloatWindow({
  3885. url: "SystemAO/desktop/shortcutCreator.html",
  3886. appicon: "img/desktop/system_icon/shortcut.png",
  3887. width:815,
  3888. height:485,
  3889. title: "New Shortcut"
  3890. });
  3891. hideAllContextMenus();
  3892. }
  3893. function openIconViaMenu(target, event){
  3894. $(".launchIconWrapper.selected").each(function(){
  3895. iconObject = $(this).parent();
  3896. //Emulate a doubleclick on icon
  3897. iconDoubleClicked(iconObject, event);
  3898. });
  3899. hideAllContextMenus();
  3900. }
  3901. //Opening a shortcut module from desktop to new tab
  3902. function openWebAppInNewTab(target, event){
  3903. $(".launchIconWrapper.selected").each(function(){
  3904. var fd = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3905. $.get("system/modules/getLaunchPara?module=" + fd.ShortcutPath, function(data) {
  3906. if (data.error !== undefined) {
  3907. console.log(data.error);
  3908. }else{
  3909. //Open in new tab
  3910. window.open(data.StartDir)
  3911. }
  3912. });
  3913. });
  3914. hideAllContextMenus();
  3915. }
  3916. function downloadFile(target, event){
  3917. if ( $(".launchIconWrapper.selected").length == 1){
  3918. //Download this file directly
  3919. var rawfiledata = $(".launchIconWrapper.selected").parent().attr("filedata");
  3920. var filedata = JSON.parse(decodeURIComponent(rawfiledata));
  3921. var filepath = filedata.Filepath;
  3922. //Resolve the link to media download link
  3923. var downloadLink = "media?file=" + filepath + "&download=true";
  3924. window.open(downloadLink)
  3925. }else if ($(".launchIconWrapper.selected").length > 1){
  3926. //Create a zip file using the fs api
  3927. var filelist = [];
  3928. $(".launchIconWrapper.selected").each(function(){
  3929. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3930. var filepath = filedata.Filepath;
  3931. filelist.push(filepath);
  3932. });
  3933. $.ajax({
  3934. url: "system/file_system/zipHandler",
  3935. data: {opr: "tmpzip", src: JSON.stringify(filelist), dest: ""},
  3936. method: "POST",
  3937. success: function(data){
  3938. if (data.error !== undefined){
  3939. alert(data.error);
  3940. }else{
  3941. //Zip completed.
  3942. window.open("media?file=" + data + "&download=true");
  3943. }
  3944. }
  3945. });
  3946. }
  3947. hideAllContextMenus();
  3948. }
  3949. function handleZipFolder(){
  3950. var filelist = [];
  3951. var filename = "desktop_" + new Date().getTime() + ".zip"
  3952. if ($(".launchIconWrapper.selected").length == 1){
  3953. filename = $(".launchIconWrapper.selected").parent().attr('filename') + ".zip";
  3954. }
  3955. $(".launchIconWrapper.selected").each(function(){
  3956. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3957. var filepath = filedata.Filepath;
  3958. if (filedata.IsDir == true){
  3959. filelist.push(filepath);
  3960. }
  3961. });
  3962. $.ajax({
  3963. url: "system/file_system/zipHandler",
  3964. data: {opr: "zip", src: JSON.stringify(filelist), dest: "user:/Desktop/" + filename},
  3965. method: "POST",
  3966. success: function(data){
  3967. if (data.error !== undefined){
  3968. alert(data.error);
  3969. }else{
  3970. //Zip completed.
  3971. console.log(data);
  3972. }
  3973. }
  3974. });
  3975. //console.log(filelist);
  3976. hideAllContextMenus();
  3977. }
  3978. function handleOpenWith(target, event){
  3979. $("#subcontextmenu").html("");
  3980. //Updates 19 May 2021: Added support for better parsing Open With List
  3981. var exts = [];
  3982. //Get all exts from the selected files
  3983. $(".launchIconWrapper.selected").each(function(){
  3984. var filename = $(this).parent().attr("filename");
  3985. var ext = "." + filename.split(".").pop();
  3986. exts.push(ext);
  3987. });
  3988. $.get("system/modules/list",function(data){
  3989. if (data.error !== undefined){
  3990. alert(data.error);
  3991. }else{
  3992. var supportedModuleCount = 0;
  3993. var openWithTargets = [];
  3994. for (var i =0; i < data.length; i++){
  3995. var thisModule = data[i];
  3996. //If this module support this ext, add it to list
  3997. var thisModuleSupportExt = thisModule.SupportedExt;
  3998. if (thisModule.Name == "File Manager"){
  3999. //Exceptional case
  4000. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  4001. }
  4002. if (thisModuleSupportExt == null || thisModuleSupportExt.length == 0){
  4003. //Not supporting anything
  4004. continue;
  4005. }
  4006. thisModuleSupportExt.forEach(supportedExt => {
  4007. if (exts.includes(supportedExt)){
  4008. //Add this to the menu
  4009. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  4010. }
  4011. })
  4012. //if (thisModule.SupportEmb == true){
  4013. // addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  4014. //}
  4015. }
  4016. //Add select more opener option
  4017. addContextMenuSeperator($("#subcontextmenu"));
  4018. addContextMenuItem($("#subcontextmenu"), lcontex("Select Other WebApps"), ``, "openOpenSelector", false);
  4019. }
  4020. showSubContextMenu(target);
  4021. });
  4022. }
  4023. function handleFileShare(target, object){
  4024. $("#subcontextmenu").html("");
  4025. //Get the selected file
  4026. var targetFile = $(".launchIconWrapper.selected")[0];
  4027. var fileData = $(targetFile).parent().attr("filedata");
  4028. if (fileData != undefined){
  4029. fileData = JSON.parse(decodeURIComponent(fileData));
  4030. //Check if the target file is shared
  4031. $.ajax({
  4032. url: "system/file_system/share/checkShared",
  4033. data: {path: fileData.Filepath},
  4034. success: function(data){
  4035. if (data.IsShared == true){
  4036. addContextMenuItem($("#subcontextmenu"), lcontex("Open Shared Link"), `<i class="external icon"></i>`, "openSharedLink", false, {
  4037. payload: {
  4038. uuid: data.ShareUUID.UUID
  4039. }
  4040. });
  4041. addContextMenuItem($("#subcontextmenu"), lcontex("Copy Link"), `<i class="copy icon"></i>`, "copySharedLink", false, {
  4042. payload: {
  4043. uuid: data.ShareUUID.UUID
  4044. }
  4045. });
  4046. addContextMenuSeperator($("#subcontextmenu"));
  4047. addContextMenuTitle($("#subcontextmenu"), lcontex(`<i class="share alternate icon"></i> ${applocale.getString("contextmenu/Change Share Settings", "Change Share Settings")}]`));
  4048. }else{
  4049. addContextMenuTitle($("#subcontextmenu"), lcontex(`<i class="share alternate icon"></i> ${applocale.getString("contextmenu/Share this File", "Share this File")}`));
  4050. }
  4051. var checkmarkStyle = `style="color: #71ba68;"`;
  4052. var anyoneClass = "";
  4053. if (data.ShareUUID.Permission == "anyone"){
  4054. anyoneClass = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  4055. }
  4056. var signedinClass = "";
  4057. if (data.ShareUUID.Permission == "signedin"){
  4058. signedinClass = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  4059. }
  4060. var sameGroupClass = "";
  4061. if (data.ShareUUID.Permission == "samegroup"){
  4062. samegroup = `<i ${checkmarkStyle} class="checkmark icon"></i>`;
  4063. }
  4064. addContextMenuItem($("#subcontextmenu"), `<i class="globe icon"></i> ${applocale.getString("contextmenu/share/link","Anyone with Link")}`, anyoneClass, "shareWithThisPermission", false, {
  4065. payload: {
  4066. type: "anyone"
  4067. }
  4068. });
  4069. addContextMenuItem($("#subcontextmenu"), `<i class="user circle outline icon"></i> ${applocale.getString( "contextmenu/share/signedin","Anyone Signed In")}`, signedinClass, "shareWithThisPermission", false, {
  4070. payload: {
  4071. type: "signedin"
  4072. }
  4073. });
  4074. addContextMenuItem($("#subcontextmenu"), `<i class="users icon"></i> ${applocale.getString("contextmenu/share/samegroup","Same Group Users")}`, sameGroupClass, "shareWithThisPermission", false,{
  4075. payload: {
  4076. type: "samegroup"
  4077. }
  4078. });
  4079. if (data.IsShared == true){
  4080. //This file is shared.
  4081. addContextMenuSeperator($("#subcontextmenu"));
  4082. addContextMenuItem($("#subcontextmenu"), lcontex("Remove Share"), `<i style="color: #d97762;" class="trash icon"></i>`, "shareWithThisPermission", false,{
  4083. payload: {
  4084. type: "remove"
  4085. }
  4086. });
  4087. }
  4088. }
  4089. });
  4090. }
  4091. showSubContextMenu(target);
  4092. }
  4093. //Copy the shared link
  4094. function copySharedLink(target, event){
  4095. var payload = getContextMenuPayload(target);
  4096. if (payload == null){
  4097. //Something wrong
  4098. return;
  4099. }
  4100. //Generate the share link
  4101. let protocol = "https://";
  4102. if (location.protocol !== 'https:') {
  4103. protocol = "http://";
  4104. }
  4105. var shareURL = protocol + window.location.hostname + ":" + window.location.port + "/share?id=" + payload.uuid;
  4106. //Copy the text to clipboard
  4107. const area = document.createElement('textarea');
  4108. document.body.appendChild(area);
  4109. area.value = shareURL;
  4110. area.select();
  4111. document.execCommand('copy');
  4112. document.body.removeChild(area);
  4113. //Update status so it show the user it has been coped
  4114. $(target).html(`<i style="color: #71ba68;" class="checkmark icon"></i> Copied!`);
  4115. setTimeout(function(){
  4116. if ($(target).length > 0){
  4117. $(target).html(`Copy Link
  4118. <span class="description">
  4119. <i class="copy icon"></i>
  4120. </span>`);
  4121. }
  4122. }, 3000);
  4123. }
  4124. //Open the shared file link
  4125. function openSharedLink(target, event){
  4126. var payload = getContextMenuPayload(target);
  4127. if (payload == null){
  4128. //Something wrong
  4129. return;
  4130. }
  4131. var targetURL = "share?id=" + payload.uuid;
  4132. window.open(targetURL);
  4133. hideAllContextMenus();
  4134. }
  4135. function shareWithThisPermission(target, event){
  4136. var payload = getContextMenuPayload(target);
  4137. if (payload == null){
  4138. //Something wrong
  4139. return;
  4140. }
  4141. //Get the selected file
  4142. var selectedFileObjects = $(".launchIconWrapper.selected");
  4143. if (selectedFileObjects.length == 0){
  4144. //Not found
  4145. return
  4146. }else if (selectedFileObjects.length > 1){
  4147. //This should not happens. If it did happens, use the first one
  4148. selectedFileObjects = selectedFileObjects[0];
  4149. }
  4150. //Extract file information
  4151. var fileData = $(selectedFileObjects).parent().attr("filedata");
  4152. fileData = JSON.parse(decodeURIComponent(fileData));
  4153. //Convert the desktop file data to ArozOS generic filedata
  4154. var afd = {
  4155. "filename": fileData.Filename,
  4156. "filepath": fileData.Filepath,
  4157. "shareMode": payload.type
  4158. };
  4159. //Create a new share for this
  4160. var targetURL = "SystemAO/file_system/file_share.html#" + encodeURIComponent(JSON.stringify([afd]));
  4161. //Calculate the window spawn position
  4162. var basePosition = $(selectedFileObjects).offset();
  4163. var left = basePosition.left + 100;
  4164. if (left + 320 > window.innerWidth){
  4165. left = basePosition.left - 350;
  4166. }
  4167. var top = basePosition.top;
  4168. if (top + 480 > window.innerHeight){
  4169. top = window.innerHeight - 480;
  4170. }
  4171. newFloatWindow({
  4172. url: targetURL,
  4173. width: 330,
  4174. height: 480,
  4175. left: left,
  4176. top: top,
  4177. appicon: "SystemAO/file_system/img/share.svg",
  4178. title: "Share File"
  4179. }, function(windowUUID){
  4180. //Set the window to fixed window
  4181. setFloatWindowResizePolicy(windowUUID, false);
  4182. });
  4183. hideAllContextMenus();
  4184. }
  4185. function openObjectProperty(target, object){
  4186. var filelist = [];
  4187. $(".launchIconWrapper.selected").each(function(){
  4188. var filepath = $(this).parent().attr("filepath");
  4189. filelist.push(filepath);
  4190. });
  4191. var hashPassthrough = encodeURIComponent(JSON.stringify(filelist));
  4192. newFloatWindow({
  4193. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  4194. width: 340,
  4195. height: 480,
  4196. appicon: "SystemAO/file_system/img/properties.png",
  4197. title: "File Properties",
  4198. });
  4199. hideAllContextMenus();
  4200. }
  4201. //Open the file extension selector
  4202. function openOpenSelector(target, event){
  4203. var filedata = $($(".launchIconWrapper.selected")[0]).parent().attr("filedata")
  4204. filedata = JSON.parse(decodeURIComponent(filedata));
  4205. var fileDescriptor = {
  4206. filepath: filedata.Filepath,
  4207. filename: filedata.Filename
  4208. }
  4209. newFloatWindow({
  4210. url: "SystemAO/file_system/defaultOpener.html#" + encodeURIComponent(JSON.stringify(fileDescriptor)),
  4211. width: 320,
  4212. height: 510,
  4213. appicon: "SystemAO/file_system/img/opener.png",
  4214. title: "Select WebApp to Open File",
  4215. });
  4216. hideAllContextMenus();
  4217. }
  4218. function openSelectedWith(target, event){
  4219. var targetModulename = $(target).text().trim();
  4220. var openFileList = [];
  4221. $(".selected.launchIconWrapper").each(function(){
  4222. var thisFiledata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4223. openFileList.push({
  4224. filename: thisFiledata.Filename,
  4225. filepath: thisFiledata.Filepath
  4226. });
  4227. });
  4228. //Find the launch info of the module
  4229. var targetModuleInfo = undefined;
  4230. for (var i =0; i < moduleInstalled.length; i++){
  4231. if (moduleInstalled[i].Name == targetModulename){
  4232. targetModuleInfo = JSON.parse(JSON.stringify(moduleInstalled[i]));
  4233. }
  4234. }
  4235. //Open the files with the given module
  4236. openFileWithModule(targetModuleInfo, openFileList);
  4237. hideAllContextMenus();
  4238. }
  4239. function getModuleInfoFromName(moduleName){
  4240. for (var i = 0; i < moduleInstalled.length; i++){
  4241. if (moduleInstalled[i].Name == moduleName){
  4242. return moduleInstalled[i];
  4243. }
  4244. }
  4245. return false
  4246. }
  4247. /*
  4248. This function is used to generate menu items for context menu.
  4249. Options example
  4250. {
  4251. payload: {
  4252. //Some JSON based payload here
  4253. }
  4254. }
  4255. */
  4256. function addContextMenuItem(target, keyword, hotkey = undefined, functionName, containSubMenu = false, options=undefined) {
  4257. var itemClass = "item";
  4258. if (containSubMenu) {
  4259. itemClass = "item submenu";
  4260. }
  4261. var payload = "";
  4262. if (options != undefined && options.payload != undefined){
  4263. payload = encodeURIComponent(JSON.stringify(options.payload));
  4264. }
  4265. if (hotkey !== undefined) {
  4266. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);" payload="${payload}">
  4267. ${keyword}
  4268. <span class="description">${hotkey}</span>
  4269. </div>`);
  4270. } else {
  4271. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);" payload="${payload}">
  4272. ${keyword}
  4273. </div>`);
  4274. }
  4275. }
  4276. function getContextMenuPayload(object){
  4277. var encodedPayload = $(object).attr("payload");
  4278. if (encodedPayload != ""){
  4279. return JSON.parse(decodeURIComponent(encodedPayload));
  4280. }else{
  4281. return null;
  4282. }
  4283. }
  4284. function listIconsize(target, event) {
  4285. $("#subcontextmenu").html("");
  4286. var smallCheckmark = undefined;
  4287. var mediumCheckmark = undefined;
  4288. var bigCheckmark = undefined;
  4289. if (desktopIconSize == "small") {
  4290. smallCheckmark = "<i class='checkmark icon'></i>";
  4291. }
  4292. if (desktopIconSize == "medium") {
  4293. mediumCheckmark = "<i class='checkmark icon'></i>";
  4294. }
  4295. if (desktopIconSize == "big") {
  4296. bigCheckmark = "<i class='checkmark icon'></i>";
  4297. }
  4298. addContextMenuItem($("#subcontextmenu"), lcontex("Small"), smallCheckmark, "setDesktopIconSize", false);
  4299. addContextMenuItem($("#subcontextmenu"), lcontex("Medium"), mediumCheckmark, "setDesktopIconSize", false);
  4300. addContextMenuItem($("#subcontextmenu"), lcontex("Big"), bigCheckmark, "setDesktopIconSize", false);
  4301. showSubContextMenu(target);
  4302. }
  4303. function setDesktopIconSize(target, evt) {
  4304. var targetSize = $(target).text().trim().toLowerCase();
  4305. if (["small", "medium", "big"].includes(targetSize)) {
  4306. desktopIconSize = targetSize;
  4307. }
  4308. refresh();
  4309. setStorage("iconsize", desktopIconSize);
  4310. hideAllContextMenus();
  4311. }
  4312. function addContextMenuSeperator(target) {
  4313. $(target).append(`<div class="divider"></div>`);
  4314. }
  4315. function addContextMenuTitle(target, title){
  4316. $(target).append(`<div class="header">
  4317. ${title}
  4318. </div>`);
  4319. }
  4320. function downloadURL() {
  4321. alert("WIP");
  4322. hideAllContextMenus();
  4323. }
  4324. function background(target, evt) {
  4325. $("#subcontextmenu").html('<div class="item"><i class="loading spinning icon"></i> Loading</div>');
  4326. $.get("system/desktop/theme", function(data) {
  4327. $("#subcontextmenu").html("");
  4328. for (var i = 0; i < data.length; i++) {
  4329. if (currentUserTheme == data[i].Theme) {
  4330. addContextMenuItem($("#subcontextmenu"), data[i].Theme, "<i class='checkmark icon'></i>", "setTheme", false);
  4331. } else {
  4332. addContextMenuItem($("#subcontextmenu"), data[i].Theme, undefined, "setTheme", false);
  4333. }
  4334. }
  4335. });
  4336. showSubContextMenu(target);
  4337. }
  4338. //Set theme from button click
  4339. function setTheme(target, evt) {
  4340. var theme = $(target).text().trim();
  4341. setDesktopTheme(theme);
  4342. hideAllContextMenus();
  4343. }
  4344. function personalization() {
  4345. //Show the personalization window
  4346. newFloatWindow({
  4347. url: "SystemAO/desktop/personalization.html",
  4348. appicon: "SystemAO/desktop/img/personalization.png",
  4349. width:640,
  4350. height:480,
  4351. title: "Personalization"
  4352. });
  4353. hideAllContextMenus();
  4354. }
  4355. //New folder on the menu start location
  4356. function newfolder(object, event) {
  4357. var closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4358. let closestPixelLocation = closestLocation[0];
  4359. let closestGridIndexLocation = closestLocation[1];
  4360. //Generate new foldername
  4361. var newFolderName = "New Folder";
  4362. var counter = 1;
  4363. while (desktopFileList.includes(newFolderName)) {
  4364. newFolderName = `New Folder(${counter})`;
  4365. counter++;
  4366. }
  4367. //Check if there are already another object at that locaton
  4368. var duplicateObject = getObjectFromLocation(closestPixelLocation[0], closestPixelLocation[1]);
  4369. var createObjectLocation = true;
  4370. if (duplicateObject !== undefined) {
  4371. //Ignore create position. Let it settle on next new slot.
  4372. createObjectLocation = false;
  4373. }
  4374. //Create the folder
  4375. requestCSRFToken(function(token){
  4376. $.post("system/file_system/newItem", {
  4377. type: "folder",
  4378. src: "user:/Desktop/",
  4379. filename: newFolderName,
  4380. csrft: token
  4381. }).done(function(data) {
  4382. if (data.error !== undefined) {
  4383. alert(data.error);
  4384. } else {
  4385. if (createObjectLocation) {
  4386. setIconDesktopLocation(newFolderName, closestGridIndexLocation[0], closestGridIndexLocation[1], function() {
  4387. //After set Desktop icon, refresh the page
  4388. refresh(function() {
  4389. //After refresh the page, highlight the new folder and set it to rename mode
  4390. var targetFolderObject = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  4391. console.log(targetFolderObject);
  4392. enableRenameOnLaunchIconObject(targetFolderObject);
  4393. });
  4394. });
  4395. }
  4396. }
  4397. });
  4398. });
  4399. /*
  4400. //Open new folder creation window
  4401. var existsingFileList = [];
  4402. for (var i =0; i < desktopFileList.length; i++){
  4403. existsingFileList.push({
  4404. filename: desktopFileList[i],
  4405. filepath: "user:/Desktop/" + desktopFileList[i]
  4406. });
  4407. }
  4408. newFloatWindow({
  4409. url: "SystemAO/file_system/newFolder.html#" + encodeURIComponent(JSON.stringify(existsingFileList)),
  4410. appicon: "SystemAO/file_system/img/new folder.png",
  4411. width:560,
  4412. height:340,
  4413. title: "New Folder"
  4414. });
  4415. */
  4416. hideAllContextMenus();
  4417. }
  4418. function enableRenameOnLaunchIconObject(object) {
  4419. renameMode = true;
  4420. $(".launchIcon").attr("draggable", "false");
  4421. var filedata = JSON.parse(decodeURIComponent($(object).attr("filedata")));
  4422. var originalName = filedata.Filename;
  4423. if (filedata.IsShortcut){
  4424. //Shortcut. Use its display name instead
  4425. originalName = filedata.ShortcutName;
  4426. }
  4427. $(object).find(".launchIconText").hide();
  4428. $(object).append(`<textarea class="renameInput ${desktopIconSize}" type="text" ondragstart="return false;" dblclick="event.stopImmediatePropagation(); event.stopImmediatePropagation();"maxlength="32">${originalName}</textarea>`);
  4429. $(object).find(".renameInput")[0].select();
  4430. var index = originalName.lastIndexOf(".");
  4431. console.log(index);
  4432. if( index >= 0){
  4433. $(object).find(".renameInput")[0].setSelectionRange(0, index);
  4434. }
  4435. //Updates 4-5-2021: Added IME support on rename input
  4436. $(object).find(".renameInput")[0].addEventListener("keydown", function(event){
  4437. if (window.ime && window.ime.handler != null){
  4438. window.ime.handler(event);
  4439. }else{
  4440. //No IME handler. Just continue the input
  4441. }
  4442. });
  4443. window.ime.focus = $(object).find(".renameInput")[0];
  4444. }
  4445. function exitRenameMode() {
  4446. if (renameMode) {
  4447. $(".launchIcon").attr("draggable", "true");
  4448. $(".launchIcon").find(".launchIconText").show();
  4449. //Update the folder to textarea content
  4450. $(".renameInput").each(function() {
  4451. if ($(this).text() == "") {
  4452. //Ignore this update
  4453. } else {
  4454. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4455. var filepath = filedata.Filepath;
  4456. var newFilename = $(this).val();
  4457. if (filedata.IsShortcut == true){
  4458. //Shortcut. Edit the shortcut content name
  4459. let currentInputTextArea = $(this);
  4460. $.ajax({
  4461. url: "/system/desktop/opr/renameShortcut",
  4462. data: {src: filepath, new: newFilename},
  4463. success: function(data){
  4464. if (data.error !== undefined){
  4465. //Cancel the operation
  4466. console.log("*ERROR* " + data.error);
  4467. currentInputTextArea.remove();
  4468. }else{
  4469. //No need to update the shortcut position (as its name not changed)
  4470. refresh(function() {
  4471. //Refresh the desktop
  4472. });
  4473. }
  4474. }
  4475. })
  4476. }else{
  4477. //Normal typed files / folder. Rename the object
  4478. let currentInputTextArea = $(this);
  4479. generateCSRFToken(function(csrftoken){
  4480. $.ajax({
  4481. url: "./system/file_system/fileOpr",
  4482. method: "POST",
  4483. data: {opr: "rename", src: JSON.stringify([filepath]), new: JSON.stringify([newFilename]), csrft: csrftoken},
  4484. success: function(data){
  4485. if (data.error !== undefined){
  4486. //Cancel the operation
  4487. alert(data.error);
  4488. console.log("*ERROR* " + data.error);
  4489. currentInputTextArea.remove();
  4490. }else{
  4491. //Update the new file position
  4492. let closestLocation = findClosestGrid($(currentInputTextArea).parent().offset().left, $(currentInputTextArea).parent().offset().top);
  4493. let closestGridIndexLocation = closestLocation[1];
  4494. setIconDesktopLocation(newFilename, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4495. //Callback after setting location
  4496. refresh(function() {
  4497. //Refresh the desktop
  4498. });
  4499. });
  4500. }
  4501. }
  4502. });
  4503. });
  4504. }
  4505. }
  4506. });
  4507. renameMode = false;
  4508. }
  4509. }
  4510. //Handle opening shortcut folder location
  4511. function handleShortcutFolderOpen(object, event){
  4512. var openPendingFolders = [];
  4513. $(".launchIconWrapper.selected").each(function(){
  4514. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4515. console.log(filedata);
  4516. if (filedata.IsShortcut == true){
  4517. if (filedata.ShortcutType == "folder"){
  4518. openPendingFolders.push(filedata.ShortcutPath);
  4519. }else if (filedata.ShortcutType == "module"){
  4520. openPendingFolders.push("web:/" + filedata.ShortcutPath);
  4521. }
  4522. }
  4523. });
  4524. //Open all folders
  4525. openPendingFolders.forEach(folder => {
  4526. newFloatWindow({
  4527. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(folder),
  4528. appicon: "SystemAO/file_system/img/small_icon.png",
  4529. width:1080,
  4530. height:580,
  4531. title: "File Manager"
  4532. });
  4533. })
  4534. hideAllContextMenus();
  4535. }
  4536. //Handle basic desktop file operations
  4537. function handleFileDelete(object, event){
  4538. var deleteFileList = [];
  4539. $(".launchIconWrapper.selected").each(function(){
  4540. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  4541. deleteFileList.push(filedata.Filepath);
  4542. });
  4543. console.log(deleteFileList);
  4544. generateCSRFToken(function(csrftoken){
  4545. $.ajax({
  4546. url: "system/file_system/fileOpr",
  4547. method:"POST",
  4548. data: {opr: "recycle", src: JSON.stringify(deleteFileList), csrft: csrftoken},
  4549. success: function(data){
  4550. if (data.error !== undefined){
  4551. alert(data.error);
  4552. }else{
  4553. refresh(undefined, true);
  4554. }
  4555. }
  4556. });
  4557. hideAllContextMenus();
  4558. });
  4559. }
  4560. //File Rename
  4561. let renamingItems = [];
  4562. function handleRename(object, event){
  4563. if ($('.launchIconWrapper.selected').length > 0){
  4564. //Enter rename mode
  4565. renamingItems = $('.launchIconWrapper.selected');
  4566. let renameTarget = $('.launchIconWrapper.selected')[0]
  4567. let fileObject = $(renameTarget).parent();
  4568. enableRenameOnLaunchIconObject(fileObject);
  4569. }
  4570. hideAllContextMenus();
  4571. }
  4572. //New item menus.
  4573. function newitemmenu(target, event) {
  4574. $("#subcontextmenu").html("");
  4575. //Append the new folder option first
  4576. addContextMenuItem($("#subcontextmenu"), lcontex('Folder'), "<i class='folder icon'></i>", "newfolder", true);
  4577. addContextMenuItem($("#subcontextmenu"), lcontex('Shortcut'), "<i class='external icon'></i>", "newshortcut", true);
  4578. addContextMenuSeperator($("#subcontextmenu"));
  4579. requestCSRFToken(function(token){
  4580. $.ajax({
  4581. url: "system/file_system/newItem",
  4582. data: {csrft: token},
  4583. success: function(data){
  4584. for (var i = 0; i < data.length; i++) {
  4585. var thisNewFile = data[i];
  4586. var icon = ao_module_utils.getIconFromExt(thisNewFile.Ext);
  4587. addContextMenuItem($("#subcontextmenu"), `<i class="${icon} icon" ext="${thisNewFile.Ext}"></i> ${thisNewFile.Desc}`, undefined, "newitem");
  4588. }
  4589. //Show sub-context menu
  4590. showSubContextMenu(target);
  4591. }
  4592. })
  4593. });
  4594. }
  4595. function showSubContextMenu(target) {
  4596. $("#subcontextmenu").show();
  4597. var targetLeft = $("#contextmenu").offset().left + $("#contextmenu").width() + 2;
  4598. var targetTop = $(target).offset().top - 1;
  4599. if (targetLeft + $("#subcontextmenu").width() > window.innerWidth){
  4600. //Overflow. Swtich to the left side of the menu
  4601. targetLeft = $("#contextmenu").offset().left - $("#subcontextmenu").width() - 2;
  4602. }
  4603. $("#subcontextmenu").css({
  4604. left: targetLeft,
  4605. top: targetTop
  4606. });
  4607. }
  4608. //Create new file item with that filename
  4609. function newitem(object, event) {
  4610. var extension = $(object).find("i").attr("ext");
  4611. //Generate a newfile name
  4612. var newfn = "NewFile" + "." + extension;
  4613. var counter = 1;
  4614. while (desktopFileList.includes(newfn)){
  4615. newfn = "NewFile (" + counter + ")." + extension;
  4616. counter++;
  4617. }
  4618. //Get the location position
  4619. let closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4620. let closestGridIndexLocation = closestLocation[1];
  4621. //Request backend to generate the new file
  4622. $.ajax({
  4623. url: "system/file_system/newItem",
  4624. data: {type: "file",src: "user:/Desktop/",filename: newfn, csrft: token},
  4625. success: function(data){
  4626. if (data.error !== undefined){
  4627. alert(data.error);
  4628. }else{
  4629. //Set the icon location
  4630. setIconDesktopLocation(newfn, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4631. //Refresh the desktop
  4632. refresh(function(){
  4633. var targetNewFile = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  4634. console.log("Renaming ", targetNewFile);
  4635. enableRenameOnLaunchIconObject(targetNewFile);
  4636. });
  4637. });
  4638. }
  4639. }
  4640. });
  4641. hideAllContextMenus();
  4642. }
  4643. document.getElementById("volumebar").parentNode.addEventListener("touchstart", function(e){
  4644. updateVolume( document.getElementById("volumebar").parentNode, e);
  4645. });
  4646. function getCoordinateFromEvent(e){
  4647. var x = -1;
  4648. var y = -1;
  4649. if (e.originalEvent == undefined){
  4650. e.originalEvent = e;
  4651. }
  4652. if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){
  4653. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  4654. x = touch.pageX;
  4655. y = touch.pageY;
  4656. } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
  4657. x = e.clientX;
  4658. y = e.clientY;
  4659. }else{
  4660. x = e.clientX;
  4661. y = e.clientY;
  4662. }
  4663. return [x,y];
  4664. }
  4665. function updateVolume(object, event){
  4666. var width = $(object).width();
  4667. var left = $(object).offset().left;
  4668. var clickPosition = getCoordinateFromEvent(event)[0];
  4669. var clickRel = clickPosition - left;
  4670. var percentage = clickRel / width * 100;
  4671. if (percentage < 0){
  4672. percentage = 0;
  4673. }else if (percentage > 100){
  4674. percentage = 100;
  4675. }
  4676. //Update the global volume
  4677. $(object).find(".bar").css("width",percentage + "%");
  4678. localStorage.setItem("global_volume", clickRel / width);
  4679. }
  4680. function refresh(callback = undefined, noflash=false) {
  4681. //Refresh desktop contents
  4682. let launchOption = {};
  4683. if (noflash){
  4684. launchOption = {
  4685. noflash: true
  4686. };
  4687. }else{
  4688. $(".launchIcon").each(function*(){
  4689. if ($(this).attr("tyoe") == "dummy"){
  4690. //Do not remove this
  4691. return;
  4692. }
  4693. $(this).remove();
  4694. });
  4695. }
  4696. if (callback == undefined) {
  4697. initDesktopFiles(launchOption, function(){
  4698. startThumbnailLoader();
  4699. });
  4700. } else {
  4701. initDesktopFiles(launchOption, function(){
  4702. startThumbnailLoader();
  4703. callback()
  4704. });
  4705. }
  4706. hideAllContextMenus();
  4707. }
  4708. function startThumbnailLoader(){
  4709. let path = "user:/Desktop";
  4710. let protocol = "wss://";
  4711. if (location.protocol !== 'https:') {
  4712. protocol = "ws://";
  4713. }
  4714. var port = window.location.port;
  4715. if (window.location.port == ""){
  4716. if (location.protocol !== 'https:') {
  4717. port = "80";
  4718. }else{
  4719. port = "443";
  4720. }
  4721. }
  4722. thumbRenderWebSocket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/handleCacheRender?folder=" + path);
  4723. thumbRenderWebSocket.onopen = function(e) {
  4724. };
  4725. thumbRenderWebSocket.onmessage = function(event) {
  4726. //Find the correct file in the current directory and place its image
  4727. let thumbData = JSON.parse(event.data);
  4728. $(".launchIcon").each(function(){
  4729. if (thumbData[1].length > 0){
  4730. if ($(this).attr("filename") == thumbData[0]){
  4731. let imageContainer = $(this).find(".launchIconImage");
  4732. imageContainer.attr("src","data:image/jpg;base64," + thumbData[1]);
  4733. imageContainer.css("padding", "0.6em");
  4734. //Load the application icon on this file
  4735. let filedata = $(this).attr("filedata");
  4736. filedata = JSON.parse(decodeURIComponent(filedata));
  4737. $.ajax({
  4738. url: "system/modules/getDefault",
  4739. data: {opr: "launch", ext: filedata.Ext},
  4740. method: "GET",
  4741. success: function(data){
  4742. if (data.error == undefined){
  4743. let iconSize = 20;
  4744. let topOffset = $(imageContainer).height() - iconSize/2 + 2;
  4745. $(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>`);
  4746. }
  4747. }
  4748. });
  4749. }
  4750. }
  4751. });
  4752. };
  4753. thumbRenderWebSocket.onclose = function(event) {
  4754. //Transfer ended
  4755. };
  4756. thumbRenderWebSocket.onerror = function(error) {
  4757. console.log("Cannot connect to WebSocket cache renderer. Falling back to AJAX request");
  4758. startFallbackThumbnailLoader();
  4759. };
  4760. }
  4761. function startFallbackThumbnailLoader(){
  4762. $(".launchIcon").each(function(){
  4763. let fd = JSON.parse(decodeURIComponent($(this).attr("filedata")))
  4764. let filepath = fd.Filepath;
  4765. let targetDOM = $(this);
  4766. $.ajax({
  4767. url: "system/file_system/loadThumbnail",
  4768. data: {vpath: filepath},
  4769. success: function(data){
  4770. if (data.error == undefined && data != undefined && data != ""){
  4771. let imageContainer = $(targetDOM).find(".launchIconImage");
  4772. imageContainer.attr("src","data:image/jpg;base64," + data);
  4773. imageContainer.css("padding", "0.6em");
  4774. $.ajax({
  4775. url: "system/modules/getDefault",
  4776. data: {opr: "launch", ext: fd.Ext},
  4777. method: "GET",
  4778. success: function(data){
  4779. if (data.error == undefined){
  4780. let iconSize = 20;
  4781. let topOffset = $(imageContainer).height() - iconSize/2 + 2;
  4782. $(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>`);
  4783. }
  4784. }
  4785. });
  4786. }
  4787. }
  4788. })
  4789. });
  4790. }
  4791. function openfm() {
  4792. //Open file explorer on desktop
  4793. newFloatWindow({
  4794. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent("user:/Desktop"),
  4795. appicon: "SystemAO/file_system/img/small_icon.png",
  4796. width: 1080,
  4797. height: 580,
  4798. title: "File Manager"
  4799. });
  4800. hideAllContextMenus();
  4801. }
  4802. /*
  4803. Notification and Notification bar related functions
  4804. Usage:
  4805. title -> The title of the notification
  4806. content -> The content of the notification
  4807. icon (optional) -> The icon of the notification
  4808. windowOpenOption (optional) -> The window opening option for user onclick redirection
  4809. */
  4810. function sendNotification(title, content, icon="notice circle", windowOpenOption=null){
  4811. if (content.length > 100){
  4812. shortenContent = content.substring(0,100) + "...";
  4813. }else{
  4814. shortenContent = content;
  4815. }
  4816. onClickOpenWindowOption = encodeURIComponent(JSON.parse(windowOpenOption));
  4817. $("#notificationlist").append(` <div class="notification object" originalcontent="${content}" redirect="${onClickOpenWindowOption}" onclick="openNotification(this);">
  4818. <p class="title"><i class="${icon} icon"></i> ${title}</p>
  4819. <p class="notifycontent">${shortenContent}</p>
  4820. <div class="closebtn" onclick="event.stopImmediatePropagation(); closeThisNotification(this);"><i class="remove icon"></i></div>
  4821. <div class="ts divider"></div>
  4822. </div>`);
  4823. $(".nonotification").hide();
  4824. }
  4825. function openNotification(obj){
  4826. newWindowOpeningOption = JSON.parse(decodeURIComponent($(obj).attr("redirect")));
  4827. if (newWindowOpeningOption == null){
  4828. //Ignore
  4829. }else{
  4830. //Start a floatWindow to the given target
  4831. newFloatWindow(newWindowOpeningOption);
  4832. }
  4833. //Clear the notiication
  4834. closeThisNotification($(obj).find(".closebtn"));
  4835. }
  4836. function closeThisNotification(obj){
  4837. $(obj).parent().slideUp("fast",function(data){
  4838. $(this).remove();
  4839. if ($(".notification.object").length == 0){
  4840. $(".nonotification").show();
  4841. }
  4842. });
  4843. }
  4844. function clearAllNotification(){
  4845. $(".notification.object").slideUp('fast',function(data){
  4846. $(this).remove();
  4847. $(".nonotification").show();
  4848. });
  4849. }
  4850. function hideAllContextMenus() {
  4851. $("#subcontextmenu").hide();
  4852. $("#contextmenu").hide()
  4853. $("#quickAccessPanel").slideUp("fast");
  4854. }
  4855. function restart(){
  4856. if (!hardwareman){
  4857. return
  4858. }
  4859. var apiObject = {
  4860. api: "/system/power/restart",
  4861. data: {},
  4862. title: applocale.getString("power/restart/text", "Password Required"),
  4863. desc: applocale.getString("power/restart/instruction", "for restarting the ArozOS Host"),
  4864. thisuser: true, //This username as default, set to false for entering other user
  4865. method: "GET"
  4866. }
  4867. apiObject = encodeURIComponent(JSON.stringify(apiObject));
  4868. newFloatWindow({
  4869. url: "SystemAO/security/authreq.html#" + apiObject,
  4870. width: 480,
  4871. height: 300,
  4872. appicon: "SystemAO/security/img/lock.svg",
  4873. title: applocale.getString("power/restart/title", "Restart - Authentication Required"),
  4874. parent: ao_module_windowID,
  4875. callback: "handleRestartCallback"
  4876. });
  4877. }
  4878. function shutdown(){
  4879. if (!hardwareman){
  4880. return
  4881. }
  4882. var apiObject = {
  4883. api: "system/power/shutdown",
  4884. data: {},
  4885. title: `<i class='red exclamation triangle icon'></i> ${applocale.getString("power/shutdown/text", "Shutdown Host")} <i class='red exclamation triangle icon'></i>`,
  4886. desc: applocale.getString("power/shutdown/instruction", "Please enter your password to confirm operation."),
  4887. thisuser: true, //This username as default, set to false for entering other user
  4888. method: "GET",
  4889. success: "SystemAO/boot/shutdown.html" //Success redirection
  4890. }
  4891. apiObject = encodeURIComponent(JSON.stringify(apiObject));
  4892. newFloatWindow({
  4893. url: "SystemAO/security/authreq.html#" + apiObject,
  4894. width: 480,
  4895. height: 300,
  4896. appicon: "SystemAO/security/img/lock.svg",
  4897. title: applocale.getString("power/shutdown/title", "Shutdown - Authentication Required"),
  4898. parent: ao_module_windowID,
  4899. callback: "handleShutdownCallback"
  4900. });
  4901. }
  4902. //Check if this server is a low memory one
  4903. function initUploadMode(){
  4904. $.ajax({
  4905. url: "system/info/getRAMinfo",
  4906. success: function(data){
  4907. if (data.error !== undefined){
  4908. //Permission denied or other reasons that cannot access harwdare info. Use default mode
  4909. lowMemoryMode = true;
  4910. }else{
  4911. //Check if ramsize > 1.8 GB (2GB). If yes, switch to large memory upload mode
  4912. var memsize = JSON.parse(data);
  4913. if (parseFloat(memsize)/ 1024 / 1024 / 1024 >= 3.8){
  4914. console.log("%c[Desktop] Setting upload mode to large memory mode", 'color: #2ba16e');
  4915. lowMemoryMode = false;
  4916. }
  4917. }
  4918. },
  4919. error: function(){
  4920. //Hardware mode disabled. Always use low memory upload mode instead
  4921. lowMemoryMode = true;
  4922. }
  4923. });
  4924. }
  4925. //Generate a loading icon for this upload task
  4926. function generateUploadingIcon(filename, position){
  4927. //Get position for appending
  4928. var onScreenLocation = getLocationFromGridIndex(position[0], position[1]);
  4929. //Append to UI
  4930. var uploadIconUUID = Date.now();
  4931. $("#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;">
  4932. <span class="launchIconWrapper">
  4933. <img class="launchIconImage medium" src="img/desktop/files_icon/${desktopIconPack}/file upload.png" draggable="false">
  4934. <p class="launchIconText ${desktopIconSize}" >${applocale.getString( "upload/message/uploading", "Uploading")}</p>
  4935. <div class="ts tiny primary progress" style="margin-top: -4px;">
  4936. <div class="bar" style="min-width: 0px !important; width: 0%;"></div>
  4937. </div>
  4938. </span>
  4939. </div>`);
  4940. return uploadIconUUID;
  4941. }
  4942. function uploadFile(file, callback=undefined, uploadingIconUUID = undefined) {
  4943. if (lowMemoryMode){
  4944. /*
  4945. Low Memory Upload Mode
  4946. */
  4947. var filename = encodeURIComponent(file.name);
  4948. var filesize = file.size;
  4949. //Open the websocket
  4950. let path = "user:/Desktop";
  4951. let protocol = "wss://";
  4952. if (location.protocol !== 'https:') {
  4953. protocol = "ws://";
  4954. }
  4955. var port = window.location.port;
  4956. if (window.location.port == ""){
  4957. if (location.protocol !== 'https:') {
  4958. port = "80";
  4959. }else{
  4960. port = "443";
  4961. }
  4962. }
  4963. let uploadDir = "user:/Desktop";
  4964. //Fixing Firefox path issues on or above FF48.0
  4965. if (isFirefox && file.webkitRelativePath != ""){
  4966. //Use the webkitRelativePath instead of the name, this is a folder upload
  4967. let pathinfo = file.webkitRelativePath.split("/");
  4968. pathinfo.pop();
  4969. let subpath = pathinfo.join("/");
  4970. uploadDir = uploadDir + subpath;
  4971. }
  4972. let socket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/lowmemUpload?filename=" + filename + "&path=" + uploadDir);
  4973. let currentSendingIndex = 0;
  4974. let chunks = Math.ceil(file.size/uploadFileChunkSize,uploadFileChunkSize);
  4975. //Define a function for sending a particular chunk
  4976. function sendChunk(id, uploadingIconUUID){
  4977. let offsetStart = id*uploadFileChunkSize;
  4978. let offsetEnd = id*uploadFileChunkSize + uploadFileChunkSize;
  4979. let thisblob = file.slice(offsetStart,offsetEnd);
  4980. socket.send(thisblob);
  4981. //console.log(id + "/" + chunks);
  4982. //Update progress to first percentage
  4983. let progress = id / (chunks-1) * 100.0;
  4984. if (progress > 100){
  4985. progress = 100;
  4986. }
  4987. if (uploadingIconUUID != undefined){
  4988. //Update the progress on the object
  4989. $("." + uploadingIconUUID + ".launchIcon").find(".bar").css("width", progress + "%");
  4990. if (progress == 100){
  4991. $("." + uploadingIconUUID + ".launchIcon").find(".progress").addClass("indeterminate");
  4992. }
  4993. }
  4994. }
  4995. //Start sending
  4996. socket.onopen = function(e) {
  4997. if (filesize < uploadFileChunkSize){
  4998. //This file is smaller than chunk size, set it to somwhere within 10% - 20% so it doesn't look like it is stuck
  4999. $("." + uploadingIconUUID + ".launchIcon").find(".bar").css("width", "15%");
  5000. }
  5001. //Send the first chunk
  5002. sendChunk(0, uploadingIconUUID);
  5003. currentSendingIndex++;
  5004. };
  5005. socket.onmessage = function(event) {
  5006. //Append to the send index
  5007. var incomingValue = event.data;
  5008. if (incomingValue == "next"){
  5009. if (currentSendingIndex == chunks + 1){
  5010. //Already finished
  5011. socket.send("done");
  5012. }else{
  5013. //Send next chunk
  5014. sendChunk(currentSendingIndex, uploadingIconUUID);
  5015. currentSendingIndex++;
  5016. }
  5017. }else if (incomingValue == "OK"){
  5018. //Merge completed
  5019. }else{
  5020. //Try to parse it as JSON
  5021. try{
  5022. var resp = JSON.parse(incomingValue.split('\\' + '"').join("\""));
  5023. console.log(resp);
  5024. if (resp.error !== undefined){
  5025. //This is an error message
  5026. sendNotification("Upload Failed", resp.error, "remove")
  5027. //Update the progress bar to error
  5028. $("." + uploadingIconUUID + ".launchIcon").find(".progress").removeClass("primary").addClass("error");
  5029. $("." + uploadingIconUUID + ".launchIcon").find(".launchIconText").text(applocale.getString("upload/message/failed", "Failed!"));
  5030. setTimeout(function(){
  5031. $("." + uploadingIconUUID + ".launchIcon").fadeOut(3000,function() { $(this).remove(); });
  5032. }, 2000);
  5033. }
  5034. }catch(ex){
  5035. //Something else
  5036. console.log(incomingValue);
  5037. console.log(ex);
  5038. }
  5039. }
  5040. };
  5041. socket.onclose = function(event) {
  5042. if (callback != undefined){
  5043. callback();
  5044. }
  5045. };
  5046. socket.onerror = function(error) {
  5047. console.log(error.message);
  5048. console.log("[Desktop] Unable to open WebSocket connection. Fall back to FORM POST upload mode. (Check your nginx / reverse proxy settings!!!)")
  5049. //Try to fallback to FORM POST upload mode
  5050. lowMemoryMode = false;
  5051. uploadFile(thisFile, callback)
  5052. return
  5053. };
  5054. }else{
  5055. let url = 'system/file_system/upload'
  5056. let uploadCurrentPath = "user:/Desktop/";
  5057. let formData = new FormData();
  5058. let xhr = new XMLHttpRequest();
  5059. formData.append('file', file);
  5060. formData.append('path', uploadCurrentPath);
  5061. xhr.open('POST', url, true)
  5062. xhr.upload.addEventListener("progress", function(e) {
  5063. console.log((e.loaded * 100.0 / e.total) || 100)
  5064. var progress = (e.loaded * 100.0 / e.total) || 100;
  5065. if (uploadingIconUUID != undefined){
  5066. //Update the progress on the object
  5067. $("." + uploadingIconUUID + ".launchIcon").find(".bar").css("width", progress + "%");
  5068. if (progress == 100){
  5069. $("." + uploadingIconUUID + ".launchIcon").find(".progress").addClass("indeterminate");
  5070. }
  5071. }
  5072. })
  5073. xhr.addEventListener('readystatechange', function(e) {
  5074. if (xhr.readyState == 4 && xhr.status == 200) {
  5075. if (callback !== undefined){
  5076. callback(e.target.response);
  5077. }
  5078. }
  5079. else if (xhr.readyState == 4 && xhr.status != 200) {
  5080. console.log("Upload failed :" + xhr.status);
  5081. //Set upload progress bar to error
  5082. $("." + uploadingIconUUID + ".launchIcon").find(".progress").removeClass("primary").addClass("error");
  5083. $("." + uploadingIconUUID + ".launchIcon").find(".launchIconText").text(applocale.getString("upload/message/failed", "Failed!"));
  5084. setTimeout(function(){
  5085. $("." + uploadingIconUUID + ".launchIcon").fadeOut(3000,function() { $(this).remove(); });
  5086. }, 2000);
  5087. }
  5088. })
  5089. xhr.send(formData);
  5090. }
  5091. }
  5092. function setStorage(key, value, callback = undefined) {
  5093. $.get("system/desktop/preference?preference=" + key + "&value=" + value, function(data) {
  5094. if (data.error !== undefined) {
  5095. console.log(data.error);
  5096. } else {
  5097. if (callback !== undefined) {
  5098. callback();
  5099. }
  5100. }
  5101. });
  5102. }
  5103. function getStorage(key, callback) {
  5104. $.get("system/desktop/preference?preference=" + key, callback);
  5105. }
  5106. function showSystemSettings(){
  5107. var hasAccessToSetting = false;
  5108. moduleInstalled.forEach(thismod => {
  5109. if (thismod.Name == "System Setting"){
  5110. openModule("System Setting");
  5111. }
  5112. })
  5113. }
  5114. function initTheme(targetTheme=undefined){
  5115. if (targetTheme == undefined){
  5116. $.get("system/file_system/preference?key=file_explorer/theme", function(data){
  5117. if (data == "darkTheme"){
  5118. setDarkTheme();
  5119. }
  5120. });
  5121. }else{
  5122. //Manual override mode
  5123. if (targetTheme == "darkTheme"){
  5124. setDarkTheme();
  5125. }else if (targetTheme == "whiteTheme"){
  5126. setWhiteTheme();
  5127. }
  5128. }
  5129. }
  5130. function setFloatWindowTheme(fwid, theme="dark"){
  5131. var targetFW = getFloatWindowByID(fwid);
  5132. if (theme == "dark"){
  5133. $(targetFW).removeClass("white");
  5134. }else if (theme == "white"){
  5135. $(targetFW).addClass("white");
  5136. }
  5137. }
  5138. function checkFileSystemAccess(){
  5139. var allowReadWrite = false;
  5140. moduleInstalled.forEach(thisModule => {
  5141. if (thisModule.Name == "File Manager"){
  5142. //This user has read write access to file system
  5143. allowReadWrite = true;
  5144. }
  5145. });
  5146. if (!allowReadWrite){
  5147. sendNotification("READ ONLY Account", "This account is read only. You cannot perform any file operations on this desktop.");
  5148. }
  5149. }
  5150. function setDarkTheme(){
  5151. $("#listMenu").addClass("darkTheme");
  5152. $("#powerIcon").attr("src","img/system/power-white.svg");
  5153. $("#quickAccessPanel").addClass("darkTheme");
  5154. $("#quickAccessPanel").find(".button").addClass("inverted");
  5155. }
  5156. function setWhiteTheme(){
  5157. $("#listMenu").removeClass("darkTheme");
  5158. $("#powerIcon").attr("src","img/system/power.svg");
  5159. $("#quickAccessPanel").removeClass("darkTheme");
  5160. $("#quickAccessPanel").find(".button").removeClass("inverted");
  5161. }
  5162. function hexToRgbA(hex, transparent=1){
  5163. var c;
  5164. if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
  5165. c= hex.substring(1).split('');
  5166. if(c.length== 3){
  5167. c= [c[0], c[0], c[1], c[1], c[2], c[2]];
  5168. }
  5169. c= '0x'+c.join('');
  5170. return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',' + transparent + ')';
  5171. }
  5172. throw new Error('Bad Hex');
  5173. }
  5174. function setThemeColor(newThemeColor){
  5175. //Update the global theme color
  5176. desktopThemeColor = newThemeColor;
  5177. //Update the related elements
  5178. $("#statusbar").css("background-color",newThemeColor);
  5179. $("#navimenu").css("background-color",hexToRgbA(newThemeColor, 0.5));
  5180. $(".floatWindow .controls").css("background-color",hexToRgbA(newThemeColor, 0.85));
  5181. //List menu theme color bar
  5182. $("#listMenu").find(".searchBar").css("border-bottom", "2px solid " + newThemeColor);
  5183. $("#volumebar").css("background-color", newThemeColor);
  5184. //Connection lost notification css
  5185. $("#connectionLost").find(".ts.card").css("background-color", hexToRgbA(newThemeColor, 0.5));
  5186. }
  5187. //Load the user define theme color to overwrite the default color if exists
  5188. function initUserDefinedThemeColor(){
  5189. $.ajax({
  5190. url: "system/file_system/preference",
  5191. data: {key: "themecolor"},
  5192. success: function(data){
  5193. if (data.error == undefined && data != ""){
  5194. setThemeColor(data);
  5195. }
  5196. }
  5197. });
  5198. }
  5199. //Float Window context menu
  5200. function getFocusedFloatWindowID(){
  5201. var targetFloatWindowId = "";
  5202. $(".floatWindow").each(function() {
  5203. var thisWindowZIndex = $(this).css("z-index");
  5204. if (parseInt(thisWindowZIndex) == 101){
  5205. targetFloatWindowId = $(this).attr("windowid");
  5206. }
  5207. });
  5208. return targetFloatWindowId;
  5209. }
  5210. function getFocusedFloatWindow(){
  5211. var focusedFwId = getFocusedFloatWindowID();
  5212. if (focusedFwId != ""){
  5213. var fw = getFloatWindowByID(focusedFwId);
  5214. return fw;
  5215. }else{
  5216. return undefined;
  5217. }
  5218. }
  5219. function refreshSelectedFloatWindow(target, event){
  5220. var fw = getFocusedFloatWindow();
  5221. if (fw != undefined){
  5222. $(fw).find("iframe")[0].contentWindow.location.reload();
  5223. }
  5224. hideAllContextMenus();
  5225. }
  5226. function maximizeSelectedFloatWindow(target, event){
  5227. var fw = getFocusedFloatWindow();
  5228. if (fw != undefined){
  5229. toggleMax($(fw).find(".buttons.maxtoggle"),event);
  5230. }
  5231. hideAllContextMenus();
  5232. }
  5233. function minimizeSelectedFloatWindow(target, event){
  5234. var fw = getFocusedFloatWindow();
  5235. if (fw != undefined){
  5236. min($(fw).find(".buttons.mintoggle"),event);
  5237. }
  5238. hideAllContextMenus();
  5239. }
  5240. function openSelectedFloatWindowInNewTab(){
  5241. var fw = getFocusedFloatWindow();
  5242. if (fw != undefined){
  5243. var currentURL = $(fw).find("iframe")[0].contentWindow.location;
  5244. window.open(currentURL);
  5245. }
  5246. hideAllContextMenus();
  5247. }
  5248. function closeSelectedFloatWindow(target, event){
  5249. var fw = getFocusedFloatWindow();
  5250. if (fw != undefined){
  5251. closeFloatWindow($(fw).find(".buttons.closetoggle"),event);
  5252. }
  5253. hideAllContextMenus();
  5254. }
  5255. function fullscreen() {
  5256. //Opening full screen will lead to hidden of all iframe for unknown reasons
  5257. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
  5258. (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
  5259. (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
  5260. (document.msFullscreenElement && document.msFullscreenElement !== null);
  5261. var elem = document.documentElement;
  5262. if (!isInFullScreen) {
  5263. if (elem.requestFullscreen) {
  5264. elem.requestFullscreen();
  5265. } else if (elem.mozRequestFullScreen) { /* Firefox */
  5266. elem.mozRequestFullScreen();
  5267. } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
  5268. elem.webkitRequestFullscreen();
  5269. } else if (elem.msRequestFullscreen) { /* IE/Edge */
  5270. elem.msRequestFullscreen();
  5271. }
  5272. } else {
  5273. if (document.exitFullscreen) {
  5274. document.exitFullscreen();
  5275. } else if (document.webkitExitFullscreen) {
  5276. document.webkitExitFullscreen();
  5277. } else if (document.mozCancelFullScreen) {
  5278. document.mozCancelFullScreen();
  5279. } else if (document.msExitFullscreen) {
  5280. document.msExitFullscreen();
  5281. }
  5282. }
  5283. hideAllContextMenus();
  5284. }
  5285. /*
  5286. Background services for keeping desktop files updated
  5287. Same mechanism is used as file explorer
  5288. */
  5289. let desktopFileHash = "";
  5290. setInterval(function(){
  5291. getDesktopHash(function(hash){
  5292. if (desktopFileHash == ""){
  5293. //Initialization
  5294. desktopFileHash = hash;
  5295. }else if (desktopFileHash != hash){
  5296. //Changed on desktop files. Refresh
  5297. refresh(undefined, true);
  5298. desktopFileHash = hash;
  5299. }
  5300. //Else, no file change on desktop
  5301. });
  5302. }, 15000);
  5303. function generateCSRFToken(callback){
  5304. $.ajax({
  5305. url: "../../system/csrf/new",
  5306. success: function(token){
  5307. callback(token);
  5308. }
  5309. })
  5310. }
  5311. function getDesktopHash(callback){
  5312. $.ajax({
  5313. url: "system/file_system/listDirHash",
  5314. data: {dir: "user:/Desktop/"},
  5315. success: function(data){
  5316. if (data.error !== undefined){
  5317. }
  5318. callback(data);
  5319. }
  5320. })
  5321. }
  5322. function bindObjectToIMEEvents(object){
  5323. object.addEventListener("keydown", function(event){
  5324. if (window.ime && window.ime.handler != null){
  5325. window.ime.handler(event);
  5326. }else{
  5327. //No IME handler. Just continue the input
  5328. }
  5329. });
  5330. object.addEventListener("focus", function(event){
  5331. if (window.ime){
  5332. //IME exists. Set this field to focused field
  5333. window.ime.focus = event.target;
  5334. }
  5335. });
  5336. }
  5337. </script>
  5338. </body>
  5339. </html>