feat: continue-activity event is extended to support webpageURL property (#30042)
Co-authored-by: Akshat Malik <amalik@microstrategy.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net>
This commit is contained in:
parent
3582a513ca
commit
d267f979b7
7 changed files with 18 additions and 8 deletions
|
@ -161,6 +161,8 @@ Returns:
|
|||
[`NSUserActivity.activityType`][activity-type].
|
||||
* `userInfo` unknown - Contains app-specific state stored by the activity on
|
||||
another device.
|
||||
* `details` Object
|
||||
* `webpageURL` String (optional) - A string identifying the URL of the webpage accessed by the activity on another device, if available.
|
||||
|
||||
Emitted during [Handoff][handoff] when an activity from a different device wants
|
||||
to be resumed. You should call `event.preventDefault()` if you want to handle
|
||||
|
|
|
@ -716,8 +716,9 @@ void App::OnDidFailToContinueUserActivity(const std::string& type,
|
|||
|
||||
void App::OnContinueUserActivity(bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) {
|
||||
if (Emit("continue-activity", type, user_info)) {
|
||||
const base::DictionaryValue& user_info,
|
||||
const base::DictionaryValue& details) {
|
||||
if (Emit("continue-activity", type, user_info, details)) {
|
||||
*prevent_default = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,8 @@ class App : public ElectronBrowserClient::Delegate,
|
|||
const std::string& error) override;
|
||||
void OnContinueUserActivity(bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) override;
|
||||
const base::DictionaryValue& user_info,
|
||||
const base::DictionaryValue& details) override;
|
||||
void OnUserActivityWasContinued(
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) override;
|
||||
|
|
|
@ -187,7 +187,8 @@ class Browser : public WindowListObserver {
|
|||
|
||||
// Resumes an activity via hand-off.
|
||||
bool ContinueUserActivity(const std::string& type,
|
||||
base::DictionaryValue user_info);
|
||||
base::DictionaryValue user_info,
|
||||
base::DictionaryValue details);
|
||||
|
||||
// Indicates that an activity was continued on another device.
|
||||
void UserActivityWasContinued(const std::string& type,
|
||||
|
|
|
@ -277,10 +277,11 @@ void Browser::DidFailToContinueUserActivity(const std::string& type,
|
|||
}
|
||||
|
||||
bool Browser::ContinueUserActivity(const std::string& type,
|
||||
base::DictionaryValue user_info) {
|
||||
base::DictionaryValue user_info,
|
||||
base::DictionaryValue details) {
|
||||
bool prevent_default = false;
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnContinueUserActivity(&prevent_default, type, user_info);
|
||||
observer.OnContinueUserActivity(&prevent_default, type, user_info, details);
|
||||
return prevent_default;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,8 @@ class BrowserObserver : public base::CheckedObserver {
|
|||
// The browser wants to resume a user activity via handoff. (macOS only)
|
||||
virtual void OnContinueUserActivity(bool* prevent_default,
|
||||
const std::string& type,
|
||||
const base::DictionaryValue& user_info) {}
|
||||
const base::DictionaryValue& user_info,
|
||||
const base::DictionaryValue& details) {}
|
||||
// The browser wants to notify that an user activity was resumed. (macOS only)
|
||||
virtual void OnUserActivityWasContinued(
|
||||
const std::string& type,
|
||||
|
|
|
@ -154,13 +154,16 @@ static NSDictionary* UNNotificationResponseToNSDictionary(
|
|||
#endif
|
||||
restorationHandler {
|
||||
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
|
||||
NSURL* url = userActivity.webpageURL;
|
||||
NSDictionary* details = url ? @{@"webpageURL" : [url absoluteString]} : @{};
|
||||
if (!userActivity.userInfo)
|
||||
return NO;
|
||||
|
||||
electron::Browser* browser = electron::Browser::Get();
|
||||
return browser->ContinueUserActivity(
|
||||
activity_type,
|
||||
electron::NSDictionaryToDictionaryValue(userActivity.userInfo))
|
||||
electron::NSDictionaryToDictionaryValue(userActivity.userInfo),
|
||||
electron::NSDictionaryToDictionaryValue(details))
|
||||
? YES
|
||||
: NO;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue