New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Accept additional notification actions #11647

Merged
merged 11 commits into from Feb 15, 2018

Conversation

Projects
None yet
4 participants
@sethlu
Member

sethlu commented Jan 16, 2018

馃崕 For macOS 10.9 and above: The first action with type button seen will be displayed on the notification, the rest listed as additional actions (shown when holding down on the primary action button).

With the following config:

  • NSUserNotificationAlertStyle set to alert in Info.plist of the app bundle
  • Probably check if alerts are enabled for the app in System Preferences (not only banners)

Using the following script:

// This doesn't produce a window...
// But should be enough to produce a native notification
const electron = require('electron')
electron.app.on('ready', function (event) {

  let n = new electron.Notification({
    title: 'Notification',
    actions: [
      {type: 'button', text: 'First'}, // This will be displayed as the action button
      {type: 'button', text: 'Second'}, // The following listed if mouse held down
      {type: 'button', text: 'Third'},
    ],
  })

  n.on('action', function (event, index) {
    console.log(index) // Should tell the index of the button activated
  })

  n.show()

})

Screenshot:

preview


Should partially address for macOS: #4424

@sethlu sethlu self-assigned this Jan 16, 2018

@sethlu sethlu requested a review from electron/notifications as a code owner Jan 16, 2018

@MarshallOfSound

This comment has been minimized.

Member

MarshallOfSound commented Jan 16, 2018

This needs some docs 馃憤

@sethlu

This comment has been minimized.

Member

sethlu commented Jan 16, 2018

@MarshallOfSound I'll update the corresponding docs a little later today.

@sethlu sethlu requested a review from electron/docs as a code owner Jan 17, 2018

@sethlu sethlu changed the title from [WIP] feat: Accept additional notification actions to feat: Accept additional notification actions Jan 17, 2018

@@ -7,14 +7,14 @@
| Action Type | Platform Support | Usage of `text` | Default `text` | Limitations |
|-------------|------------------|-----------------|----------------|-------------|
| `button` | macOS | Used as the label for the button | "Show" | Maximum of one button, if multiple are provided only the last is used. This action is also incompatible with `hasReply` and will be ignored if `hasReply` is `true`. |
| `button` | macOS | Used as the label for the button | "Show" (or a localized string by system default if first of such `button`, otherwise empty) | Only the first one is used. If multiple are provided, those beyond the first will be listed as additional actions (displayed when mouse active over the action button). Any of such action also is incompatible with `hasReply` and will be ignored if `hasReply` is `true`. |

This comment has been minimized.

@zeke

zeke Jan 17, 2018

Member

slight wording nit: "Any such action is incompatible"

sethlu added some commits Jan 16, 2018

Accept additional notification actions
Change to the existing API definition: The first action with type `button` seen will be displayed on the notification, the rest listed as additional actions (shown when holding down on the primary action button)
NSUserNotification should respond
NSUserNotification is expected to responsd to `@selector(setContentImage:)` with macOS ^10.9
@zcbenz

zcbenz approved these changes Feb 15, 2018

馃憤

@zcbenz zcbenz merged commit fdda1c5 into electron:master Feb 15, 2018

7 of 8 checks passed

continuous-integration/jenkins/pr-head This commit cannot be built
Details
ci/circleci: electron-linux-arm Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm-test Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64-test Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-ia32 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-x64 Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@jwheare jwheare referenced this pull request Jun 5, 2018

Open

Notification actions #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment