Skip to content

Commit

Permalink
You need to keep the IExtension alive, so that we can do callbacks in…
Browse files Browse the repository at this point in the history
…to it
  • Loading branch information
zadjii-msft committed May 10, 2023
1 parent a5711a8 commit 82dc26f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 14 deletions.
10 changes: 6 additions & 4 deletions scratch/ExtensionComponent/ExtensionClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace winrt::ExtensionComponent::implementation
return 101;
}

winrt::fire_and_forget ExtensionClass::_webMessageReceived(const IInspectable& sender,
const winrt::Microsoft::Web::WebView2::Core::CoreWebView2WebMessageReceivedEventArgs& args)
void ExtensionClass::_webMessageReceived(const IInspectable& sender,
winrt::Microsoft::Web::WebView2::Core::CoreWebView2WebMessageReceivedEventArgs args)
{
auto message{ args.TryGetWebMessageAsString() };
if (!message.empty())
Expand All @@ -37,11 +37,13 @@ namespace winrt::ExtensionComponent::implementation
{
//MyButtonHandler(uri);
auto query = winrt::Windows::Foundation::WwwFormUrlDecoder(uri.Query());
query;
winrt::hstring asdf = query.First().Current().Value();

Check failure on line 40 in scratch/ExtensionComponent/ExtensionClass.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`asdf` is not a recognized word. (unrecognized-spelling)
auto sendInput = winrt::SampleExtensions::SendInputArgs(asdf);

Check failure on line 41 in scratch/ExtensionComponent/ExtensionClass.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`asdf` is not a recognized word. (unrecognized-spelling)
this->_SendInputRequestedHandlers(*this, sendInput);
}
}

co_return;
return;
}

winrt::fire_and_forget ExtensionClass::_makeWebView(const WUX::Controls::StackPanel parent)
Expand Down
18 changes: 15 additions & 3 deletions scratch/ExtensionComponent/ExtensionClass.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "ExtensionClass.g.h"

Expand All @@ -13,10 +13,22 @@ namespace winrt::ExtensionComponent::implementation
int32_t DoTheThing();
winrt::Windows::UI::Xaml::FrameworkElement PaneContent();

// typed event handler for the SendInputRequested event
winrt::event_token SendInputRequested(winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable, winrt::SampleExtensions::SendInputArgs> const& handler)
{
return _SendInputRequestedHandlers.add(handler);
}
void SendInputRequested(winrt::event_token const& token) noexcept
{
_SendInputRequestedHandlers.remove(token);
}

private:
winrt::fire_and_forget _makeWebView(const winrt::Windows::UI::Xaml::Controls::StackPanel parent);
winrt::fire_and_forget _webMessageReceived(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Microsoft::Web::WebView2::Core::CoreWebView2WebMessageReceivedEventArgs& args);
void _webMessageReceived(const winrt::Windows::Foundation::IInspectable& sender,
winrt::Microsoft::Web::WebView2::Core::CoreWebView2WebMessageReceivedEventArgs args);

winrt::event<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable, winrt::SampleExtensions::SendInputArgs>> _SendInputRequestedHandlers;
};
}

Expand Down
2 changes: 1 addition & 1 deletion scratch/ExtensionHost/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace winrt::ExtensionHost::implementation
return;

winrt::ExtensionHost::FooClass myFoo{};
winrt::ExtensionComponent::Class bar;
winrt::ExtensionComponent::ExtensionClass bar;
auto wat = bar.MyProperty();
wat *= 2;
myFoo.MyProperty(wat);
Expand Down
1 change: 1 addition & 0 deletions scratch/ScratchIslandApp/Package/Package.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Import Project="$(OpenConsoleDir)src\wap-common.build.post.props" />
<ItemGroup>
<ProjectReference Include="..\WindowExe\WindowExe.vcxproj" />
<ProjectReference Include="..\..\SampleExtensions\SampleExtensions.vcxproj" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 20 additions & 5 deletions scratch/ScratchIslandApp/SampleApp/MyPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "MyPage.h"
#include <LibraryResources.h>
#include "MyPage.g.cpp"
#include <winrt/SampleExtensions.h>
#include "MySettings.h"

