desktop.system 270 KB

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