Skip to content

Commit

Permalink
Enable notifications on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed Dec 30, 2022
1 parent a958665 commit 6034296
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 92 deletions.
55 changes: 0 additions & 55 deletions app/src/lib/find-toast-activator-clsid.ts

This file was deleted.

9 changes: 5 additions & 4 deletions app/src/main-process/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ if (__DARWIN__) {
possibleProtocols.add('github-windows')
}

// On Windows, in order to get notifications properly working for dev builds,
// we'll want to set the right App User Model ID from production builds.
// We have to inform Electron of our package ID (== "app user model ID") as otherwise notifications won't work correctly.
// Package/AUMIDs can be discovered with the Get-StartApps powershell cmdlet. When packaged as MSIX using Conveyor the
// package ID is the name of the app combined with a text-encoded hash of the X.509 signing certificate subject name.
// It is therefore stable as long as the package is always signed with the same identity (doesn't have to be the same key).
if (__WIN32__) {
app.setAppUserModelId('com.squirrel.GitHubDesktop.GitHubDesktop')
app.setAppUserModelId('GithubDesktop_49jahnq5qzr1m!GithubDesktop')
}

app.on('window-all-closed', () => {
Expand All @@ -131,7 +133,6 @@ if (__WIN32__ && process.argv.length > 1) {

// TODO(low): Support the CLI launcher.

// TODO(low): Fix notifications by adding appx manifest data: https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast-desktop-cpp-wrl#packaged
initializeDesktopNotifications()

function handleAppURL(url: string) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main-process/menu/build-default-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export function buildDefaultMenu({
)
}

if (__RELEASE_CHANNEL__ === 'development' || __RELEASE_CHANNEL__ === 'test') {
if (true || __RELEASE_CHANNEL__ === 'development' || __RELEASE_CHANNEL__ === 'test') {
helpItems.push({
label: 'Show notification',
click: emit('test-show-notification'),
Expand Down
29 changes: 5 additions & 24 deletions app/src/main-process/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {
initializeNotifications,
onNotificationEvent,
terminateNotifications,
} from 'desktop-notifications'
import { BrowserWindow } from 'electron'
import { findToastActivatorClsid } from '../lib/find-toast-activator-clsid'
import { DesktopAliveEvent } from '../lib/stores/alive-store'
import {initializeNotifications, onNotificationEvent, terminateNotifications,} from 'desktop-notifications'
import {BrowserWindow} from 'electron'
import {DesktopAliveEvent} from '../lib/stores/alive-store'
import * as ipcWebContents from './ipc-webcontents'

let windowsToastActivatorClsid: string | undefined = undefined
Expand All @@ -21,22 +16,8 @@ export function initializeDesktopNotifications() {
return
}

if (windowsToastActivatorClsid !== undefined) {
return
}

windowsToastActivatorClsid = findToastActivatorClsid()

if (windowsToastActivatorClsid === undefined) {
log.error(
'Toast activator CLSID not found in any of the shortcuts. 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}'
}

// This CLSID is originally a hash of a string calculated by Squirrel, but we can just continue using it post Conveyorization.
windowsToastActivatorClsid = '{27D44D0C-A542-5B90-BCDB-AC3126048BA2}'
log.info(`Using toast activator CLSID ${windowsToastActivatorClsid}`)
initializeNotifications({ toastActivatorClsid: windowsToastActivatorClsid })
}
Expand Down
7 changes: 0 additions & 7 deletions app/src/ui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,6 @@ export class App extends React.Component<IAppProps, IAppState> {
}

private testShowNotification() {
if (
__RELEASE_CHANNEL__ !== 'development' &&
__RELEASE_CHANNEL__ !== 'test'
) {
return
}

showNotification({
title: 'Test notification',
body: 'Click here! This is a test notification',
Expand Down
22 changes: 21 additions & 1 deletion conveyor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,28 @@ app {
}
}

windows {
// Register a COM object that will be invoked by Windows when the user interacts with a "toast" notification for things like
// pull requests being opened, etc. See https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast-desktop-cpp-wrl#packaged
manifests.msix.extensions-xml = """
<!--Register COM CLSID LocalServer32 registry key-->
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="GitHubDesktop.exe" DisplayName="Toast activator">
<com:Class Id="27D44D0C-A542-5B90-BCDB-AC3126048BA2" DisplayName="Toast activator"/>
</com:ExeServer>
</com:ComServer>
</com:Extension>

<!--Specify which CLSID to activate when toast clicked-->
<desktop:Extension Category="windows.toastNotificationActivation">
<desktop:ToastNotificationActivation ToastActivatorCLSID="27D44D0C-A542-5B90-BCDB-AC3126048BA2" />
</desktop:Extension>
"""
}

// To do:
// - There is a CLI tool. It could be exposed by default on Windows.
}

conveyor.compatibility-level = 5
conveyor.compatibility-level = 6

0 comments on commit 6034296

Please sign in to comment.