Skip to content

Commit

Permalink
Merge pull request #276 from raisingthefloor/master
Browse files Browse the repository at this point in the history
Morphic for Windows v1.3
  • Loading branch information
christopher-rtf authored Jun 30, 2021
2 parents c853d1b + dc0c606 commit d4a9780
Show file tree
Hide file tree
Showing 40 changed files with 2,125 additions and 894 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ obj/
Morphic.*Setup/Generated.wxs
Morphic.Client/appsettings.Local.json
Morphic.Client/appsettings.json
Morphic.Client/app.manifest
Morphic.Client/BuildVersion.txt
Morphic.Bar
265 changes: 227 additions & 38 deletions Morphic.Client/App.xaml.cs

Large diffs are not rendered by default.

59 changes: 48 additions & 11 deletions Morphic.Client/Bar/BarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private void OnBarOnReloadRequired(object? sender, EventArgs args)
{
var result = LoadFromBarJson(AppPaths.GetConfigFile("basic-bar.json5", true));
AppOptions.Current.LastCommunity = null;
AppOptions.Current.LastMorphicbarId = null;
return result;
}

Expand Down Expand Up @@ -249,7 +250,7 @@ private void OnBarOnReloadRequired(object? sender, EventArgs args)
/// </summary>
/// <param name="session">The current session.</param>
/// <param name="showCommunityId">Force this community to show.</param>
public async Task LoadSessionBarAsync(MorphicSession session, string communityId)
public async Task LoadSessionBarAsync(MorphicSession session, string communityId, string? morphicbarId)
{
if (this.firstBar && AppOptions.Current.Launch.BarFile != null)
{
Expand Down Expand Up @@ -308,27 +309,63 @@ public async Task LoadSessionBarAsync(MorphicSession session, string communityId

if (community != null)
{
userBar ??= await session.GetBar(community.Id);
var legacyBars = await session.GetBarsAsync(community.Id);
foreach (var legacyBar in legacyBars) {
var useThisBar = false;
if (morphicbarId == null)
{
// if the user selected this community id instead of a specific morphicbar (Morphic v1.0-v1.2), then use the first bar
useThisBar = true;
}
else if (legacyBar.Id == morphicbarId)
{
// if the user previously selected this specific morphicbar, use it
useThisBar = true;
}

this.Logger.LogInformation($"Showing bar for community {community.Id} {community.Name}");
string barJson = this.GetUserBarJson(userBar);
BarData? barData = this.LoadFromBarJson(userBar.Id, barJson);
if (barData != null)
{
barData.CommunityId = community.Id;
if (useThisBar == true)
{
// OBSERVATION: not sure why the "??=" (userBar == null) check is done here; this logic seems brittle
if (userBar == null)
{
userBar = legacyBar;
break;
}
}
}
// NOTE: if the morphicbar was not found, we do not set it to null (to remain consistent with previous code logic)

AppOptions.Current.LastCommunity = community?.Id;
// added to protect against not finding the specific community bar
if (userBar != null)
{
this.Logger.LogInformation($"Showing bar for community {community.Id} {community.Name}");
string barJson = this.GetUserBarJson(userBar);
BarData? barData = this.LoadFromBarJson(userBar.Id, barJson);
if (barData != null)
{
barData.CommunityId = community.Id;
}

AppOptions.Current.LastCommunity = community?.Id;
AppOptions.Current.LastMorphicbarId = userBar.Id;
}
else
{
// if the community or the specific community bar could not be found, show the Basic MorphicBar instead
this.LoadBasicMorphicBar();

AppOptions.Current.LastCommunity = null;
AppOptions.Current.LastMorphicbarId = null;
}
}
else
{
// if the community could not be found, show the Basic MorphicBar instead
this.LoadBasicMorphicBar();

AppOptions.Current.LastCommunity = null;
AppOptions.Current.LastMorphicbarId = null;
}

AppOptions.Current.Communities = session.Communities.Select(c => c.Id).ToArray();
}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions Morphic.Client/Bar/Data/Actions/BarAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ private async Task SendTelemetryForBarAction(string? source = null, bool? toggle
}
break;
case "copy":
// NOTE: this is the basic bar variant of "copy" (below)
{
await App.Current.Countly_RecordEventAsync("screenSnip");
}
Expand Down Expand Up @@ -248,6 +249,12 @@ private async Task SendTelemetryForBarAction(string? source = null, bool? toggle
case "screen-zoom":
// this action type's telemetry is logged elsewhere
break;
case "snip":
// NOTE: this is the custom bar variant of "copy" (above)
{
await App.Current.Countly_RecordEventAsync("screenSnip");
}
break;
default:
// we do not understand this action type (for telemetry logging purposes)
Debug.Assert(false, "Unknown Action ID (missing telemetry hooks)");
Expand Down
21 changes: 14 additions & 7 deletions Morphic.Client/Bar/Data/Actions/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class Functions
{
private readonly static SemaphoreSlim _captureTextSemaphore = new SemaphoreSlim(1, 1);

[InternalFunction("screenshot")]
public static async Task<IMorphicResult> ScreenshotAsync(FunctionArgs args)
[InternalFunction("snip")]
public static async Task<IMorphicResult> ScreenSnipAsync(FunctionArgs args)
{
// Hide all application windows
Dictionary<Window, double> opacity = new Dictionary<Window, double>();
Expand All @@ -54,12 +54,19 @@ public static async Task<IMorphicResult> ScreenshotAsync(FunctionArgs args)
// Give enough time for the windows to disappear
await Task.Delay(500);

// Hold down the windows key while pressing shift + s
const uint windowsKey = 0x5b; // VK_LWIN
Keyboard.PressKey(windowsKey, true);
System.Windows.Forms.SendKeys.SendWait("+s");
Keyboard.PressKey(windowsKey, false);
//// method 1: hold down the windows key while pressing shift + s
//// NOTE: this method does not seem to work when we have uiAccess set to true in our manifest (oddly)
//const uint windowsKey = 0x5b; // VK_LWIN
//Keyboard.PressKey(windowsKey, true);
//System.Windows.Forms.SendKeys.SendWait("+s");
//Keyboard.PressKey(windowsKey, false);

// method 2: open up the special windows URI of ms-screenclip:
var openPath = "ms-screenclip:";
Process.Start(new ProcessStartInfo(openPath)
{
UseShellExecute = true
});
}
finally
{
Expand Down
27 changes: 27 additions & 0 deletions Morphic.Client/Bar/Data/Actions/SettingAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ protected override Task<IMorphicResult> InvokeAsyncImpl(string? source = null, b
return Task.FromResult(IMorphicResult.ErrorResult);
}

public async Task<bool> CanExecute(string id)
{
bool canExecute = true;

if (Setting?.Range != null)
{
var range = Setting.Range;
var idRequiresCountRefresh = Setting.Id == "zoom";

var min = await range.GetMin(0, idRequiresCountRefresh);
var max = await range.GetMax(0, idRequiresCountRefresh) - 1;

var currentValue = (int)(Setting.CurrentValue ?? 0);

if (id == "inc" && currentValue >= max)
{
canExecute = false;
}
else if (id == "dec" && currentValue <= min)
{
canExecute = false;
}
}

return canExecute;
}

public override void Deserialized(BarData bar)
{
base.Deserialized(bar);
Expand Down
31 changes: 9 additions & 22 deletions Morphic.Client/Bar/Data/BarData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public BarData(IServiceProvider? serviceProvider)
/// <returns>true if the item belongs on the primary bar.</returns>
private bool IsPrimaryItem(BarItem item)
{
return !item.Hidden && item.IsPrimary && !item.Overflow;
return !item.Hidden && !item.Overflow;
}

/// <summary>
Expand All @@ -147,13 +147,18 @@ private bool IsSecondaryItem(BarItem item)
public IEnumerable<BarItem> PrimaryItems => this.AllItems.Where(this.IsPrimaryItem)
.OrderByDescending(item => item.Priority);

// OBSERVATION: the usage of the "Overflow" bool in sorting and the general nomenclature of "Overflow" and "Priority" leave room for bugs;
// at first glance, "Overflow" should be a filter for secondary items rather than a descending sort order and
// "Priority" (which is the index value) seems like it should ordered in ascending order;
// we should rethink our terminology and refactor the logic here and the variable naming and logic related to these variables
//
/// <summary>
/// Gets the items for the additional buttons.
/// </summary>
public IEnumerable<BarItem> SecondaryItems => this.AllItems.Where(this.IsSecondaryItem)
.OrderByDescending(item => item.IsPrimary)
.ThenByDescending(item => item.Priority);

.OrderByDescending(item => item.Overflow)
.ThenByDescending(item => item.Priority);

public string? CommunityId { get; set; }

private ILogger logger = App.Current.ServiceProvider.GetRequiredService<ILogger<BarData>>();
Expand Down Expand Up @@ -274,7 +279,6 @@ private bool IsSecondaryItem(BarItem item)
throw new NotImplementedException();
}
//extraBarItem.ColorValue = "#00FF00";
extraBarItem.IsPrimary = true;
//
if (extraBarItemShouldBeAdded == true)
{
Expand All @@ -288,7 +292,6 @@ private bool IsSecondaryItem(BarItem item)
spacerBarItem.ToolTip = "";
spacerBarItem.Text = "";
spacerBarItem.ColorValue = "#FFFFFF";
spacerBarItem.IsPrimary = true;
//
defaultBar?.AllItems.Add(spacerBarItem);
}
Expand Down Expand Up @@ -331,22 +334,6 @@ public void Deserialized()
this.DefaultTheme.Apply(Theme.DefaultItem());
this.ControlTheme.Apply(Theme.DefaultControl()).Apply(this.DefaultTheme);

if (this.hasDeserialized)
{
// If a bar has no primary items, it looks stupid. Make all the items primary, and make them over-flow to
// the secondary bar.
bool hasPrimary = this.PrimaryItems.Any(item => !item.IsDefault);
if (!hasPrimary)
{
foreach (BarItem item in this.SecondaryItems)
{
item.IsPrimary = true;
}

this.Overflow = BarOverflow.Secondary;
}
}

this.AllItems.ForEach(item =>
{
item.IsDefault = !this.hasDeserialized;
Expand Down
12 changes: 7 additions & 5 deletions Morphic.Client/Bar/Data/BarItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public BarItem(BarData bar)
/// </summary>
public BarData Bar { get; set; }

/// <summary>
/// true if the item is to be displayed on the pull-out bar.
/// </summary>
[JsonProperty("is_primary")]
public bool IsPrimary { get; set; }
// NOTE: this property has been deprecated, as the determination of if an item should be on the bar (and not in the overflow drawer) is now based on position and available room
//
///// <summary>
///// true if the item is to be displayed on the pull-out bar.
///// </summary>
//[JsonProperty("is_primary")]
//public bool IsPrimary { get; set; }

/// <summary>
/// true if the item should over-flow to the secondary bar, because it doesn't fit.
Expand Down
2 changes: 1 addition & 1 deletion Morphic.Client/Bar/UI/QuickHelpWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Title="QuickHelpWindow"
Height="160"
Width="750"
Background="#CC000000"
Background="Black"
BorderBrush="White"
BorderThickness="1"
HorizontalAlignment="Center"
Expand Down
Loading

0 comments on commit d4a9780

Please sign in to comment.