using namespace std::chrono_literals;
Expand Down Expand Up @@ -89,7 +88,8 @@ namespace winrt::SampleApp::implementation
_connection.WriteInput(L"Successfully added package dependency to ");
_connection.WriteInput(dynDep._pfn);
_connection.WriteInput(L"\r\n");
this->_extensions.push_back(std::move(dynDep));

this->_extensions.emplace_back(std::move(dynDep), nullptr);
}
else
{
Expand All @@ -112,6 +112,14 @@ namespace winrt::SampleApp::implementation
{
_lookupCatalog();
}

winrt::fire_and_forget MyPage::SendInputHandler(Windows::Foundation::IInspectable const&, winrt::SampleExtensions::SendInputArgs args)
{
co_await winrt::resume_foreground(Dispatcher());
_connection.WriteInput(args.Input());
_connection.WriteInput(L"\r\n");
}

winrt::fire_and_forget MyPage::ActivateInstanceButtonHandler(Windows::Foundation::IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&)
{
if (_extensions.size() == 0)
Expand All @@ -122,20 +130,27 @@ namespace winrt::SampleApp::implementation

auto hr = S_OK;
Windows::Foundation::IInspectable foo{ nullptr };

auto& extension = _extensions.at(0);

// auto className = winrt::hstring{ L"ExtensionComponent.Class" };
auto className = _extensions.at(0)._implementationClassName;
auto className = extension.app._implementationClassName;
const auto nameForAbi = static_cast<HSTRING>(winrt::get_abi(className));
hr = RoActivateInstance(nameForAbi, (::IInspectable**)winrt::put_abi(foo));

if (foo)
{
if (const auto& ext{ foo.try_as<winrt::SampleExtensions::IExtension>() })
{
auto oneOhOne = ext.DoTheThing();
extension.instance = ext;

auto oneOhOne = extension.instance.DoTheThing();
oneOhOne++;

auto fwe = ext.PaneContent();
auto fwe = extension.instance.PaneContent();
OutOfProcContent().Children().Append(fwe);

extension.instance.SendInputRequested({ get_weak(), &MyPage::SendInputHandler });
}
}
else
Expand Down
9 changes: 8 additions & 1 deletion scratch/ScratchIslandApp/SampleApp/MyPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ namespace winrt::SampleApp::implementation
}
};

struct Extension
{
DynamicDependency app;
winrt::SampleExtensions::IExtension instance{ nullptr };
};

struct MyPage : MyPageT<MyPage>
{
public:
Expand All @@ -72,14 +78,15 @@ namespace winrt::SampleApp::implementation

void ClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
winrt::fire_and_forget ActivateInstanceButtonHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
winrt::fire_and_forget SendInputHandler(Windows::Foundation::IInspectable const& sender, winrt::SampleExtensions::SendInputArgs args);

private:
friend struct MyPageT<MyPage>; // for Xaml to bind events
winrt::Windows::Foundation::IAsyncAction _lookupCatalog() noexcept;

winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _connection{ nullptr };

std::vector<DynamicDependency> _extensions;
std::vector<Extension> _extensions;
};
}

Expand Down
2 changes: 2 additions & 0 deletions scratch/ScratchIslandApp/SampleApp/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@ TRACELOGGING_DECLARE_PROVIDER(g_hSampleAppProvider);
#include <winrt/Windows.ApplicationModel.AppExtensions.h>
#include <appmodel.h>

#include <winrt/SampleExtensions.h>

// Manually include til after we include Windows.Foundation to give it winrt superpowers
#include "til.h"

1 comment on commit 82dc26f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (6)

asdf
debugbreak
impelentation
PACKAGEDEPENDENCY
restrictederrorinfo
sendinput

Previously acknowledged words that are now absent ASDF Hirots NULs spand xwwyzz xxyyzz :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the dev/migrie/fhl/dyndep branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/4936442558/attempts/1'
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. If it doesn't work for you, you can manually add (one word per line) / remove items to expect.txt and the excludes.txt files.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.