Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7ff7914

Browse files
committed
chore: added notifications for vpn lifecycle start/stop
1 parent29943c8 commit7ff7914

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

‎App/Views/TrayWindow.xaml.cs

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
usingMicrosoft.UI.Xaml.Controls;
1212
usingMicrosoft.UI.Xaml.Media.Animation;
1313
usingSystem;
14+
usingSystem.Collections.Generic;
1415
usingSystem.Runtime.InteropServices;
16+
usingSystem.Threading;
1517
usingSystem.Threading.Tasks;
1618
usingWindows.Graphics;
1719
usingWindows.System;
@@ -21,7 +23,7 @@
2123

2224
namespaceCoder.Desktop.App.Views;
2325

24-
publicsealedpartialclassTrayWindow:Window
26+
publicsealedpartialclassTrayWindow:Window,INotificationHandler
2527
{
2628
privateconstintWIDTH=300;
2729

@@ -33,17 +35,25 @@ public sealed partial class TrayWindow : Window
3335
privateint_lastWindowHeight;
3436
privateStoryboard?_currentSb;
3537

38+
privateVpnLifecycleprevVpnLifecycle=VpnLifecycle.Stopped;
39+
privateRpcLifecycleprevRpcLifecycle=RpcLifecycle.Disconnected;
40+
41+
privateNativeApi.POINT?_lastActivatePosition;
42+
3643
privatereadonlyIRpcController_rpcController;
3744
privatereadonlyICredentialManager_credentialManager;
3845
privatereadonlyISyncSessionController_syncSessionController;
3946
privatereadonlyIUpdateController_updateController;
47+
privatereadonlyIUserNotifier_userNotifier;
4048
privatereadonlyTrayWindowLoadingPage_loadingPage;
4149
privatereadonlyTrayWindowDisconnectedPage_disconnectedPage;
4250
privatereadonlyTrayWindowLoginRequiredPage_loginRequiredPage;
4351
privatereadonlyTrayWindowMainPage_mainPage;
4452

45-
publicTrayWindow(IRpcControllerrpcController,ICredentialManagercredentialManager,
53+
publicTrayWindow(
54+
IRpcControllerrpcController,ICredentialManagercredentialManager,
4655
ISyncSessionControllersyncSessionController,IUpdateControllerupdateController,
56+
IUserNotifieruserNotifier,
4757
TrayWindowLoadingPageloadingPage,
4858
TrayWindowDisconnectedPagedisconnectedPage,TrayWindowLoginRequiredPageloginRequiredPage,
4959
TrayWindowMainPagemainPage)
@@ -52,12 +62,14 @@ public TrayWindow(IRpcController rpcController, ICredentialManager credentialMan
5262
_credentialManager=credentialManager;
5363
_syncSessionController=syncSessionController;
5464
_updateController=updateController;
65+
_userNotifier=userNotifier;
5566
_loadingPage=loadingPage;
5667
_disconnectedPage=disconnectedPage;
5768
_loginRequiredPage=loginRequiredPage;
5869
_mainPage=mainPage;
5970

6071
InitializeComponent();
72+
_userNotifier.RegisterHandler("TrayWindow",this);
6173
AppWindow.Hide();
6274
Activated+=Window_Activated;
6375
RootFrame.SizeChanged+=RootFrame_SizeChanged;
@@ -142,9 +154,55 @@ private void SetPageByState(RpcModel rpcModel, CredentialModel credentialModel,
142154
}
143155
}
144156

157+
privatevoidNotifyUser(RpcModelrpcModel)
158+
{
159+
// This method is called when the state changes, but we don't want to notify
160+
// the user if the state hasn't changed.
161+
varisRpcLifecycleChanged=rpcModel.RpcLifecycle!=RpcLifecycle.Connecting&&prevRpcLifecycle!=rpcModel.RpcLifecycle;
162+
varisVpnLifecycleChanged=(rpcModel.VpnLifecycle==VpnLifecycle.Started||rpcModel.VpnLifecycle==VpnLifecycle.Stopped)&&prevVpnLifecycle!=rpcModel.VpnLifecycle;
163+
164+
if(!isRpcLifecycleChanged&&!isVpnLifecycleChanged)
165+
{
166+
return;
167+
}
168+
varmessage=string.Empty;
169+
// Compose the message based on the lifecycle changes
170+
if(isRpcLifecycleChanged)
171+
message+=rpcModel.RpcLifecycleswitch
172+
{
173+
RpcLifecycle.Connected=>"Connected to Coder vpn service.",
174+
RpcLifecycle.Disconnected=>"Disconnected from Coder vpn service.",
175+
_=>""// This will never be hit.
176+
};
177+
178+
if(message.Length>0&&isVpnLifecycleChanged)
179+
message+=" ";
180+
181+
if(isVpnLifecycleChanged)
182+
message+=rpcModel.VpnLifecycleswitch
183+
{
184+
VpnLifecycle.Started=>"Coder Connect started.",
185+
VpnLifecycle.Stopped=>"Coder Connect stopped.",
186+
_=>""// This will never be hit.
187+
};
188+
189+
// Save state for the next notification check
190+
prevRpcLifecycle=rpcModel.RpcLifecycle;
191+
prevVpnLifecycle=rpcModel.VpnLifecycle;
192+
193+
if(_aw.IsVisible)
194+
{
195+
return;// No need to notify if the window is not visible.
196+
}
197+
198+
// Trigger notification
199+
_userNotifier.ShowActionNotification(message,string.Empty,nameof(TrayWindow),null,CancellationToken.None);
200+
}
201+
145202
privatevoidRpcController_StateChanged(object?_,RpcModelmodel)
146203
{
147204
SetPageByState(model,_credentialManager.GetCachedCredentials(),_syncSessionController.GetState());
205+
NotifyUser(model);
148206
}
149207

150208
privatevoidCredentialManager_CredentialsChanged(object?_,CredentialModelmodel)
@@ -316,6 +374,11 @@ private void Tray_Exit()
316374
_=((App)Application.Current).ExitApplication();
317375
}
318376

377+
publicvoidHandleNotificationActivation(IDictionary<string,string>args)
378+
{
379+
Tray_Open();
380+
}
381+
319382
publicstaticclassNativeApi
320383
{
321384
[DllImport("dwmapi.dll")]
@@ -336,7 +399,7 @@ internal enum TaskbarPosition { Left, Top, Right, Bottom }
336399
internalreadonlyrecordstructTaskbarInfo(TaskbarPositionPosition,intGap,boolAutoHide);
337400

338401
// -----------------------------------------------------------------------------
339-
// Taskbar helpers ABM_GETTASKBARPOS / ABM_GETSTATE via SHAppBarMessage
402+
// Taskbar helpers ABM_GETTASKBARPOS / ABM_GETSTATE via SHAppBarMessage
340403
// -----------------------------------------------------------------------------
341404
privatestaticTaskbarInfoGetTaskbarInfo(DisplayAreaarea)
342405
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp