desktop.system 274 KB

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