desktop.system 310 KB

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