desktop.system 236 KB

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