예제 #1
0
 public void MessageError(string message)
 {
     new NSObject().InvokeOnMainThread(() => // BeginInvokeOnMainThread
     {
         GuiUtils.MessageBoxError(message);
     });
 }
예제 #2
0
        public void Log(LogEntry l)
        {
            string msg = l.Message;

            TableLogsController.AddLog(l);

            if (l.Type >= LogType.InfoImportant)
            {
                RequestAttention();
            }

            if (l.Type == LogType.Fatal)
            {
                GuiUtils.MessageBoxError(msg);
            }
        }
예제 #3
0
        public override void OnReceive(Json data)
        {
            base.OnReceive(data);

            string cmd = data["command"].Value as string;

            if (cmd == "log")
            {
                if (data["type"].Value as string == "fatal")
                {
                    if (SplashWindow != null)
                    {
                        SplashWindow.MessageError(data["message"].Value as string);
                    }
                    else if (MainWindow != null)
                    {
                        MainWindow.MessageError(data["message"].Value as string);
                    }
                    else
                    {
                        GuiUtils.MessageBoxError(data["message"].Value as string);
                    }
                }
            }
            else if (cmd == "init.step")
            {
                if (SplashWindow != null)
                {
                    SplashWindow.SetStatus(data["message"].Value as string);
                }
            }
            else if (cmd == "engine.ui")
            {
                SplashWindow.SetStatus("Loading UI");

                //UpdateInterfaceStyle();

                new NSObject().InvokeOnMainThread(() => // BeginInvokeOnMainThread
                {
                    MainWindow        = new MainWindowController();
                    bool startVisible = Engine.Storage.GetBool("gui.osx.visible");
                    if (startVisible)
                    {
                        MainWindow.Window.MakeKeyAndOrderFront(null);
                    }
                    else
                    {
                        MainWindow.Window.IsVisible = false;
                    }
                    UiClient.Instance.SplashWindow.RequestCloseForReady();
                });
            }
            else if (cmd == "ui.notification")
            {
                if (MainWindow != null)
                {
                    new NSObject().InvokeOnMainThread(() => // BeginInvokeOnMainThread
                    {
                        MainWindow.ShowNotification(data["message"].Value as string, data["level"].Value as string);
                    });
                }
            }
            else if (cmd == "ui.status")
            {
                if (MainWindow != null)
                {
                    string textFull  = data["full"].Value as string;
                    string textShort = textFull;
                    if (data.HasKey("short"))
                    {
                        textShort = data["short"].Value as string;
                    }

                    new NSObject().InvokeOnMainThread(() => // BeginInvokeOnMainThread
                    {
                        MainWindow.SetStatus(textFull, textShort);
                    });
                }
            }
            else if (cmd == "ui.main-status")
            {
                string appIcon       = data["app_icon"].Value as string;
                string appColor      = data["app_color"].Value as string;
                string actionIcon    = data["action_icon"].Value as string;
                string actionCommand = data["action_command"].Value as string;
                string actionText    = data["action_text"].Value as string;

                if (MainWindow != null)
                {
                    new NSObject().InvokeOnMainThread(() => // BeginInvokeOnMainThread
                    {
                        MainWindow.SetMainStatus(appIcon, appColor, actionIcon, actionCommand, actionText);
                    });
                }
            }
            else if (cmd == "ui.updater.available")
            {
                new NSObject().InvokeOnMainThread(() => // BeginInvokeOnMainThread
                {
                    MainWindow.ShowUpdater();
                });
            }
            else if (cmd == "ui.frontmessage")
            {
                new NSObject().InvokeOnMainThread(() => // BeginInvokeOnMainThread
                {
                    MainWindow.FrontMessage(data["message"].Value as Json);
                });
            }
            else if (cmd == "system.report.progress")
            {
                string step = data["step"].Value as string;
                string text = data["body"].Value as string;
                int    perc = Conversions.ToInt32(data["perc"].Value, 0);

                if (MainWindow != null)
                {
                    new NSObject().InvokeOnMainThread(() => // BeginInvokeOnMainThread
                    {
                        if ((m_windowReport == null) || (m_windowReport.Window.IsVisible == false))
                        {
                            m_windowReport = new WindowReportController();
                            GuiUtils.ShowWindowWithFocus(m_windowReport, this.MainWindow);
                        }

                        if (m_windowReport != null)
                        {
                            m_windowReport.SetStep(step, text, perc);
                        }
                    });
                }
            }
        }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            Window.Title = Constants.Name + " - " + Messages.WindowsSettingsTitle;

            TableTabsController = new TableTabsController(TableTabs, TabMain);

            ChkNetLock.Activated += (object sender, EventArgs e) =>
            {
                if (GuiUtils.GetCheck(ChkNetLock))
                {
                    if ((Engine.Instance as UI.Cocoa.Osx.Engine).MainWindow.NetworkLockKnowledge() == false)
                    {
                        GuiUtils.SetCheck(ChkNetLock, false);
                    }
                }
            };

            TableRoutes.Delegate = new TableRoutingDelegate(this);

            LblDnsServers.StringValue = Messages.WindowsSettingsDnsServers;
            TableDnsServers.Delegate  = new TableDnsServersDelegate(this);

            TableAdvancedEvents.Delegate = new TableAdvancedEventsDelegate(this);

            LblLoggingHelp.StringValue = Messages.WindowsSettingsLoggingHelp;

            TableRoutingController        = new TableRoutingController(this.TableRoutes);
            TableDnsServersController     = new TableDnsServersController(this.TableDnsServers);
            TableAdvancedEventsController = new TableAdvancedEventsController(this.TableAdvancedEvents);

            CmdSave.Activated += (object sender, EventArgs e) =>
            {
                try
                {
                    if (Check())
                    {
                        SaveOptions();
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    Core.Engine.Instance.Logs.Log(LogType.Fatal, ex);
                }
            };

            CmdCancel.Activated += (object sender, EventArgs e) =>
            {
                Close();
            };

            // General

            CmdGeneralTos.Activated += (object sender, EventArgs e) =>
            {
                WindowTosController tos = new WindowTosController();
                tos.Window.ReleasedWhenClosed = true;
                NSApplication.SharedApplication.RunModalForWindow(tos.Window);
                tos.Window.Close();
            };

            CmdResetToDefault.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.Instance.OnAskYesNo(Messages.ResetSettingsConfirm))
                {
                    Engine.Instance.Storage.ResetAll(false);
                    ReadOptions();
                    GuiUtils.MessageBoxInfo(Messages.ResetSettingsDone);
                }
            };

            // UI

            CboUiUnit.RemoveAllItems();
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit0);
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit1);
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit2);

            // Protocols

            CmdProtocolsHelp1.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.protocols");
            };

            CmdProtocolsHelp2.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.udp_vs_tcp");
            };

            ChkProtocolsAutomatic.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };

            TableProtocols.Delegate  = new TableProtocolsDelegate(this);
            TableProtocolsController = new TableProtocolsController(this.TableProtocols);

            // Proxy
            CboProxyType.RemoveAllItems();
            CboProxyType.AddItem("None");
            CboProxyType.AddItem("Http");
            CboProxyType.AddItem("Socks");
            CboProxyType.AddItem("Tor");
            CboProxyWhen.RemoveAllItems();
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenAlways);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenWeb);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenOpenVPN);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenNone);

            CmdProxyTorHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.tor");
            };
            CboProxyType.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();

                if (GuiUtils.GetSelected(CboProxyType) == "Tor")
                {
                    TxtProxyPort.StringValue = "9150";
                }
                else
                {
                    TxtProxyPort.StringValue = "8080";
                }
            };
            CboProxyAuthentication.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };
            CmdProxyTorTest.Activated += (object sender, EventArgs e) =>
            {
                string result = TorControl.Test(TxtProxyHost.StringValue, Conversions.ToInt32(TxtProxyTorControlPort.StringValue), TxtProxyTorControlPassword.StringValue);
                GuiUtils.MessageBoxInfo(result);
            };

            // Routes
            CboRoutesOtherwise.RemoveAllItems();
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("in"));
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("out"));
            CboRoutesOtherwise.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };

            TableRoutes.DoubleClick += (object sender, EventArgs e) =>
            {
                RouteEdit();
            };

            CmdRouteAdd.Activated += (object sender, EventArgs e) =>
            {
                RouteAdd();
            };

            CmdRouteRemove.Activated += (object sender, EventArgs e) =>
            {
                RouteRemove();
            };

            CmdRouteEdit.Activated += (object sender, EventArgs e) =>
            {
                RouteEdit();
            };

            // Advanced - General

            CmdAdvancedHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.advanced");
            };

            CboIpV6.RemoveAllItems();
            CboIpV6.AddItem("None");
            CboIpV6.AddItem("Disable");

            CboAdvancedManifestRefresh.RemoveAllItems();
            CboAdvancedManifestRefresh.AddItem("Automatic");
            CboAdvancedManifestRefresh.AddItem("Never");
            CboAdvancedManifestRefresh.AddItem("Every minute");
            CboAdvancedManifestRefresh.AddItem("Every ten minute");
            CboAdvancedManifestRefresh.AddItem("Every one hour");

            LblOpenVpnRcvBuf.StringValue = Messages.WindowsSettingsOpenVpnRcvBuf + ":";
            LblOpenVpnSndBuf.StringValue = Messages.WindowsSettingsOpenVpnSndBuf + ":";
            CboOpenVpnRcvBuf.RemoveAllItems();
            CboOpenVpnRcvBuf.AddItem(Messages.Automatic);
            CboOpenVpnRcvBuf.AddItem(Messages.WindowsSettingsOpenVpnDefault);
            CboOpenVpnRcvBuf.AddItem("8 KB");
            CboOpenVpnRcvBuf.AddItem("16 KB");
            CboOpenVpnRcvBuf.AddItem("32 KB");
            CboOpenVpnRcvBuf.AddItem("64 KB");
            CboOpenVpnRcvBuf.AddItem("128 KB");
            CboOpenVpnRcvBuf.AddItem("256 KB");
            CboOpenVpnRcvBuf.AddItem("512 KB");
            CboOpenVpnSndBuf.RemoveAllItems();
            CboOpenVpnSndBuf.AddItem(Messages.Automatic);
            CboOpenVpnSndBuf.AddItem(Messages.WindowsSettingsOpenVpnDefault);
            CboOpenVpnSndBuf.AddItem("8 KB");
            CboOpenVpnSndBuf.AddItem("16 KB");
            CboOpenVpnSndBuf.AddItem("32 KB");
            CboOpenVpnSndBuf.AddItem("64 KB");
            CboOpenVpnSndBuf.AddItem("128 KB");
            CboOpenVpnSndBuf.AddItem("256 KB");
            CboOpenVpnSndBuf.AddItem("512 KB");

            CmdAdvancedOpenVpnPath.Activated += (object sender, EventArgs e) =>
            {
                GuiUtils.SelectFile(this.Window, TxtAdvancedOpenVpnPath);
            };


            // Advanced - DNS
            TableDnsServers.DoubleClick += (object sender, EventArgs e) =>
            {
                DnsServersEdit();
            };

            CmdDnsAdd.Activated += (object sender, EventArgs e) =>
            {
                DnsServersAdd();
            };

            CmdDnsRemove.Activated += (object sender, EventArgs e) =>
            {
                DnsServersRemove();
            };

            CmdDnsEdit.Activated += (object sender, EventArgs e) =>
            {
                DnsServersEdit();
            };

            // Advanced - Net Lock
            CmdLockHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.lock");
            };
            CboLockMode.RemoveAllItems();
            CboLockMode.AddItem("None");
            CboLockMode.AddItem("Automatic");
            foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes)
            {
                CboLockMode.AddItem(lockPlugin.GetName());
            }

            LblRoutesNetworkLockWarning.StringValue = Messages.WindowsSettingsRouteLockHelp;
            LblLockRoutingOutWarning.StringValue    = Messages.NetworkLockNotAvailableWithRouteOut;

            // Advanced - Logging

            TxtLoggingPath.Changed += (object sender, EventArgs e) =>
            {
                RefreshLogPreview();
            };

            CmdLoggingOpen.Activated += (object sender, EventArgs e) =>
            {
                List <string> paths = Engine.Instance.Logs.ParseLogFilePath(TxtLoggingPath.StringValue);
                foreach (string path in paths)
                {
                    if (Core.Platform.Instance.OpenDirectoryInFileManager(path) == false)
                    {
                        GuiUtils.MessageBoxError(MessagesFormatter.Format(Messages.WindowsSettingsLogsCannotOpenDirectory, path));
                    }
                }
            };

            // Directives
            CboOpenVpnDirectivesSkipDefault.RemoveAllItems();
            CboOpenVpnDirectivesSkipDefault.AddItem(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1);
            CboOpenVpnDirectivesSkipDefault.AddItem(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2);
            CmdOpenVpnDirectivesHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.directives");
            };
            CmdOpenVpnDirectivesCustomPathBrowse.Activated += (object sender, EventArgs e) =>
            {
                GuiUtils.SelectFile(this.Window, TxtOpenVpnDirectivesCustomPath);
            };

            // Advanced - Events

            TableAdvancedEvents.DoubleClick += (object sender, EventArgs e) =>
            {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsEdit.Activated += (object sender, EventArgs e) =>
            {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsClear.Activated += (object sender, EventArgs e) =>
            {
                AdvancedEventClear();
            };

            ReadOptions();

            EnableIde();

            RefreshLogPreview();
        }