Exemplo n.º 1
0
 static public DevServerHostDialog GetInstance()
 {
     if (_instance == null)
     {
         _instance = new DevServerHostDialog();
     }
     return(_instance);
 }
        public void ShowDevOptionsDialog()
        {
            if (_devOptionsDialog != null || !IsEnabled)
            {
                return;
            }
            Log.Info(ReactConstants.Tag, "Before build DevOptionHandler");
            DispatcherHelpers.RunOnDispatcher(() =>
            {
                var options = new[]
                {
                    new DevOptionHandler(
                        "Reload JavaScript",
                        HandleReloadJavaScript),
                    new DevOptionHandler(
                        IsRemoteDebuggingEnabled
                            ? "Stop JS Remote Debugging"
                            : "Start JS Remote Debugging",
                        () =>
                    {
                        IsRemoteDebuggingEnabled = !IsRemoteDebuggingEnabled;
                        HandleReloadJavaScript();
                    }),
                    new DevOptionHandler(
                        _devSettings.IsHotModuleReplacementEnabled
                            ? "Disable Hot Reloading"
                            : "Enable Hot Reloading",
                        () =>
                    {
                        _devSettings.IsHotModuleReplacementEnabled = !_devSettings.IsHotModuleReplacementEnabled;
                        HandleReloadJavaScript();
                    }),
                    new DevOptionHandler(
                        _devSettings.IsReloadOnJavaScriptChangeEnabled
                            ? "Disable Live Reload"
                            : "Enable Live Reload",
                        () =>
                        _devSettings.IsReloadOnJavaScriptChangeEnabled =
                            !_devSettings.IsReloadOnJavaScriptChangeEnabled),
                    new DevOptionHandler(
                        _devSettings.IsElementInspectorEnabled
                            ? "Hide Inspector"
                            : "Show Inspector",
                        () =>
                    {
                        _devSettings.IsElementInspectorEnabled = !_devSettings.IsElementInspectorEnabled;
                        _reactInstanceCommandsHandler.ToggleElementInspector();
                    }),
                    new DevOptionHandler(
                        "Set Host IP Address",
                        () =>
                    {
                        _devSettings.DebugServerHost = "109.123.120.200:8084";
                        _devServerHostDialog         = DevServerHostDialog.GetInstance();
                        HideDevOptionsDialog();
                        _devServerHostDialog.Show();
                        _devServerHostDialog.ResetCloseEvent();
                        _devServerHostDialog.Closed += (dialog, __) =>
                        {
                            var ipText = ((DevServerHostDialog)dialog).text;
                            if (ipText.IndexOf(':') == -1)
                            {
                                ipText += ":8081";
                            }
                            _devSettings.DebugServerHost = ipText;
                            Log.Info(ReactConstants.Tag, "IP is " + ipText);
                        };
                    }),
                };

                _devOptionsDialogOpen = true;
                _devOptionsDialog     = DevOptionDialog.GetInstance();
                _devOptionsDialog.ResetCloseEvent();
                _devOptionsDialog.Closed += (_, __) =>
                {
                    _devOptionsDialogOpen    = false;
                    _dismissDevOptionsDialog = null;
                    _devOptionsDialog        = null;
                };

                foreach (var option in options)
                {
                    _devOptionsDialog.Add(option);
                }

                if (_redBoxDialog != null)
                {
                    _dismissRedBoxDialog();
                }


                if (Application.Current != null && ReactProgram.RctWindow != null)
                {
                    _devOptionsDialog.Owner = ReactProgram.RctWindow;
                }

                _dismissDevOptionsDialog = _devOptionsDialog.Close;
                _devOptionsDialog.Show();

                foreach (var option in options)
                {
                    option.HideDialog = _dismissDevOptionsDialog;
                }
            });
        }