-
Notifications
You must be signed in to change notification settings - Fork 5
chore: add connect/disconnect notifications on Coder Connect #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ibetitsmike
wants to merge
7
commits into
main
Choose a base branch
from
mike/40-connect-notification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−9
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ff7914
chore: added notifications for vpn lifecycle start/stop
ibetitsmike 08d523f
added a default handler
ibetitsmike 9e12405
typo
ibetitsmike ea7d39b
format
ibetitsmike 87a6a78
remove unecessary change
ibetitsmike 370f3d2
PR review fixes
ibetitsmike 2411356
fmt fixes
ibetitsmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,12 @@ | |
using Microsoft.UI.Windowing; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Documents; | ||
using Microsoft.UI.Xaml.Media.Animation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Windows.Graphics; | ||
using Windows.System; | ||
|
@@ -33,17 +36,23 @@ public sealed partial class TrayWindow : Window | |
private int _lastWindowHeight; | ||
private Storyboard? _currentSb; | ||
|
||
private VpnLifecycle curVpnLifecycle = VpnLifecycle.Stopped; | ||
private RpcLifecycle curRpcLifecycle = RpcLifecycle.Disconnected; | ||
|
||
private readonly IRpcController _rpcController; | ||
private readonly ICredentialManager _credentialManager; | ||
private readonly ISyncSessionController _syncSessionController; | ||
private readonly IUpdateController _updateController; | ||
private readonly IUserNotifier _userNotifier; | ||
private readonly TrayWindowLoadingPage _loadingPage; | ||
private readonly TrayWindowDisconnectedPage _disconnectedPage; | ||
private readonly TrayWindowLoginRequiredPage _loginRequiredPage; | ||
private readonly TrayWindowMainPage _mainPage; | ||
|
||
public TrayWindow(IRpcController rpcController, ICredentialManager credentialManager, | ||
public TrayWindow( | ||
IRpcController rpcController, ICredentialManager credentialManager, | ||
ISyncSessionController syncSessionController, IUpdateController updateController, | ||
IUserNotifier userNotifier, | ||
TrayWindowLoadingPage loadingPage, | ||
TrayWindowDisconnectedPage disconnectedPage, TrayWindowLoginRequiredPage loginRequiredPage, | ||
TrayWindowMainPage mainPage) | ||
|
@@ -52,6 +61,7 @@ public TrayWindow(IRpcController rpcController, ICredentialManager credentialMan | |
_credentialManager = credentialManager; | ||
_syncSessionController = syncSessionController; | ||
_updateController = updateController; | ||
_userNotifier = userNotifier; | ||
_loadingPage = loadingPage; | ||
_disconnectedPage = disconnectedPage; | ||
_loginRequiredPage = loginRequiredPage; | ||
|
@@ -142,9 +152,54 @@ private void SetPageByState(RpcModel rpcModel, CredentialModel credentialModel, | |
} | ||
} | ||
|
||
private void MaybeNotifyUser(RpcModel rpcModel) | ||
{ | ||
// This method is called when the state changes, but we don't want to notify | ||
// the user if the state hasn't changed. | ||
var isRpcLifecycleChanged = rpcModel.RpcLifecycle == RpcLifecycle.Disconnected && curRpcLifecycle != rpcModel.RpcLifecycle; | ||
var isVpnLifecycleChanged = (rpcModel.VpnLifecycle == VpnLifecycle.Started || rpcModel.VpnLifecycle == VpnLifecycle.Stopped) && curVpnLifecycle != rpcModel.VpnLifecycle; | ||
|
||
if (!isRpcLifecycleChanged && !isVpnLifecycleChanged) | ||
{ | ||
return; | ||
} | ||
|
||
var oldRpcLifeycle = curRpcLifecycle; | ||
var oldVpnLifecycle = curVpnLifecycle; | ||
curRpcLifecycle = rpcModel.RpcLifecycle; | ||
curVpnLifecycle = rpcModel.VpnLifecycle; | ||
|
||
var messages = new List<string>(); | ||
|
||
if (oldRpcLifeycle != RpcLifecycle.Disconnected && curRpcLifecycle == RpcLifecycle.Disconnected) | ||
{ | ||
messages.Add("Disconnected from Coder background service."); | ||
} | ||
|
||
if (oldVpnLifecycle != curVpnLifecycle) | ||
{ | ||
switch (curVpnLifecycle) | ||
{ | ||
case VpnLifecycle.Started: | ||
messages.Add("Coder Connect started."); | ||
break; | ||
case VpnLifecycle.Stopped: | ||
messages.Add("Coder Connect stopped."); | ||
break; | ||
} | ||
} | ||
|
||
if (messages.Count == 0) return; | ||
if (_aw.IsVisible) return; | ||
|
||
var message = string.Join(" ", messages); | ||
_userNotifier.ShowActionNotification(message, string.Empty, null, null, CancellationToken.None); | ||
} | ||
|
||
private void RpcController_StateChanged(object? _, RpcModel model) | ||
{ | ||
SetPageByState(model, _credentialManager.GetCachedCredentials(), _syncSessionController.GetState()); | ||
MaybeNotifyUser(model); | ||
} | ||
|
||
private void CredentialManager_CredentialsChanged(object? _, CredentialModel model) | ||
|
@@ -297,7 +352,7 @@ private void Window_Activated(object sender, WindowActivatedEventArgs e) | |
} | ||
|
||
[RelayCommand] | ||
private void Tray_Open() | ||
public void Tray_Open() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this fix something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needed to expose as public to make sure we can all it from another class |
||
{ | ||
MoveResizeAndActivate(); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.