Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions InvisibleMan-XRay/Assets/Localization/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
<system:String x:Key="Lang.ToolTip.Update">Update</system:String>

<system:String x:Key="Lang.Notify.Open">Open Invisible Man XRay</system:String>
<system:String x:Key="Lang.Notify.Run">Run</system:String>
<system:String x:Key="Lang.Notify.Stop">Stop</system:String>
<system:String x:Key="Lang.Notify.Mode">Mode</system:String>
<system:String x:Key="Lang.Notify.Update">Check for updates</system:String>
<system:String x:Key="Lang.Notify.About">About</system:String>
Expand Down
2 changes: 2 additions & 0 deletions InvisibleMan-XRay/Assets/Localization/fa-IR.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
<system:String x:Key="Lang.ToolTip.Update">بروزرسانی</system:String>

<system:String x:Key="Lang.Notify.Open">باز کردن برنامه</system:String>
<system:String x:Key="Lang.Notify.Run">اجرا</system:String>
<system:String x:Key="Lang.Notify.Stop">توقف</system:String>
<system:String x:Key="Lang.Notify.Mode">حالت</system:String>
<system:String x:Key="Lang.Notify.Update">بررسی بروزرسانی</system:String>
<system:String x:Key="Lang.Notify.About">درباره</system:String>
Expand Down
2 changes: 2 additions & 0 deletions InvisibleMan-XRay/Assets/Localization/ru-RU.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
<system:String x:Key="Lang.ToolTip.Update">Обновить</system:String>

<system:String x:Key="Lang.Notify.Open">Открыть Invisible Man XRay</system:String>
<system:String x:Key="Lang.Notify.Run">Запуск</system:String>
<system:String x:Key="Lang.Notify.Stop">Стоп</system:String>
<system:String x:Key="Lang.Notify.Mode">Режим</system:String>
<system:String x:Key="Lang.Notify.Update">Проверить обновления</system:String>
<system:String x:Key="Lang.Notify.About">О программе</system:String>
Expand Down
2 changes: 2 additions & 0 deletions InvisibleMan-XRay/Assets/Localization/zh-Hans.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
<system:String x:Key="Lang.ToolTip.Update">更新</system:String>

<system:String x:Key="Lang.Notify.Open">打开主界面</system:String>
<system:String x:Key="Lang.Notify.Run">运行</system:String>
<system:String x:Key="Lang.Notify.Stop">停止</system:String>
<system:String x:Key="Lang.Notify.Mode">代理模式</system:String>
<system:String x:Key="Lang.Notify.Update">检查更新</system:String>
<system:String x:Key="Lang.Notify.About">关于</system:String>
Expand Down
4 changes: 3 additions & 1 deletion InvisibleMan-XRay/Factories/WindowFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public MainWindow CreateMainWindow()
BroadcastHandler broadcastHandler = handlersManager.GetHandler<BroadcastHandler>();
SettingsHandler settingsHandler = handlersManager.GetHandler<SettingsHandler>();
LinkHandler linkHandler = handlersManager.GetHandler<LinkHandler>();
NotifyHandler notifyHandler = handlersManager.GetHandler<NotifyHandler>();

MainWindow mainWindow = new MainWindow();
mainWindow.Setup(
Expand All @@ -54,7 +55,8 @@ public MainWindow CreateMainWindow()
onGenerateClientId: settingsHandler.GenerateClientId,
onGitHubClick: linkHandler.OpenGitHubRepositoryLink,
onBugReportingClick: linkHandler.OpenBugReportingLink,
onCustomLinkClick: linkHandler.OpenCustomLink
onCustomLinkClick: linkHandler.OpenCustomLink,
onChangeRunningStatus: notifyHandler.UpdateConnectionStatus
);

return mainWindow;
Expand Down
54 changes: 36 additions & 18 deletions InvisibleMan-XRay/Handlers/NotifyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class NotifyHandler : Handler, IDisposable
private Action onCloseClick;
private Action onProxyModeClick;
private Action onTunnelModeClick;
private Action onSwitchConnectionClick;

private Dictionary<Mode, ToolStripMenuItem> modeItems;

Expand All @@ -35,7 +36,8 @@ public void Setup(
Action onAboutClick,
Action onCloseClick,
Action onProxyModeClick,
Action onTunnelModeClick
Action onTunnelModeClick,
Action onSwitchConnectionClick
)
{
this.getMode = getMode;
Expand All @@ -45,6 +47,14 @@ Action onTunnelModeClick
this.onCloseClick = onCloseClick;
this.onProxyModeClick = onProxyModeClick;
this.onTunnelModeClick = onTunnelModeClick;
this.onSwitchConnectionClick = onSwitchConnectionClick;
}

public void UpdateConnectionStatus(bool isRunning)
{
string switchConnectionLocalizationKey = isRunning ? Localization.NOTIFY_STOP : Localization.NOTIFY_RUN;
ToolStripItem switchConnectionMenuItem = notifyIcon.ContextMenuStrip.Items.Find(Localization.NOTIFY_RUN, false).First();
switchConnectionMenuItem.Text = LocalizationService.GetTerm(switchConnectionLocalizationKey);
}

public void CheckModeItem(Mode mode)
Expand Down Expand Up @@ -88,42 +98,44 @@ private void AddMenuStrip()
{
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
modeItems = new Dictionary<Mode, ToolStripMenuItem>() {
{ Mode.PROXY, CreateItem("Proxy", OnProxyModeClick, true, getMode.Invoke() == Mode.PROXY) },
{ Mode.TUN, CreateItem("TUN", OnTunnelModeClick, true, getMode.Invoke() == Mode.TUN) }
{ Mode.PROXY, CreateItem(nameof(Mode.PROXY), "Proxy", OnProxyModeClick, true, getMode.Invoke() == Mode.PROXY) },
{ Mode.TUN, CreateItem(nameof(Mode.TUN), "TUN", OnTunnelModeClick, true, getMode.Invoke() == Mode.TUN) }
};

AddMenuItem(LocalizationService.GetTerm(Localization.NOTIFY_OPEN), OnOpenClick);
AddMenuItem(LocalizationService.GetTerm(Localization.NOTIFY_MODE), delegate { }, modeItems.Values.ToArray());
AddMenuItem(LocalizationService.GetTerm(Localization.NOTIFY_UPDATE), OnUpdateClick);
AddMenuItem(LocalizationService.GetTerm(Localization.NOTIFY_ABOUT), OnAboutClick);
AddMenuItem(LocalizationService.GetTerm(Localization.NOTIFY_CLOSE), OnCloseClick);

AddMenuItem(Localization.NOTIFY_OPEN, LocalizationService.GetTerm(Localization.NOTIFY_OPEN), OnOpenClick);
AddMenuItem(Localization.NOTIFY_RUN, LocalizationService.GetTerm(Localization.NOTIFY_RUN), OnSwitchConnectionClick);
AddMenuItem(Localization.NOTIFY_MODE, LocalizationService.GetTerm(Localization.NOTIFY_MODE), delegate { }, modeItems.Values.ToArray());
AddMenuItem(Localization.NOTIFY_UPDATE, LocalizationService.GetTerm(Localization.NOTIFY_UPDATE), OnUpdateClick);
AddMenuItem(Localization.NOTIFY_ABOUT, LocalizationService.GetTerm(Localization.NOTIFY_ABOUT), OnAboutClick);
AddMenuItem(Localization.NOTIFY_CLOSE, LocalizationService.GetTerm(Localization.NOTIFY_CLOSE), OnCloseClick);

notifyIcon.ContextMenuStrip = contextMenuStrip;

void AddMenuItem(string text, Action onClick, ToolStripMenuItem[] children = default)
void AddMenuItem(string key, string text, Action onClick, ToolStripMenuItem[] children = default)
{
ToolStripMenuItem item = CreateItem(text, onClick);
ToolStripMenuItem item = CreateItem(key, text, onClick);

if (children != null)
foreach(ToolStripMenuItem child in children)
item.DropDownItems.Add(child);

contextMenuStrip.Items.Add(item);
}

ToolStripMenuItem CreateItem(
string text,
Action onClick,
string key,
string text,
Action onClick,
bool isToggle = default,
bool isChecked = default
)
{
ToolStripMenuItem item = new ToolStripMenuItem() { Text = text, Checked = isChecked };
item.Click += (sender, e) => {
ToolStripMenuItem item = new ToolStripMenuItem() { Name = key, Text = text, Checked = isChecked };
item.Click += (sender, e) => {
HandleToggleClick();
onClick.Invoke();
onClick.Invoke();
};

return item;

void HandleToggleClick()
Expand Down Expand Up @@ -154,6 +166,12 @@ void OnOpenClick()
onOpenClick.Invoke();
}

void OnSwitchConnectionClick()
{
AnalyticsService.SendEvent(new SwitchConnectionClickedEvent());
onSwitchConnectionClick.Invoke();
}

void OnUpdateClick()
{
AnalyticsService.SendEvent(new CheckForUpdateClickedEvent());
Expand Down
11 changes: 9 additions & 2 deletions InvisibleMan-XRay/Managers/Initializers/HandlersInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ void SetupNotifyHandler()
onUpdateClick: OpenUpdateWindow,
onAboutClick: OpenAboutWindow,
onCloseClick: CloseApplication,
onProxyModeClick: () => { OnModeClick(Mode.PROXY); },
onTunnelModeClick: () => { OnModeClick(Mode.TUN); }
onProxyModeClick: () => OnModeClick(Mode.PROXY),
onTunnelModeClick: () => OnModeClick(Mode.TUN),
onSwitchConnectionClick: () => OnSwitchConnectionClick()
);

void CloseApplication()
Expand Down Expand Up @@ -137,6 +138,12 @@ void OnModeClick(Mode mode)
}
}

void OnSwitchConnectionClick()
{
MainWindow mainWindow = windowFactory.GetMainWindow();
mainWindow.SwitchConnection();
}

void SetupDeepLinkHandler()
{
HandlersManager.GetHandler<DeepLinkHandler>().Setup(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace InvisibleManXRay.Services.Analytics.Notify
{
public class SwitchConnectionClickedEvent : NotifyEvent
{

}
}
2 changes: 2 additions & 0 deletions InvisibleMan-XRay/Values/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static class Localization
public const string CANT_TUNNEL_SYSTEM = "Lang.Message.CantTunnelSystem";
public const string NO_LOG_FILE = "Lang.Message.NoLogFile";
public const string NO_FILE_CHOOSEN = "Lang.Message.NoFileChoosen";
public const string NOTIFY_RUN = "Lang.Notify.Run";
public const string NOTIFY_STOP = "Lang.Notify.Stop";
public const string NOTIFY_OPEN = "Lang.Notify.Open";
public const string NOTIFY_MODE = "Lang.Notify.Mode";
public const string NOTIFY_UPDATE = "Lang.Notify.Update";
Expand Down
43 changes: 42 additions & 1 deletion InvisibleMan-XRay/Windows/MainWindow/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace InvisibleManXRay

public partial class MainWindow : Window
{
private enum ConnectionStatus { STOPPED, WAITING, RUNNING }

private bool isRerunRequest;

private Func<bool> isNeedToShowPolicyWindow;
Expand All @@ -35,6 +37,7 @@ public partial class MainWindow : Window
private Action onGitHubClick;
private Action onBugReportingClick;
private Action<string> onCustomLinkClick;
private Action<bool> onChangeRunningStatus;

private BackgroundWorker runWorker;
private BackgroundWorker updateWorker;
Expand Down Expand Up @@ -233,7 +236,9 @@ public void Setup(
Action onGenerateClientId,
Action onGitHubClick,
Action onBugReportingClick,
Action<string> onCustomLinkClick)
Action<string> onCustomLinkClick,
Action<bool> onChangeRunningStatus
)
{
this.isNeedToShowPolicyWindow = isNeedToShowPolicyWindow;
this.shouldStartHidden = shouldStartHidden;
Expand All @@ -256,6 +261,7 @@ public void Setup(
this.onGitHubClick = onGitHubClick;
this.onBugReportingClick = onBugReportingClick;
this.onCustomLinkClick = onCustomLinkClick;
this.onChangeRunningStatus = onChangeRunningStatus;

UpdateUI();
}
Expand Down Expand Up @@ -301,6 +307,24 @@ public void TryDisableModeAndRerun()
isRerunRequest = true;
}

public void SwitchConnection()
{
ConnectionStatus status = GetCurrentConnectionStatus();

switch(status)
{
case ConnectionStatus.RUNNING:
OnStopButtonClick(null, null);
break;
case ConnectionStatus.WAITING:
OnCancelButtonClick(null, null);
break;
default:
OnRunButtonClick(null, null);
break;
}
}

private void OnManageServersClick(object sender, RoutedEventArgs e)
{
OpenServerWindow();
Expand Down Expand Up @@ -433,6 +457,8 @@ private void ShowRunStatus()
buttonStop.Visibility = Visibility.Visible;
buttonCancel.Visibility = Visibility.Hidden;
buttonRun.Visibility = Visibility.Hidden;

onChangeRunningStatus.Invoke(true);
}

private void ShowStopStatus()
Expand All @@ -444,6 +470,8 @@ private void ShowStopStatus()
buttonRun.Visibility = Visibility.Visible;
buttonCancel.Visibility = Visibility.Hidden;
buttonStop.Visibility = Visibility.Hidden;

onChangeRunningStatus.Invoke(false);
}

private void ShowWaitForRunStatus()
Expand All @@ -455,6 +483,19 @@ private void ShowWaitForRunStatus()
buttonCancel.Visibility = Visibility.Visible;
buttonRun.Visibility = Visibility.Hidden;
buttonStop.Visibility = Visibility.Hidden;

onChangeRunningStatus.Invoke(true);
}

private ConnectionStatus GetCurrentConnectionStatus()
{
if (statusWaitForRun.Visibility == Visibility.Visible)
return ConnectionStatus.WAITING;

if (statusRun.Visibility == Visibility.Visible)
return ConnectionStatus.RUNNING;

return ConnectionStatus.STOPPED;
}

protected override void OnClosing(CancelEventArgs e)
Expand Down