< Summary

Class:DCL.MainDesktop
Assembly:MainDesktop
File(s):/tmp/workspace/explorer-desktop/unity-renderer-desktop/Assets/Scripts/MainScripts/DCL/MainDesktop/MainDesktop.cs
Covered lines:0
Uncovered lines:64
Coverable lines:64
Total lines:163
Line coverage:0% (0 of 64)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
InitializeDataStore()0%2100%
FeatureFlagsReady(...)0%2100%
InitializeCommunication()0%6200%
SetupPlugins()0%2100%
InitializeSettings()0%2100%
Dispose()0%2100%
DesktopDestroy()0%2100%
OnCommunicationEstablished(...)0%6200%
Update()0%30500%
Start()0%2100%
InitializeSceneDependencies()0%2100%
SetupServices()0%2100%

File(s)

/tmp/workspace/explorer-desktop/unity-renderer-desktop/Assets/Scripts/MainScripts/DCL/MainDesktop/MainDesktop.cs

#LineLine coverage
 1using System;
 2using DCL.SettingsCommon;
 3using DCL.Components;
 4using MainScripts.DCL.Controllers.HUD.Preloading;
 5using MainScripts.DCL.Controllers.LoadingFlow;
 6using MainScripts.DCL.Controllers.SettingsDesktop;
 7using MainScripts.DCL.Utils;
 8using UnityEngine;
 9using RPC;
 10
 11namespace DCL
 12{
 13    /// <summary>
 14    /// This is the MainDesktop entry point.
 15    /// Most of the application subsystems should be initialized from this class Awake() event.
 16    /// </summary>
 17    public class MainDesktop : Main
 18    {
 19        [SerializeField] private bool logWs = false;
 20        private LoadingFlowController loadingFlowController;
 21        private PreloadingController preloadingController;
 22        private bool isConnectionLost;
 023        private BaseVariable<FeatureFlag> featureFlags => DataStore.i.featureFlags.flags;
 24
 25        protected override void Awake()
 26        {
 027            CommandLineParserUtils.ParseArguments();
 028            isConnectionLost = false;
 29
 030            DCLVideoTexture.videoPluginWrapperBuilder = VideoProviderFactory.CreateVideoProvider;
 31
 032            featureFlags.OnChange += FeatureFlagsReady;
 33
 034            InitializeSettings();
 35
 036            base.Awake();
 037            DataStore.i.wsCommunication.communicationEstablished.OnChange += OnCommunicationEstablished;
 038            DataStore.i.performance.multithreading.Set(true);
 039            DataStore.i.performance.maxDownloads.Set(50);
 040            Texture.allowThreadedTextureCreation = true;
 041        }
 42
 43        protected override void InitializeDataStore()
 44        {
 045            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettingsDesktop.GLTF_TEX_MAX_SIZE_DESKTOP);
 046            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettingsDesktop.GENERAL_TEX_MAX_SIZE_DESKTOP)
 047            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 048        }
 49
 50        private void FeatureFlagsReady(FeatureFlag current, FeatureFlag previous)
 51        {
 052            DCLVideoTexture.videoPluginWrapperBuilder = VideoProviderFactory.CreateVideoProvider;
 053            DataStore.i.featureFlags.flags.OnChange -= FeatureFlagsReady;
 054        }
 55
 56        protected override void InitializeCommunication()
 57        {
 058            DataStore.i.debugConfig.logWs = logWs;
 59            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 60            //              IntegrationTestSuite_Legacy base class.
 061            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 62            {
 063                var withSSL = true;
 064                int startPort = CommandLineParserUtils.startPort;
 65
 66#if UNITY_EDITOR
 067                withSSL = DebugConfigComponent.i.webSocketSSL;
 068                startPort = 5000;
 69#endif
 70
 071                int endPort = startPort + 100;
 072                kernelCommunication = new WebSocketCommunication(withSSL, startPort, endPort);
 73            }
 074        }
 75
 76        protected override void SetupPlugins()
 77        {
 078            pluginSystem = PluginSystemFactoryDesktop.Create();
 079            pluginSystem.Initialize();
 080        }
 81
 82        private void InitializeSettings()
 83        {
 084            Settings.CreateSharedInstance(new DefaultSettingsFactory()
 85                .WithGraphicsQualitySettingsPresetPath("DesktopGraphicsQualityPresets"));
 086        }
 87
 88        protected override void Dispose()
 89        {
 90            try
 91            {
 092                DataStore.i.wsCommunication.communicationEstablished.OnChange -= OnCommunicationEstablished;
 93
 094                base.Dispose();
 095                DesktopDestroy();
 096            }
 97            catch (Exception e)
 98            {
 099                Debug.LogException(e);
 0100            }
 0101        }
 102
 103        private void DesktopDestroy()
 104        {
 0105            loadingFlowController.Dispose();
 0106            preloadingController.Dispose();
 107#if !AV_PRO_PRESENT
 0108            DCLVideoPlayer.StopAllThreads();
 109#endif
 0110        }
 111
 112        void OnCommunicationEstablished(bool current, bool previous)
 113        {
 0114            if (current == false && previous)
 115            {
 0116                isConnectionLost = true;
 117            }
 0118        }
 119
 120        protected override void Update()
 121        {
 0122            base.Update();
 0123            loadingFlowController.Update();
 124
 0125            if (isConnectionLost)
 126            {
 0127                DesktopUtils.Quit();
 128            }
 129
 130            // TODO: Remove this after we refactor InputController to support overrides from desktop or to use the lates
 131            // This shortcut will help some users to fix the small resolution bugs that may happen if the player prefs a
 0132            if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
 133                && Input.GetKeyDown(KeyCode.F11))
 134            {
 0135                DisplaySettings newDisplaySettings = new DisplaySettings { windowMode = WindowMode.Borderless };
 0136                SettingsDesktop.i.displaySettings.Apply(newDisplaySettings);
 0137                SettingsDesktop.i.displaySettings.Save();
 138            }
 0139        }
 140
 141        protected override void Start()
 142        {
 0143            loadingFlowController = new LoadingFlowController(
 144                DataStore.i.HUDs.loadingHUD.fatalError,
 145                DataStore.i.HUDs.loadingHUD.visible,
 146                CommonScriptableObjects.rendererState,
 147                DataStore.i.wsCommunication.communicationEstablished);
 148
 0149            base.Start();
 0150        }
 151
 152        protected override void InitializeSceneDependencies()
 153        {
 0154            base.InitializeSceneDependencies();
 0155            preloadingController = new PreloadingController();
 0156        }
 157
 158        protected override void SetupServices()
 159        {
 0160            Environment.Setup(ServiceLocatorDesktopFactory.CreateDefault());
 0161        }
 162    }
 163}