forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to Altitude Angel integration (ArduPilot#3147)
* Fixing integration and login * Switched constants to config * Add scopes to user display on settings * Minor package updates * Including home location in plan and VTOL capability * Remove snk * Adding user agent with version to requests * User interface improvements * User interface improvements * Disable script errors * Clean up * External browser login * Exception handler in cancel * Features dependent on token scopes actually present * First start experience check and tweak * Adding map altitude filtering * Info panel link in external browser and basic UTM zone * Tidy * Adding initial contact number support * Delay sign in till main window open * Fix gitignore * Better panel layout * Tweak * Message display improvements * Don't steal window focus * Improve info panel with dragging and curl click on plan map * Ctrl+Click on planning map for info * About and enable/disable improvements * Adding Polly retries to some missing places * Cleanup of unused types * Rate cards now in map info panel * Retry signin * Showing excluded map data * Fix first start * One sign in at a time * Fix readable list * Support info in About * Fix token expiry retry, policy retries and write back settings when set * Fixing client override and enable * Clickable messages * Better exception display in wait panel * Layout improvements * Correcting rate calc and zone display * Map loaded messages shorter * Better message display * In case JWT isn't valid * Better sign in handling that does not get in the way when signed out, including better messages * Removing loading message * Use Flurl instead of HttpClient * Settings layout tweak * Policy tweak * Telemetry and flight improvements * Moving state out of main mission planner adapter. New settings. * New and more consistent messaging. Renaming classes. * New keyed service locator and better http policy wrapping * Split out API and flight clients * Split out auth client and cancellation tokens in flight * More moving around of client code. Better exception formatting. More precision on altitude. * Submitting flight plans via flight approvals * Minor * Minor message change * Reorganization of types to simplify project. Adding surveillance client for use later. * Fixing potential cancel bug * Fix ctrl+click flight planning map bug * Fixing dispose (thanks @casrya!) * Adding missing cancellation tokens --------- Co-authored-by: rupertbenbrook <[email protected]>
- Loading branch information
1 parent
142a91a
commit 9aae69f
Showing
229 changed files
with
5,410 additions
and
3,163 deletions.
There are no files selected for viewing
446 changes: 237 additions & 209 deletions
446
ExtLibs/AltitudeAngelWings.Plugin/AASettings.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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
125 changes: 125 additions & 0 deletions
125
ExtLibs/AltitudeAngelWings.Plugin/ControlOverlayMessageDisplay.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
using AltitudeAngelWings.Model; | ||
using AltitudeAngelWings.Service.Messaging; | ||
using Message = AltitudeAngelWings.Model.Message; | ||
|
||
namespace AltitudeAngelWings.Plugin | ||
{ | ||
public class ControlOverlayMessageDisplay : IMessageDisplay | ||
{ | ||
private const int LeftOffset = 5; | ||
|
||
private readonly Control _parent; | ||
private readonly IUiThreadInvoke _uiThreadInvoke; | ||
private readonly int _bottomOffset; | ||
|
||
public ControlOverlayMessageDisplay(Control parent, IUiThreadInvoke uiThreadInvoke, int bottomOffset) | ||
{ | ||
_parent = parent; | ||
_uiThreadInvoke = uiThreadInvoke; | ||
_bottomOffset = bottomOffset; | ||
} | ||
|
||
public void AddMessage(Message message) | ||
{ | ||
var label = CreateLabel(message); | ||
_uiThreadInvoke.Invoke(() => | ||
{ | ||
if (!_parent.Visible) return; | ||
_parent.SuspendLayout(); | ||
var labels = GetMessageLabels(); | ||
if (!string.IsNullOrEmpty(message.Key)) | ||
{ | ||
var matchingKeys = labels.Where(l => l.Name == message.Key).ToList(); | ||
foreach (var remove in matchingKeys) | ||
{ | ||
_parent.Controls.Remove(remove); | ||
labels.Remove(remove); | ||
remove.Dispose(); | ||
} | ||
} | ||
_parent.Controls.Add(label); | ||
label.BringToFront(); | ||
labels.Add(label); | ||
LayoutLabels(labels); | ||
_parent.ResumeLayout(); | ||
}); | ||
} | ||
|
||
public void RemoveMessage(Message message) | ||
{ | ||
_uiThreadInvoke.Invoke(() => | ||
{ | ||
if (!_parent.Visible) return; | ||
_parent.SuspendLayout(); | ||
var labels = GetMessageLabels(); | ||
foreach (var label in labels) | ||
{ | ||
if (label.Tag != message) continue; | ||
_parent.Controls.Remove(label); | ||
labels.Remove(label); | ||
label.Dispose(); | ||
break; | ||
} | ||
LayoutLabels(labels); | ||
_parent.ResumeLayout(); | ||
}); | ||
} | ||
|
||
private Label CreateLabel(Message message) | ||
{ | ||
var label = new Label | ||
{ | ||
Tag = message, | ||
Text = message.Content, | ||
Name = message.Key ?? "", | ||
AutoSize = true, | ||
ForeColor = GetColorForMessage(message), | ||
BackColor = Color.Transparent, | ||
Visible = true, | ||
Anchor = AnchorStyles.Bottom | AnchorStyles.Left, | ||
TextAlign = ContentAlignment.MiddleLeft, | ||
Padding = new Padding(5, 0, 5, 1), | ||
Font = new Font("Microsoft Sans Serif", 9, FontStyle.Regular) | ||
}; | ||
if (message.OnClick == null) | ||
{ | ||
return label; | ||
} | ||
|
||
label.Cursor = Cursors.Hand; | ||
label.Click += (sender, e) => | ||
{ | ||
message.OnClick(); | ||
RemoveMessage(message); | ||
}; | ||
return label; | ||
} | ||
|
||
private static Color GetColorForMessage(Message message) | ||
{ | ||
switch (message.Type) | ||
{ | ||
case MessageType.Error: | ||
return Color.Red; | ||
default: | ||
return message.OnClick == null ? Color.White : Color.LawnGreen; | ||
} | ||
} | ||
|
||
private void LayoutLabels(ICollection<Label> labels) | ||
{ | ||
var totalHeight = 0; | ||
foreach (var label in labels) | ||
{ | ||
totalHeight += label.Height; | ||
label.Location = new Point(LeftOffset, _parent.Height - totalHeight - _bottomOffset); | ||
} | ||
} | ||
|
||
private IList<Label> GetMessageLabels() => _parent.Controls.OfType<Label>().Where(l => l.Tag is Message).ToList(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
ExtLibs/AltitudeAngelWings.Plugin/ExternalWebBrowserAuthorizeCodeProvider.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Specialized; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using AltitudeAngelWings.Clients; | ||
using AltitudeAngelWings.Clients.Auth; | ||
using AltitudeAngelWings.Clients.Auth.Model; | ||
using AltitudeAngelWings.Model; | ||
using AltitudeAngelWings.Service.Messaging; | ||
using MissionPlanner.Plugin; | ||
|
||
namespace AltitudeAngelWings.Plugin | ||
{ | ||
public class ExternalWebBrowserAuthorizeCodeProvider : IAuthorizeCodeProvider | ||
{ | ||
private readonly ISettings _settings; | ||
private readonly IAuthClient _authClient; | ||
private readonly IMessagesService _messages; | ||
private readonly PluginHost _host; | ||
private readonly IUiThreadInvoke _uiThreadInvoke; | ||
private string _pollId; | ||
|
||
public ExternalWebBrowserAuthorizeCodeProvider(ISettings settings, IAuthClient authClient, IMessagesService messages, PluginHost host, IUiThreadInvoke uiThreadInvoke) | ||
{ | ||
_settings = settings; | ||
_authClient = authClient; | ||
_messages = messages; | ||
_host = host; | ||
_uiThreadInvoke = uiThreadInvoke; | ||
} | ||
|
||
public void GetAuthorizeParameters(NameValueCollection parameters) | ||
{ | ||
// Generate a random poll id | ||
_pollId = Guid.NewGuid().ToString("N"); | ||
|
||
// Add poll id to the parameters | ||
parameters.Add("poll_id", _pollId); | ||
} | ||
|
||
public async Task<string> GetAuthorizeCode(Uri authorizeUri) | ||
{ | ||
if (string.IsNullOrWhiteSpace(_settings.ClientId) || string.IsNullOrWhiteSpace(_settings.ClientSecret)) | ||
{ | ||
await _messages.AddMessageAsync(Message.ForAction( | ||
"BadClientCredentials", | ||
"Client ID and Client Secret are not set correctly. Click here to open settings.", | ||
() => AASettings.Instance.Show(_host.MainForm), | ||
() => _settings.TokenResponse.IsValidForAuth())); | ||
return null; | ||
} | ||
|
||
return await _uiThreadInvoke.Invoke(() => UiTask.ShowDialog(async cancellationToken => | ||
{ | ||
var tokens = await _authClient.GetTokenFromClientCredentials(cancellationToken); | ||
Process.Start(authorizeUri.ToString()); | ||
|
||
string code; | ||
do | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); | ||
code = await _authClient.GetAuthorizationCode(tokens.AccessToken, _pollId, cancellationToken); | ||
} while (!cancellationToken.IsCancellationRequested && code == null); | ||
|
||
return code; | ||
}, | ||
"Opening a browser to sign in to Altitude Angel. Please sign in using the browser.")); | ||
} | ||
} | ||
} |
Oops, something went wrong.