From d12af16583285b367f06491850ac8ef03f9b296f Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Sat, 7 Nov 2015 18:15:40 -0800 Subject: [PATCH] fix(deps): Remove nodobjc until we re-enable native notifications --- package.json | 1 - src/browser/application.coffee | 3 - .../native-notification-manager.coffee | 190 +++++++++--------- 3 files changed, 95 insertions(+), 99 deletions(-) diff --git a/package.json b/package.json index 4fb5daca0..c613dbdda 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "moment": "^2.8", "moment-timezone": "^0.3", "nslog": "^2.0.0", - "NodObjC": "git+https://github.com/TooTallNate/NodObjC", "node-uuid": "^1.4", "optimist": "0.4.0", "pathwatcher": "^4.4.0", diff --git a/src/browser/application.coffee b/src/browser/application.coffee index 743697683..650317ea1 100644 --- a/src/browser/application.coffee +++ b/src/browser/application.coffee @@ -3,7 +3,6 @@ BrowserWindow = require 'browser-window' WindowManager = require './window-manager' ApplicationMenu = require './application-menu' AutoUpdateManager = require './auto-update-manager' -NativeNotificationManager = require './native-notification-manager' NylasProtocolHandler = require './nylas-protocol-handler' SharedFileManager = require './shared-file-manager' @@ -58,7 +57,6 @@ class Application client.on 'error', createApplication windowManager: null - notificationManager: null applicationMenu: null nylasProtocolHandler: null resourcePath: null @@ -89,7 +87,6 @@ class Application @devMode = true @windowManager = new WindowManager({@resourcePath, @config, @devMode, @safeMode}) - @notificationManager = new NativeNotificationManager() @autoUpdateManager = new AutoUpdateManager(@version, @config, @specMode) @applicationMenu = new ApplicationMenu(@version) @_databasePhase = 'setup' diff --git a/src/browser/native-notification-manager.coffee b/src/browser/native-notification-manager.coffee index e2c41bc3a..7995e0a9f 100644 --- a/src/browser/native-notification-manager.coffee +++ b/src/browser/native-notification-manager.coffee @@ -1,95 +1,95 @@ -ipc = require 'ipc' -BrowserWindow = require 'browser-window' - -class NativeNotificationManagerUnavailable - -class NativeNotificationManagerWindows - constructor: -> - -class NativeNotificationManagerMacOSX - constructor: -> - @$ = require('nodobjc') - @$.framework('Foundation') - - @_lastNotifId = 1 - - @_center = @$.NSUserNotificationCenter('defaultUserNotificationCenter') - @_center('removeAllDeliveredNotifications') - - Delegate = @$.NSObject.extend('NylasNotificationDelegate') - Delegate.addMethod('userNotificationCenter:didActivateNotification:', [@$.void, [Delegate, @$.selector, @$.id, @$.id]], @didActivateNotification) - Delegate.addMethod('userNotificationCenter:shouldPresentNotification:', ['c', [Delegate, @$.selector, @$.id, @$.id]], @shouldPresentNotification) - Delegate.register() - @_delegate = Delegate('alloc')('init') - @_center('setDelegate', @_delegate) - - # Ensure that these objects are never, ever garbage collected - global.__nativeNotificationManagerMacOSXDelegate = Delegate - global.__nativeNotificationManagerMacOSX = @ - - ipc.on('fire-native-notification', @onFireNotification) - - shouldPresentNotification: (self, _cmd, center, notif) => - return true - - didActivateNotification: (self, _cmd, center, notif) => - center("removeDeliveredNotification", notif) - - [header, id, tag] = (""+notif('identifier')).split(':::') - - # Avoid potential conflicts with other libraries that may have pushed - # notifications on our behalf. - return unless header is 'N1' - - NSUserNotificationActivationType = [ - "none", - "contents-clicked", - "action-clicked", - "replied", - "additional-action-clicked" - ] - - payload = - tag: tag - activationType: NSUserNotificationActivationType[(""+notif('activationType'))/1] - - if payload.activationType is "replied" - payload.response = (""+notif('response')).replace("{\n}", '') - if payload.response is "null" - payload.response = null - - console.log("Received notification: " + JSON.stringify(payload)) - BrowserWindow.getAllWindows().forEach (win) -> - win.webContents.send('activate-native-notification', payload) - - onFireNotification: (event, {title, subtitle, body, tag, canReply}) => - # By default on Mac OS X, delivering another notification with the same identifier - # triggers an update, which does not re-display the notification. To make subsequent - # calls with the same `tag` redisplay the notification, we: - - # 1. Assign each notification a unique identifier, so it's not considered an update - identifier = "N1:::#{@_lastNotifId}:::#{tag}" - @_lastNotifId += 1 - - # 2. Manually remove any previous notification with the same tag - delivered = @_center("deliveredNotifications") - for existing in delivered - [x, x, existingTag] = (""+existing('identifier')).split(':::') - if existingTag is tag - @_center('removeDeliveredNotification', existing) - - # 3. Fire a new notification - notification = @$.NSUserNotification('alloc')('init') - notification('setTitle', @$.NSString('stringWithUTF8String', title)) - notification('setIdentifier', @$.NSString('stringWithUTF8String', identifier)) - notification('setSubtitle', @$.NSString('stringWithUTF8String', subtitle)) if subtitle - notification('setInformativeText', @$.NSString('stringWithUTF8String', body)) if body - notification('setHasReplyButton', canReply) - @_center('deliverNotification', notification) - -if process.platform is 'darwin' - module.exports = NativeNotificationManagerMacOSX -else if process.platform is 'win32' - module.exports = NativeNotificationManagerWindows -else - module.exports = NativeNotificationManagerUnavailable +# ipc = require 'ipc' +# BrowserWindow = require 'browser-window' +# +# class NativeNotificationManagerUnavailable +# +# class NativeNotificationManagerWindows +# constructor: -> +# +# class NativeNotificationManagerMacOSX +# constructor: -> +# @$ = require('nodobjc') +# @$.framework('Foundation') +# +# @_lastNotifId = 1 +# +# @_center = @$.NSUserNotificationCenter('defaultUserNotificationCenter') +# @_center('removeAllDeliveredNotifications') +# +# Delegate = @$.NSObject.extend('NylasNotificationDelegate') +# Delegate.addMethod('userNotificationCenter:didActivateNotification:', [@$.void, [Delegate, @$.selector, @$.id, @$.id]], @didActivateNotification) +# Delegate.addMethod('userNotificationCenter:shouldPresentNotification:', ['c', [Delegate, @$.selector, @$.id, @$.id]], @shouldPresentNotification) +# Delegate.register() +# @_delegate = Delegate('alloc')('init') +# @_center('setDelegate', @_delegate) +# +# # Ensure that these objects are never, ever garbage collected +# global.__nativeNotificationManagerMacOSXDelegate = Delegate +# global.__nativeNotificationManagerMacOSX = @ +# +# ipc.on('fire-native-notification', @onFireNotification) +# +# shouldPresentNotification: (self, _cmd, center, notif) => +# return true +# +# didActivateNotification: (self, _cmd, center, notif) => +# center("removeDeliveredNotification", notif) +# +# [header, id, tag] = (""+notif('identifier')).split(':::') +# +# # Avoid potential conflicts with other libraries that may have pushed +# # notifications on our behalf. +# return unless header is 'N1' +# +# NSUserNotificationActivationType = [ +# "none", +# "contents-clicked", +# "action-clicked", +# "replied", +# "additional-action-clicked" +# ] +# +# payload = +# tag: tag +# activationType: NSUserNotificationActivationType[(""+notif('activationType'))/1] +# +# if payload.activationType is "replied" +# payload.response = (""+notif('response')).replace("{\n}", '') +# if payload.response is "null" +# payload.response = null +# +# console.log("Received notification: " + JSON.stringify(payload)) +# BrowserWindow.getAllWindows().forEach (win) -> +# win.webContents.send('activate-native-notification', payload) +# +# onFireNotification: (event, {title, subtitle, body, tag, canReply}) => +# # By default on Mac OS X, delivering another notification with the same identifier +# # triggers an update, which does not re-display the notification. To make subsequent +# # calls with the same `tag` redisplay the notification, we: +# +# # 1. Assign each notification a unique identifier, so it's not considered an update +# identifier = "N1:::#{@_lastNotifId}:::#{tag}" +# @_lastNotifId += 1 +# +# # 2. Manually remove any previous notification with the same tag +# delivered = @_center("deliveredNotifications") +# for existing in delivered +# [x, x, existingTag] = (""+existing('identifier')).split(':::') +# if existingTag is tag +# @_center('removeDeliveredNotification', existing) +# +# # 3. Fire a new notification +# notification = @$.NSUserNotification('alloc')('init') +# notification('setTitle', @$.NSString('stringWithUTF8String', title)) +# notification('setIdentifier', @$.NSString('stringWithUTF8String', identifier)) +# notification('setSubtitle', @$.NSString('stringWithUTF8String', subtitle)) if subtitle +# notification('setInformativeText', @$.NSString('stringWithUTF8String', body)) if body +# notification('setHasReplyButton', canReply) +# @_center('deliverNotification', notification) +# +# if process.platform is 'darwin' +# module.exports = NativeNotificationManagerMacOSX +# else if process.platform is 'win32' +# module.exports = NativeNotificationManagerWindows +# else +# module.exports = NativeNotificationManagerUnavailable