Skip to content

Commit

Permalink
Merge pull request RocketChat#320 from RocketChat/feature/mac-os-noti…
Browse files Browse the repository at this point in the history
…fication-reply

[NEW] Allow reply notifications on Mac OS
  • Loading branch information
gdelavald authored Aug 10, 2017
2 parents 6730748 + 518fe5b commit 4dc80ef
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
"lodash": "^4.17.4",
"spellchecker": "^3.4.1"
},
"optionalDependencies": {
"node-mac-notifier": "0.0.13"
},
"devDependencies": {
"chai": "^4.1.1",
"electron": "^1.6.11",
Expand Down
7 changes: 7 additions & 0 deletions src/background.custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import windowStateKeeper from './background/windowState';
import certificate from './background/certificate';
import idle from '@paulcbetts/system-idle-time';
import { checkForUpdates } from './background/autoUpdate';
import jetpack from 'fs-jetpack';

const appDataDir = jetpack.cwd(app.getAppPath());
const packageJson = appDataDir.read('./package.json', 'json');
if (packageJson && packageJson.build && packageJson.build.appId) {
global.BUNDLE_ID = packageJson.build.appId;
}

process.env.GOOGLE_API_KEY = 'AIzaSyADqUh_c1Qhji3Cp1NE43YrcpuPkmhXD-c';

Expand Down
26 changes: 24 additions & 2 deletions src/public/lib/Notification.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
const { ipcRenderer } = require('electron');
const { ipcRenderer, remote } = require('electron');

class Notification extends window.Notification {
if (process.platform === 'darwin') {
const NodeNotification = require('node-mac-notifier');
window.Notification = class extends NodeNotification {
constructor (title, options) {
options.bundleId = remote.getGlobal('BUNDLE_ID');
super(title, options);
}

static requestPermission () {
return;
}

static get permission () {
return 'granted';
}
};
}

class Notification extends window.Notification {
constructor (title, options) {
super(title, options);
ipcRenderer.send('notification-shim', title, options);

// Handle correct notification using unique tag
ipcRenderer.once(`clicked-${options.tag}`, () => this.onclick());
}


get onclick () {
return super.onclick;
}
Expand Down
57 changes: 55 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ binary-extensions@^1.0.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.9.0.tgz#66506c16ce6f4d6928a5b3cd6a33ca41e941e37b"

bindings@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7"

bindings@~1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11"
Expand Down Expand Up @@ -1030,6 +1034,10 @@ esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"

event-target-shim@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-1.1.1.tgz#a86e5ee6bdaa16054475da797ccddf0c55698491"

execa@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777"
Expand Down Expand Up @@ -2319,6 +2327,13 @@ macaddress@^0.2.7:
version "0.2.8"
resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12"

macos-notification-state@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/macos-notification-state/-/macos-notification-state-1.1.0.tgz#ee59671e05c1ec388c0b09101ef611c85b4b4e0e"
dependencies:
bindings "^1.2.1"
nan "^2.4.0"

make-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.0.0.tgz#97a011751e91dd87cfadef58832ebb04936de978"
Expand Down Expand Up @@ -2467,7 +2482,15 @@ [email protected]:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"

nan@^2.0.0, nan@^2.3.0:
mz@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/mz/-/mz-2.6.0.tgz#c8b8521d958df0a4f2768025db69c719ee4ef1ce"
dependencies:
any-promise "^1.0.0"
object-assign "^4.0.1"
thenify-all "^1.0.0"

nan@^2.0.0, nan@^2.3.0, nan@^2.4.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"

Expand All @@ -2481,6 +2504,32 @@ node-emoji@^1.8.1:
dependencies:
lodash.toarray "^4.4.0"

node-gyp@^3.6.0:
version "3.6.2"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.6.2.tgz#9bfbe54562286284838e750eac05295853fa1c60"
dependencies:
fstream "^1.0.0"
glob "^7.0.3"
graceful-fs "^4.1.2"
minimatch "^3.0.2"
mkdirp "^0.5.0"
nopt "2 || 3"
npmlog "0 || 1 || 2 || 3 || 4"
osenv "0"
request "2"
rimraf "2"
semver "~5.3.0"
tar "^2.0.0"
which "1"

[email protected]:
version "0.0.13"
resolved "https://registry.yarnpkg.com/node-mac-notifier/-/node-mac-notifier-0.0.13.tgz#d64b76ed181f4795d4445ba2d3ad0d6f7298f7e2"
dependencies:
bindings "^1.2.1"
event-target-shim "^1.1.1"
node-uuid "^1.4.7"

node-pre-gyp@^0.6.36:
version "0.6.36"
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.36.tgz#db604112cb74e0d477554e9b505b17abddfab786"
Expand All @@ -2495,7 +2544,11 @@ node-pre-gyp@^0.6.36:
tar "^2.2.1"
tar-pack "^3.4.0"

[email protected]:
node-uuid@^1.4.7:
version "1.4.8"
resolved "https://registry.yarnpkg.com/node-uuid/-/node-uuid-1.4.8.tgz#b040eb0923968afabf8d32fb1f17f1167fdab907"

"nopt@2 || 3", [email protected]:
version "3.0.6"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
dependencies:
Expand Down

0 comments on commit 4dc80ef

Please sign in to comment.