Skip to content

Commit 2da59de

Browse files
authored
User/aeloros/feedback (#1191)
* pr feedback batch 1 * more feedback * more feedback
1 parent a9089e9 commit 2da59de

6 files changed

Lines changed: 30 additions & 33 deletions

File tree

dev/AppLifecycle/AppInstance.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
3434
// Push past the '----' commandline argument prefix.
3535
argsStart += 4;
3636

37-
auto argsEnd = commandLine.find_first_of(L" ", argsStart);
37+
auto argsEnd = commandLine.find_first_of(L' ', argsStart);
3838

3939
// Separate the argument from any behind it on the command-line.
4040
std::wstring argument;
@@ -53,7 +53,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
5353
}
5454

5555
// We explicitly use find_first_of here, so that the resulting data may contain : as a valid character.
56-
auto argsDelim = argument.find_first_of(L":");
56+
auto argsDelim = argument.find_first_of(L':');
5757
if (argsDelim == std::wstring::npos)
5858
{
5959
return { argument, L"" };
@@ -316,7 +316,6 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
316316
{
317317
ExtendedActivationKind kind = ExtendedActivationKind::Launch;
318318
IInspectable data;
319-
bool foundArgs = false;
320319

321320
// For packaged, try to get platform args first.
322321
if (HasIdentity())
@@ -325,13 +324,12 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
325324
{
326325
data = args;
327326
kind = static_cast<ExtendedActivationKind>(args.Kind());
328-
foundArgs = true;
329327
}
330328
}
331329

332330
// Handle all Windows App SDK types next (both packaged and unpackaged).
333-
std::wstring commandLine = std::wstring(GetCommandLine());
334-
if (!foundArgs)
331+
std::wstring commandLine{ GetCommandLine() };
332+
if (data == nullptr)
335333
{
336334
auto [contractArgument, contractData] = ParseCommandLine(commandLine);
337335

@@ -349,10 +347,10 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
349347
}
350348
}
351349

352-
if (CompareStringOrdinal(contractArgument.c_str(), -1, c_protocolArgumentString, -1, TRUE) == CSTR_EQUAL)
350+
if (CompareStringOrdinal(contractArgument.c_str(), static_cast<int>(contractArgument.size()), c_protocolArgumentString, -1, TRUE) == CSTR_EQUAL)
353351
{
354352
kind = ExtendedActivationKind::Protocol;
355-
auto args = make<ProtocolActivatedEventArgs>(contractData);
353+
auto args = make<ProtocolActivatedEventArgs>(contractData.c_str());
356354
data = args;
357355

358356
// Encoded launch is a protocol launch where the argument data is
@@ -364,17 +362,15 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
364362
{
365363
std::tie(kind, data) = GetEncodedLaunchActivatedEventArgs(args);
366364
}
367-
368-
foundArgs = true;
369365
}
370366
}
371367
}
372368

373369
// All scenarios should just be marked as Launch.
374-
if (!foundArgs)
370+
if (data == nullptr)
375371
{
376372
kind = ExtendedActivationKind::Launch;
377-
data = make<LaunchActivatedEventArgs>(commandLine);
373+
data = make<LaunchActivatedEventArgs>(commandLine.c_str());
378374
}
379375

380376
return make<AppActivationArguments>(kind, data);

dev/AppLifecycle/ExtensionContract.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
3939
{
4040
if (CompareStringOrdinal(pair.Name().c_str(), -1, c_contractIdKeyName, -1, TRUE) == CSTR_EQUAL)
4141
{
42+
auto contractId = pair.Value().c_str();
4243
for (const auto& extension : c_extensionMap)
4344
{
44-
std::wstring contractId = pair.Value().c_str();
45-
if (CompareStringOrdinal(contractId.c_str(), -1, extension.contractId, -1, TRUE) == CSTR_EQUAL)
45+
if (CompareStringOrdinal(contractId, -1, extension.contractId, -1, TRUE) == CSTR_EQUAL)
4646
{
47-
return { extension.kind, extension.factory(uri).as<winrt::Windows::Foundation::IInspectable>() };
47+
return { extension.kind, extension.factory(uri) };
4848
}
4949
}
5050
}

dev/AppLifecycle/FileActivatedEventArgs.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
1010
using namespace winrt::Windows::ApplicationModel::Activation;
1111
using namespace winrt::Windows::Storage;
1212

13-
constexpr PCWSTR c_fileContractId = L"Windows.File";
13+
constexpr inline PCWSTR c_fileContractId = L"Windows.File";
1414

1515
class FileActivatedEventArgs : public winrt::implements<FileActivatedEventArgs, IFileActivatedEventArgs, ActivatedEventArgsBase,
1616
IInternalValueMarshalable>
1717
{
1818
public:
19-
FileActivatedEventArgs(const std::wstring verb, const std::wstring file, const bool delayVerification = false)
19+
FileActivatedEventArgs(const winrt::hstring verb, const winrt::hstring file, const bool delayVerification = false)
2020
{
2121
if (verb.empty())
2222
{
@@ -47,16 +47,17 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
4747
static winrt::Windows::Foundation::IInspectable Deserialize(winrt::Windows::Foundation::Uri const& uri)
4848
{
4949
auto query = uri.QueryParsed();
50-
auto verb = std::wstring(query.GetFirstValueByName(L"Verb"));
51-
auto file = std::wstring(query.GetFirstValueByName(L"File"));
50+
auto verb = query.GetFirstValueByName(L"Verb");
51+
auto file = query.GetFirstValueByName(L"File");
5252
return make<FileActivatedEventArgs>(verb, file);
5353
}
5454

5555
// IInternalValueMarshalable
5656
winrt::Windows::Foundation::Uri Serialize()
5757
{
5858
auto uri = GenerateEncodedLaunchUri(L"App", c_fileContractId);
59-
uri += L"&Verb=" + m_verb + std::wstring(L"&File=") + m_path;
59+
uri += L"&Verb=" + winrt::Windows::Foundation::Uri::EscapeComponent(m_verb.c_str());
60+
uri += L"&File=" + winrt::Windows::Foundation::Uri::EscapeComponent(m_path.c_str());
6061
return winrt::Windows::Foundation::Uri(uri);
6162
}
6263

@@ -72,8 +73,8 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
7273
}
7374

7475
private:
75-
std::wstring m_verb;
76-
std::wstring m_path;
76+
winrt::hstring m_verb;
77+
winrt::hstring m_path;
7778
IVector<IStorageItem> m_files;
7879
};
7980
}

dev/AppLifecycle/LaunchActivatedEventArgs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
1515
ActivatedEventArgsBase, IInternalValueMarshalable>
1616
{
1717
public:
18-
LaunchActivatedEventArgs(const std::wstring& args) : m_args(std::move(args))
18+
LaunchActivatedEventArgs(const winrt::hstring args) : m_args(args)
1919
{
2020
m_kind = ActivationKind::Launch;
2121
}
2222

2323
static winrt::Windows::Foundation::IInspectable Deserialize(winrt::Windows::Foundation::Uri const& uri)
2424
{
2525
auto query = uri.QueryParsed();
26-
auto args = std::wstring(query.GetFirstValueByName(L"Arguments"));
26+
auto args = query.GetFirstValueByName(L"Arguments");
2727
return make<LaunchActivatedEventArgs>(args);
2828
}
2929

3030
// IInternalValueMarshalable
3131
winrt::Windows::Foundation::Uri Serialize()
3232
{
33-
auto uri = GenerateEncodedLaunchUri(L"App", c_launchContractId) + L"&Arguments=" + m_args;
33+
auto uri = GenerateEncodedLaunchUri(L"App", c_launchContractId) + L"&Arguments=" + winrt::Windows::Foundation::Uri::EscapeComponent(m_args.c_str());
3434
return winrt::Windows::Foundation::Uri(uri);
3535
}
3636

@@ -47,6 +47,6 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
4747
}
4848

4949
private:
50-
std::wstring m_args;
50+
winrt::hstring m_args;
5151
};
5252
}

dev/AppLifecycle/ProtocolActivatedEventArgs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
1616
IInternalValueMarshalable>
1717
{
1818
public:
19-
ProtocolActivatedEventArgs(const std::wstring& uri) : m_uri(winrt::Windows::Foundation::Uri(std::move(uri)))
19+
ProtocolActivatedEventArgs(const winrt::hstring uri) : m_uri(winrt::Windows::Foundation::Uri(uri))
2020
{
2121
m_kind = ActivationKind::Protocol;
2222
}
2323

2424
static winrt::Windows::Foundation::IInspectable Deserialize(winrt::Windows::Foundation::Uri const& uri)
2525
{
2626
auto query = uri.QueryParsed();
27-
auto args = std::wstring(query.GetFirstValueByName(L"Uri"));
27+
auto args = query.GetFirstValueByName(L"Uri");
2828
return make<ProtocolActivatedEventArgs>(args);
2929
}
3030

3131
// IInternalValueMarshalable
3232
winrt::Windows::Foundation::Uri Serialize()
3333
{
34-
auto uri = GenerateEncodedLaunchUri(L"App", c_protocolContractId) + L"&Uri=" + m_uri.AbsoluteUri();
34+
auto uri = GenerateEncodedLaunchUri(L"App", c_protocolContractId) + L"&Uri=" + winrt::Windows::Foundation::Uri::EscapeComponent(m_uri.AbsoluteUri());
3535
return winrt::Windows::Foundation::Uri(uri);
3636
}
3737

dev/AppLifecycle/StartupActivatedEventArgs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
1515
ActivatedEventArgsBase, IInternalValueMarshalable>
1616
{
1717
public:
18-
StartupActivatedEventArgs(const std::wstring& taskId) : m_taskId(taskId)
18+
StartupActivatedEventArgs(const winrt::hstring taskId) : m_taskId(taskId)
1919
{
2020
m_kind = ActivationKind::StartupTask;
2121
}
2222

2323
static winrt::Windows::Foundation::IInspectable Deserialize(winrt::Windows::Foundation::Uri const& uri)
2424
{
2525
auto query = uri.QueryParsed();
26-
auto taskId = std::wstring(query.GetFirstValueByName(L"TaskId"));
26+
auto taskId = query.GetFirstValueByName(L"TaskId");
2727
return make<StartupActivatedEventArgs>(taskId);
2828
}
2929

3030
// IInternalValueMarshalable
3131
winrt::Windows::Foundation::Uri Serialize()
3232
{
33-
auto uri = GenerateEncodedLaunchUri(L"App", c_startupTaskContractId) + L"&TaskId=" + m_taskId;
33+
auto uri = GenerateEncodedLaunchUri(L"App", c_startupTaskContractId) + L"&TaskId=" + winrt::Windows::Foundation::Uri::EscapeComponent(m_taskId.c_str());
3434
return winrt::Windows::Foundation::Uri(uri);
3535
}
3636

@@ -41,7 +41,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
4141
}
4242

4343
private:
44-
std::wstring m_taskId;
44+
winrt::hstring m_taskId;
4545
};
4646
}
4747

0 commit comments

Comments
 (0)