desktop.system 280 KB

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