Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
vlabo committed Sep 13, 2022
1 parent 9294447 commit 017771f
Show file tree
Hide file tree
Showing 11 changed files with 1,860 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vs
x64
x86
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
> **Check out our main project at [safing/portmaster](https://github.com/safing/portmaster)**
# Portmaster wintoast

[WinToast](https://github.com/mohabouje/WinToast) is a lightly library written in C++ which brings a complete integration of the modern toast notifications of Windows 8 & Windows 10. This copy of the project adds Visual Studio build support and a C api layer on top so it can be used by the [Portmaster](https://github.com/safing/portmaster).
33 changes: 33 additions & 0 deletions portmaster-wintoast.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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;c++;cppm;ixx;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;h++;hm;inl;inc;ipp;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;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\wintoastlib.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\notification_glue.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\wintoastlib.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\notification_glue.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions portmaster-wintoast.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32811.315
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "portmaster-wintoast", "portmaster-wintoast.vcxproj", "{33A12040-98BF-44EA-B8FF-B260253DBDB7}"
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
{33A12040-98BF-44EA-B8FF-B260253DBDB7}.Debug|x64.ActiveCfg = Debug|x64
{33A12040-98BF-44EA-B8FF-B260253DBDB7}.Debug|x64.Build.0 = Debug|x64
{33A12040-98BF-44EA-B8FF-B260253DBDB7}.Debug|x86.ActiveCfg = Debug|Win32
{33A12040-98BF-44EA-B8FF-B260253DBDB7}.Debug|x86.Build.0 = Debug|Win32
{33A12040-98BF-44EA-B8FF-B260253DBDB7}.Release|x64.ActiveCfg = Release|x64
{33A12040-98BF-44EA-B8FF-B260253DBDB7}.Release|x64.Build.0 = Release|x64
{33A12040-98BF-44EA-B8FF-B260253DBDB7}.Release|x86.ActiveCfg = Release|Win32
{33A12040-98BF-44EA-B8FF-B260253DBDB7}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7A7B3120-7492-4857-B10E-E82ABF9D0076}
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions portmaster-wintoast.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
167 changes: 167 additions & 0 deletions portmaster-wintoast.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{33a12040-98bf-44ea-b8ff-b260253dbdb7}</ProjectGuid>
<RootNamespace>portmaster-wintoast</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>portmaster-wintoast</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetName>portmaster-wintoast</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetName>portmaster-wintoast</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetName>portmaster-wintoast</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetName>portmaster-wintoast</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;PORTMASTERWINNOTIFY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;PORTMASTERWINNOTIFY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;PORTMASTERWINNOTIFY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\notification_glue.h" />
<ClInclude Include="src\wintoastlib.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\notification_glue.cpp" />
<ClCompile Include="src\wintoastlib.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
4 changes: 4 additions & 0 deletions portmaster-wintoast.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
109 changes: 109 additions & 0 deletions src/notification_glue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "notification_glue.h"
#include "wintoastlib.h"

using namespace WinToastLib;

static callback_func activatedCallback = NULL;

class WinToastHandler : public IWinToastHandler
{
public:
WinToastHandler() {}

void toastActivated() const override {}
void toastActivated(int actionIndex) const override {
if(activatedCallback != NULL) {
// Calling go function
activatedCallback(m_id, actionIndex);
}
}
void toastDismissed(WinToastDismissalReason state) const override {}
void toastFailed() const override {}

void setID(uint64_t id) {
m_id = id;
}
private:
uint64_t m_id;
};

uint64_t PortmasterToastInitialize(const wchar_t *appName, const wchar_t *company, const wchar_t *productName, const wchar_t *subProduct, const wchar_t *versionInfo) {
WinToast::instance()->setAppName(appName);
const auto aumi = WinToast::configureAUMI(company, productName, subProduct, versionInfo);
WinToast::instance()->setAppUserModelId(aumi);

WinToast::WinToastError error;
if (!WinToast::instance()->initialize(&error)) {
return 0;
}

return 1;
}

uint64_t PortmasterToastIsInitialized() {
return (uint64_t) WinToast::instance()->isInitialized();
}

void* PortmasterToastCreateNotification(const wchar_t *title, const wchar_t *content) {
WinToastTemplate *templ = new WinToastTemplate(WinToastTemplate::ImageAndText02);

templ->setTextField(title, WinToastTemplate::FirstLine);
templ->setTextField(content, WinToastTemplate::SecondLine);

templ->setDuration(WinToastTemplate::Duration::Long);
templ->setAudioOption(WinToastTemplate::AudioOption::Default);
templ->setAudioPath(WinToastTemplate::AudioSystemFile::Call1);

return templ;
}

uint64_t PortmasterToastAddButton(void *notification, wchar_t *buttonText) {
if(notification == NULL || buttonText == NULL) {
return 0;
}

WinToastTemplate *winToastPtr = (WinToastTemplate*) notification;
winToastPtr->addAction(buttonText);
return 1;
}

uint64_t PortmasterToastSetImage(void *notification, wchar_t *imagePath) {
if(notification == NULL || imagePath == NULL) {
return 0;
}

WinToastTemplate *winToastPtr = (WinToastTemplate*) notification;
winToastPtr->setImagePath(imagePath);
return 1;
}

uint64_t PortmasterToastShow(void *notification) {
if(notification == NULL) {
return -1;
}
WinToastTemplate *winToastPtr = (WinToastTemplate*) notification;

auto handler = std::make_shared<WinToastHandler>();
int64_t toastID = WinToast::instance()->showToast(*winToastPtr, handler);
handler->setID(toastID);
delete winToastPtr;
return toastID; // -1 for error
}

uint64_t PortmasterToastHide(uint64_t notificationID) {
bool success = WinToast::instance()->hideToast(notificationID);
if(!success) {
return 0;
}

return 1;
}

uint64_t PortmasterToastActivatedCallback(callback_func func) {
if(func == NULL) {
return 0;
}

activatedCallback = func;
return 1;
}
Loading

0 comments on commit 017771f

Please sign in to comment.