desktop.system 305 KB

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