desktop.system 314 KB

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