mirror of
https://github.com/desktop/desktop
synced 2024-08-24 18:57:33 +00:00
Merge pull request #13797 from desktop/windows-notifications-fixes
Fix Windows notifications with `desktop-notifications`
This commit is contained in:
commit
628a59d9ad
|
@ -26,6 +26,7 @@
|
|||
"codemirror-mode-elixir": "^1.1.2",
|
||||
"compare-versions": "^3.6.0",
|
||||
"deep-equal": "^1.0.1",
|
||||
"desktop-notifications": "^0.1.4",
|
||||
"desktop-trampoline": "desktop/desktop-trampoline#v0.9.8",
|
||||
"detect-arm64-translation": "https://github.com/desktop/node-detect-arm64-translation#v1.0.4",
|
||||
"dexie": "^2.0.0",
|
||||
|
|
55
app/src/lib/find-toast-activator-clsid.ts
Normal file
55
app/src/lib/find-toast-activator-clsid.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import * as path from 'path'
|
||||
import * as os from 'os'
|
||||
import { shell } from 'electron'
|
||||
|
||||
/**
|
||||
* Checks all Windows shortcuts created by Squirrel looking for the toast
|
||||
* activator CLSID needed to handle Windows notifications from the Action Center.
|
||||
*/
|
||||
export function findToastActivatorClsid() {
|
||||
const shortcutPaths = [
|
||||
path.join(
|
||||
os.homedir(),
|
||||
'AppData',
|
||||
'Roaming',
|
||||
'Microsoft',
|
||||
'Windows',
|
||||
'Start Menu',
|
||||
'Programs',
|
||||
'GitHub, Inc',
|
||||
'GitHub Desktop.lnk'
|
||||
),
|
||||
path.join(os.homedir(), 'Desktop', 'GitHub Desktop.lnk'),
|
||||
]
|
||||
|
||||
for (const shortcutPath of shortcutPaths) {
|
||||
const toastActivatorClsid = findToastActivatorClsidInShorcut(shortcutPath)
|
||||
|
||||
if (toastActivatorClsid !== undefined) {
|
||||
return toastActivatorClsid
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
function findToastActivatorClsidInShorcut(shortcutPath: string) {
|
||||
try {
|
||||
const shortcutDetails = shell.readShortcutLink(shortcutPath)
|
||||
|
||||
if (
|
||||
shortcutDetails.toastActivatorClsid === undefined ||
|
||||
shortcutDetails.toastActivatorClsid === ''
|
||||
) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return shortcutDetails.toastActivatorClsid
|
||||
} catch (error) {
|
||||
log.error(
|
||||
`Error looking for toast activator CLSID in shortcut ${shortcutPath}`,
|
||||
error
|
||||
)
|
||||
return undefined
|
||||
}
|
||||
}
|
|
@ -1,4 +1,32 @@
|
|||
import { focusWindow } from '../../../ui/main-process-proxy'
|
||||
import {
|
||||
DesktopNotification,
|
||||
initializeNotifications,
|
||||
} from 'desktop-notifications'
|
||||
import { findToastActivatorClsid } from '../../find-toast-activator-clsid'
|
||||
|
||||
let windowsToastActivatorClsid: string | undefined = undefined
|
||||
|
||||
function initializeWindowsNotifications() {
|
||||
if (windowsToastActivatorClsid !== undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
windowsToastActivatorClsid = findToastActivatorClsid()
|
||||
|
||||
if (windowsToastActivatorClsid === undefined) {
|
||||
log.error(
|
||||
'Toast activator CLSID not found in any of the shortucts. Falling back to known CLSIDs.'
|
||||
)
|
||||
|
||||
// This is generated by Squirrel.Windows here:
|
||||
// https://github.com/Squirrel/Squirrel.Windows/blob/7396fa50ccebf97e28c79ef519c07cb9eee121be/src/Squirrel/UpdateManager.ApplyReleases.cs#L258
|
||||
windowsToastActivatorClsid = '{27D44D0C-A542-5B90-BCDB-AC3126048BA2}'
|
||||
}
|
||||
|
||||
log.info(`Using toast activator CLSID ${windowsToastActivatorClsid}`)
|
||||
initializeNotifications(windowsToastActivatorClsid)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a notification with a title, a body, and a function to handle when the
|
||||
|
@ -9,6 +37,18 @@ export function showNotification(
|
|||
body: string,
|
||||
onClick: () => void
|
||||
) {
|
||||
if (__WIN32__) {
|
||||
initializeWindowsNotifications()
|
||||
|
||||
const notification = new DesktopNotification(title, body)
|
||||
notification.onclick = () => {
|
||||
focusWindow()
|
||||
onClick()
|
||||
}
|
||||
notification.show()
|
||||
return
|
||||
}
|
||||
|
||||
const notification = new Notification(title, {
|
||||
body,
|
||||
})
|
||||
|
|
|
@ -333,6 +333,15 @@ delegates@^1.0.0:
|
|||
resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a"
|
||||
integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=
|
||||
|
||||
desktop-notifications@^0.1.4:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/desktop-notifications/-/desktop-notifications-0.1.4.tgz#698c5822fb88d7a2289f36b4f64eaac8b5bdefed"
|
||||
integrity sha512-3ADhNvqL9ISbN17x/hWcYUcGHvWJxPnoxxsQbmrU26wpk2eakvDplCm0fvNIpHx/Ar5O7n1VmMOVmLr8W6B8sQ==
|
||||
dependencies:
|
||||
node-addon-api "^4.3.0"
|
||||
prebuild-install "^7.0.1"
|
||||
uuid "^8.3.2"
|
||||
|
||||
desktop-trampoline@desktop/desktop-trampoline#v0.9.8:
|
||||
version "0.9.8"
|
||||
resolved "https://codeload.github.com/desktop/desktop-trampoline/tar.gz/cbd3dbb31d0d3ea9f325067f48bfbf60b6663a57"
|
||||
|
@ -1785,6 +1794,11 @@ uuid@^3.0.1:
|
|||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"
|
||||
integrity sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==
|
||||
|
||||
uuid@^8.3.2:
|
||||
version "8.3.2"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
|
||||
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
|
||||
|
||||
warning@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
|
||||
|
|
Loading…
Reference in a new issue