Toast 通知操作:网站未进入前台
美好的一天,
我正在 PowerShell 脚本中创建 toast 通知,并且我已添加一个“更多信息”按钮作为操作。
<toast>
<actions>
<action arguments="http://google.com" content="more information" activationType="protocol" />
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
这工作正常,但它启动了 Microsoft Edge Chromium,但没有将其带到前台。因此,如果您已经打开了 Edge,乍一看感觉好像单击通知上的按钮没有执行任何操作。该页面确实打开了,只是不像您在询问“更多信息”时所希望的那样当着您的面打开。我希望它能显示在您面前,因为我的用户在技能/知识上差异很大。
我正在寻找一种解决方案,我可以执行以下操作之一:
- 让 PowerShell 中的某些内容知道用户单击了该按钮,并使用代码手动操作请求,而不是让 Windows 处理它。
- 让按钮将网站带到顶部。
- 创建以不同方式执行操作的自定义协议。我读到了一些关于此的松散内容,但无法理解它的含义,这只是一个没有上下文的即兴评论,仅包含它以防它启发比我更有见识的人。
我一开始认为这可能是与 Edge 本身相关的行为,但是在 Windows 运行对话框中输入“http://google.com”绝对会将其带到前面。 (正如我所期望的那样)
以防万一它是一个因素。 PowerShell 5.1 是首选,但 7 对我来说是一个选择。
感谢您能够提供的任何帮助。
---附加信息---
这适用于使用此方法从 Toast 通知启动的所有网站。不幸的是,我没有任何东西可以用来测试非自定义通知,看看它是否做同样的事情。
上面的 XML 用于创建 toast 通知。下面是 PowerShell 代码,可能有助于您更好地理解它。
$ToastTitle = "TOAST NOTIFICATION"
$Signature = "From TEAMNAME"
$BannerImage = "C:\temp\toast-test\toast.jpg"
$EventTitle = "Testing Title"
$EventText = "This is where there would normally be info. This is just a test though."
$site = "http://google.com/"
$MoreInfoTitle = "More Information"
$FirstName = (net user $env:USERNAME /domain | Select-String "Full Name").ToString().Split(",")[-1].trim()
if ($FirstName) {
$CustomHello = "$CustomHello $FirstName"
}
#Specify Launcher App ID, the App that will claim ownership of the toast notification, doesn't affect functionality.
$LauncherID = "AppName"
#Load Assemblies
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
#Build XML Template
[xml]$toastTemplate = @"
<toast duration="long" scenario="reminder">
<visual>
<binding template="ToastGeneric">
<text>$CustomHello</text>
<text>$ToastTitle</text>
<text placement="attribution">$Signature</text>
<image placement="hero" src="$BannerImage"/>
<group>
<subgroup>
<text hint-style="title" hint-wrap="true" >$EventTitle</text>
</subgroup>
</group>
<group>
<subgroup>
<text hint-style="body" hint-wrap="true" >$EventText</text>
</subgroup>
</group>
</binding>
</visual>
<audio src="ms-winsoundevent:notification.default"/>
</toast>
"@
[xml]$ToastActionSnooze = @"
<toast>
<actions>
<input id="SnoozeTimer" type="selection" title="Select a Snooze Interval" defaultInput="15">
<selection id="15" content="15 Minutes"/>
<selection id="30" content="30 Minutes"/>
<selection id="60" content="1 Hour"/>
<selection id="120" content="2 Hours"/>
<selection id="240" content="4 Hours"/>
</input>
<action arguments="$site" content="$MoreInfoTitle" activationType="protocol" />
<action activationType="system" arguments="snooze" hint-inputId="SnoozeTimer" content="" id="test-snooze"/>
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
"@
[xml]$ToastAction = @"
<toast>
<actions>
<action arguments="$site" content="$MoreInfoTitle" activationType="protocol" />
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
"@
#If the Snooze parameter was passed, add additional XML elements to Toast
If ($Snooze) {
[void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($ToastActionSnooze.toast.actions, $true))
}
else {
[void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($ToastAction.toast.actions, $true))
}
#Prepare XML
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
$ToastXml.LoadXml($ToastTemplate.OuterXml)
#Prepare and Create Toast
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)```
Good Day
I am creating toast notifications from within a PowerShell script and there is a "more information" button that I have added as an action.
<toast>
<actions>
<action arguments="http://google.com" content="more information" activationType="protocol" />
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
This works fine however it launches Microsoft Edge Chromium without bringing it to the foreground. So if you already have Edge open it feels at first glance like clicking the button on the notification did nothing. The page does open, just not in your face like you'd hope when asking for "more information". I am hoping to have it show up on top and right in your face as my users vary WILDLY in skill/knowledge.
I am looking for a solution where I can do one of the following:
- Have something in PowerShell know that the user clicked that button and action the request manually with code rather than letting Windows handle it.
- Have the button bring the website to the top.
- Create a custom protocol that performs the action differently. I read something loose about this however was not able to understand what was meant by it, and it was just an off hand comment with no context, only including it in case it inspires someone more knowledgably then myself.
I thought at first it may be behavior related to Edge itself however typing "http://google.com" into a Windows Run Dialog absolutely brings it to the front. (as I expect it too)
In case its a factor. PowerShell 5.1 is preferred however 7 is an option for me.
Thanks for any help you may be able to provide.
---Addtional Info---
This is for all sites launched from a toast notification using this method. I unfortunately do not have anything to use to test a non custom notification to see if it does the same thing or not.
The XML above is used to create the toast notification. Here is the PowerShell code that might help make more sense of it.
$ToastTitle = "TOAST NOTIFICATION"
$Signature = "From TEAMNAME"
$BannerImage = "C:\temp\toast-test\toast.jpg"
$EventTitle = "Testing Title"
$EventText = "This is where there would normally be info. This is just a test though."
$site = "http://google.com/"
$MoreInfoTitle = "More Information"
$FirstName = (net user $env:USERNAME /domain | Select-String "Full Name").ToString().Split(",")[-1].trim()
if ($FirstName) {
$CustomHello = "$CustomHello $FirstName"
}
#Specify Launcher App ID, the App that will claim ownership of the toast notification, doesn't affect functionality.
$LauncherID = "AppName"
#Load Assemblies
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
#Build XML Template
[xml]$toastTemplate = @"
<toast duration="long" scenario="reminder">
<visual>
<binding template="ToastGeneric">
<text>$CustomHello</text>
<text>$ToastTitle</text>
<text placement="attribution">$Signature</text>
<image placement="hero" src="$BannerImage"/>
<group>
<subgroup>
<text hint-style="title" hint-wrap="true" >$EventTitle</text>
</subgroup>
</group>
<group>
<subgroup>
<text hint-style="body" hint-wrap="true" >$EventText</text>
</subgroup>
</group>
</binding>
</visual>
<audio src="ms-winsoundevent:notification.default"/>
</toast>
"@
[xml]$ToastActionSnooze = @"
<toast>
<actions>
<input id="SnoozeTimer" type="selection" title="Select a Snooze Interval" defaultInput="15">
<selection id="15" content="15 Minutes"/>
<selection id="30" content="30 Minutes"/>
<selection id="60" content="1 Hour"/>
<selection id="120" content="2 Hours"/>
<selection id="240" content="4 Hours"/>
</input>
<action arguments="$site" content="$MoreInfoTitle" activationType="protocol" />
<action activationType="system" arguments="snooze" hint-inputId="SnoozeTimer" content="" id="test-snooze"/>
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
"@
[xml]$ToastAction = @"
<toast>
<actions>
<action arguments="$site" content="$MoreInfoTitle" activationType="protocol" />
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
"@
#If the Snooze parameter was passed, add additional XML elements to Toast
If ($Snooze) {
[void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($ToastActionSnooze.toast.actions, $true))
}
else {
[void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($ToastAction.toast.actions, $true))
}
#Prepare XML
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
$ToastXml.LoadXml($ToastTemplate.OuterXml)
#Prepare and Create Toast
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你差一点就答对了。只需使用此 LauncherId
并使用最后一行代码即可:
You nearly had it right. Just take this LauncherId
and use this last line of code: