desktop.system 266 KB

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