Skip to content

Commit

Permalink
Merge pull request #20 from desktop/fix-terminate-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiou87 authored Jun 6, 2022
2 parents dbe412f + d79fc83 commit 11a4b9a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions sample-app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
onNotificationEvent,
requestNotificationsPermission,
getNotificationSettingsUrl,
terminateNotifications,
} from 'desktop-notifications'

const createWindow = () => {
Expand All @@ -29,6 +30,9 @@ const createWindow = () => {
})
)
win.webContents.openDevTools()
win.on('closed', () => {
terminateNotifications()
})
return win
}

Expand Down
9 changes: 8 additions & 1 deletion src/mac/main_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@
return deferred.Promise();
}

Napi::Value terminateNotifications(const Napi::CallbackInfo &info)
{
const Napi::Env &env = info.Env();
desktopNotificationsManager = nil;
return env.Undefined();
}

Napi::Value closeNotification(const Napi::CallbackInfo &info)
{
const Napi::Env &env = info.Env();
Expand Down Expand Up @@ -254,9 +261,9 @@
Napi::Object Init(Napi::Env env, Napi::Object exports)
{
exports.Set(Napi::String::New(env, "initializeNotifications"), Napi::Function::New(env, initializeNotifications));
exports.Set(Napi::String::New(env, "terminateNotifications"), Napi::Function::New(env, terminateNotifications));
exports.Set(Napi::String::New(env, "showNotification"), Napi::Function::New(env, showNotification));
exports.Set(Napi::String::New(env, "closeNotification"), Napi::Function::New(env, closeNotification));
exports.Set(Napi::String::New(env, "requestNotificationsPermission"), Napi::Function::New(env, requestNotificationsPermission));
exports.Set(Napi::String::New(env, "getNotificationsPermission"), Napi::Function::New(env, getNotificationsPermission));
exports.Set(Napi::String::New(env, "requestNotificationsPermission"), Napi::Function::New(env, requestNotificationsPermission));

Expand Down
5 changes: 0 additions & 5 deletions src/win/DesktopNotificationsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ HRESULT DesktopNotificationsManager::RegisterClassObjects(const std::wstring &to
DesktopNotificationsManager::~DesktopNotificationsManager()
{
m_callback.Release();

for (auto n : m_desktopNotifications)
{
closeNotification(n);
}
m_desktopNotifications.clear();

UnregisterClassObjects();
Expand Down

0 comments on commit 11a4b9a

Please sign in to comment.