desktop.system 239 KB

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