desktop.system 280 KB

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