desktop.system 282 KB

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