[win] added sources to use system notifications

This commit is contained in:
Maxim Kadushkin
2019-12-24 16:34:20 +03:00
parent 6de26cfefe
commit 1a7d5e6a94
23 changed files with 4022 additions and 1 deletions

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Mohammed Boujemaoui Boulaghmoudi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,246 @@
![releases](https://img.shields.io/github/tag/mohabouje/WinToast.svg)
![issues](https://img.shields.io/github/issues/mohabouje/WinToast.svg)
![license](https://img.shields.io/github/license/mohabouje/WinToast.svg)
![GitHub contributors](https://img.shields.io/github/contributors/mohabouje/WinToast.svg)
![built](https://img.shields.io/badge/built%20with-MVSC-6f62ba.svg)
![dowloads](https://img.shields.io/github/downloads/mohabouje/WinToast/total.svg)
[![GitHub forks](https://img.shields.io/github/forks/mohabouje/WinToast.svg?style=social&label=Fork)]()
[![GitHub stars](https://img.shields.io/github/stars/mohabouje/WinToast.svg?style=social&label=Star)]()
[![GitHub watchers](https://img.shields.io/github/watchers/mohabouje/WinToast.svg?style=social&label=Watch)]()
***
WinToast
===================
WinToast is a lightly library written in C++ which brings a complete integration of the modern **toast notifications** of **Windows 8** & **Windows 10**.
Toast notifications allows your app to inform the users about relevant information and timely events that they should see and take action upon inside your app, such as a new instant message, a new friend request, breaking news, or a calendar event.
1. [Toast Templates](#id1)
2. [Event Handler](#id3)
3. [Expiration Time](#id4)
4. [Additional features available on Windows 10](#id5)
5. [Error Handling](#id2)
6. [Example of usage](#id6)
7. [Toast configuration on Windows 10](#id7)
8. [Projects using WinToast](#id8)
<div id='id1' />
## Toast Templates
WinToast integrates all standard templates available in the [ToastTemplateType enumeration](https://msdn.microsoft.com/en-us/library/windows/apps/br208660.aspx).
| Template | Description | Example |
| :------- | ----: | :---: |
| `ImageAndText01` | A large image and a single string wrapped across three lines of text. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601606.png) |
| `ImageAndText02` | A large image, one string of bold text on the first line, one string of regular text wrapped across the second and third lines. | ![12](https://i-msdn.sec.s-msft.com/dynimg/IC601607.png) |
| `ImageAndText03` | A large image, one string of bold text wrapped across the first two lines, one string of regular text on the third line. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601608.png) |
| `ImageAndText04` | A large image, one string of bold text on the first line, one string of regular text on the second line, one string of regular text on the third line. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601609.png) |
| `Text01` | Single string wrapped across three lines of text. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601602.png)|
| `Text02` | One string of bold text on the first line, one string of regular text wrapped across the second and third lines. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601603.png) |
| `Text03` | One string of bold text wrapped across the first two lines, one string of regular text on the third line. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601604.png)|
| `Text04` | One string of bold text on the first line, one string of regular text on the second line, one string of regular text on the third line. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601605.png) |
Example of a `ImageAndText02` template:
```cpp
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
templ.setTextField(L"title", WinToastTemplate::FirstLine);
templ.setTextField(L"subtitle", WinToastTemplate::SecondLine);
templ.setImagePath(L"C:/example.png");
```
**Note:** The user can use the default system sound or specify a sound to play when a toast notification is displayed. Same behavior for the toast notification image, by default Windows try to use the app icon.*
<div id='id3' />
## Event Handler
WinToast handle different events:
- **Activated**: Occurs when user activates a toast notification through a click or touch. Apps that are running subscribe to this event
- **Dismissed**: Occurs when a toast notification leaves the screen, either by expiring or being explicitly dismissed by the user.
* Application Hidden: The application hid the toast using ToastNotifier.hide.
* User Canceled: The user dismissed the toast.
* Timed Out: The toast has expired
- **Failed**: Occurs when an error is caused when Windows attempts to raise a toast notification.
Create your custom handler to interact with the user actions by subclassing the interface `IWinToastHandler`:
```cpp
class WinToastHandlerExample : public IWinToastHandler {
public:
WinToastHandlerExample();
// Public interfaces
void toastActivated() const override;
void toastDismissed(WinToastDismissalReason state) const override;
void toastFailed() const override;
};
```
<div id='id4' />
## Expiration Time
Set the time after which a toast notification is no longer considered current or valid and should not be displayed. Windows attempts to raise toast notifications immediately after you call Show, so this property is rarely used.
> For Windows 8.x app, this property also causes the toast notification to be removed from the
> Action Center once the specified data and time is reached.
**Note:** Default Windows behavior is to hide notification automatically after time set in Windows Ease of Access Settings.
If you need to preserve notification in Windows Action Center for longer period of time, you have to call `WinToastTemplate::setExpiration` method.
<div id='id5' />
## Additional features available on Windows 10
If your system supports the new modern features (Version > Windows 8.1) available in Windows 10, you can add some interesting fields as:
- **Actions**: you can add your own actions, this fact allow you to interact with user in a different way:
```cpp
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::Text02);
templ.setTextField(L"Do you think this feature is cool?", WinToastTemplate::FirstLine);
templ.setTextField(L"Ofc,it is!", WinToastTemplate::SecondLine);
std::vector<std::wstring> actions;
actions.push_back(L"Yes");
actions.push_back(L"No");
for (auto const &action : actions)
templ.addAction(action);
WinToast::instance()->showToast(templ, handler)
```
!["Toast with some actions"](https://lh3.googleusercontent.com/uJE_H0aBisOZ-9GynEWgA7Hha8tHEI-i0aHrFuOFDBsPSD-IJ-qEN0Y7XY4VI5hp_5MQ9xjWbFcm)
- **Attribution text**: you can add/remove the attribution text, by default is empty. Use `WinToastTemplate::setAttributionText` to modify it.
- **Duration**: The amount of time the toast should display. This attribute can have one of the following values:
- *System*: default system configuration.
- *Short*: default system short time configuration.
- *Long*: default system long time configuration.
- **Audio Properties**: you can modify the different behaviors of the sound:
- *Default*: plays the audio file just one time.
- *Silent*: turn off the sound.
- *Loop*: plays the given sound in a loop during the toast existence.
> WinToast allows the modification of the default audio file. Add
> the given file in to your projects resources (*must be ms-appx:// or
> ms-appdata:// path*) and define it by calling: `WinToastTemplate::setAudioPath`
***By default, WinToast checks if your systems support the features, ignoring the not supported ones.***
<div id='id2' />
## Error Handling
There are several reasons WinToast can fail that's why the library notifies caller about fail reason. Those are the code for each failure:
| WinToastError | Error Code | Error message |
|--|--|--|
| `NoError` | 0x00 | No error. The process was executed correctly |
| `NotInitialized` | 0x01 | The library has not been initialized |
| `SystemNotSupported` | 0x02 | The OS does not support WinToast |
| `ShellLinkNotCreated` | 0x03 | The library was not able to create a Shell Link for the app |
| `InvalidAppUserModelID` | 0x04 | The AUMI is not a valid one |
| `InvalidParameters` | 0x05 | The parameters used to configure the library are not valid normally because an invalid AUMI or App Name |
| `NotDisplayed` | 0x06 | The toast was created correctly but WinToast was not able to display the toast |
| `UnknownError` | 0x07 | Unknown error |
A common example of usage is to check while initializing the library or showing a toast notification the possible failure code:
```cpp
WinToast::WinToastError error;
const bool succedded = WinToast::instance()->initialize(&error);
if (!succedded) {
std::wcout << L"Error, could not initialize the lib. Error number: "
<< error << std::endl;
}
...
// Configure the template
...
const bool launched = WinToast::instance()->showToast(templ, handler, &error);
if (!launched) {
std::wcout << L"Error: Could not launch your toast notification. Error: "
<< error << std::endl;
}
```
<div id='id6' />
## Example of Usage
*For an easy usage, you can just use the available singleton instance.*
First step, Import the header file wintoastlib.h to your project. You should check if your Windows Version is supported by the library.
```cpp
using namespace WinToastLib;
....
if (!WinToast::isCompatible()) {
std::wcout << L"Error, your system in not supported!" << std::endl;
}
```
Configure your [App User Model Id](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459%28v=vs.85%29.aspx), this can be done by using the existing helper:
```cpp
WinToast::instance()->setAppName(L"WinToastExample");
const auto aumi = WinToast::configureAUMI(L"mohabouje", L"wintoast", L"wintoastexample", L"20161006");
WinToast::instance()->setAppUserModelId(aumi);
```
Initialize all the dependencies and check if WinToast has been initialized successfully in your system:
```cpp
if (!WinToast::instance()->initialize()) {
std::wcout << L"Error, could not initialize the lib!" << std::endl;
}
```
Implement your own action handler by subclassing the interface `IWinToastHandler` and custom your template:
```cpp
WinToastHandlerExample* handler = new WinToastHandlerExample;
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
templ.setImagePath(L"C:/example.png");
templ.setTextField(L"title", WinToastTemplate::FirstLine);
templ.setTextField(L"subtitle", WinToastTemplate::SecondLine);
```
Finally show the results:
```cpp
if (!WinToast::instance()->showToast(templ, handler)) {
std::wcout << L"Error: Could not launch your toast notification!" << std::endl;
}
```
<div id='id7' />
## Installation
If you are using a package manager, there is a port for [vcpkg](https://github.com/microsoft/vcpkg/). Otherwise, the easiest way is to copy the source files as external dependencies.
## Toast configuration on Windows 10
Windows allows the configuration of the default behavior of a toast notification. This can be done in the *Ease of Access* configuration by modifying the *Other options* tab.
The system configuration helps you to define how long you want notifications to appear for (5 seconds to 5 minutes) as turning on visual notifications for sound.
![Ease of Access configuration](https://camo.githubusercontent.com/56c8edd1a7a4a43be07ba211d9d828478fdbad39/68747470733a2f2f7777772e686f77746f6765656b2e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031362f30332f656173655f6f665f6163636573732e706e67)
<div id='id8' />
## Projects using WinToast
- [Git for Windows](https://github.com/git-for-windows/git): A fork of Git containing Windows-specific patches.
- [QGIS](https://github.com/qgis/QGIS): QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
- [MEGAsync](https://github.com/meganz/MEGAsync): Easy automated syncing between your computers and your MEGA Cloud Drive
- [chatterino2](https://github.com/Chatterino/chatterino2): Chat client for twitch.tv
- [nheko](https://github.com/mujx/nheko): Desktop client for the Matrix protocol.
- [EDPathFinder](https://github.com/neotron/EDPathFinder): A program that creates an optimal route that passes through two or more systems in Elite.
- [AntiExploit](https://github.com/Empier/Anti-Exploit): antiexploit utility for Windows.
- [Zroya](https://github.com/malja/zroya): Python extension for creating native Windows notifications..
- [PidginWinToastNotifications](https://github.com/ChristianGalla/PidginWinToastNotifications): Windows Toast Notification Plugin for Pidgin.
- [Dnai-Editor](https://github.com/Nicolas-Constanty/Dnai.Editor): Visual Scripting, node editor.
- [Spectral](https://gitlab.com/b0/spectral): A glossy client for Matrix, written in QtQuick Controls 2 and C++.

View File

@ -0,0 +1,185 @@
# WinToast
WinToast is a lightly library written in C++ which brings a complete integration of the modern **toast notifications** of **Windows 8** & **Windows 10**.
Toast notifications allows your app to inform the users about relevant information and timely events that they should see and take action upon inside your app, such as a new instant message, a new friend request, breaking news, or a calendar event.
## Event Handler
WinToast implements a common interface `IWinToastHandler` to handle events:
- **Activated**: Occurs when user activates a toast notification through a click or touch. Apps that are running subscribe to this event
- **Dismissed**: Occurs when a toast notification leaves the screen, either by expiring or being explicitly dismissed by the user.
* Application Hidden: The application hid the toast using ToastNotifier.hide.
* User Canceled: The user dismissed the toast.
* Timed Out: The toast has expired
- **Failed**: Occurs when an error is caused when Windows attempts to raise a toast notification.
Users can creates their own custom handler to interact with the user actions. For example:
```cpp
class WinToastHandlerExample : public IWinToastHandler {
public:
WinToastHandlerExample();
// Public interfaces
void toastActivated() const override;
void toastDismissed(WinToastDismissalReason state) const override;
void toastFailed() const override;
};
```
## Error Handling
There are several reasons WinToast can fail that's why the library notifies the caller about any possible failure reason. Those are the code for each failure:
| WinToastError | Error Code | Error message |
| ----------------------- | ---------- | ------------------------------------------------------------ |
| `NoError` | 0x00 | No error. The process was executed correctly |
| `NotInitialized` | 0x01 | The library has not been initialized |
| `SystemNotSupported` | 0x02 | The OS does not support WinToast |
| `ShellLinkNotCreated` | 0x03 | The library was not able to create a Shell Link for the app |
| `InvalidAppUserModelID` | 0x04 | The AUMI is not a valid one |
| `InvalidParameters` | 0x05 | The parameters used to configure the library are not valid normally because an invalid AUMI or App Name |
| `NotDisplayed` | 0x06 | The toast was created correctly but WinToast was not able to display the toast |
| `UnknownError` | 0x07 | Unknown error |
A common example of usage is to check while initializing the library or showing a toast notification the possible failure code:
```cpp
WinToast::WinToastError error;
const bool succedded = WinToast::instance()->initialize(&error);
if (!succedded) {
std::wcout << L"Error, could not initialize the lib. Error: "
<< WinToast::strerror(error) << std::endl;
}
```
## Properties
### Templates
WinToast integrates all standard templates available in the [ToastTemplateType enumeration](https://msdn.microsoft.com/en-us/library/windows/apps/br208660.aspx).
| Template | Description | Example |
| :--------------- | -----------------------------------------------------------: | :----------------------------------------------------------: |
| `ImageAndText01` | A large image and a single string wrapped across three lines of text. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601606.png) |
| `ImageAndText02` | A large image, one string of bold text on the first line, one string of regular text wrapped across the second and third lines. | ![12](https://i-msdn.sec.s-msft.com/dynimg/IC601607.png) |
| `ImageAndText03` | A large image, one string of bold text wrapped across the first two lines, one string of regular text on the third line. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601608.png) |
| `ImageAndText04` | A large image, one string of bold text on the first line, one string of regular text on the second line, one string of regular text on the third line. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601609.png) |
| `Text01` | Single string wrapped across three lines of text. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601602.png) |
| `Text02` | One string of bold text on the first line, one string of regular text wrapped across the second and third lines. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601603.png) |
| `Text03` | One string of bold text wrapped across the first two lines, one string of regular text on the third line. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601604.png) |
| `Text04` | One string of bold text on the first line, one string of regular text on the second line, one string of regular text on the third line. | ![enter image description here](https://i-msdn.sec.s-msft.com/dynimg/IC601605.png) |
Example of a `ImageAndText02` template:
```cpp
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
templ.setTextField(L"title", WinToastTemplate::FirstLine);
templ.setTextField(L"subtitle", WinToastTemplate::SecondLine);
templ.setImagePath(L"C:/example.png");
```
**Note:** The user can use the default system sound or specify a sound to play when a toast notification is displayed. Same behavior for the toast notification image, by default Windows try to use the app icon.
### Expiration Time
This property sets the time after which a toast notification is no longer considered current or valid and should not be displayed. Windows attempts to raise toast notifications immediately after you call Show, so this property is rarely used.
> For Windows 8.x app, this property also causes the toast notification to be removed from the
> Action Center once the specified data and time is reached.
> Not: Default Windows behavior is to hide notification automatically after time set in Windows Ease of Access Settings.
If you need to preserve notification in Windows Action Center for longer period of time, you have to call `WinToastTemplate::setExpiration` method.
### Actions
WinToast provides an easy interface to add actions (buttons) to a toast notification. This feature allows the interaction with user in a different way:
```cpp
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::Text02);
templ.setTextField(L"Do you think this feature is cool?", WinToastTemplate::FirstLine);
templ.setTextField(L"Ofc,it is!", WinToastTemplate::SecondLine);
std::vector<std::wstring> actions;
actions.push_back(L"Yes");
actions.push_back(L"No");
for (auto const &action : actions)
templ.addAction(action);
WinToast::instance()->showToast(templ, handler)
```
This code will display something like this:
!["Toast with some actions"](https://lh3.googleusercontent.com/uJE_H0aBisOZ-9GynEWgA7Hha8tHEI-i0aHrFuOFDBsPSD-IJ-qEN0Y7XY4VI5hp_5MQ9xjWbFcm)
### Atribution Text
In the latest versions of Windows, users can add/remove an attribution text (empty by default). WinToast integrates a simple interface to change this property `WinToastTemplate::setAttributionText`:
```c++
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::Text01);
templ.setTextField(L"Do you think this feature is cool?", WinToastTemplate::FirstLine);
templ.setAttributionText(L"This is an attribution text");
WinToast::instance()->showToast(templ, handler)
```
### Duration
Users can change the amount of time the toast should be displayed. This attribute can have one of the following values:
- *System*: default system configuration.
- *Short*: default system short time configuration.
- *Long*: default system long time configuration.
```c++
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::Text01);
templ.setFirstLine(L"I will be displayed for a long time");
templ.setDuration(WinToastTemplate::Duration::Long);
WinToast::instance()->showToast(templ, handler)
```
### Audio
Users can modify the different behaviors of the sound. For instance, users can specify the default play mode:
- *Default*: plays the audio file just one time.
- *Silent*: turn off the sound.
- *Loop*: plays the given sound in a loop during the toast existence.
> WinToast allows the modification of the default audio file. There are different audio files installed by default in the system that can be used via the `WinToastTemplate::AudioSystemFile` enumeration. See more details in this [link](https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio).
>
> For instance, to display an alarm that will play the same sound in a loop we could do something like this:
>
> ```c++
> WinToastTemplate templ = WinToastTemplate(WinToastTemplate::Text01);
> templ.setFirstLine(L"I am an alarm");
> templ.setDuration(WinToastTemplate::Duration::Long);
> templ.setAudioMode(WinToastTemplate::AudioOption::Loop);
> templ.setAudioPath(WinToastTemplate::AudioSystemFile::Alarm);
> WinToast::instance()->showToast(templ, handler)
> ```
## Toast configuration on Windows 10
Windows allows the configuration of the default behavior of a toast notification. This can be done in the *Ease of Access* configuration by modifying the *Other options* tab.
The system configuration helps you to define how long you want notifications to appear for (5 seconds to 5 minutes) as turning on visual notifications for sound.
![Ease of Access configuration](https://camo.githubusercontent.com/56c8edd1a7a4a43be07ba211d9d828478fdbad39/68747470733a2f2f7777772e686f77746f6765656b2e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031362f30332f656173655f6f665f6163636573732e706e67)
<div id='id8' />
## Projects using WinToast
- [Git for Windows](https://github.com/git-for-windows/git): A fork of Git containing Windows-specific patches.
- [QGIS](https://github.com/qgis/QGIS): QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
- [nheko](https://github.com/mujx/nheko): Desktop client for the Matrix protocol.
- [EDPathFinder](https://github.com/neotron/EDPathFinder): A program that creates an optimal route that passes through two or more systems in Elite.
- [AntiExploit](https://github.com/Empier/Anti-Exploit): antiexploit utility for Windows.
- [Zroya](https://github.com/malja/zroya): Python extension for creating native Windows notifications..
- [PidginWinToastNotifications](https://github.com/ChristianGalla/PidginWinToastNotifications): Windows Toast Notification Plugin for Pidgin.
- [Dnai-Editor](https://github.com/Nicolas-Constanty/Dnai.Editor): Visual Scripting, node editor.
- [Spectral](https://gitlab.com/b0/spectral): A glossy client for Matrix, written in QtQuick Controls 2 and C++.

View File

@ -0,0 +1,20 @@
WinToast Console Example!
===================
WinToast Contole Example [OPTIONS]
--action : Set the actions in buttons
--aumi : Set the App User Model Id
--appname : Set the default appname
--appid : Set the App Id
--expirems : Set the default expiration time
--text : Set the text for the notifications
--image : set the image path
--help : Print the help description
Example:
"WinToast Contole Example.exe" --appname "Yolo" --aumi "My.Console.Example" --image "if_terminal_298878.png" --expirems 10000 --action Yes --action No --text "Do you want to try to take over the world?"

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinToast Console Example", "WinToast Console Example.vcxproj", "{7C5AC60D-8668-47B6-9D05-FB363F854065}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x64.ActiveCfg = Debug|Win32
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x64.Build.0 = Debug|Win32
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x86.ActiveCfg = Debug|Win32
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Debug|x86.Build.0 = Debug|Win32
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Release|x64.ActiveCfg = Release|x64
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Release|x64.Build.0 = Release|x64
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Release|x86.ActiveCfg = Release|Win32
{7C5AC60D-8668-47B6-9D05-FB363F854065}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ABA98BF8-B665-455B-A51E-B36DD616139C}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{7C5AC60D-8668-47B6-9D05-FB363F854065}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>WIN32;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
<Link>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Platform)'=='x64'">
<Link>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<Optimization>MinSpace</Optimization>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\wintoastlib.cpp" />
<ClCompile Include="main.cpp">
<AdditionalIncludeDirectories>..\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\wintoastlib.h" />
</ItemGroup>
<ItemGroup>
<Image Include="if_terminal_298878.png" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\.editorconfig" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\wintoastlib.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\wintoastlib.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="if_terminal_298878.png">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<None Include="..\..\.editorconfig" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LocalDebuggerCommandArguments>--appname "Yolo" --aumi "My.Console.Example" --image "$(ProjectDir)if_terminal_298878.png" --expirems 10000 --action Yes --action No --text "Do you want to try to take over the world?"</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -0,0 +1,184 @@
#include "wintoastlib.h"
#include <string> // std::string, std::stoi
using namespace WinToastLib;
class CustomHandler : public IWinToastHandler {
public:
void toastActivated() const {
std::wcout << L"The user clicked in this toast" << std::endl;
exit(0);
}
void toastActivated(int actionIndex) const {
std::wcout << L"The user clicked on action #" << actionIndex << std::endl;
exit(16 + actionIndex);
}
void toastDismissed(WinToastDismissalReason state) const {
switch (state) {
case UserCanceled:
std::wcout << L"The user dismissed this toast" << std::endl;
exit(1);
break;
case TimedOut:
std::wcout << L"The toast has timed out" << std::endl;
exit(2);
break;
case ApplicationHidden:
std::wcout << L"The application hid the toast using ToastNotifier.hide()" << std::endl;
exit(3);
break;
default:
std::wcout << L"Toast not activated" << std::endl;
exit(4);
break;
}
}
void toastFailed() const {
std::wcout << L"Error showing current toast" << std::endl;
exit(5);
}
};
enum Results {
ToastClicked, // user clicked on the toast
ToastDismissed, // user dismissed the toast
ToastTimeOut, // toast timed out
ToastHided, // application hid the toast
ToastNotActivated, // toast was not activated
ToastFailed, // toast failed
SystemNotSupported, // system does not support toasts
UnhandledOption, // unhandled option
MultipleTextNotSupported, // multiple texts were provided
InitializationFailure, // toast notification manager initialization failure
ToastNotLaunched // toast could not be launched
};
#define COMMAND_ACTION L"--action"
#define COMMAND_AUMI L"--aumi"
#define COMMAND_APPNAME L"--appname"
#define COMMAND_APPID L"--appid"
#define COMMAND_EXPIREMS L"--expirems"
#define COMMAND_TEXT L"--text"
#define COMMAND_HELP L"--help"
#define COMMAND_IMAGE L"--image"
#define COMMAND_SHORTCUT L"--only-create-shortcut"
#define COMMAND_AUDIOSTATE L"--audio-state"
#define COMMAND_ATTRIBUTE L"--attribute"
void print_help() {
std::wcout << "WinToast Console Example [OPTIONS]" << std::endl;
std::wcout << "\t" << COMMAND_ACTION << L" : Set the actions in buttons" << std::endl;
std::wcout << "\t" << COMMAND_AUMI << L" : Set the App User Model Id" << std::endl;
std::wcout << "\t" << COMMAND_APPNAME << L" : Set the default appname" << std::endl;
std::wcout << "\t" << COMMAND_APPID << L" : Set the App Id" << std::endl;
std::wcout << "\t" << COMMAND_EXPIREMS << L" : Set the default expiration time" << std::endl;
std::wcout << "\t" << COMMAND_TEXT << L" : Set the text for the notifications" << std::endl;
std::wcout << "\t" << COMMAND_IMAGE << L" : set the image path" << std::endl;
std::wcout << "\t" << COMMAND_ATTRIBUTE << L" : set the attribute for the notification" << std::endl;
std::wcout << "\t" << COMMAND_SHORTCUT << L" : create the shortcut for the app" << std::endl;
std::wcout << "\t" << COMMAND_AUDIOSTATE << L" : set the audio state: Default = 0, Silent = 1, Loop = 2" << std::endl;
std::wcout << "\t" << COMMAND_HELP << L" : Print the help description" << std::endl;
}
int wmain(int argc, LPWSTR *argv)
{
if (argc == 1) {
print_help();
return 0;
}
if (!WinToast::isCompatible()) {
std::wcerr << L"Error, your system in not supported!" << std::endl;
return Results::SystemNotSupported;
}
LPWSTR appName = L"Console WinToast Example",
appUserModelID = L"WinToast Console Example",
text = NULL,
imagePath = NULL,
attribute = L"default";
std::vector<std::wstring> actions;
INT64 expiration = 0;
bool onlyCreateShortcut = false;
WinToastTemplate::AudioOption audioOption = WinToastTemplate::AudioOption::Default;
int i;
for (i = 1; i < argc; i++)
if (!wcscmp(COMMAND_IMAGE, argv[i]))
imagePath = argv[++i];
else if (!wcscmp(COMMAND_ACTION, argv[i]))
actions.push_back(argv[++i]);
else if (!wcscmp(COMMAND_EXPIREMS, argv[i]))
expiration = wcstol(argv[++i], NULL, 10);
else if (!wcscmp(COMMAND_APPNAME, argv[i]))
appName = argv[++i];
else if (!wcscmp(COMMAND_AUMI, argv[i]) || !wcscmp(COMMAND_APPID, argv[i]))
appUserModelID = argv[++i];
else if (!wcscmp(COMMAND_TEXT, argv[i]))
text = argv[++i];
else if (!wcscmp(COMMAND_ATTRIBUTE, argv[i]))
attribute = argv[++i];
else if (!wcscmp(COMMAND_SHORTCUT, argv[i]))
onlyCreateShortcut = true;
else if (!wcscmp(COMMAND_AUDIOSTATE, argv[i]))
audioOption = static_cast<WinToastTemplate::AudioOption>(std::stoi(argv[++i]));
else if (!wcscmp(COMMAND_HELP, argv[i])) {
print_help();
return 0;
} else {
std::wcerr << L"Option not recognized: " << argv[i] << std::endl;
return Results::UnhandledOption;
}
WinToast::instance()->setAppName(appName);
WinToast::instance()->setAppUserModelId(appUserModelID);
if (onlyCreateShortcut) {
if (imagePath || text || actions.size() > 0 || expiration) {
std::wcerr << L"--only-create-shortcut does not accept images/text/actions/expiration" << std::endl;
return 9;
}
enum WinToast::ShortcutResult result = WinToast::instance()->createShortcut();
return result ? 16 + result : 0;
}
if (!text)
text = L"Hello, world!";
if (!WinToast::instance()->initialize()) {
std::wcerr << L"Error, your system in not compatible!" << std::endl;
return Results::InitializationFailure;
}
bool withImage = (imagePath != NULL);
WinToastTemplate templ( withImage ? WinToastTemplate::ImageAndText02 : WinToastTemplate::Text02);
templ.setTextField(text, WinToastTemplate::FirstLine);
templ.setAudioOption(audioOption);
templ.setAttributionText(attribute);
for (auto const &action : actions)
templ.addAction(action);
if (expiration)
templ.setExpiration(expiration);
if (withImage)
templ.setImagePath(imagePath);
if (WinToast::instance()->showToast(templ, new CustomHandler()) < 0) {
std::wcerr << L"Could not launch your toast notification!";
return Results::ToastFailed;
}
// Give the handler a chance for 15 seconds (or the expiration plus 1 second)
Sleep(expiration ? (DWORD)expiration + 1000 : 15000);
exit(2);
}

View File

@ -0,0 +1,27 @@
#-------------------------------------------------
#
# Project created by QtCreator 2016-10-01T17:29:36
#
#-------------------------------------------------
QT += core gui
CONFIG += c++11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = WinToastExample
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
../../../src/wintoastlib.cpp
HEADERS += mainwindow.h \
../../../src/wintoastlib.h
FORMS += mainwindow.ui
#win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../lib/Release/ -lWinToastLib
#else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../lib/Debug/ -lWinToastLib

View File

@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,94 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <qfiledialog.h>
#include <qmessagebox.h>
#include "../../../src/wintoastlib.h"
using namespace WinToastLib;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->audioMode->addItem("Default", WinToastTemplate::AudioOption::Default);
ui->audioMode->addItem("Loop", WinToastTemplate::AudioOption::Loop);
ui->audioMode->addItem("Silence", WinToastTemplate::AudioOption::Silent);
ui->audioSystemFile->addItem("Default", WinToastTemplate::AudioSystemFile::DefaultSound);
ui->audioSystemFile->addItem("Mail", WinToastTemplate::AudioSystemFile::Mail);
ui->audioSystemFile->addItem("SMS", WinToastTemplate::AudioSystemFile::SMS);
ui->audioSystemFile->addItem("Alarm", WinToastTemplate::AudioSystemFile::Alarm);
WinToast::instance()->setAppName(L"WinToastExample");
WinToast::instance()->setAppUserModelId(
WinToast::configureAUMI(L"mohabouje", L"wintoast", L"wintoastexample", L"20161006"));
if (!WinToast::instance()->initialize()) {
qDebug() << "Error, your system in not compatible!";
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_imagePathSelector_clicked()
{
const QString fileName = QFileDialog::getOpenFileName(this, "Select an image", QDir::currentPath(), "*.png");
if (fileName.isEmpty())
return;
ui->imagePath->setText(QDir::toNativeSeparators(fileName));
}
class CustomHandler : public IWinToastHandler {
public:
void toastActivated() const {
std::wcout << L"The user clicked in this toast" << std::endl;
}
void toastActivated(int actionIndex) const {
std::wcout << L"The user clicked on button #" << actionIndex << L" in this toast" << std::endl;
}
void toastFailed() const {
std::wcout << L"Error showing current toast" << std::endl;
}
void toastDismissed(WinToastDismissalReason state) const {
switch (state) {
case UserCanceled:
std::wcout << L"The user dismissed this toast" << std::endl;
break;
case ApplicationHidden:
std::wcout << L"The application hid the toast using ToastNotifier.hide()" << std::endl;
break;
case TimedOut:
std::wcout << L"The toast has timed out" << std::endl;
break;
default:
std::wcout << L"Toast not activated" << std::endl;
break;
}
}
};
void MainWindow::on_showToast_clicked()
{
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::ImageAndText04);
templ.setImagePath(ui->imagePath->text().toStdWString());
templ.setTextField(ui->firstLine->text().toStdWString(), WinToastTemplate::FirstLine);
templ.setTextField(ui->secondLine->text().toStdWString(), WinToastTemplate::SecondLine);
templ.setTextField(ui->secondLine->text().toStdWString(), WinToastTemplate::ThirdLine);
templ.setExpiration(ui->spinBox->value() * 1000);
templ.setAudioPath(static_cast<WinToastTemplate::AudioSystemFile>(ui->audioSystemFile->currentData().toInt()));
templ.setAudioOption(static_cast<WinToastTemplate::AudioOption>(ui->audioMode->currentData().toInt()));
if (ui->addYes->isChecked()) templ.addAction(L"Yes");
if (ui->addNo->isChecked()) templ.addAction(L"No");
if (WinToast::instance()->showToast(templ, new CustomHandler()) < 0) {
QMessageBox::warning(this, "Error", "Could not launch your toast notification!");
}
}

View File

@ -0,0 +1,27 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_imagePathSelector_clicked();
void on_showToast_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,190 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>220</height>
</rect>
</property>
<property name="windowTitle">
<string>WinToast Example</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="2">
<widget class="QComboBox" name="audioSystemFile"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>First Line</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Second Line</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="addYes">
<property name="text">
<string>Add Yes Action</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Audio System File</string>
</property>
</widget>
</item>
<item row="11" column="2">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="showToast">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show Toast</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Image Path</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="addNo">
<property name="text">
<string>Add No Action</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="secondLine"/>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Expiration time (secs)</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="firstLine"/>
</item>
<item row="6" column="0">
<widget class="QSpinBox" name="spinBox">
<property name="maximum">
<number>10</number>
</property>
<property name="singleStep">
<number>2</number>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="imagePath">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="imagePathSelector">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="2">
<widget class="QComboBox" name="audioMode"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Audio Mode</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,217 @@
/* * Copyright (C) 2016-2019 Mohammed Boujemaoui <mohabouje@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef WINTOASTLIB_H
#define WINTOASTLIB_H
#include <Windows.h>
#include <sdkddkver.h>
#include <WinUser.h>
#include <ShObjIdl.h>
#include <wrl/implements.h>
#include <wrl/event.h>
#include <windows.ui.notifications.h>
#include <strsafe.h>
#include <Psapi.h>
#include <ShlObj.h>
#include <roapi.h>
#include <propvarutil.h>
#include <functiondiscoverykeys.h>
#include <iostream>
#include <winstring.h>
#include <string.h>
#include <vector>
#include <map>
using namespace Microsoft::WRL;
using namespace ABI::Windows::Data::Xml::Dom;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::UI::Notifications;
using namespace Windows::Foundation;
namespace WinToastLib {
class IWinToastHandler {
public:
enum WinToastDismissalReason {
UserCanceled = ToastDismissalReason::ToastDismissalReason_UserCanceled,
ApplicationHidden = ToastDismissalReason::ToastDismissalReason_ApplicationHidden,
TimedOut = ToastDismissalReason::ToastDismissalReason_TimedOut
};
virtual ~IWinToastHandler() = default;
virtual void toastActivated() const = 0;
virtual void toastActivated(int actionIndex) const = 0;
virtual void toastDismissed(WinToastDismissalReason state) const = 0;
virtual void toastFailed() const = 0;
};
class WinToastTemplate {
public:
enum Duration { System, Short, Long };
enum AudioOption { Default = 0, Silent, Loop };
enum TextField { FirstLine = 0, SecondLine, ThirdLine };
enum WinToastTemplateType {
ImageAndText01 = ToastTemplateType::ToastTemplateType_ToastImageAndText01,
ImageAndText02 = ToastTemplateType::ToastTemplateType_ToastImageAndText02,
ImageAndText03 = ToastTemplateType::ToastTemplateType_ToastImageAndText03,
ImageAndText04 = ToastTemplateType::ToastTemplateType_ToastImageAndText04,
Text01 = ToastTemplateType::ToastTemplateType_ToastText01,
Text02 = ToastTemplateType::ToastTemplateType_ToastText02,
Text03 = ToastTemplateType::ToastTemplateType_ToastText03,
Text04 = ToastTemplateType::ToastTemplateType_ToastText04,
};
enum AudioSystemFile {
DefaultSound,
IM,
Mail,
Reminder,
SMS,
Alarm,
Alarm2,
Alarm3,
Alarm4,
Alarm5,
Alarm6,
Alarm7,
Alarm8,
Alarm9,
Alarm10,
Call,
Call1,
Call2,
Call3,
Call4,
Call5,
Call6,
Call7,
Call8,
Call9,
Call10,
};
WinToastTemplate(_In_ WinToastTemplateType type = WinToastTemplateType::ImageAndText02);
~WinToastTemplate();
void setFirstLine(_In_ const std::wstring& text);
void setSecondLine(_In_ const std::wstring& text);
void setThirdLine(_In_ const std::wstring& text);
void setTextField(_In_ const std::wstring& txt, _In_ TextField pos);
void setAttributionText(_In_ const std::wstring & attributionText);
void setImagePath(_In_ const std::wstring& imgPath);
void setAudioPath(_In_ WinToastTemplate::AudioSystemFile audio);
void setAudioPath(_In_ const std::wstring& audioPath);
void setAudioOption(_In_ WinToastTemplate::AudioOption audioOption);
void setDuration(_In_ Duration duration);
void setExpiration(_In_ INT64 millisecondsFromNow);
void addAction(_In_ const std::wstring& label);
std::size_t textFieldsCount() const;
std::size_t actionsCount() const;
bool hasImage() const;
const std::vector<std::wstring>& textFields() const;
const std::wstring& textField(_In_ TextField pos) const;
const std::wstring& actionLabel(_In_ std::size_t pos) const;
const std::wstring& imagePath() const;
const std::wstring& audioPath() const;
const std::wstring& attributionText() const;
INT64 expiration() const;
WinToastTemplateType type() const;
WinToastTemplate::AudioOption audioOption() const;
Duration duration() const;
private:
std::vector<std::wstring> _textFields{};
std::vector<std::wstring> _actions{};
std::wstring _imagePath{};
std::wstring _audioPath{};
std::wstring _attributionText{};
INT64 _expiration{0};
AudioOption _audioOption{WinToastTemplate::AudioOption::Default};
WinToastTemplateType _type{WinToastTemplateType::Text01};
Duration _duration{Duration::System};
};
class WinToast {
public:
enum WinToastError {
NoError = 0,
NotInitialized,
SystemNotSupported,
ShellLinkNotCreated,
InvalidAppUserModelID,
InvalidParameters,
InvalidHandler,
NotDisplayed,
UnknownError
};
enum ShortcutResult {
SHORTCUT_UNCHANGED = 0,
SHORTCUT_WAS_CHANGED = 1,
SHORTCUT_WAS_CREATED = 2,
SHORTCUT_MISSING_PARAMETERS = -1,
SHORTCUT_INCOMPATIBLE_OS = -2,
SHORTCUT_COM_INIT_FAILURE = -3,
SHORTCUT_CREATE_FAILED = -4
};
WinToast(void);
virtual ~WinToast();
static WinToast* instance();
static bool isCompatible();
static bool isSupportingModernFeatures();
static std::wstring configureAUMI(_In_ const std::wstring& companyName,
_In_ const std::wstring& productName,
_In_ const std::wstring& subProduct = std::wstring(),
_In_ const std::wstring& versionInformation = std::wstring());
static const std::wstring& strerror(_In_ WinToastError error);
virtual bool initialize(_Out_ WinToastError* error = nullptr);
virtual bool isInitialized() const;
virtual bool hideToast(_In_ INT64 id);
virtual INT64 showToast(_In_ const WinToastTemplate& toast, _In_ IWinToastHandler* handler, _Out_ WinToastError* error = nullptr);
virtual void clear();
virtual enum ShortcutResult createShortcut();
const std::wstring& appName() const;
const std::wstring& appUserModelId() const;
void setAppUserModelId(_In_ const std::wstring& aumi);
void setAppName(_In_ const std::wstring& appName);
protected:
bool _isInitialized{false};
bool _hasCoInitialized{false};
std::wstring _appName{};
std::wstring _aumi{};
std::map<INT64, ComPtr<IToastNotification>> _buffer{};
HRESULT validateShellLinkHelper(_Out_ bool& wasChanged);
HRESULT createShellLinkHelper();
HRESULT setImageFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& path);
HRESULT setAudioFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& path, _In_opt_ WinToastTemplate::AudioOption option = WinToastTemplate::AudioOption::Default);
HRESULT setTextFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& text, _In_ UINT32 pos);
HRESULT setAttributionTextFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& text);
HRESULT addActionHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& action, _In_ const std::wstring& arguments);
HRESULT addDurationHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& duration);
ComPtr<IToastNotifier> notifier(_In_ bool* succeded) const;
void setError(_Out_ WinToastError* error, _In_ WinToastError value);
};
}
#endif // WINTOASTLIB_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,217 @@
/* * Copyright (C) 2016-2019 Mohammed Boujemaoui <mohabouje@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef WINTOASTLIB_H
#define WINTOASTLIB_H
#include <Windows.h>
#include <sdkddkver.h>
#include <WinUser.h>
#include <ShObjIdl.h>
#include <wrl/implements.h>
#include <wrl/event.h>
#include <windows.ui.notifications.h>
#include <strsafe.h>
#include <Psapi.h>
#include <ShlObj.h>
#include <roapi.h>
#include <propvarutil.h>
#include <functiondiscoverykeys.h>
#include <iostream>
#include <winstring.h>
#include <string.h>
#include <vector>
#include <map>
using namespace Microsoft::WRL;
using namespace ABI::Windows::Data::Xml::Dom;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::UI::Notifications;
using namespace Windows::Foundation;
namespace WinToastLib {
class IWinToastHandler {
public:
enum WinToastDismissalReason {
UserCanceled = ToastDismissalReason::ToastDismissalReason_UserCanceled,
ApplicationHidden = ToastDismissalReason::ToastDismissalReason_ApplicationHidden,
TimedOut = ToastDismissalReason::ToastDismissalReason_TimedOut
};
virtual ~IWinToastHandler() = default;
virtual void toastActivated() const = 0;
virtual void toastActivated(int actionIndex) const = 0;
virtual void toastDismissed(WinToastDismissalReason state) const = 0;
virtual void toastFailed() const = 0;
};
class WinToastTemplate {
public:
enum Duration { System, Short, Long };
enum AudioOption { Default = 0, Silent, Loop };
enum TextField { FirstLine = 0, SecondLine, ThirdLine };
enum WinToastTemplateType {
ImageAndText01 = ToastTemplateType::ToastTemplateType_ToastImageAndText01,
ImageAndText02 = ToastTemplateType::ToastTemplateType_ToastImageAndText02,
ImageAndText03 = ToastTemplateType::ToastTemplateType_ToastImageAndText03,
ImageAndText04 = ToastTemplateType::ToastTemplateType_ToastImageAndText04,
Text01 = ToastTemplateType::ToastTemplateType_ToastText01,
Text02 = ToastTemplateType::ToastTemplateType_ToastText02,
Text03 = ToastTemplateType::ToastTemplateType_ToastText03,
Text04 = ToastTemplateType::ToastTemplateType_ToastText04,
};
enum AudioSystemFile {
DefaultSound,
IM,
Mail,
Reminder,
SMS,
Alarm,
Alarm2,
Alarm3,
Alarm4,
Alarm5,
Alarm6,
Alarm7,
Alarm8,
Alarm9,
Alarm10,
Call,
Call1,
Call2,
Call3,
Call4,
Call5,
Call6,
Call7,
Call8,
Call9,
Call10,
};
WinToastTemplate(_In_ WinToastTemplateType type = WinToastTemplateType::ImageAndText02);
~WinToastTemplate();
void setFirstLine(_In_ const std::wstring& text);
void setSecondLine(_In_ const std::wstring& text);
void setThirdLine(_In_ const std::wstring& text);
void setTextField(_In_ const std::wstring& txt, _In_ TextField pos);
void setAttributionText(_In_ const std::wstring & attributionText);
void setImagePath(_In_ const std::wstring& imgPath);
void setAudioPath(_In_ WinToastTemplate::AudioSystemFile audio);
void setAudioPath(_In_ const std::wstring& audioPath);
void setAudioOption(_In_ WinToastTemplate::AudioOption audioOption);
void setDuration(_In_ Duration duration);
void setExpiration(_In_ INT64 millisecondsFromNow);
void addAction(_In_ const std::wstring& label);
std::size_t textFieldsCount() const;
std::size_t actionsCount() const;
bool hasImage() const;
const std::vector<std::wstring>& textFields() const;
const std::wstring& textField(_In_ TextField pos) const;
const std::wstring& actionLabel(_In_ std::size_t pos) const;
const std::wstring& imagePath() const;
const std::wstring& audioPath() const;
const std::wstring& attributionText() const;
INT64 expiration() const;
WinToastTemplateType type() const;
WinToastTemplate::AudioOption audioOption() const;
Duration duration() const;
private:
std::vector<std::wstring> _textFields{};
std::vector<std::wstring> _actions{};
std::wstring _imagePath{};
std::wstring _audioPath{};
std::wstring _attributionText{};
INT64 _expiration{0};
AudioOption _audioOption{WinToastTemplate::AudioOption::Default};
WinToastTemplateType _type{WinToastTemplateType::Text01};
Duration _duration{Duration::System};
};
class WinToast {
public:
enum WinToastError {
NoError = 0,
NotInitialized,
SystemNotSupported,
ShellLinkNotCreated,
InvalidAppUserModelID,
InvalidParameters,
InvalidHandler,
NotDisplayed,
UnknownError
};
enum ShortcutResult {
SHORTCUT_UNCHANGED = 0,
SHORTCUT_WAS_CHANGED = 1,
SHORTCUT_WAS_CREATED = 2,
SHORTCUT_MISSING_PARAMETERS = -1,
SHORTCUT_INCOMPATIBLE_OS = -2,
SHORTCUT_COM_INIT_FAILURE = -3,
SHORTCUT_CREATE_FAILED = -4
};
WinToast(void);
virtual ~WinToast();
static WinToast* instance();
static bool isCompatible();
static bool isSupportingModernFeatures();
static std::wstring configureAUMI(_In_ const std::wstring& companyName,
_In_ const std::wstring& productName,
_In_ const std::wstring& subProduct = std::wstring(),
_In_ const std::wstring& versionInformation = std::wstring());
static const std::wstring& strerror(_In_ WinToastError error);
virtual bool initialize(_Out_ WinToastError* error = nullptr);
virtual bool isInitialized() const;
virtual bool hideToast(_In_ INT64 id);
virtual INT64 showToast(_In_ const WinToastTemplate& toast, _In_ IWinToastHandler* handler, _Out_ WinToastError* error = nullptr);
virtual void clear();
virtual enum ShortcutResult createShortcut();
const std::wstring& appName() const;
const std::wstring& appUserModelId() const;
void setAppUserModelId(_In_ const std::wstring& aumi);
void setAppName(_In_ const std::wstring& appName);
protected:
bool _isInitialized{false};
bool _hasCoInitialized{false};
std::wstring _appName{};
std::wstring _aumi{};
std::map<INT64, ComPtr<IToastNotification>> _buffer{};
HRESULT validateShellLinkHelper(_Out_ bool& wasChanged);
HRESULT createShellLinkHelper();
HRESULT setImageFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& path);
HRESULT setAudioFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& path, _In_opt_ WinToastTemplate::AudioOption option = WinToastTemplate::AudioOption::Default);
HRESULT setTextFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& text, _In_ UINT32 pos);
HRESULT setAttributionTextFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& text);
HRESULT addActionHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& action, _In_ const std::wstring& arguments);
HRESULT addDurationHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& duration);
ComPtr<IToastNotifier> notifier(_In_ bool* succeded) const;
void setError(_Out_ WinToastError* error, _In_ WinToastError value);
};
}
#endif // WINTOASTLIB_H

View File

@ -40,6 +40,11 @@ win32 {
DEFINES += URL_APPCAST_UPDATES=$$join(LINK,,\\\",\\\")
LIBS += -L$$PWD/3dparty/WinSparkle/$$PLATFORM_BUILD -lWinSparkle
HEADERS += $$PWD/3dparty/WinToast/src/wintoastlib.h\
$$PWD/src/win/cnotifications.h
SOURCES += $$PWD/3dparty/WinToast/src/wintoastlib.cpp \
$$PWD/src/win/cnotifications.cpp
message(updates is turned on)
message(url: $$join(LINK,,\\\",\\\"))
}

View File

@ -0,0 +1,60 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "cnotifications.h"
#include <QDebug>
using namespace NSEditorNotifications;
CWinToastHandler::CWinToastHandler()
{
}
void CWinToastHandler::toastActivated() const
{
}
void CWinToastHandler::toastActivated(int actionIndex) const
{
qDebug() << "toast dismissed: " << actionIndex;
}
void CWinToastHandler::toastDismissed(WinToastLib::IWinToastHandler::WinToastDismissalReason state) const
{
qDebug() << "toast dismissed: " << state;
}
void CWinToastHandler::toastFailed() const
{
qDebug() << "toast failed";
}

View File

@ -0,0 +1,55 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef CNOTIFICATIONS_H
#define CNOTIFICATIONS_H
#include "3dparty/WinToast/src/wintoastlib.h"
namespace NSEditorNotifications {
class CWinToastHandler : public WinToastLib::IWinToastHandler
{
public:
CWinToastHandler();
// Public interfaces
void toastActivated() const override;
void toastActivated(int actionIndex) const override;
void toastDismissed(WinToastLib::IWinToastHandler::WinToastDismissalReason state) const override;
void toastFailed() const override;
};
}
#endif // CNOTIFICATIONS_H

View File

@ -60,6 +60,7 @@
#ifdef _UPDMODULE
#include "3dparty/WinSparkle/include/winsparkle.h"
#include "win/cnotifications.h"
#include "../version.h"
#endif
@ -824,9 +825,33 @@ void CMainWindow::slot_mainPageReady()
}
#if defined(_UPDMODULE)
using namespace WinToastLib;
#define TO_WSTR(str) L ## str
#define WSTR(str) TO_WSTR(str)
void CMainWindow::updateFound()
{
CLogger::log("found updates");
CLogger::log("updates found");
if ( WinToast::isCompatible() ) {
WinToast::instance()->setAppName(WSTR(APP_SIMPLE_WINDOW_TITLE));
WinToast::instance()->setAppUserModelId(WSTR(APP_USER_MODEL_ID));
if ( !WinToast::instance()->initialize() ) {
CLogger::log("WinToast lib intialize error");
} else {
WinToastTemplate templ{WinToastTemplate::Text01};
templ.setTextField(QString("Application updates is found").toStdWString(), WinToastTemplate::FirstLine);
// templ.setTextField(QString("New version is found").toStdWString(), WinToastTemplate::SecondLine);
// templ.setAttributionText(L"Attribution text");
/** TODO: showing toast sends update window to back accordingly to main window
* it's need to check update whitout ui window and show info on page 'about' if toasts available */
// if ( !WinToast::instance()->showToast(templ, new NSEditorNotifications::CWinToastHandler) ) {
// CLogger::log("WinToast: could not launch your toast notification!");
// }
}
}
}
void CMainWindow::updateNotFound()