mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 973489 - Part 1. Support toast notification on desktop mode. r=jimm
This commit is contained in:
parent
28699ea040
commit
3f0c9bcc6a
@ -13,6 +13,10 @@ var AlertsHelper = {
|
||||
}
|
||||
this._listener = aListener;
|
||||
|
||||
if (Services.metro.foreground) {
|
||||
// Firefox is in the foreground, no need for a notification.
|
||||
return;
|
||||
}
|
||||
Services.metro.showNativeToast(aTitle, aText, aImageURL, aCookie);
|
||||
},
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
* implementation of this interface for non-Windows systems, for testing and
|
||||
* development purposes only.
|
||||
*/
|
||||
[scriptable, uuid(b6cbef4a-eec1-470b-8e74-9f4120f678c6)]
|
||||
[scriptable, uuid(dde6eee6-ad11-475b-b7d7-bee8e46e5756)]
|
||||
interface nsIWinMetroUtils : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -40,6 +40,11 @@ interface nsIWinMetroUtils : nsISupports
|
||||
*/
|
||||
attribute boolean updatePending;
|
||||
|
||||
/*
|
||||
* Determine if metro firefox is running in the foreground.
|
||||
*/
|
||||
readonly attribute boolean foreground;
|
||||
|
||||
/**
|
||||
* Show the settings flyout
|
||||
*/
|
||||
@ -53,8 +58,13 @@ interface nsIWinMetroUtils : nsISupports
|
||||
|
||||
/**
|
||||
* Displays a native Windows 8 toast.
|
||||
*
|
||||
* @param aAppId Application ID for current application.
|
||||
* If using Metro mode, it can be null string.
|
||||
*/
|
||||
void showNativeToast(in AString aTitle, in AString aMessage, in AString anImage, in AString aCookie);
|
||||
void showNativeToast(in AString aTitle, in AString aMessage,
|
||||
in AString anImage, in AString aCookie,
|
||||
[optional] in AString aAppId);
|
||||
|
||||
/**
|
||||
* Secondary tiles are a Windows 8 specific feature for pinning new tiles
|
||||
|
@ -22,7 +22,8 @@ void
|
||||
ToastNotificationHandler::DisplayNotification(HSTRING title,
|
||||
HSTRING msg,
|
||||
HSTRING imagePath,
|
||||
const nsAString& aCookie)
|
||||
const nsAString& aCookie,
|
||||
const nsAString& aAppId)
|
||||
{
|
||||
mCookie = aCookie;
|
||||
|
||||
@ -50,13 +51,14 @@ ToastNotificationHandler::DisplayNotification(HSTRING title,
|
||||
SetNodeValueString(msg, msgTextNodeRoot.Get(), toastXml.Get());
|
||||
SetNodeValueString(imagePath, srcAttribute.Get(), toastXml.Get());
|
||||
|
||||
CreateWindowsNotificationFromXml(toastXml.Get());
|
||||
CreateWindowsNotificationFromXml(toastXml.Get(), aAppId);
|
||||
}
|
||||
|
||||
void
|
||||
ToastNotificationHandler::DisplayTextNotification(HSTRING title,
|
||||
HSTRING msg,
|
||||
const nsAString& aCookie)
|
||||
const nsAString& aCookie,
|
||||
const nsAString& aAppId)
|
||||
{
|
||||
mCookie = aCookie;
|
||||
|
||||
@ -75,7 +77,7 @@ ToastNotificationHandler::DisplayTextNotification(HSTRING title,
|
||||
SetNodeValueString(title, titleTextNodeRoot.Get(), toastXml.Get());
|
||||
SetNodeValueString(msg, msgTextNodeRoot.Get(), toastXml.Get());
|
||||
|
||||
CreateWindowsNotificationFromXml(toastXml.Get());
|
||||
CreateWindowsNotificationFromXml(toastXml.Get(), aAppId);
|
||||
}
|
||||
|
||||
ComPtr<IXmlDocument>
|
||||
@ -91,7 +93,8 @@ ToastNotificationHandler::InitializeXmlForTemplate(ToastTemplateType templateTyp
|
||||
}
|
||||
|
||||
void
|
||||
ToastNotificationHandler::CreateWindowsNotificationFromXml(IXmlDocument *toastXml)
|
||||
ToastNotificationHandler::CreateWindowsNotificationFromXml(IXmlDocument *toastXml,
|
||||
const nsAString& aAppId)
|
||||
{
|
||||
ComPtr<IToastNotification> notification;
|
||||
ComPtr<IToastNotificationFactory> factory;
|
||||
@ -107,7 +110,14 @@ ToastNotificationHandler::CreateWindowsNotificationFromXml(IXmlDocument *toastXm
|
||||
&ToastNotificationHandler::OnDismiss).Get(), &dismissedToken));
|
||||
|
||||
ComPtr<IToastNotifier> notifier;
|
||||
mToastNotificationManagerStatics->CreateToastNotifier(¬ifier);
|
||||
if (aAppId.IsEmpty()) {
|
||||
AssertHRESULT(mToastNotificationManagerStatics->CreateToastNotifier(
|
||||
¬ifier));
|
||||
} else {
|
||||
AssertHRESULT(mToastNotificationManagerStatics->CreateToastNotifierWithId(
|
||||
HStringReference(PromiseFlatString(aAppId).get()).Get(),
|
||||
¬ifier));
|
||||
}
|
||||
notifier->Show(notification.Get());
|
||||
|
||||
MetroUtils::FireObserver("metro_native_toast_shown", mCookie.get());
|
||||
|
@ -25,8 +25,11 @@ class ToastNotificationHandler {
|
||||
ToastNotificationHandler() {};
|
||||
~ToastNotificationHandler() {};
|
||||
|
||||
void DisplayNotification(HSTRING title, HSTRING msg, HSTRING imagePath, const nsAString& aCookie);
|
||||
void DisplayTextNotification(HSTRING title, HSTRING msg, const nsAString& aCookie);
|
||||
void DisplayNotification(HSTRING title, HSTRING msg, HSTRING imagePath,
|
||||
const nsAString& aCookie, const nsAString& aAppId);
|
||||
void DisplayTextNotification(HSTRING title, HSTRING msg,
|
||||
const nsAString& aCookie,
|
||||
const nsAString& aAppId);
|
||||
HRESULT OnActivate(IToastNotification *notification, IInspectable *inspectable);
|
||||
HRESULT OnDismiss(IToastNotification *notification,
|
||||
IToastDismissedEventArgs* aArgs);
|
||||
@ -35,6 +38,7 @@ class ToastNotificationHandler {
|
||||
nsString mCookie;
|
||||
ComPtr<IToastNotificationManagerStatics> mToastNotificationManagerStatics;
|
||||
|
||||
void CreateWindowsNotificationFromXml(IXmlDocument *toastXml);
|
||||
void CreateWindowsNotificationFromXml(IXmlDocument *toastXml,
|
||||
const nsAString& aAppId);
|
||||
ComPtr<IXmlDocument> InitializeXmlForTemplate(ToastTemplateType templateType);
|
||||
};
|
||||
|
@ -200,13 +200,8 @@ nsWinMetroUtils::LaunchInDesktop(const nsAString &aPath, const nsAString &aArgum
|
||||
NS_IMETHODIMP
|
||||
nsWinMetroUtils::ShowNativeToast(const nsAString &aTitle,
|
||||
const nsAString &aMessage, const nsAString &anImage,
|
||||
const nsAString &aCookie)
|
||||
const nsAString &aCookie, const nsAString& aAppId)
|
||||
{
|
||||
// Firefox is in the foreground, no need for a notification.
|
||||
if (::GetActiveWindow() == ::GetForegroundWindow()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ToastNotificationHandler* notification_handler =
|
||||
new ToastNotificationHandler;
|
||||
|
||||
@ -215,9 +210,10 @@ nsWinMetroUtils::ShowNativeToast(const nsAString &aTitle,
|
||||
|
||||
if (anImage.Length() > 0) {
|
||||
HSTRING imagePath = HStringReference(anImage.BeginReading()).Get();
|
||||
notification_handler->DisplayNotification(title, msg, imagePath, aCookie);
|
||||
notification_handler->DisplayNotification(title, msg, imagePath, aCookie,
|
||||
aAppId);
|
||||
} else {
|
||||
notification_handler->DisplayTextNotification(title, msg, aCookie);
|
||||
notification_handler->DisplayTextNotification(title, msg, aCookie, aAppId);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -333,5 +329,12 @@ nsWinMetroUtils::SetUpdatePending(bool aUpdatePending)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWinMetroUtils::GetForeground(bool* aForeground)
|
||||
{
|
||||
*aForeground = (::GetActiveWindow() == ::GetForegroundWindow());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // widget
|
||||
} // mozilla
|
||||
|
Loading…
Reference in New Issue
Block a user