private void UpdateDisconnectedUITheme(bool isPaused) { GuiConnectButtonImage.Image = Colors.IsDarkMode ? NSImage.ImageNamed("buttonConnectDark") : NSImage.ImageNamed("buttonConnect"); if (isPaused == false) { GuiConnectButtonText.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Button_Connect"), Colors.ConnectButtonTextColor, NSTextAlignment.Center); GuiLabelToDoDescription.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Label_ClickToConnect"), __ToDoDescriptionTextColor, NSTextAlignment.Center); } else { GuiConnectButtonText.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Button_Resume"), Colors.ConnectButtonTextColor, NSTextAlignment.Center); GuiLabelToDoDescription.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Label_ClickToResume"), __ToDoDescriptionTextColor, NSTextAlignment.Center); } }
private void InitDefaultNetworkActionsButton() { NSMenuItem menuUntrusted = new NSMenuItem("", OnNetworksDefaultAction_Changed) { AttributedTitle = AttributedString.Create(LocalizedStrings.Instance.LocalizedString("NetworkConfig_Untrusted"), NSColor.SystemRedColor, NSTextAlignment.Left), Tag = (int)NetworkActionsConfig.WiFiActionTypeEnum.Untrusted }; NSMenuItem menuTrusted = new NSMenuItem("", OnNetworksDefaultAction_Changed) { AttributedTitle = AttributedString.Create(LocalizedStrings.Instance.LocalizedString("NetworkConfig_Trusted"), NSColor.SystemBlueColor, NSTextAlignment.Left), Tag = (int)NetworkActionsConfig.WiFiActionTypeEnum.Trusted }; NSMenuItem menuNoAction = new NSMenuItem("", OnNetworksDefaultAction_Changed) { AttributedTitle = AttributedString.Create(LocalizedStrings.Instance.LocalizedString("NetworkConfig_NoAction"), NSColor.SystemGrayColor, NSTextAlignment.Left), Tag = (int)NetworkActionsConfig.WiFiActionTypeEnum.None }; NetworksDefaultActionBtn.Menu.RemoveAllItems(); NetworksDefaultActionBtn.Menu.AddItem(menuUntrusted); NetworksDefaultActionBtn.Menu.AddItem(menuTrusted); NetworksDefaultActionBtn.Menu.AddItem(menuNoAction); if (NetworksDefaultActionBtn.Menu.Delegate == null) { NetworksDefaultActionBtn.Menu.Delegate = new MenuDelegateInvertHighlitedItem(); } NetworksDefaultActionBtn.SelectItemWithTag((int)__Settings.NetworkActions.DefaultActionType); }
public override void WindowDidLoad() { base.WindowDidLoad(); GuiBtnLaunchAtLogin.IntValue = (__Settings.RunOnLogin) ? 1 : 0; // Add 'WARNING' text of red color to the WireGuard description text NSMutableAttributedString wgDescriptionText = new NSMutableAttributedString(); var warningStr = AttributedString.Create("WARNING: ", NSColor.Red, GuiWireGuardDescription.Alignment, GuiWireGuardDescription.Font); wgDescriptionText.Insert(GuiWireGuardDescription.AttributedStringValue, 0); wgDescriptionText.Insert(warningStr, 0); GuiWireGuardDescription.AttributedStringValue = wgDescriptionText; }
private void Initialize() { _timerHideWnd.Elapsed += OnTimerHideWindowEvent; this.Window.OnDoubleClick += () => { OnDoubleClick?.Invoke(); }; this.Window.OnClick += () => { OnClick?.Invoke(); }; Window.IsVisible = false; Window.AlphaValue = 0.9f; // set background colors Window.BackgroundColor = WindowBackgroundColor; FirewallStatusLabel.TextColor = TextStatusColor; VPNStatusLabel.TextColor = TextStatusColor; PauseTimeLeftLabel.TextColor = TextStatusColor; FirewallLabel.TextColor = TextLabelColor; VPNLabel.TextColor = TextLabelColor; ResumeInLabel.TextColor = TextLabelColor; NSImage resumeBtnImage = NSImage.ImageNamed("iconPlayWhite"); resumeBtnImage.Size = new CoreGraphics.CGSize(9, 12); ResumeBtn.Image = resumeBtnImage; ResumeBtn.TitleTextAttributedString = AttributedString.Create(" " + __appServices.LocalizedString("Button_Resume"), NSColor.White, null, UIUtils.GetSystemFontOfSize(12f, NSFontWeight.Semibold)); ResumeBtn.BackgroundColor = NSColor.Black; ResumeBtn.IconLocation = CustomButton.IconLocationEnum.Right; ResumeBtn.CornerRadius = 7; // locationg UI elements on right place // (some elements are located not on rihght places (in order to easiest view in Xcode designer during developing)) nfloat offset = FirewallLabel.Frame.Y - ResumeInLabel.Frame.Y; CoreGraphics.CGRect oldFrame = Window.Frame; Window.SetFrame(new CoreGraphics.CGRect(oldFrame.X, oldFrame.Y + offset, oldFrame.Width, oldFrame.Height - offset), false); // update data according to ViewModel (on property changed) __viewModel = new FloatingOverlayWindowViewModel(__AppState, __service, __appServices, __MainViewModel); __viewModel.PropertyChanged += _viewModel_PropertyChanged; __viewModel.Initialize(); __MainViewModel.PropertyChanged += MainViewModel_PropertyChanged; EnsureUIConsistent(); }
private void ShowConnectedAnimation() { View.IsVisibleCircles = false; GuiConnectButtonImage.Hidden = false; GuiConnectButtonText.Hidden = false; UpdateToDoLabelHiddenStatus(false); GuiConnectButtonImage.AlphaValue = 0f; GuiLabelToDoDescription.AlphaValue = 0f; GuiConnectButtonText.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Button_Disconnect"), __ConnectedButtonTextColor, NSTextAlignment.Center); GuiConnectButtonText.AlphaValue = 1f; GuiLabelToDoDescription.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Label_ClickToDisconnect"), __ToDoDescriptionTextColor, NSTextAlignment.Center); GuiConnectButtonImage.Image = NSImage.ImageNamed("buttonConnected"); var frame = GuiConnectButtonImage.Frame; CGRect oldBounds = new CGRect(0, 0, frame.Width, frame.Height); nfloat offset = frame.Width * 0.1f; CGRect newBounds = new CGRect(-offset, -offset, oldBounds.Width + offset * 2, oldBounds.Height + offset * 2); GuiConnectButtonImage.Bounds = newBounds; NSAnimationContext.RunAnimation((NSAnimationContext context) => { context.Duration = 0.5f; ((NSView)GuiConnectButtonImage.Animator).Bounds = oldBounds; ((NSView)GuiConnectButtonImage.Animator).AlphaValue = 1f; ((NSView)GuiLabelToDoDescription.Animator).AlphaValue = 1f; }, () => { GuiConnectButtonImage.Bounds = oldBounds; ShowConnectedStatusAtimation(); }); }
private void ShowDisconnectingAnimation(bool isPausing = false) { View.IsVisibleCircles = true; if (isPausing == false) { GuiConnectButtonText.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Button_Disconnecting"), Colors.ConnectButtonTextColor, NSTextAlignment.Center); } else { GuiConnectButtonText.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Button_Pausing"), Colors.ConnectButtonTextColor, NSTextAlignment.Center); } GuiConnectButtonText.AlphaValue = 1f; UpdateToDoLabelHiddenStatus(true); var frame = GuiConnectButtonImage.Frame; CGRect oldBounds = new CGRect(0, 0, frame.Width, frame.Height); nfloat offset = frame.Width * 0.4f; CGRect newBounds = new CGRect(-offset, -offset, oldBounds.Width + offset * 2, oldBounds.Height + offset * 2); GuiConnectButtonImage.Bounds = oldBounds; NSAnimationContext.RunAnimation((NSAnimationContext context) => { context.Duration = 0.5f; ((NSView)GuiConnectButtonImage.Animator).Bounds = newBounds; ((NSView)GuiConnectButtonImage.Animator).AlphaValue = 0f; }, () => { GuiConnectButtonImage.Bounds = oldBounds; }); AnimateButtonTextBlinking(); }
private void RecreateNetworkActionsButtonItems() { NSMenuItem menuUntrusted = new NSMenuItem("", NetworkActionButton_Changed) { AttributedTitle = AttributedString.Create(GetActionName(WiFiActionTypeEnum.Untrusted), NSColor.SystemRedColor, NSTextAlignment.Center), Tag = (int)WiFiActionTypeEnum.Untrusted }; NSMenuItem menuTrusted = new NSMenuItem("", NetworkActionButton_Changed) { AttributedTitle = AttributedString.Create(GetActionName(WiFiActionTypeEnum.Trusted), NSColor.SystemBlueColor, NSTextAlignment.Center), Tag = (int)WiFiActionTypeEnum.Trusted }; NSMenuItem menuNoAction = new NSMenuItem("", NetworkActionButton_Changed) { AttributedTitle = AttributedString.Create(GetActionName(WiFiActionTypeEnum.None), NSColor.Black, NSTextAlignment.Center), Tag = (int)WiFiActionTypeEnum.None }; NSMenuItem menuDefaultAction = new NSMenuItem("", NetworkActionButton_Changed) { AttributedTitle = (__MainViewModel.WiFiActionType == WiFiActionTypeEnum.Default && __MainViewModel.Settings.NetworkActions.DefaultActionType == WiFiActionTypeEnum.None) ? AttributedString.Create(LocalizedStrings.Instance.LocalizedString("NetworkConfig_ActionNotSet"), NSColor.SystemGrayColor, NSTextAlignment.Center) : AttributedString.Create(GetActionName(WiFiActionTypeEnum.Default) + ": " + GetActionName(__MainViewModel.Settings.NetworkActions.DefaultActionType), NSColor.SystemGrayColor, NSTextAlignment.Center), Tag = (int)WiFiActionTypeEnum.Default }; GuiNetworkActionPopUpBtn.Menu.RemoveAllItems(); GuiNetworkActionPopUpBtn.Menu.AddItem(menuUntrusted); GuiNetworkActionPopUpBtn.Menu.AddItem(menuTrusted); //GuiNetworkActionPopUpBtn.Menu.AddItem(menuNoAction); // 'No action' available only for 'Default' action GuiNetworkActionPopUpBtn.Menu.AddItem(menuDefaultAction); GuiNetworkActionPopUpBtn.SelectItemWithTag((int)__MainViewModel.WiFiActionType); if (GuiNetworkActionPopUpBtn.Menu.Delegate == null) { GuiNetworkActionPopUpBtn.Menu.Delegate = new MenuDelegateInvertHighlitedItem(); } }
private void ShowConnectingAnimation(bool isResuming = false) { if (!NSThread.IsMain) { InvokeOnMainThread(() => ShowConnectingAnimation(isResuming)); return; } // prepare GUI controls GuiConnectButtonImage.Hidden = false; GuiConnectButtonImage.Image = Colors.IsDarkMode ? NSImage.ImageNamed("buttonConnectDark") : NSImage.ImageNamed("buttonConnecting"); if (isResuming == false) { GuiConnectButtonText.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Button_Connecting"), Colors.ConnectButtonTextColor, NSTextAlignment.Center); } else { GuiConnectButtonText.AttributedStringValue = AttributedString.Create( LocalizedStrings.Instance.LocalizedString("Button_Resuming"), Colors.ConnectButtonTextColor, NSTextAlignment.Center); } GuiConnectButtonText.AlphaValue = 1f; View.IsVisibleCircles = false; // initialize animation NSColor startCircleColor = Colors.ConnectiongAnimationCircleColor; UpdateToDoLabelHiddenStatus(true); __animationLayer.FillColor = NSColor.Clear.CGColor; __animationLayer.StrokeColor = startCircleColor.CGColor; var frame = GuiConnectButtonImage.Frame; var startCircle = CGPath.EllipseFromRect( new CGRect(frame.X + 6, frame.Y + 6, frame.Width - 12, frame.Height - 12) ); var endCircle = CGPath.EllipseFromRect( new CGRect(frame.X + 3, frame.Y + 3, frame.Width - 6, frame.Height - 6) ); CABasicAnimation circleRadiusAnimation = CABasicAnimation.FromKeyPath("path"); circleRadiusAnimation.From = FromObject(startCircle); circleRadiusAnimation.To = FromObject(endCircle); CABasicAnimation lineWidthAnimation = CABasicAnimation.FromKeyPath("lineWidth"); lineWidthAnimation.From = FromObject(1); lineWidthAnimation.To = FromObject(8); CAAnimationGroup animationGroup = new CAAnimationGroup(); animationGroup.Animations = new CAAnimation[] { circleRadiusAnimation, lineWidthAnimation }; animationGroup.Duration = 1f; animationGroup.RepeatCount = float.PositiveInfinity; animationGroup.AutoReverses = true; __animationLayer.AddAnimation(animationGroup, null); AnimateButtonTextBlinking(); }
private void UpdateWiFiInfoGuiData() { if (!NSThread.IsMain) { InvokeOnMainThread(() => UpdateWiFiInfoGuiData()); return; } try { UpdateToDoLabelHiddenStatus(); WifiState state = __MainViewModel.WiFiState; if (__MainViewModel.Settings.IsNetworkActionsEnabled == false) { GuiWiFiButton.Hidden = true; GuiNetworkActionPopUpBtn.Hidden = true; return; } NSFont wifiLabelFont = UIUtils.GetSystemFontOfSize(14, NSFontWeight.Thin); if (state == null || string.IsNullOrEmpty(state.Network.SSID)) { GuiWiFiButton.AttributedTitle = AttributedString.Create(LocalizedStrings.Instance.LocalizedString("Label_NoWiFiConnection"), NSColor.SystemGrayColor, NSTextAlignment.Center, wifiLabelFont); GuiWiFiButton.Image = null; GuiWiFiButton.Enabled = false; GuiWiFiButton.Hidden = false; GuiNetworkActionPopUpBtn.Hidden = true; } else { if (state.ConnectedToInsecureNetwork) { GuiWiFiButton.Image = NSImage.ImageNamed("iconWiFiSmallRed"); string networkName = " " + state.Network.SSID + " "; string fullText = networkName + "(" + LocalizedStrings.Instance.LocalizedString("Label_InsecureWiFiConnection") + ") "; NSMutableAttributedString attrTitle = new NSMutableAttributedString(fullText); NSStringAttributes stringAttributes0 = new NSStringAttributes(); stringAttributes0.ForegroundColor = __ToDoDescriptionTextColor; stringAttributes0.Font = wifiLabelFont; NSStringAttributes stringAttributes1 = new NSStringAttributes(); stringAttributes1.ForegroundColor = NSColor.SystemRedColor; stringAttributes1.Font = wifiLabelFont; attrTitle.AddAttributes(stringAttributes0, new NSRange(0, networkName.Length)); attrTitle.AddAttributes(stringAttributes1, new NSRange(networkName.Length, fullText.Length - networkName.Length)); attrTitle.SetAlignment(NSTextAlignment.Center, new NSRange(0, fullText.Length)); GuiWiFiButton.AttributedTitle = attrTitle; } else { GuiWiFiButton.Image = NSImage.ImageNamed("iconWiFiSmallBlue"); GuiWiFiButton.AttributedTitle = AttributedString.Create(" " + state.Network.SSID, __ToDoDescriptionTextColor, NSTextAlignment.Center, wifiLabelFont); } RecreateNetworkActionsButtonItems(); GuiWiFiButton.Enabled = true; GuiWiFiButton.Hidden = false; GuiNetworkActionPopUpBtn.Hidden = false; } } catch (Exception ex) { GuiWiFiButton.Hidden = true; GuiNetworkActionPopUpBtn.Hidden = true; Logging.Info($"{ex}"); } }
public override void AwakeFromNib() { base.AwakeFromNib(); // Disable title-bar (but keep close/minimize/expand buttons on content-view) // IMPORTANT! 'FullSizeContentView' implemented since OS X 10.10 !!! Window.TitleVisibility = NSWindowTitleVisibility.Hidden; Window.TitlebarAppearsTransparent = true; Window.StyleMask |= NSWindowStyle.FullSizeContentView; // Progress indicator if (!__SessionStatus.IsActive) { __DaysLeft = 0; } // Normally we should show it days left <= 3 // if '__DaysLeft' > 3 - set max value to __DaysLeft+1 int maxValue = 3; if (__DaysLeft > 3) { maxValue = __DaysLeft + 1; } GuiProgressIndicator.MinValue = 0; GuiProgressIndicator.MaxValue = maxValue; GuiProgressIndicator.DoubleValue = maxValue - __DaysLeft; string cancelBtnText = LocalizedStrings.Instance.LocalizedString("Button_ContinueTrial"); string subscriptionBtnText; if (__SessionStatus.IsOnFreeTrial) { subscriptionBtnText = LocalizedStrings.Instance.LocalizedString("Button_GetSubscription"); } else { subscriptionBtnText = LocalizedStrings.Instance.LocalizedString("Button_RenewSubscription"); } // BUTTON Continue Trial GuiButtonCancel.Gradient = new NSGradient(NSColor.FromRgb(240, 244, 247), NSColor.FromRgb(240, 244, 247)); GuiButtonCancel.BorderColor = NSColor.SystemGrayColor; GuiButtonCancel.TitleForegroundColor = NSColor.Black; GuiButtonCancel.TitleFont = UIUtils.GetSystemFontOfSize(13f, NSFontWeight.Medium); GuiButtonCancel.TitleText = cancelBtnText; // BUTTON Get Subscription GuiButtonGoToAccount.Gradient = new NSGradient(NSColor.FromRgb(128, 187, 249), NSColor.FromRgb(17, 130, 254)); GuiButtonGoToAccount.BorderShadow = new NSShadow { ShadowOffset = new CoreGraphics.CGSize(0f, 1f), ShadowColor = NSColor.FromRgba(0, 0, 0, 0.18f) }; GuiButtonGoToAccount.TitleText = subscriptionBtnText; GuiButtonGoToAccount.TitleFont = UIUtils.GetSystemFontOfSize(13f, NSFontWeight.Medium); GuiButtonGoToAccount.TitleForegroundColor = NSColor.White; // TITLE if (!__SessionStatus.IsActive) { string title = LocalizedStrings.Instance.LocalizedString("Label_SubscriptionExpired"); if (__SessionStatus.IsOnFreeTrial) { title = LocalizedStrings.Instance.LocalizedString("Label_FreeTrialExpired"); } NSMutableAttributedString attrTitle = new NSMutableAttributedString(title); NSStringAttributes stringAttributes0 = new NSStringAttributes(); stringAttributes0.Font = UIUtils.GetSystemFontOfSize(20f, NSFontWeight.Medium); attrTitle.AddAttributes(stringAttributes0, new NSRange(0, title.Length)); GuiLabelTitleText.AttributedStringValue = attrTitle; // DESCRIPTION string description = LocalizedStrings.Instance.LocalizedString("Label_AccountDaysLeftDescription_Expired"); if (__SessionStatus.IsOnFreeTrial) { description = LocalizedStrings.Instance.LocalizedString("Label_TrialDaysLeftDescription_Expired"); } description = string.Format(description, __DaysLeft); GuiLabelDescriptionText.AttributedStringValue = AttributedString.Create(description, null, NSTextAlignment.Left); } else { string title; string daysStr = string.Format("{0}", __DaysLeft); if (__DaysLeft == 0) { title = LocalizedStrings.Instance.LocalizedString("Label_AccountDaysLeftTitle_LastDay_PARAMETRIZED"); if (__SessionStatus.IsOnFreeTrial) { title = LocalizedStrings.Instance.LocalizedString("Label_TrialDaysLeftTitle_LastDay_PARAMETRIZED"); } daysStr = ""; } else if (__DaysLeft == 1) { title = LocalizedStrings.Instance.LocalizedString("Label_AccountDaysLeftTitle_OneDay_PARAMETRIZED"); if (__SessionStatus.IsOnFreeTrial) { title = LocalizedStrings.Instance.LocalizedString("Label_TrialDaysLeftTitle_OneDay_PARAMETRIZED"); } } else { title = LocalizedStrings.Instance.LocalizedString("Label_AccountDaysLeftTitle_PARAMETRIZED"); if (__SessionStatus.IsOnFreeTrial) { title = LocalizedStrings.Instance.LocalizedString("Label_TrialDaysLeftTitle_PARAMETRIZED"); } } int numberSymbolPos = title.LastIndexOf("{0}", StringComparison.Ordinal); title = string.Format(title, daysStr); NSMutableAttributedString attrTitle = new NSMutableAttributedString(title); NSStringAttributes stringAttributes0 = new NSStringAttributes(); stringAttributes0.Font = UIUtils.GetSystemFontOfSize(20f, NSFontWeight.Medium); NSStringAttributes stringAttributes1 = new NSStringAttributes(); stringAttributes1.ForegroundColor = TitleDaysTextColor; attrTitle.AddAttributes(stringAttributes0, new NSRange(0, title.Length)); attrTitle.AddAttributes(stringAttributes1, new NSRange(numberSymbolPos, title.Length - numberSymbolPos)); GuiLabelTitleText.AttributedStringValue = attrTitle; // DESCRIPTION string description; if (__DaysLeft == 0) { description = LocalizedStrings.Instance.LocalizedString("Label_AccountDaysLeftDescription_LastDay"); if (__SessionStatus.IsOnFreeTrial) { description = LocalizedStrings.Instance.LocalizedString("Label_TrialDaysLeftDescription_LastDay"); } } else if (__DaysLeft == 1) { description = LocalizedStrings.Instance.LocalizedString("Label_AccountDaysLeftDescription_OneDay"); if (__SessionStatus.IsOnFreeTrial) { description = LocalizedStrings.Instance.LocalizedString("Label_TrialDaysLeftDescription_OneDay"); } } else { description = LocalizedStrings.Instance.LocalizedString("Label_AccountDaysLeftDescription_PARAMETRIZED"); if (__SessionStatus.IsOnFreeTrial) { description = LocalizedStrings.Instance.LocalizedString("Label_TrialDaysLeftDescription_PARAMETRIZED"); } } description = string.Format(description, __DaysLeft); GuiLabelDescriptionText.AttributedStringValue = AttributedString.Create(description, null, NSTextAlignment.Left); } }