desktop.system 249 KB

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