-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind to Page properties, and add support for item propchange's (#186)
A lot of this is just samples work, so skip on down to `src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ActionBarViewModel.cs`. * Updates the Action Bar with the title of the currently active page when we navigate to it * listens for PropChanged events from `ICommandItem`s in lists and on `IPage`'s (to display a loading bar) * Also didn't put this on the ShellPage quite yet, because the diff was already massive, and there's complicated "are _we_ loading the page? did the `IPage` say it was loading?" plumbing that needs to be done. * adds rudimentary support for showing an exception, if there's an error we catch * I didn't add log this everywhere yet though, since we're not 100% confident on the messaging infrastructure here * I decided against putting this on the shell page, because I want users to be able to _go back_ from a page with an exception, and that didn't seem trivial if it was on the shellpage itself * Then updates a bunch of extensions to better utilize the loading state. * Then discovers a really weird bug with event callbacks in WinRT, so I decided to wrap those in try/catches to have extensions explode less often. (#181) * Then also adds a bunch of "evil" samples, to make a unified place of "things to try and break us" ref #73 --------- Co-authored-by: Mike Griese <[email protected]>
- Loading branch information
1 parent
ef35a4c
commit 2b98619
Showing
31 changed files
with
557 additions
and
142 deletions.
There are no files selected for viewing
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
5 changes: 3 additions & 2 deletions
5
src/modules/cmdpal/Exts/ProcessMonitorExtension/Properties/launchSettings.json
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
{ | ||
"profiles": { | ||
"ProcessMonitorExtension (Package)": { | ||
"commandName": "MsixPackage" | ||
"commandName": "MsixPackage", | ||
"doNotLaunchApp": true | ||
}, | ||
"ProcessMonitorExtension (Unpackaged)": { | ||
"commandName": "Project" | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/modules/cmdpal/Exts/SamplePagesExtension/EvilSampleListPage.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,32 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Timers; | ||
using Microsoft.CmdPal.Extensions; | ||
using Microsoft.CmdPal.Extensions.Helpers; | ||
|
||
namespace SamplePagesExtension; | ||
|
||
internal sealed partial class EvilSampleListPage : ListPage | ||
{ | ||
public EvilSampleListPage() | ||
{ | ||
Icon = new(string.Empty); | ||
Name = "Open"; | ||
} | ||
|
||
public override IListItem[] GetItems() | ||
{ | ||
IListItem[] commands = [ | ||
new ListItem(new EvilSampleListPage()) | ||
{ | ||
Subtitle = "Doesn't matter, I'll blow up before you see this", | ||
}, | ||
]; | ||
|
||
_ = commands[9001]; // Throws | ||
|
||
return commands; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/modules/cmdpal/Exts/SamplePagesExtension/EvilSamplesPage.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,42 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.CmdPal.Extensions; | ||
using Microsoft.CmdPal.Extensions.Helpers; | ||
|
||
namespace SamplePagesExtension; | ||
|
||
public partial class EvilSamplesPage : ListPage | ||
{ | ||
private readonly IListItem[] _commands = [ | ||
new ListItem(new EvilSampleListPage()) | ||
{ | ||
Title = "List Page without items", | ||
Subtitle = "Throws exception on GetItems", | ||
}, | ||
new ListItem(new ExplodeInFiveSeconds(false)) | ||
{ | ||
Title = "Page that will throw an exception after loading it", | ||
Subtitle = "Throws exception on GetItems _after_ a ItemsChanged", | ||
}, | ||
new ListItem(new ExplodeInFiveSeconds(true)) | ||
{ | ||
Title = "Page that keeps throwing exceptions", | ||
Subtitle = "Will throw every 5 seconds once you open it", | ||
}, | ||
new ListItem(new SelfImmolateCommand()) | ||
{ | ||
Title = "Terminate this extension", | ||
Subtitle = "Will exit this extension (while it's loaded!)", | ||
}, | ||
]; | ||
|
||
public EvilSamplesPage() | ||
{ | ||
Name = "Evil Samples"; | ||
Icon = new("👿"); // Info | ||
} | ||
|
||
public override IListItem[] GetItems() => _commands; | ||
} |
50 changes: 50 additions & 0 deletions
50
src/modules/cmdpal/Exts/SamplePagesExtension/ExplodeInFiveSeconds.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,50 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Timers; | ||
using Microsoft.CmdPal.Extensions; | ||
using Microsoft.CmdPal.Extensions.Helpers; | ||
|
||
namespace SamplePagesExtension; | ||
|
||
internal sealed partial class ExplodeInFiveSeconds : ListPage | ||
{ | ||
private readonly bool _repeat; | ||
|
||
private IListItem[] Commands => [ | ||
new ListItem(new NoOpCommand()) | ||
{ | ||
Title = "This page will explode in five seconds!", | ||
Subtitle = _repeat ? "Not only that, I'll _keep_ exploding every 5 seconds after that" : string.Empty, | ||
}, | ||
]; | ||
|
||
private bool shouldExplode; | ||
private static Timer timer; | ||
|
||
public ExplodeInFiveSeconds(bool repeat) | ||
{ | ||
_repeat = repeat; | ||
Icon = new(string.Empty); | ||
Name = "Open"; | ||
} | ||
|
||
public override IListItem[] GetItems() | ||
{ | ||
if (shouldExplode) | ||
{ | ||
_ = Commands[9001]; // Throws | ||
} | ||
else | ||
{ | ||
timer = new Timer(5000); | ||
timer.Elapsed += (object source, ElapsedEventArgs e) => { RaiseItemsChanged(9000); }; | ||
timer.AutoReset = _repeat; // Keep repeating | ||
timer.Enabled = true; | ||
} | ||
|
||
shouldExplode = true; | ||
return Commands; | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/modules/cmdpal/Exts/SamplePagesExtension/SampleUpdatingItemsPage.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,43 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Timers; | ||
using Microsoft.CmdPal.Extensions; | ||
using Microsoft.CmdPal.Extensions.Helpers; | ||
using Microsoft.VisualBasic; | ||
|
||
namespace SamplePagesExtension; | ||
|
||
public partial class SampleUpdatingItemsPage : ListPage | ||
{ | ||
private readonly ListItem hourItem = new(new NoOpCommand()); | ||
private readonly ListItem minuteItem = new(new NoOpCommand()); | ||
private readonly ListItem secondItem = new(new NoOpCommand()); | ||
private static Timer timer; | ||
|
||
public SampleUpdatingItemsPage() | ||
{ | ||
Name = "Open"; | ||
Icon = new(string.Empty); | ||
} | ||
|
||
public override IListItem[] GetItems() | ||
{ | ||
if (timer == null) | ||
{ | ||
timer = new Timer(500); | ||
timer.Elapsed += (object source, ElapsedEventArgs e) => | ||
{ | ||
var current = DateAndTime.Now; | ||
hourItem.Title = $"{current.Hour}"; | ||
minuteItem.Title = $"{current.Minute}"; | ||
secondItem.Title = $"{current.Second}"; | ||
}; | ||
timer.AutoReset = true; // Keep repeating | ||
timer.Enabled = true; | ||
} | ||
|
||
return [hourItem, minuteItem, secondItem]; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/modules/cmdpal/Exts/SamplePagesExtension/SelfImmolateCommand.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,18 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Diagnostics; | ||
using Microsoft.CmdPal.Extensions; | ||
using Microsoft.CmdPal.Extensions.Helpers; | ||
|
||
namespace SamplePagesExtension; | ||
|
||
public partial class SelfImmolateCommand : InvokableCommand | ||
{ | ||
public override ICommandResult Invoke() | ||
{ | ||
Process.GetCurrentProcess().Kill(); | ||
return base.Invoke(); | ||
} | ||
} |
Oops, something went wrong.