desktop.system 282 KB

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