mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
Form pages are all wired up
This commit is contained in:
@@ -201,7 +201,7 @@ public partial class MastodonPostForm : Form
|
||||
{
|
||||
"type": "Image",
|
||||
"url": "${author_avatar_url}",
|
||||
"size": "Small",
|
||||
"size": "Medium",
|
||||
"style": "Person"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -56,7 +56,7 @@ internal sealed partial class AddBookmarkForm : Form
|
||||
|
||||
public override string DataJson() => throw new NotImplementedException();
|
||||
|
||||
public override string StateJson() => throw new NotImplementedException();
|
||||
public override string StateJson() => "{}";
|
||||
|
||||
public override CommandResult SubmitForm(string payload)
|
||||
{
|
||||
|
||||
@@ -69,7 +69,7 @@ internal sealed partial class BookmarkPlaceholderForm : Form
|
||||
|
||||
public override string DataJson() => throw new NotImplementedException();
|
||||
|
||||
public override string StateJson() => throw new NotImplementedException();
|
||||
public override string StateJson() => "{}";
|
||||
|
||||
public override CommandResult SubmitForm(string payload)
|
||||
{
|
||||
|
||||
@@ -75,7 +75,7 @@ internal sealed partial class SettingsForm : Form
|
||||
""";
|
||||
}
|
||||
|
||||
public override string StateJson() => throw new NotImplementedException();
|
||||
public override string StateJson() => "{}";
|
||||
|
||||
public override CommandResult SubmitForm(string payload)
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ internal sealed partial class SampleForm : Form
|
||||
return json;
|
||||
}
|
||||
|
||||
public override string StateJson() => throw new NotImplementedException();
|
||||
public override string StateJson() => "{}";
|
||||
|
||||
public override CommandResult SubmitForm(string payload)
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ internal sealed partial class SpongeSettingsForm : Form
|
||||
|
||||
public override string DataJson() => throw new NotImplementedException();
|
||||
|
||||
public override string StateJson() => throw new NotImplementedException();
|
||||
public override string StateJson() => "{}";
|
||||
|
||||
public override CommandResult SubmitForm(string payload)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ internal sealed partial class YouTubeAPIForm : Form
|
||||
|
||||
public override string DataJson() => throw new NotImplementedException();
|
||||
|
||||
public override string StateJson() => throw new NotImplementedException();
|
||||
public override string StateJson() => "{}";
|
||||
|
||||
public override CommandResult SubmitForm(string payload)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// 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.Text.Json;
|
||||
using AdaptiveCards.ObjectModel.WinUI3;
|
||||
using AdaptiveCards.Templating;
|
||||
using Microsoft.CmdPal.Extensions;
|
||||
@@ -33,15 +34,36 @@ public partial class FormViewModel(IForm _form, IPageContext context) : Extensio
|
||||
return;
|
||||
}
|
||||
|
||||
TemplateJson = model.TemplateJson();
|
||||
StateJson = model.StateJson();
|
||||
DataJson = model.DataJson();
|
||||
try
|
||||
{
|
||||
TemplateJson = model.TemplateJson();
|
||||
StateJson = model.StateJson();
|
||||
DataJson = model.DataJson();
|
||||
|
||||
AdaptiveCardTemplate template = new(TemplateJson);
|
||||
var cardJson = template.Expand(DataJson);
|
||||
Card = AdaptiveCard.FromJsonString(cardJson);
|
||||
AdaptiveCardTemplate template = new(TemplateJson);
|
||||
var cardJson = template.Expand(DataJson);
|
||||
Card = AdaptiveCard.FromJsonString(cardJson);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// If we fail to parse the card JSON, then display _our own card_
|
||||
// with the exception
|
||||
AdaptiveCardTemplate template = new(ErrorCardJson);
|
||||
|
||||
// todo: we could probably stick Card.Errrors in there too
|
||||
var dataJson = $$"""
|
||||
{
|
||||
"error_message": {{JsonSerializer.Serialize(e.Message)}},
|
||||
"error_stack": {{JsonSerializer.Serialize(e.StackTrace)}},
|
||||
"inner_exception": {{JsonSerializer.Serialize(e.InnerException?.Message)}},
|
||||
"template_json": {{JsonSerializer.Serialize(TemplateJson)}},
|
||||
"data_json": {{JsonSerializer.Serialize(DataJson)}}
|
||||
}
|
||||
""";
|
||||
var cardJson = template.Expand(dataJson);
|
||||
Card = AdaptiveCard.FromJsonString(cardJson);
|
||||
}
|
||||
|
||||
// TODO catch and replace with our error card
|
||||
UpdateProperty(nameof(Card));
|
||||
}
|
||||
|
||||
@@ -78,4 +100,45 @@ public partial class FormViewModel(IForm _form, IPageContext context) : Extensio
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly string ErrorCardJson = """
|
||||
{
|
||||
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
|
||||
"type": "AdaptiveCard",
|
||||
"version": "1.5",
|
||||
"body": [
|
||||
{
|
||||
"type": "TextBlock",
|
||||
"text": "Error parsing form from extension",
|
||||
"wrap": true,
|
||||
"style": "heading",
|
||||
"size": "ExtraLarge",
|
||||
"weight": "Bolder",
|
||||
"color": "Attention"
|
||||
},
|
||||
{
|
||||
"type": "TextBlock",
|
||||
"wrap": true,
|
||||
"text": "${error_message}",
|
||||
"color": "Attention"
|
||||
},
|
||||
{
|
||||
"type": "TextBlock",
|
||||
"text": "${error_stack}",
|
||||
"fontType": "Monospace"
|
||||
},
|
||||
{
|
||||
"type": "TextBlock",
|
||||
"wrap": true,
|
||||
"text": "Inner exception:"
|
||||
},
|
||||
{
|
||||
"type": "TextBlock",
|
||||
"wrap": true,
|
||||
"text": "${inner_exception}",
|
||||
"color": "Attention"
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user