desktop.system 282 KB

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